public static List <string> ManualSolve(Problem p, Domain d) { List <string> lPlan = new List <string>(); State sStart = new State(p); foreach (GroundedPredicate gp in p.Known) { sStart.AddPredicate(gp); } State sCurrent = null, sNext = null; Dictionary <State, Action> dMapStateToGeneratingAction = new Dictionary <State, Action>(); dMapStateToGeneratingAction[sStart] = null; Dictionary <State, State> dParents = new Dictionary <State, State>(); dParents[sStart] = null; int cProcessed = 0; List <string> lActionNames = new List <string>(); sCurrent = sStart; while (!p.IsGoalState(sCurrent)) { List <Action> lActions = new List <Action>(d.GroundAllActions(sCurrent.Predicates, false)); Console.WriteLine("Available actions:"); for (int i = 0; i < lActions.Count; i++) { Console.WriteLine(i + ") " + lActions[i].Name); } Console.Write("Choose action number: "); int iAction = int.Parse(Console.ReadLine()); Action a = lActions[iAction]; sNext = sCurrent.Apply(a); lPlan.Add(a.Name); foreach (Predicate pNew in sNext.Predicates) { if (!sCurrent.Predicates.Contains(pNew)) { Console.WriteLine(pNew); } } if (!dParents.Keys.Contains(sNext)) { dParents[sNext] = sCurrent; dMapStateToGeneratingAction[sNext] = a; } sCurrent = sNext; cProcessed++; } return(lPlan); //return GeneratePlan(sCurrent, null, dParents, dMapStateToGeneratingAction); }
public static bool VerifyPlan(Domain dJoint, Problem pJoint, List <string> lPlan) { List <State> lStates = new List <State>(); State sInitial = new State(pJoint); foreach (Predicate p in pJoint.Known) { sInitial.AddPredicate(p); } State sCurrent = sInitial; int i = 0; foreach (string sAction in lPlan) { State sNew = sCurrent.Apply(sAction); if (sNew == null) { return(false); } lStates.Add(sNew); sCurrent = sNew; i++; } CompoundFormula joinGoal = new CompoundFormula("and"); foreach (GroundedPredicate gGp in pJoint.Goal.GetAllPredicates()) { if (!gGp.Name.Equals("and")) { joinGoal.AddOperand(gGp); } } pJoint.Goal = joinGoal; if (pJoint.IsGoalState(sCurrent)) { PlanCost = lPlan.Count; return(true); } return(false); }