From 135852b74b697ac7dd20efa11070ac1f8448896f Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Thu, 2 Nov 2023 17:11:12 -0400 Subject: [PATCH] Moved search algorithms to folder --- .../rairlab/planner/ContextNormPlanner.java | 1 + .../java/org/rairlab/planner/GoalTracker.java | 1 + .../java/org/rairlab/planner/Py4JServer.java | 37 +++++++------------ .../planner/{ => search}/AStarPlanner.java | 7 +++- .../{ => search}/BreadthFirstPlanner.java | 6 ++- .../{ => search}/DepthFirstPlanner.java | 4 +- .../rairlab/planner/utils/LearningSystem.java | 2 +- .../org/rairlab/planner/utils/Runner.java | 2 +- .../org/rairlab/planner/utils/Sandbox.java | 3 +- 9 files changed, 33 insertions(+), 30 deletions(-) rename src/main/java/org/rairlab/planner/{ => search}/AStarPlanner.java (96%) rename src/main/java/org/rairlab/planner/{ => search}/BreadthFirstPlanner.java (92%) rename src/main/java/org/rairlab/planner/{ => search}/DepthFirstPlanner.java (99%) diff --git a/src/main/java/org/rairlab/planner/ContextNormPlanner.java b/src/main/java/org/rairlab/planner/ContextNormPlanner.java index 2563284..5c4556e 100644 --- a/src/main/java/org/rairlab/planner/ContextNormPlanner.java +++ b/src/main/java/org/rairlab/planner/ContextNormPlanner.java @@ -2,6 +2,7 @@ package org.rairlab.planner; import org.rairlab.planner.utils.PlanningProblem; import org.rairlab.shadow.prover.representations.formula.Formula; +import org.rairlab.planner.search.DepthFirstPlanner; import java.util.Optional; import java.util.Set; diff --git a/src/main/java/org/rairlab/planner/GoalTracker.java b/src/main/java/org/rairlab/planner/GoalTracker.java index 257a4fa..d87eb75 100644 --- a/src/main/java/org/rairlab/planner/GoalTracker.java +++ b/src/main/java/org/rairlab/planner/GoalTracker.java @@ -4,6 +4,7 @@ import org.rairlab.planner.utils.PlanningProblem; import org.rairlab.shadow.prover.representations.formula.Formula; import org.rairlab.shadow.prover.utils.CollectionUtils; import org.rairlab.shadow.prover.utils.Sets; +import org.rairlab.planner.search.DepthFirstPlanner; import java.util.Comparator; import java.util.Optional; diff --git a/src/main/java/org/rairlab/planner/Py4JServer.java b/src/main/java/org/rairlab/planner/Py4JServer.java index 959c526..c937fef 100644 --- a/src/main/java/org/rairlab/planner/Py4JServer.java +++ b/src/main/java/org/rairlab/planner/Py4JServer.java @@ -1,11 +1,9 @@ package org.rairlab.planner; import org.rairlab.planner.utils.PlanningProblem; -import org.rairlab.shadow.prover.core.ccprovers.CognitiveCalculusProver; -import org.rairlab.shadow.prover.core.proof.Justification; -import org.rairlab.shadow.prover.representations.formula.Formula; -import org.rairlab.shadow.prover.utils.Problem; -import org.rairlab.shadow.prover.utils.ProblemReader; +import org.rairlab.planner.heuristics.ConstantHeuristic; +import org.rairlab.planner.search.AStarPlanner; + import org.rairlab.shadow.prover.utils.Reader; import py4j.GatewayServer; @@ -14,24 +12,20 @@ import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.*; -import java.util.stream.Collectors; public final class Py4JServer { - - private DepthFirstPlanner depthFirstPlanner; + private AStarPlanner astarplanner; public Py4JServer(){ - - depthFirstPlanner = new DepthFirstPlanner(); - + astarplanner = new AStarPlanner(); } - public Planner getPlanner(){ - return depthFirstPlanner; + public AStarPlanner getPlanner(){ + return astarplanner; } public static void main(String[] args) throws UnknownHostException { @@ -49,29 +43,26 @@ public final class Py4JServer { } - public ArrayList newEmptyList(){ - - return new ArrayList(); - } - public String proveFromDescription(String fileString){ try { List planningProblemList = (PlanningProblem.readFromFile(new ByteArrayInputStream(fileString.getBytes()))); - Planner depthFirstPlanner = new DepthFirstPlanner(); + AStarPlanner astarplanner = new AStarPlanner(); PlanningProblem planningProblem = planningProblemList.get(0); - Optional> optionalPlans = depthFirstPlanner.plan( + Set plans = astarplanner.plan( planningProblem.getBackground(), planningProblem.getActions(), planningProblem.getStart(), - planningProblem.getGoal()); + planningProblem.getGoal(), + ConstantHeuristic::h + ); - if(optionalPlans.isPresent()) { - return optionalPlans.get().toString(); + if(plans.size() > 0) { + return plans.toString(); } else { return "FAILED"; diff --git a/src/main/java/org/rairlab/planner/AStarPlanner.java b/src/main/java/org/rairlab/planner/search/AStarPlanner.java similarity index 96% rename from src/main/java/org/rairlab/planner/AStarPlanner.java rename to src/main/java/org/rairlab/planner/search/AStarPlanner.java index 38b299b..ec79e63 100644 --- a/src/main/java/org/rairlab/planner/AStarPlanner.java +++ b/src/main/java/org/rairlab/planner/search/AStarPlanner.java @@ -1,7 +1,12 @@ -package org.rairlab.planner; +package org.rairlab.planner.search; import org.rairlab.shadow.prover.representations.formula.Formula; +import org.rairlab.planner.State; +import org.rairlab.planner.Action; +import org.rairlab.planner.Plan; +import org.rairlab.planner.Operations; + import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; diff --git a/src/main/java/org/rairlab/planner/BreadthFirstPlanner.java b/src/main/java/org/rairlab/planner/search/BreadthFirstPlanner.java similarity index 92% rename from src/main/java/org/rairlab/planner/BreadthFirstPlanner.java rename to src/main/java/org/rairlab/planner/search/BreadthFirstPlanner.java index b2c32d6..d230a12 100644 --- a/src/main/java/org/rairlab/planner/BreadthFirstPlanner.java +++ b/src/main/java/org/rairlab/planner/search/BreadthFirstPlanner.java @@ -1,7 +1,11 @@ -package org.rairlab.planner; +package org.rairlab.planner.search; import org.rairlab.shadow.prover.representations.formula.Formula; + import org.rairlab.planner.Action; +import org.rairlab.planner.State; +import org.rairlab.planner.Plan; + import java.util.*; diff --git a/src/main/java/org/rairlab/planner/DepthFirstPlanner.java b/src/main/java/org/rairlab/planner/search/DepthFirstPlanner.java similarity index 99% rename from src/main/java/org/rairlab/planner/DepthFirstPlanner.java rename to src/main/java/org/rairlab/planner/search/DepthFirstPlanner.java index 6d96c74..7c7f52c 100644 --- a/src/main/java/org/rairlab/planner/DepthFirstPlanner.java +++ b/src/main/java/org/rairlab/planner/search/DepthFirstPlanner.java @@ -1,8 +1,10 @@ -package org.rairlab.planner; +package org.rairlab.planner.search; import org.rairlab.planner.utils.Commons; import org.rairlab.planner.utils.PlanningProblem; import org.rairlab.planner.utils.Visualizer; +import org.rairlab.planner.*; + import org.rairlab.shadow.prover.core.proof.Justification; import org.rairlab.shadow.prover.representations.formula.Formula; import org.rairlab.shadow.prover.utils.CollectionUtils; diff --git a/src/main/java/org/rairlab/planner/utils/LearningSystem.java b/src/main/java/org/rairlab/planner/utils/LearningSystem.java index d796990..0c16c98 100644 --- a/src/main/java/org/rairlab/planner/utils/LearningSystem.java +++ b/src/main/java/org/rairlab/planner/utils/LearningSystem.java @@ -1,7 +1,7 @@ package org.rairlab.planner.utils; import com.diogonunes.jcdp.color.ColoredPrinter; -import org.rairlab.planner.DepthFirstPlanner; +import org.rairlab.planner.search.DepthFirstPlanner; import org.rairlab.planner.GoalTracker; import org.rairlab.planner.Plan; import org.rairlab.planner.Planner; diff --git a/src/main/java/org/rairlab/planner/utils/Runner.java b/src/main/java/org/rairlab/planner/utils/Runner.java index 9f0d65d..c540233 100644 --- a/src/main/java/org/rairlab/planner/utils/Runner.java +++ b/src/main/java/org/rairlab/planner/utils/Runner.java @@ -1,6 +1,6 @@ package org.rairlab.planner.utils; -import org.rairlab.planner.AStarPlanner; +import org.rairlab.planner.search.AStarPlanner; import org.rairlab.planner.Plan; import org.rairlab.planner.heuristics.ConstantHeuristic; import org.rairlab.shadow.prover.utils.Reader; diff --git a/src/main/java/org/rairlab/planner/utils/Sandbox.java b/src/main/java/org/rairlab/planner/utils/Sandbox.java index 3818e56..c6e28d5 100644 --- a/src/main/java/org/rairlab/planner/utils/Sandbox.java +++ b/src/main/java/org/rairlab/planner/utils/Sandbox.java @@ -3,13 +3,12 @@ package org.rairlab.planner.utils; import com.diogonunes.jcdp.color.ColoredPrinter; import com.diogonunes.jcdp.color.api.Ansi; import org.rairlab.planner.*; -import org.rairlab.shadow.prover.representations.formula.Predicate; +import org.rairlab.planner.search.DepthFirstPlanner; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; -import static org.rairlab.shadow.prover.utils.Reader.readFormulaFromString; /** * Created by naveensundarg on 12/22/17.