public IterativeDeepeningSearchTests() { foreach (var name in new[] { "A", "B", "C", "D", "E", "F" }) { _states[name] = new DummyProblemState(0, name); } _goalState = DummyProblemState.CreateGoalState(); _states[_goalState.Name] = _goalState; }
public DepthLimitedSearchTests() { foreach (var name in new[] { "A", "B", "C", "D", "E", "F" }) { _states[name] = new DummyProblemState(0, name); } _goalState = DummyProblemState.CreateGoalState(); _states[_goalState.Name] = _goalState; }
public void ExpandNodeTest() { var state1 = new DummyProblemState(8); var state2 = new DummyProblemState(6); var rootNextStates = new[] { state1, state2 }; var root = new Node <DummyProblemState>(new DummyProblemState(0, rootNextStates)); var children = root.ExpandNode().ToList(); Assert.Equal(2, children.Count); Assert.Contains(children, node => node.State == state1 && node.Parent == root); Assert.Contains(children, node => node.State == state2 && node.Parent == root); }
public void ShouldFindOptimalPath() { var states = new Dictionary <string, DummyProblemState> { ["A"] = new DummyProblemState(0, "A"), ["Goal from A"] = DummyProblemState.CreateGoalState(42), ["B from A"] = new DummyProblemState(2, "B"), ["H from A"] = new DummyProblemState(1, "B"), ["E from A"] = new DummyProblemState(3, "E"), ["C from B"] = new DummyProblemState(4, "C"), ["D from C"] = new DummyProblemState(3, "D"), ["Goal from D"] = DummyProblemState.CreateGoalState(4), ["F from E"] = new DummyProblemState(1, "F"), ["Goal from F"] = DummyProblemState.CreateGoalState(2) }; SetPaths(states); var problem = new DummyProblem(states["A"]); var astars = new[] { new AStarSearch <DummyProblemState>(new NoHeuristicFunction <DummyProblemState>()), new AStarSearch <DummyProblemState>(new DummyHeuristicFunction(new Dictionary <string, int> { ["A"] = 8, ["B"] = 6, ["C"] = 5, ["D"] = 4, ["E"] = 7, ["F"] = 2, [DummyProblemState.CreateGoalState().Name] = 0, })) }; foreach (var astar in astars) { var result = astar.Search(problem).ToList(); Assert.Equal(6, result.Sum(s => s.Cost)); Assert.Equal(new[] { states["A"], states["E from A"], states["F from E"], states["Goal from F"] }, result); } }