public void NoDice() { var planningActions = new List <PlanningAction <string> >() { new PlanningAction <string>( name: "init", conditions: x => true, effects: x => { x = "init"; } ), new PlanningAction <string>( name: "execute", conditions: x => x == "init", effects: x => { x = "finish"; }) }; var plan = new GraphPlan <string>(Enums.PlanningMethod.DepthFirst, planningActions, new StringComparerer()); var actions = plan.MakePlan("init", "init"); actions.PrintToConsole(); }
public void BasicTest() { var planningActions = new List <PlanningAction <string> >() { new PlanningAction <string>( name: "init", conditions: x => true, effects: x => { x = "init"; } ), new PlanningAction <string>( name: "execute", conditions: x => x == "init", effects: x => { x = "finish"; }) }; //var actions = plan.Prepare() // .AddState().Finish() // .Solve("init", "finish") // .PrintToConsole(); var plan = new GraphPlan <string>(Enums.PlanningMethod.DepthFirst, planningActions, new StringComparerer()); var actions = plan.MakePlan("init", "finish"); actions.PrintToConsole(); //.Do("init") }
public void TestSimpleGame() { var initState = new SimpleGame.SimpleGameState(); var endState = new SimpleGame.SimpleGameState(); endState.Player.hasAxe = false; endState.Player.Wood = 20; endState.axeAvailable = false; var planningActions = new List <PlanningAction <SimpleGame.SimpleGameState> >() { new PlanningAction <SimpleGame.SimpleGameState>( name: "chopWood", conditions: x => { return(x.Player.hasAxe); }, effects: x => { x.Player.Wood++; if (x.Player.axeLife > 0) { x.Player.axeLife--; } } ), new PlanningAction <SimpleGame.SimpleGameState>( name: "getAxe", conditions: x => { return(!x.Player.hasAxe && x.axeAvailable); }, effects: x => { x.Player.hasAxe = true; x.axeAvailable = false; } ), new PlanningAction <SimpleGame.SimpleGameState>( name: "createAxe", conditions: x => { return(x.Player.Wood >= 5); }, effects: x => { x.Player.hasAxe = true; x.Player.Wood -= 2; } ) }; var plan = new GraphPlan <SimpleGame.SimpleGameState>(Enums.PlanningMethod.DepthFirst, planningActions, new GameStateComparer()); var actions = plan.MakePlan(initState, endState); actions.Do(initState); }
public static void Main() { EntitySet objects = new EntitySet(); objects.addObject("Ax", "Cargo"); objects.addObject("Bx", "Cargo"); objects.addObject("Rx", "Rocket"); objects.addObject("Lx", "Place"); objects.addObject("Px", "Place"); Conjunction init = new Conjunction("At (Ax, Lx) & At (Bx, Lx) & At (Rx, Lx) & HasFuel (Rx)"); Conjunction goal = new Conjunction("At (Ax, Px) & At (Bx, Px)"); OperatorHead opMoveHead = new OperatorHead("move", new ParaList("Rocket ?r, Place ?from, Place ?to")); Condition opMoveCond = new Condition("?from != ?to"); Conjunction opMovePre = new Conjunction("At (?r, ?from) & HasFuel (?r)"); Conjunction opMoveAdd = new Conjunction("At (?r, ?to)"); Conjunction opMoveDel = new Conjunction("At (?r, ?from) & HasFuel (?r)"); Operator opMove = new Operator(opMoveHead, opMoveCond, opMovePre, opMoveAdd, opMoveDel); OperatorHead opUnloadHead = new OperatorHead("unload", new ParaList("Rocket ?r, Place ?p, Cargo ?c")); Condition opUnloadCond = new Condition(""); Conjunction opUnloadPre = new Conjunction("At (?r, ?p) & In (?c, ?r)"); Conjunction opUnloadAdd = new Conjunction("At (?c, ?p)"); Conjunction opUnloadDel = new Conjunction("In (?c, ?r)"); Operator opUnload = new Operator(opUnloadHead, opUnloadCond, opUnloadPre, opUnloadAdd, opUnloadDel); OperatorHead opLoadHead = new OperatorHead("load", new ParaList("Rocket ?r, Place ?p, Cargo ?c")); Condition opLoadCond = new Condition(""); Conjunction opLoadPre = new Conjunction("At (?r, ?p) & At (?c, ?p)"); Conjunction opLoadAdd = new Conjunction("In (?c, ?r)"); Conjunction opLoadDel = new Conjunction("At (?c, ?p)"); Operator opLoad = new Operator(opLoadHead, opLoadCond, opLoadPre, opLoadAdd, opLoadDel); OperatorSet opSet = new OperatorSet(); opSet.Operators.Add(opMove); opSet.Operators.Add(opUnload); opSet.Operators.Add(opLoad); GraphPlan graph = new GraphPlan(objects, init, goal, opSet); bool res = graph.CreateGraph(); //Assert.IsTrue(res); res = graph.SearchGoal(); //Assert.IsTrue(res); List <string> plan = graph.GetPlan(); foreach (string step in plan) { System.Console.WriteLine(step); } }
public void Init() { var restoreServer = PlanningActions.ServerActions.Plan_RestoreServer(); var server_online = PlanningActions.ServerActions.Plan_GoOnline(); var restoration = PlanningActions.ServerActions.Plan_WaitingForRestoration(); var actions = new IPlanningAction <Models.Server>[] { restoreServer, server_online, restoration }; planner = new GraphPlan <Models.Server>(Enums.PlanningMethod.DepthFirst, actions, new ServerComparer()); }
public static bool DijkstraWithPlan <V, E>( this Graph <V, E> graph, int from, int to, WeightCalculator <E> calculator, out GraphPlan <V, E> path, ExplorationCallbacks <V, E> callbacks = default ) { return(graph.AStarWithPlan(from, to, ZeroHeuristics, calculator, out path, callbacks)); }
public void GraphPlanTest_Robot() { EntitySet objects = new EntitySet(); objects.addObject("green", "Color"); objects.addObject("red", "Color"); objects.addObject("sec1", "Section"); Conjunction init = new Conjunction("CurrentColor (green)"); Conjunction goal = new Conjunction("Painted (sec1, red)"); OperatorHead opPaintHead = new OperatorHead("Paint", new ParaList("Section ?sec, Color ?clr")); Condition opPaintCond = new Condition(""); Conjunction opPaintPre = new Conjunction("CurrentColor (?clr)"); Conjunction opPaintAdd = new Conjunction("Painted (?sec, ?clr)"); Conjunction opPaintDel = new Conjunction(""); Operator opPaint = new Operator(opPaintHead, opPaintCond, opPaintPre, opPaintAdd, opPaintDel); OperatorHead opChangeColorHead = new OperatorHead("ChangeColor", new ParaList("Color ?old, Color ?new")); Condition opChangeColorCond = new Condition("?old != ?new"); Conjunction opChangeColorPre = new Conjunction("CurrentColor (?old)"); Conjunction opChangeColorAdd = new Conjunction("CurrentColor (?new)"); Conjunction opChangeColorDel = new Conjunction("CurrentColor (?old)"); Operator opChangeColor = new Operator(opChangeColorHead, opChangeColorCond, opChangeColorPre, opChangeColorAdd, opChangeColorDel); OperatorSet opSet = new OperatorSet(); opSet.Operators.Add(opPaint); opSet.Operators.Add(opChangeColor); GraphPlan graph = new GraphPlan(objects, init, goal, opSet); bool res = graph.CreateGraph(); Assert.IsTrue(res); res = graph.SearchGoal(); Assert.IsTrue(res); List <string> plan = graph.GetPlan(); //foreach (string step in plan) //{ // System.Console.WriteLine(step); //} Assert.AreEqual(2, plan.Count); Assert.AreEqual("ChangeColor ( green, red )", plan[0]); Assert.AreEqual("Paint ( sec1, red )", plan[1]); }
public void GraphPlanTest_Blocks() { EntitySet objects = new EntitySet(); objects.addObject("b1", "Block"); objects.addObject("b2", "Block"); objects.addObject("b3", "Block"); objects.addObject("Table", "Block"); Conjunction init = new Conjunction("ON (b1, b2) & ON (b2, Table) & ON (b3, Table) & Clear (b1) & Clear (b3) & Clear (Table)"); Conjunction goal = new Conjunction("ON (b3, Table) & ON (b2, b3) & ON (b1, b2)"); OperatorHead opMoveHead = new OperatorHead("Move", new ParaList("Block ?obj, Block ?from, Block ?to")); Condition opMoveCond = new Condition("?obj != ?from & ?obj != ?to & ?from != ?to & ?to != Table"); Conjunction opMovePre = new Conjunction("ON (?obj, ?from) & Clear (?obj) & Clear (?to)"); Conjunction opMoveAdd = new Conjunction("ON (?obj, ?to) & Clear (?from)"); Conjunction opMoveDel = new Conjunction("ON (?obj, ?from) & Clear (?to)"); Operator opMove = new Operator(opMoveHead, opMoveCond, opMovePre, opMoveAdd, opMoveDel); OperatorHead opMoveToTableHead = new OperatorHead("MoveToTable", new ParaList("Block ?obj, Block ?from")); Condition opMoveToTableCond = new Condition("?obj != ?from & ?obj != Table & ?from != Table"); Conjunction opMoveToTablePre = new Conjunction("Clear (?obj) & ON (?obj, ?from)"); Conjunction opMoveToTableAdd = new Conjunction("ON (?obj, Table) & Clear (?from)"); Conjunction opMoveToTableDel = new Conjunction("ON (?obj, ?from)"); Operator opMoveToTable = new Operator(opMoveToTableHead, opMoveToTableCond, opMoveToTablePre, opMoveToTableAdd, opMoveToTableDel); OperatorSet opSet = new OperatorSet(); opSet.Operators.Add(opMove); opSet.Operators.Add(opMoveToTable); GraphPlan graph = new GraphPlan(objects, init, goal, opSet); bool res = graph.CreateGraph(); Assert.IsTrue(res); res = graph.SearchGoal(); Assert.IsTrue(res); List <string> plan = graph.GetPlan(); Assert.AreEqual(3, plan.Count); Assert.AreEqual("MoveToTable ( b1, b2 )", plan[0]); Assert.AreEqual("Move ( b2, Table, b3 )", plan[1]); Assert.AreEqual("Move ( b1, Table, b2 )", plan[2]); }
public void SimpleState_hanoi_tower_solver_test() { //A1 1 B1 | C1 | //A2 2 B2 | C2 | //A3 3 B3 | C3 | //A4 4 B4 | C4 | //A5 5 B5 | C5 | //A6 6 B6 | C6 | //A7 7 B7 | C7 | // / \ / \ / \ var initialState = new State { { "A1", 1 }, { "A2", 2 }, { "A3", 3 }, { "A4", 4 }, { "A5", 5 }, { "A6", 6 }, { "A7", 7 }, }; var goalState = new State { { "C1", 1 }, { "C2", 2 }, { "C3", 3 }, { "C4", 4 }, { "C5", 5 }, { "C6", 6 }, { "C7", 7 }, }; var planningActions = new List <IPlanningAction <State> > { new PlanningAction <State>( name: "Move from A to B", conditions: state => Validate(state, "A", "B"), effects: state => Move(state, "A", "B")), new PlanningAction <State>( name: "Move from A to C", conditions: state => Validate(state, "A", "C"), effects: state => Move(state, "A", "C")), new PlanningAction <State>( name: "Move from B to A", conditions: state => Validate(state, "B", "A"), effects: state => Move(state, "B", "A")), new PlanningAction <State>( name: "Move from B to C", conditions: state => Validate(state, "B", "C"), effects: state => Move(state, "B", "C")), new PlanningAction <State>( name: "Move from C to A", conditions: state => Validate(state, "C", "A"), effects: state => Move(state, "C", "A")), new PlanningAction <State>( name: "Move from C to B", conditions: state => Validate(state, "C", "B"), effects: state => Move(state, "C", "B")), }; var plan = new GraphPlan <State>(Enums.PlanningMethod.DepthFirst, planningActions.ToArray(), new StateComparer()) .MakePlan(initialState, goalState) .PrintToConsole(); }