public void testAStarSearch() { // added to narrow down bug report filed by L.N.Sudarshan of // Thoughtworks and Xin Lu of UCI try { // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {2,0,5,6,4,8,3,7,1}); // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {0,8,7,6,5,4,3,2,1}); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 }); Problem problem = new Problem(board, EightPuzzleFunctionFactory .getActionsFunction(), EightPuzzleFunctionFactory .getResultFunction(), new EightPuzzleGoalTest()); Search search = new AStarSearch(new GraphSearch(), new ManhattanHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); Assert.assertEquals(23, agent.getActions().size()); Assert.assertEquals("926", agent.getInstrumentation().getProperty( "nodesExpanded")); Assert.assertEquals("534", agent.getInstrumentation().getProperty( "queueSize")); Assert.assertEquals("535", agent.getInstrumentation().getProperty( "maxQueueSize")); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception thrown"); } }
public void testAStarSearch() { // added to narrow down bug report filed by L.N.Sudarshan of // Thoughtworks and Xin Lu of UCI // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {2,0,5,6,4,8,3,7,1}); // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {0,8,7,6,5,4,3,2,1}); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 }); //EightPuzzleBoard board = new EightPuzzleBoard(new int[] //{ 1, 0, 2, 3, 4, 5, 6, 7, 8 }); IProblem <EightPuzzleBoard, IAction> problem = new BidirectionalEightPuzzleProblem(board); ISearchForActions <EightPuzzleBoard, IAction> search = new AStarSearch <EightPuzzleBoard, IAction>( new GraphSearch <EightPuzzleBoard, IAction>(), EightPuzzleFunctions.createManhattanHeuristicFunction()); SearchAgent <EightPuzzleBoard, IAction> agent = new SearchAgent <EightPuzzleBoard, IAction>(problem, search); Assert.AreEqual(23, agent.getActions().Size()); Assert.AreEqual("1133", // "926" GraphSearchReduced Frontier agent.getInstrumentation().getProperty("nodesExpanded")); Assert.AreEqual("676", // "534" GraphSearchReduced Frontier agent.getInstrumentation().getProperty("queueSize")); Assert.AreEqual("677", // "535" GraphSearchReduced Frontier agent.getInstrumentation().getProperty("maxQueueSize")); }
public void testGreedyBestFirstSearch() { try { // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {2,0,5,6,4,8,3,7,1}); // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {0,8,7,6,5,4,3,2,1}); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 }); Problem problem = new Problem(board, EightPuzzleFunctionFactory .getActionsFunction(), EightPuzzleFunctionFactory .getResultFunction(), new EightPuzzleGoalTest()); Search search = new GreedyBestFirstSearch(new GraphSearch(), new ManhattanHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); Assert.assertEquals(49, agent.getActions().size()); Assert.assertEquals("197", agent.getInstrumentation().getProperty( "nodesExpanded")); Assert.assertEquals("140", agent.getInstrumentation().getProperty( "queueSize")); Assert.assertEquals("141", agent.getInstrumentation().getProperty( "maxQueueSize")); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception thrown."); } }
public void testGenerateCorrect3Successors() { List<Action> actions = new ArrayList<Action>(EightPuzzleFunctionFactory .getActionsFunction().actions(board)); Assert.assertEquals(3, actions.size()); // test first successor EightPuzzleBoard expectedFirst = new EightPuzzleBoard(new int[] { 1, 2, 0, 3, 4, 5, 6, 7, 8 }); EightPuzzleBoard actualFirst = (EightPuzzleBoard) EightPuzzleFunctionFactory .getResultFunction().result(board, actions.get(0)); Assert.assertEquals(expectedFirst, actualFirst); Assert.assertEquals(EightPuzzleBoard.UP, actions.get(0)); // test second successor EightPuzzleBoard expectedSecond = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 8, 6, 7, 0 }); EightPuzzleBoard actualSecond = (EightPuzzleBoard) EightPuzzleFunctionFactory .getResultFunction().result(board, actions.get(1)); Assert.assertEquals(expectedSecond, actualSecond); Assert.assertEquals(EightPuzzleBoard.DOWN, actions.get(1)); // test third successor EightPuzzleBoard expectedThird = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 0, 4, 6, 7, 8 }); EightPuzzleBoard actualThird = (EightPuzzleBoard) (EightPuzzleBoard) EightPuzzleFunctionFactory .getResultFunction().result(board, actions.get(2)); Assert.assertEquals(expectedThird, actualThird); Assert.assertEquals(EightPuzzleBoard.LEFT, actions.get(2)); }
public void testGenerateCorrect3Successors() { ICollection <IAction> actions = CollectionFactory.CreateQueue <IAction>(EightPuzzleFunctions.getActions(board)); Assert.AreEqual(3, actions.Size()); // test first successor EightPuzzleBoard expectedFirst = new EightPuzzleBoard(new int[] { 1, 2, 0, 3, 4, 5, 6, 7, 8 }); EightPuzzleBoard actualFirst = (EightPuzzleBoard)EightPuzzleFunctions.getResult(board, actions.Get(0)); Assert.AreEqual(expectedFirst, actualFirst); Assert.AreEqual(EightPuzzleBoard.UP, actions.Get(0)); // test second successor EightPuzzleBoard expectedSecond = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 8, 6, 7, 0 }); EightPuzzleBoard actualSecond = (EightPuzzleBoard)EightPuzzleFunctions.getResult(board, actions.Get(1)); Assert.AreEqual(expectedSecond, actualSecond); Assert.AreEqual(EightPuzzleBoard.DOWN, actions.Get(1)); // test third successor EightPuzzleBoard expectedThird = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 0, 4, 6, 7, 8 }); EightPuzzleBoard actualThird = (EightPuzzleBoard)EightPuzzleFunctions.getResult(board, actions.Get(2)); Assert.AreEqual(expectedThird, actualThird); Assert.AreEqual(EightPuzzleBoard.LEFT, actions.Get(2)); }
public void ShuffleEigthPuzzleInitialState(AriciePropertyEditorControl ape) { var eightPuzzleBoard = new EightPuzzleBoard(EightPuzzleInitialState.ToArray()); var actionsFunction = EightPuzzleFunctionFactory.getActionsFunction(); var resultFunction = EightPuzzleFunctionFactory.getResultFunction(); var previousBoards = new HashSet <EightPuzzleBoard>(); for (int i = 0; i < EightPuzzleShuffleMoves; i++) { Object[] successors = actionsFunction.actions(eightPuzzleBoard).toArray(); EightPuzzleBoard nextState; do { var choosenSuccessorIdx = CryptoHelper.Random.Next(successors.Length); var objAction = (aima.core.agent.Action)successors[choosenSuccessorIdx]; nextState = (EightPuzzleBoard)resultFunction.result(eightPuzzleBoard, objAction); } while (previousBoards.Contains(nextState)); previousBoards.Add(eightPuzzleBoard); eightPuzzleBoard = (EightPuzzleBoard)nextState; } EightPuzzleInitialState = new List <int>(eightPuzzleBoard.getState()); ape.ItemChanged = true; }
public static void Main(params string[] args) { IRandom r = CommonFactory.CreateRandom(); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }); for (int i = 0; i < 50; ++i) { int th = r.Next(4); if (th == 0) { board.moveGapUp(); } if (th == 1) { board.moveGapDown(); } if (th == 2) { board.moveGapLeft(); } if (th == 3) { board.moveGapRight(); } } System.Console.WriteLine(board); }
public void testHeuristicCalculation() { MisplacedTilleHeuristicFunction fn = new MisplacedTilleHeuristicFunction(); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 2, 0, 5, 6, 4, 8, 3, 7, 1 }); Assert.assertEquals(7.0, fn.h(board), 0.001); board = new EightPuzzleBoard(new int[] { 6, 2, 5, 3, 4, 8, 0, 7, 1 }); Assert.assertEquals(6.0, fn.h(board), 0.001); board = new EightPuzzleBoard(new int[] { 6, 2, 5, 3, 4, 8, 7, 0, 1 }); Assert.assertEquals(7.0, fn.h(board), 0.001); }
public void testGenerateCorrectWhenGapMovedRightward() { board.moveGapLeft();// gives { 1, 2, 5, 3, 0, 4, 6, 7, 8 } Assert.assertEquals(new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 0, 4, 6, 7, 8 }), board); List<Action> actions = new ArrayList<Action>(EightPuzzleFunctionFactory .getActionsFunction().actions(board)); Assert.assertEquals(4, actions.size()); EightPuzzleBoard expectedFourth = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 0, 6, 7, 8 }); EightPuzzleBoard actualFourth = (EightPuzzleBoard) (EightPuzzleBoard) EightPuzzleFunctionFactory .getResultFunction().result(board, actions.get(3)); Assert.assertEquals(expectedFourth, actualFourth); Assert.assertEquals(EightPuzzleBoard.RIGHT, actions.get(3)); }
public void testGenerateCorrectWhenGapMovedRightward() { board.moveGapLeft();// gives { 1, 2, 5, 3, 0, 4, 6, 7, 8 } Assert.AreEqual(new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 0, 4, 6, 7, 8 }), board); ICollection <IAction> actions = CollectionFactory.CreateQueue <IAction>(EightPuzzleFunctions.getActions(board)); Assert.AreEqual(4, actions.Size()); EightPuzzleBoard expectedFourth = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 0, 6, 7, 8 }); EightPuzzleBoard actualFourth = (EightPuzzleBoard)EightPuzzleFunctions.getResult(board, actions.Get(3)); Assert.AreEqual(expectedFourth, actualFourth); Assert.AreEqual(EightPuzzleBoard.RIGHT, actions.Get(3)); }
public void testGreedyBestFirstSearchReducedFrontier() { // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {2,0,5,6,4,8,3,7,1}); // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {0,8,7,6,5,4,3,2,1}); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 }); IProblem <EightPuzzleBoard, IAction> problem = new BidirectionalEightPuzzleProblem(board); QueueBasedSearch <EightPuzzleBoard, IAction> search = new GreedyBestFirstSearch <EightPuzzleBoard, IAction> (new GraphSearchReducedFrontier <EightPuzzleBoard, IAction>(), EightPuzzleFunctions.createManhattanHeuristicFunction()); SearchAgent <EightPuzzleBoard, IAction> agent = new SearchAgent <EightPuzzleBoard, IAction>(problem, search); Assert.AreEqual(49, agent.getActions().Size()); Assert.AreEqual("197", agent.getInstrumentation().getProperty("nodesExpanded")); Assert.AreEqual("140", agent.getInstrumentation().getProperty("queueSize")); Assert.AreEqual("141", agent.getInstrumentation().getProperty("maxQueueSize")); }
public void testHeuristicCalculation() { IToDoubleFunction <Node <EightPuzzleBoard, IAction> > h = EightPuzzleFunctions.createMisplacedTileHeuristicFunction(); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 2, 0, 5, 6, 4, 8, 3, 7, 1 }); Assert.AreEqual(6.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); board = new EightPuzzleBoard(new int[] { 6, 2, 5, 3, 4, 8, 0, 7, 1 }); Assert.AreEqual(5.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); board = new EightPuzzleBoard(new int[] { 6, 2, 5, 3, 4, 8, 7, 0, 1 }); Assert.AreEqual(6.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); board = new EightPuzzleBoard(new int[] { 8, 1, 2, 3, 4, 5, 6, 7, 0 }); Assert.AreEqual(1.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }); Assert.AreEqual(0.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); }
public void setUp() { board = new EightPuzzleBoard(); }
public void setUp() { board = new EightPuzzleBoard(new int[] { 0, 5, 4, 6, 1, 8, 7, 3, 2 }); }
public void setUp() { board = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 0, 6, 7, 8 }); }
public void setUp() { board = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 0, 6, 7, 8 }); }
public void setUp() { board = new EightPuzzleBoard(); }
public void setUp() { board = new EightPuzzleBoard(new int[] { 0, 5, 4, 6, 1, 8, 7, 3, 2 }); }