From 3d01e065a600c817b8e8eba2625711c19fbeaf69 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Tue, 31 Oct 2023 12:02:57 -0400 Subject: [PATCH] Added new case of trivial actions --- .../java/com/naveensundarg/planner/Action.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/naveensundarg/planner/Action.java b/src/main/java/com/naveensundarg/planner/Action.java index bc9a91e..e6f315b 100644 --- a/src/main/java/com/naveensundarg/planner/Action.java +++ b/src/main/java/com/naveensundarg/planner/Action.java @@ -156,21 +156,23 @@ public class Action { public Action instantiate(Map binding){ + // Apply binding to precondition, additions, and deletions Set newPreconditions = preconditions.stream().map(x->x.apply(binding)).collect(Collectors.toSet()); Set newAdditions = additions.stream().map(x->x.apply(binding)).collect(Collectors.toSet()); Set newDeletions = deletions.stream().map(x->x.apply(binding)).collect(Collectors.toSet()); - List newFreeVraibles = CollectionUtils.newEmptyList(); + // Allow for partial instantiation, grab variables that aren't + List newFreeVariables = CollectionUtils.newEmptyList(); for(Variable var: freeVariables){ if(!binding.keySet().contains(var)){ - newFreeVraibles.add(var); + newFreeVariables.add(var); } } List valuesList = interestedVars.stream().collect(Collectors.toList());; Compound shorthand = (Compound)(new Compound(name, valuesList)).apply(binding); - return new Action(name, newPreconditions, newAdditions, newDeletions, newFreeVraibles, shorthand); + return new Action(name, newPreconditions, newAdditions, newDeletions, newFreeVariables, shorthand); } public String getName() { @@ -183,13 +185,16 @@ public class Action { public boolean computeTrivialOrNot(){ + // All the additions are already in the preconditions and nothing gets deleted boolean case1Trivial = Sets.subset(additions, preconditions) && deletions.isEmpty(); + // There are no additions and the deletes that are there are already negated in the precondition so they don't exist. boolean case2Trivial = additions.isEmpty() && deletions.stream().allMatch(x->preconditions.stream().anyMatch(y->y.equals(Logic.negated(x)))); - boolean trivial = case1Trivial || case2Trivial; + // All additions are already in preconditions and the deletions are negated in the preconditions + boolean case3Trivial = Sets.subset(additions, preconditions) && deletions.stream().allMatch(x->preconditions.stream().anyMatch(y->y.equals(Logic.negated(x)))); - return trivial; + return case1Trivial || case2Trivial || case3Trivial; } public Compound getShorthand() {