예제 #1
0
        public void setAstarOpenList_CanBeCalledOnlyOnce_CallingTwiceResultsInException()
        {
            ReachableSymmetryDetectionPrunning rsd = new ReachableSymmetryDetectionPrunning();
            AStarMax solver = new AStarMax(_basicClean5X5World.GetInitialSearchNode <RsdGridSearchNode>(), rsd, new GoalOnLocation(_basicClean5X5World.Goal));

            Assert.IsNotNull(rsd);
            rsd.setAstarOpenList(solver.OpenList);
            rsd.setAstarOpenList(solver.OpenList);
        }
예제 #2
0
        public void PruneNode_ReturnsTrueOnRelevantStateOnly_TriggredWhenNeededByReachableSymmetryDetectionCase2()
        {
            //More Complicated case - prune inside the ShouldPrune method, return Yes for the should prune but replace nodes
            RsdGridSearchNode initialState         = _basicWorld5X5Blocked.GetInitialSearchNode <RsdGridSearchNode>();
            ReachableSymmetryDetectionPrunning rsd = new ReachableSymmetryDetectionPrunning();
            AStarMax solver = new AStarMax(_basicWorld5X5Blocked.GetInitialSearchNode <RsdGridSearchNode>(), rsd, new GoalOnLocation(_basicWorld5X5Blocked.Goal));

            rsd.setAstarOpenList(solver.OpenList);
            Assert.IsFalse(rsd.ShouldPrune(initialState));
            //Flow 1:
            //↓→*
            //→↑#
            //###
            var Flow2Node = new RsdGridSearchNode(initialState, MoveDirection.Down);

            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Right);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Up);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Right);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            //Flow 2:
            //→→*
            //  #
            //###
            var Flow1Node = new RsdGridSearchNode(initialState, MoveDirection.Right);

            Assert.IsTrue(rsd.ShouldPrune(Flow1Node));
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Right);
            Assert.IsTrue(rsd.ShouldPrune(Flow1Node));
        }
예제 #3
0
        public void PruneNode_ReturnsTrueOnRelevantStateOnly_TriggredWhenNeededByBasicSymmetryCase()
        {
            RsdGridSearchNode initialState         = _basicClean5X5World.GetInitialSearchNode <RsdGridSearchNode>();
            ReachableSymmetryDetectionPrunning rsd = new ReachableSymmetryDetectionPrunning();
            AStarMax solver = new AStarMax(_basicClean5X5World.GetInitialSearchNode <RsdGridSearchNode>(), rsd, new GoalOnLocation(_basicClean5X5World.Goal));

            rsd.setAstarOpenList(solver.OpenList);
            Assert.IsFalse(rsd.ShouldPrune(initialState));
            //Flow 1:
            //↓→↓
            //↓↑↓
            //→↑*
            var Flow1Node = new RsdGridSearchNode(initialState, MoveDirection.Down);

            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Down);
            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Right);
            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Up);
            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Up);
            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Right);
            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Down);
            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Down);
            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            //Flow 2:
            //→→↓
            //↓←←
            //→→*
            var Flow2Node = new RsdGridSearchNode(initialState, MoveDirection.Right);

            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Right);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Down);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Left);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Left);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Down);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Right);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Right);
            Assert.IsTrue(rsd.ShouldPrune(Flow2Node));
        }
        public void AStarGrid_BasicRun_BCCHeuristicsRSD_Success2()
        {
            RsdGridSearchNode initialState             = _basicWorldBccAndPruningCheck.GetInitialSearchNode <RsdGridSearchNode>();
            ReachableSymmetryDetectionPrunning pruning = new ReachableSymmetryDetectionPrunning();
            AStarMax astar = new AStarMax(initialState, pruning, new GoalOnLocation(_basicWorldV1.Goal));

            Assert.IsNotNull(astar);
            pruning.setAstarOpenList(astar.OpenList);
            var howEnded = astar.Run(Int32.MaxValue);
            var maxGoal  = astar.GetMaxGoal();

            Assert.IsNotNull(maxGoal);
            Assert.AreEqual(State.Ended, howEnded);
        }
예제 #5
0
        public void setAstarSolve_BasicWorld4x4_SolveCorrectly()
        {
            ReachableSymmetryDetectionPrunning rsd = new ReachableSymmetryDetectionPrunning();
            AStarMax solver = new AStarMax(_basicWorld4x4.GetInitialSearchNode <RsdGridSearchNode>(), rsd, new GoalOnLocation(_basicWorld4x4.Goal));

            rsd.setAstarOpenList(solver.OpenList);
            Assert.IsNotNull(rsd);
            Assert.IsNotNull(solver);
            var howEnded = solver.Run(10);

            Assert.AreEqual(State.Ended, howEnded);
            var goal = (RsdGridSearchNode)solver.GetMaxGoal();

            Assert.IsNotNull(goal);
            Assert.AreEqual(14, goal.g);
        }
예제 #6
0
        public void Integration_altbccWithRsdBug_ShouldFindSolution()
        {
            _specialCase01 = new World(File.ReadAllText(@"..\..\altbcc-rsd-bug001.grd"), new AlternateStepsBiconnectedComponentsHeuristic());
            var      prune = new ReachableSymmetryDetectionPrunning();
            AStarMax astar = new AStarMax(_specialCase01.GetInitialSearchNode <RsdGridSearchNode>(), prune, new GoalOnLocation(_specialCase01.Goal));

            Assert.IsNotNull(astar);
            prune.setAstarOpenList(astar.OpenList);
            astar.Run(Int32.MaxValue);
            var      AstarMaxGoal = astar.GetMaxGoal();
            DfBnbMax dfbnb        = new DfBnbMax(_specialCase01.GetInitialSearchNode <GridSearchNode>(), new GoalOnLocation(_specialCase01.Goal));

            Assert.IsNotNull(dfbnb);
            dfbnb.Run(Int32.MaxValue);
            var DfbnbMaxGoal = dfbnb.GetMaxGoal();

            Assert.AreEqual(AstarMaxGoal.g, DfbnbMaxGoal.g);
        }
예제 #7
0
        public void PruneNode_ReturnsTrueOnRelevantStateOnly_TriggredWhenNeededByReachableSymmetryDetectionCase1()
        {
            RsdGridSearchNode initialState         = _basicWorld5X5Blocked.GetInitialSearchNode <RsdGridSearchNode>();
            ReachableSymmetryDetectionPrunning rsd = new ReachableSymmetryDetectionPrunning();
            AStarMax solver = new AStarMax(_basicWorld5X5Blocked.GetInitialSearchNode <RsdGridSearchNode>(), rsd, new GoalOnLocation(_basicWorld5X5Blocked.Goal));

            rsd.setAstarOpenList(solver.OpenList);
            Assert.IsFalse(rsd.ShouldPrune(initialState));
            //Flow 1:
            //→→*
            //  #
            //###
            var Flow1Node = new RsdGridSearchNode(initialState, MoveDirection.Right);

            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            solver.OpenList.Add(Flow1Node);
            Flow1Node = new RsdGridSearchNode(Flow1Node, MoveDirection.Right);
            Assert.IsFalse(rsd.ShouldPrune(Flow1Node));
            solver.OpenList.Add(Flow1Node);
            //Flow 2:
            //↓→*
            //→↑#
            //###
            var Flow2Node = new RsdGridSearchNode(initialState, MoveDirection.Down);

            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            solver.OpenList.Add(Flow2Node);
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Right);
            Assert.IsFalse(rsd.ShouldPrune(Flow2Node));
            solver.OpenList.Add(Flow2Node);
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Up);
            Assert.IsTrue(rsd.ShouldPrune(Flow2Node));
            //Prune = no adding here (psss... it will be added from the pruning replace)
            Flow2Node = new RsdGridSearchNode(Flow2Node, MoveDirection.Right);
            Assert.IsTrue(rsd.ShouldPrune(Flow2Node));
        }