예제 #1
0
파일: WCSP.java 프로젝트: acares/ProbCog
 public static WCSP fromFile(File f) throws IOException {
   BufferedReader br = new BufferedReader(new FileReader(f));
   String l = br.readLine();
   String[] elems = l.split(" ");
   int numVars = Integer.parseInt(elems[1]);
   int numConstraints = Integer.parseInt(elems[3]);
   long top = Long.parseLong(elems[4]);
   elems = br.readLine().split(" ");
   int[] domSizes = new int[numVars];
   for (int i = 0; i < numVars; i++) domSizes[i] = Integer.parseInt(elems[i]);
   WCSP wcsp = new WCSP(domSizes, top);
   for (int i = 0; i < numConstraints; i++) {
     elems = br.readLine().split(" ");
     int arity = Integer.parseInt(elems[0]);
     int[] varIndices = new int[arity];
     for (int j = 1; j <= arity; j++) varIndices[j - 1] = Integer.parseInt(elems[j]);
     long defaultCost = Long.parseLong(elems[1 + arity]);
     int numTuples = Integer.parseInt(elems[1 + arity + 1]);
     Constraint c = new Constraint(defaultCost, varIndices, numTuples);
     for (int j = 0; j < numTuples; j++) {
       elems = br.readLine().split(" ");
       int[] assignment = new int[arity];
       for (int k = 0; k < arity; k++) assignment[k] = Integer.parseInt(elems[k]);
       long cost = Long.parseLong(elems[arity]);
       c.addTuple(assignment, cost);
     }
     wcsp.addConstraint(c);
   }
   return wcsp;
 }
예제 #2
0
파일: WCSP.java 프로젝트: acares/ProbCog
 public static void main(String[] args) {
   WCSP wcsp;
   try {
     // File inFile = new File("/home/nyga/code/prac/models/filling/temp.wcsp");
     File inFile = new File("/usr/wiss/nyga/temp.wcsp");
     wcsp = WCSP.fromFile(inFile);
     Stopwatch sw = new Stopwatch();
     sw.start();
     wcsp.unifyConstraints();
     System.out.println("unification time: " + sw.getElapsedTimeSecs());
     // wcsp.writeWCSP(new PrintStream("/home/nyga/code/prac/models/filling/unified.wcsp"),
     // "unifiedWCSP");
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }