Example how to get all true/false combinations of variables which fulfill a boolean formula?
Closed this issue · 2 comments
axkr commented
Is there an example available how to get all true/false combinations of variables which fulfill a boolean formula?
axkr commented
I now have used this "template" for a formula to get the possible combinations and converted the literals to True
or False
values. See commits for Symja issue 9.
Is this correct? Are there better solutions by iterating through the assignments?
FormulaFactory factory = new FormulaFactory();
final SATSolver miniSat = MiniSat.miniSat(factory);
miniSat.add(formula);
List<Assignment> assignments = miniSat.enumerateAllModels();
for (int i = 0; i < assignments.size(); i++) {
System.out.println(assignments.get(i).literals());
}
czengler commented
Sorry for the delay in my answer. Yes - this is the intended way to generate all models of a formula. You can also include a list of variables in the method enumerateAllModels()
if you don't need all models of the formula but just the models for certain variables. (Projected Model Enumeration)