/** * 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); } } } }
/** Set all clauses to unsatisfied */ public void clearClauses() { for (Clause c : clauses) { c.setSatisfiedVar(0); } }