コード例 #1
0
ファイル: Formula.java プロジェクト: schambersnh/school
 /**
  * Gets the "flip value" of setting this var to newValue. If setting var to newValue resulted in
  * breaking two expressions and fixing one, the retval would be -1.
  *
  * @param val the variable to set
  * @param newValue the value of the variable (1 for true, -1 for false)
  */
 public int getFlipValue(int val, int newValue) {
   int newVariable = 0;
   int notVariable = 0;
   int flipVal = 0;
   if (val < 0 && newValue == -1) {
     newVariable = val;
   } else if (val < 0 && newValue == 1) {
     newVariable = val * -1;
   } else {
     newVariable = val * newValue;
   }
   notVariable = -newVariable;
   for (Clause c : clauses) {
     int varSize = c.getVariables().size();
     for (int i = 0; i < varSize; i++) {
       int var = c.getVariables().get(i);
       if (var == newVariable) {
         flipVal++;
         break;
       } else if (c.isSatisfied() && c.getSatisfiedVar() == notVariable) {
         flipVal--;
       }
     }
   }
   return flipVal;
 }
コード例 #2
0
ファイル: Formula.java プロジェクト: schambersnh/school
 /**
  * Get all unsatisfied clauses
  *
  * @return
  */
 public ArrayList<Clause> getUnsatisfied() {
   ArrayList<Clause> retval = new ArrayList<Clause>();
   for (Clause c : clauses) {
     if (!c.isSatisfied()) {
       retval.add(c);
     }
   }
   return retval;
 }
コード例 #3
0
ファイル: Formula.java プロジェクト: schambersnh/school
 /**
  * Returns true if flipping this variable breaks nothing, false otherwise
  *
  * @param val
  * @param newValue
  * @return
  */
 public boolean isPositiveFlip(int val, int newValue) {
   int newVariable = 0;
   int notVariable = 0;
   if (val < 0 && newValue == -1) {
     newVariable = val;
   } else if (val < 0 && newValue == 1) {
     newVariable = val * -1;
   } else {
     newVariable = val * newValue;
   }
   notVariable = -newVariable;
   for (Clause c : clauses) {
     int varSize = c.getVariables().size();
     for (int i = 0; i < varSize; i++) {
       if (c.isSatisfied() && c.getSatisfiedVar() == notVariable) {
         return false;
       }
     }
   }
   return true;
 }
コード例 #4
0
ファイル: Formula.java プロジェクト: schambersnh/school
 /**
  * Sets the variable in the formula
  *
  * @param val the variable to set
  * @param newValue the value of the variable (1 for true, -1 for false)
  */
 public void setVariable(int val, int newValue) {
   int newVariable = 0;
   int notVariable = 0;
   if (val < 0 && newValue == -1) {
     newVariable = val;
   } else if (val < 0 && newValue == 1) {
     newVariable = val * -1;
   } else {
     newVariable = val * newValue;
   }
   notVariable = -newVariable;
   for (Clause c : clauses) {
     int varSize = c.getVariables().size();
     for (int i = 0; i < varSize; i++) {
       int var = c.getVariables().get(i);
       if (var == newVariable) {
         c.setSatisfiedVar(var);
         break;
       } else if (c.isSatisfied() && c.getSatisfiedVar() == notVariable) {
         c.setSatisfiedVar(0);
       }
     }
   }
 }