Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * 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);
       }
     }
   }
 }