00001 import java.io.PrintStream;
00002 import java.util.Properties;
00003
00004 import org.python.core.PyObject;
00005 import org.python.util.PythonInterpreter;
00006 import edu.tum.cs.srldb.Database;
00007
00008 import java.io.File;
00009
00010
00011 public class CardinalityConstraintsDemo implements Runnable {
00012
00013 protected int m_StudentCount, m_CourseCount, m_DefiniteCourseConstraint, m_lBCount, m_lICount, m_SampleCount;
00014 protected String m_Tag;
00015 static PythonInterpreter jython = null;
00016 protected static String script;
00017
00018 public CardinalityConstraintsDemo(int studentCount, int courseCount, int definiteCourseConstraint) {
00019 m_StudentCount = studentCount;
00020 m_CourseCount = courseCount;
00021 m_DefiniteCourseConstraint = definiteCourseConstraint;
00022 m_lBCount = 6;
00023 m_lICount = 6;
00024 m_SampleCount = 1;
00025 m_Tag = "";
00026 }
00027 public CardinalityConstraintsDemo(int studentCount, int courseCount, int definiteCourseConstraint, int bCount, int lCount) {
00028 this(studentCount, courseCount, definiteCourseConstraint);
00029 m_lBCount = bCount;
00030 m_lICount = lCount;
00031 }
00032
00033 public CardinalityConstraintsDemo(int studentCount, int courseCount, int definiteCourseConstraint, int bCount, int lCount, int sampleCount, String tag) {
00034 this(studentCount, courseCount, definiteCourseConstraint, bCount, lCount);
00035 m_SampleCount = sampleCount;
00036 m_Tag = tag;
00037 }
00038
00039 public void run() {
00040 try {
00041 genParameterizedDB();
00042 } catch (Exception ex) {
00043 System.err.println(ex);
00044 }
00045 }
00046
00047 protected void genParameterizedDB() throws Exception {
00048 jython.exec("global GUID");
00049 for (int i = 0; i < m_SampleCount; i++) {
00050 jython.exec("GUID = 1");
00051
00052 jython.exec("sys.argv = []");
00053 jython.exec("sys.argv.append('" + script + "')");
00054 jython.exec("sys.argv.append('" + m_StudentCount + "')");
00055 jython.exec("sys.argv.append('" + m_CourseCount + "')");
00056 jython.exec("sys.argv.append('" + m_DefiniteCourseConstraint + "')");
00057 jython.exec("sys.argv.append('" + m_lBCount + "')");
00058 jython.exec("sys.argv.append('" + m_lICount + "')");
00059
00060 jython.execfile(script);
00061 PyObject dbObj = jython.get("db");
00062 if(dbObj == null) {
00063 throw new Exception("Generator script does not define 'db' object!");
00064 }
00065 Database db = (Database) dbObj.__tojava__(Database.class);
00066 db.check();
00067 File outFile, outFile2;
00068 String prefix = new String("DB-"+m_StudentCount+"-"+m_CourseCount+"-"+m_DefiniteCourseConstraint+"-"+m_lBCount+"-"+m_lICount+"-"+i);
00069 if (m_Tag != "") {
00070 prefix = prefix+"-"+m_Tag;
00071 }
00072 outFile = new File(prefix + ".db");
00073 outFile2 = new File(prefix + ".blogdb");
00074 PrintStream outDB = new PrintStream(outFile);
00075 db.writeMLNDatabase(outDB);
00076 outDB = new PrintStream(outFile2);
00077 db.writeBLOGDatabase(outDB);
00078 }
00079 }
00080
00084 public static void main(String[] args) {
00085 Properties props = new Properties();
00086
00087
00088 props.put("python.path", "/usr/wiss/jain/work/code/SRLDB/bin:/usr/wiss/jain/work/code/SRLDB/datagen");
00089 PythonInterpreter.initialize(System.getProperties(), props, null);
00090
00091 jython = new PythonInterpreter();
00092 jython.exec("import sys");
00093 CardinalityConstraintsDemo xg = null;
00094 try {
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 script = "gen_simple_exact.py";
00107 for (int i = 15; i <= 35; i += 5) {
00108 xg = new CardinalityConstraintsDemo(45,i,6,6,0,1,"Lp");
00109 xg.genParameterizedDB();
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 } catch (Exception e) {
00123 System.err.println(e);
00124 }
00125 }
00126
00127 }