From b39002908df78c43318be3ef13cc5199e1ca25ad Mon Sep 17 00:00:00 2001 From: Paul Tristan Wagner Date: Wed, 6 Mar 2024 02:38:06 +0100 Subject: [PATCH] Fix bug in full lazy SMT solver --- .../smt/solver/FullLazySMTSolver.java | 4 ++++ .../solver/SimplexOptimizationSolver.java | 20 ++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/paultristanwagner/satchecking/smt/solver/FullLazySMTSolver.java b/src/main/java/me/paultristanwagner/satchecking/smt/solver/FullLazySMTSolver.java index 2f40bbb..18a0f7f 100644 --- a/src/main/java/me/paultristanwagner/satchecking/smt/solver/FullLazySMTSolver.java +++ b/src/main/java/me/paultristanwagner/satchecking/smt/solver/FullLazySMTSolver.java @@ -26,6 +26,10 @@ public SMTResult solve() { Set selectedConstraints = new HashSet<>(); for (Literal trueLiteral : trueLiterals) { + if(!cnf.getConstraintLiteralMap().inverse().containsKey(trueLiteral.getName())) { + continue; + } + C constraint = cnf.getConstraintLiteralMap().inverse().get(trueLiteral.getName()); selectedConstraints.add(constraint); diff --git a/src/main/java/me/paultristanwagner/satchecking/theory/solver/SimplexOptimizationSolver.java b/src/main/java/me/paultristanwagner/satchecking/theory/solver/SimplexOptimizationSolver.java index 453281f..e6b6a52 100644 --- a/src/main/java/me/paultristanwagner/satchecking/theory/solver/SimplexOptimizationSolver.java +++ b/src/main/java/me/paultristanwagner/satchecking/theory/solver/SimplexOptimizationSolver.java @@ -15,7 +15,6 @@ import me.paultristanwagner.satchecking.theory.LinearConstraint; import me.paultristanwagner.satchecking.theory.LinearConstraint.MaximizingConstraint; import me.paultristanwagner.satchecking.theory.LinearConstraint.MinimizingConstraint; -import me.paultristanwagner.satchecking.theory.LinearTerm; import me.paultristanwagner.satchecking.theory.SimplexResult; import me.paultristanwagner.satchecking.theory.arithmetic.Number; import org.apache.commons.lang3.tuple.Pair; @@ -38,12 +37,9 @@ public class SimplexOptimizationSolver implements TheorySolver private int columns; private Number[][] tableau; - private List originalConstraints; + private final List originalConstraints; private List constraints; - private List differences; - private Map origin; - private LinearConstraint originalObjective; private LinearConstraint objective; @@ -58,8 +54,6 @@ public SimplexOptimizationSolver() { this.originalConstraints = new ArrayList<>(); this.constraints = new ArrayList<>(); - this.differences = new ArrayList<>(); - this.origin = new HashMap<>(); this.substitutions = HashBiMap.create(); this.offsets = new HashMap<>(); @@ -105,8 +99,6 @@ public void clear() { this.originalConstraints.clear(); this.constraints.clear(); - this.origin.clear(); - this.differences.clear(); this.substitutions.clear(); this.offsets.clear(); @@ -185,7 +177,7 @@ public SimplexResult solve() { } if (violatingRow == -1) { - VariableAssignment solution = calculateSolution(); + VariableAssignment solution = calculateSolution(); result = SimplexResult.feasible(solution); break; } @@ -228,7 +220,7 @@ public SimplexResult solve() { } if (pivotColumn == -1) { - VariableAssignment solution = calculateSolution(); + VariableAssignment solution = calculateSolution(); Number optimum = calculateObjectiveValue(); @@ -253,7 +245,7 @@ public SimplexResult solve() { } if (pivotRow == -1) { - VariableAssignment solution = calculateSolution(); + VariableAssignment solution = calculateSolution(); Set allConstraints = new HashSet<>(originalConstraints); result = SimplexResult.unbounded(solution, allConstraints); return result; @@ -500,8 +492,8 @@ private Number getValue(String variable) { return value; } - private VariableAssignment calculateSolution() { - VariableAssignment assignment = new VariableAssignment(); + private VariableAssignment calculateSolution() { + VariableAssignment assignment = new VariableAssignment<>(); for (String variable : originalVariables) { Number value = getValue(variable);