Skip to content

Commit

Permalink
using SolverState to store min bounds of variables + patch get-value
Browse files Browse the repository at this point in the history
  • Loading branch information
yanntm committed May 4, 2024
1 parent 6181334 commit 26565c5
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import org.smtlib.ISolver;
import org.smtlib.SMT;
import org.smtlib.command.C_assert;
import org.smtlib.command.C_declare_fun;
import org.smtlib.IExpr;
import org.smtlib.IExpr.IFactory;
import org.smtlib.IExpr.ISymbol;
Expand All @@ -27,8 +29,13 @@ public class SolverState {
private Map<String,VarType> varTypes = new HashMap<>();
private SMT smt = new SMT();
private SolutionType numericType = SolutionType.Real;
private Map<String,Integer> minBounds = new HashMap<>();
ISolver solver;


public void setMinBounds(String var, int min) {
minBounds.put(var, min);
}

public void addVars (String prefix, int nbVar, VarType type) {
SparseBoolArray all = new SparseBoolArray();
Expand Down Expand Up @@ -74,10 +81,15 @@ public void declareVars(VarSet toDeclare) {
// use current numeric type : Real or Int
smtType = smt.smtConfig.sortFactory.createSortExpression(ef.symbol(numericType.toString()));

Integer min = minBounds.get(prefix);

for (int i = 0; i < values.size(); i++) {
int index = values.keyAt(i);
ISymbol si = ef.symbol(prefix + index);
script.add(new org.smtlib.command.C_declare_fun(si, Collections.emptyList(), smtType));
script.add(new C_declare_fun(si, Collections.emptyList(), smtType));
if (min != null) {
script.add(new C_assert(ef.fcn(ef.symbol(">="), si, ef.numeral(min))));
}
}
}

Expand Down Expand Up @@ -112,8 +124,12 @@ public void stop() {

public SparseIntArray getValues(String prefix) {
SparseBoolArray bvars = declaredVars.getVars().getOrDefault(prefix, new SparseBoolArray());
IExpr [] vars = new IExpr[bvars.size()];
for (int i=0, ie = bvars.size(); i < ie ; i++) {
int nbVars = bvars.size();
if (nbVars==0) {
return new SparseIntArray();
}
IExpr [] vars = new IExpr[nbVars];
for (int i=0, ie = nbVars; i < ie ; i++) {
vars[i] = smt.smtConfig.exprFactory.symbol(prefix + bvars.keyAt(i));
}
IResponse reply = solver.get_value(vars);
Expand Down

0 comments on commit 26565c5

Please sign in to comment.