Handling edge cases in precondition -> formula

This commit is contained in:
Brandon Rozek 2023-11-20 17:20:48 -05:00
parent 492e7bac14
commit a747b38233
No known key found for this signature in database
GPG key ID: 26E457DA82C9F480
2 changed files with 11 additions and 1 deletions

View file

@ -49,7 +49,14 @@ public class Action {
this.freeVariables = freeVariables; this.freeVariables = freeVariables;
if (preconditions.size() > 1) {
this.precondition = new And(preconditions.stream().collect(Collectors.toList())); this.precondition = new And(preconditions.stream().collect(Collectors.toList()));
} else if (preconditions.size() == 1) {
this.precondition = preconditions.iterator().next();
} else {
this.precondition = State.TRUE;
}
this.weight = preconditions.stream().mapToInt(Formula::getWeight).sum() + this.weight = preconditions.stream().mapToInt(Formula::getWeight).sum() +
additions.stream().mapToInt(Formula::getWeight).sum() + additions.stream().mapToInt(Formula::getWeight).sum() +

View file

@ -12,14 +12,17 @@ import java.util.Set;
public class State { public class State {
final Set<Formula> formulae; final Set<Formula> formulae;
static Formula TRUE;
static Formula FALSE; static Formula FALSE;
static{ static{
try { try {
TRUE = Reader.readFormulaFromString("(or P (not P))");
FALSE = Reader.readFormulaFromString("(and P (not P))"); FALSE = Reader.readFormulaFromString("(and P (not P))");
} catch (Reader.ParsingException e) { } catch (Reader.ParsingException e) {
e.printStackTrace(); e.printStackTrace();
TRUE = null;
FALSE = null; FALSE = null;
} }