public void TC_HeuristicStatistics() { var sasProblem = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_Gripper.sas"))); var heuristic = new StripsHeuristic(sasProblem); Assert.AreEqual(4, heuristic.GetValue(new Planner.SAS.State(0, 0, 0, 0, 0, 0, 0))); Assert.AreEqual(3, heuristic.GetValue(new Planner.SAS.State(1, 0, 0, 0, 0, 0, 0))); Assert.AreEqual(2, heuristic.GetValue(new Planner.SAS.State(0, 1, 1, 0, 0, 0, 0))); Assert.AreEqual(0, heuristic.GetValue(new Planner.SAS.State(1, 1, 1, 1, 0, 0, 0))); Assert.AreEqual(0, heuristic.Statistics.BestHeuristicValue); Assert.AreEqual(4, heuristic.Statistics.HeuristicCallsCount); Assert.AreEqual(9, heuristic.Statistics.SumOfHeuristicValues); Assert.AreEqual(2.25, heuristic.Statistics.AverageHeuristicValue); }
public void TC_StripsHeuristic() { var sasProblem = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_Gripper.sas"))); var pddlProblem = new Planner.PDDL.Problem(new PDDLInputData(GetFilePath("TC_Gripper_D.pddl"), GetFilePath("TC_Gripper_P.pddl"))); var heuristic = new StripsHeuristic(sasProblem); Assert.AreEqual(4, heuristic.GetValue(sasProblem.GetInitialState())); Assert.AreEqual(4, heuristic.GetValue(new Planner.SAS.State(0, 0, 0, 0, 0, 0, 0))); Assert.AreEqual(3, heuristic.GetValue(new Planner.SAS.State(1, 0, 0, 0, 0, 0, 0))); Assert.AreEqual(2, heuristic.GetValue(new Planner.SAS.State(0, 1, 1, 0, 0, 0, 0))); Assert.AreEqual(0, heuristic.GetValue(new Planner.SAS.State(1, 1, 1, 1, 0, 0, 0))); Assert.AreEqual(4, heuristic.GetValue(sasProblem.GetGoalConditions())); Assert.AreEqual(0, heuristic.GetValue(new Planner.SAS.Conditions(new Planner.SAS.Assignment(0, 0)))); Assert.AreEqual(2, heuristic.GetValue(new Planner.SAS.Conditions(new Planner.SAS.Assignment(1, 1), new Planner.SAS.Assignment(2, 1)))); Assert.AreEqual(1, heuristic.GetValue(new Planner.SAS.ConditionsClause(new Planner.SAS.Conditions(new Planner.SAS.Assignment(0, 1), new Planner.SAS.Assignment(1, 1)), new Planner.SAS.Conditions(new Planner.SAS.Assignment(2, 1))))); Assert.AreEqual(int.MaxValue, heuristic.GetValue(new Planner.SAS.ConditionsContradiction())); Assert.AreEqual(4, heuristic.GetValue(sasProblem.GetGoalConditions().GetCorrespondingRelativeStates(sasProblem).First())); Assert.AreEqual("STRIPS Heuristic", heuristic.GetName()); Assert.AreEqual(11, heuristic.GetCallsCount()); var data = new PDDLInputData(GetFilePath("TC_Gripper_D.pddl"), GetFilePath("TC_Gripper_P.pddl")); Planner.PDDL.IdManager idManager = new Planner.PDDL.IdManager(data); Planner.PDDL.PrimitivesFactory factory = new Planner.PDDL.PrimitivesFactory(idManager); Planner.PDDL.GroundingManager groundingManager = new Planner.PDDL.GroundingManager(data, idManager); Planner.PDDL.EvaluationManager evaluationManager = new Planner.PDDL.EvaluationManager(groundingManager, pddlProblem.RigidRelations); var atPred = factory.CreatePredicate("at", "ball1", "roomb"); var atPred2 = factory.CreatePredicate("at", "ball2", "roomb"); var heuristic2 = new StripsHeuristic(pddlProblem); Assert.AreEqual(2, heuristic2.GetValue(pddlProblem.GetInitialState())); Assert.AreEqual(1, heuristic2.GetValue(new Planner.PDDL.State(new HashSet <Planner.PDDL.IAtom> { atPred }, null, null, idManager))); Assert.AreEqual(0, heuristic2.GetValue(new Planner.PDDL.State(new HashSet <Planner.PDDL.IAtom> { atPred, atPred2 }, null, null, idManager))); Assert.AreEqual(2, heuristic2.GetValue(pddlProblem.GetGoalConditions())); Assert.AreEqual(1, heuristic2.GetValue(new Planner.PDDL.Conditions(new Planner.PDDL.PredicateExpression(atPred, idManager), evaluationManager))); Assert.AreEqual(1, heuristic2.GetValue(new Planner.PDDL.ConditionsCNF(new HashSet <Planner.PDDL.IConjunctCNF> { new Planner.PDDL.PredicateLiteralCNF(new Planner.PDDL.PredicateExpression(atPred, idManager), false) }, evaluationManager, null))); Assert.AreEqual(2, heuristic2.GetValue(pddlProblem.GetGoalConditions().GetCorrespondingRelativeStates(pddlProblem).First())); Assert.AreEqual("STRIPS Heuristic", heuristic2.GetName()); Assert.AreEqual(7, heuristic2.GetCallsCount()); }