public void fValue_getFvalueForChildNode_Equals1() { RsdGridSearchNode initialSearchNode = _basicWorld.GetInitialSearchNode <RsdGridSearchNode>(); RsdGridSearchNode gn = new RsdGridSearchNode(initialSearchNode, MoveDirection.Down); Assert.AreEqual(1, gn.g); }
public void Children_NoChildrenOnVisitedLocations_ManuallyCheck() { RsdGridSearchNode initialSearchNode = _basicWorld3X3.GetInitialSearchNode <RsdGridSearchNode>(); //GoingToTheGoalPosition var gridNode = new RsdGridSearchNode(initialSearchNode, MoveDirection.Down); foreach (var nodeChild in gridNode.Children) { var gridNodeChild = nodeChild as RsdGridSearchNode; Assert.AreNotEqual(initialSearchNode.HeadLocation, gridNodeChild.HeadLocation); } var gridNode2 = new RsdGridSearchNode(gridNode, MoveDirection.Right); foreach (var nodeChild in gridNode2.Children) { var gridNodeChild = nodeChild as RsdGridSearchNode; Assert.AreNotEqual(initialSearchNode.HeadLocation, gridNodeChild.HeadLocation); Assert.AreNotEqual(gridNode.HeadLocation, gridNodeChild.HeadLocation); } var gridNode3 = new RsdGridSearchNode(gridNode2, MoveDirection.Up); foreach (var nodeChild in gridNode3.Children) { var gridNodeChild = nodeChild as RsdGridSearchNode; Assert.AreNotEqual(initialSearchNode.HeadLocation, gridNodeChild.HeadLocation); Assert.AreNotEqual(gridNode.HeadLocation, gridNodeChild.HeadLocation); Assert.AreNotEqual(gridNode2.HeadLocation, gridNodeChild.HeadLocation); } }
public void Constructor_CreatesStateWithParent_Created() { RsdGridSearchNode initialSearchNode = _basicWorld.GetInitialSearchNode <RsdGridSearchNode>(); RsdGridSearchNode gn = new RsdGridSearchNode(initialSearchNode, MoveDirection.Down); Assert.IsNotNull(gn); }
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)); }
public void IsPrune_NotWorkingWithoutAstarOpenList_Exception() { RsdGridSearchNode initialState = _basicClean5X5World.GetInitialSearchNode <RsdGridSearchNode>(); ReachableSymmetryDetectionPrunning rsd = new ReachableSymmetryDetectionPrunning(); AStarMax solver = new AStarMax(_basicClean5X5World.GetInitialSearchNode <RsdGridSearchNode>(), rsd, new GoalOnLocation(_basicClean5X5World.Goal)); Assert.IsNotNull(rsd); Assert.IsFalse(rsd.ShouldPrune(initialState)); }
public void Children_GoalHaveNoChildren_CountEquals0() { RsdGridSearchNode initialSearchNode = _basicWorld3X3.GetInitialSearchNode <RsdGridSearchNode>(); //GoingToTheGoalPosition var gridNode = new RsdGridSearchNode(initialSearchNode, MoveDirection.Down); gridNode = new RsdGridSearchNode(gridNode, MoveDirection.Down); gridNode = new RsdGridSearchNode(gridNode, MoveDirection.Right); gridNode = new RsdGridSearchNode(gridNode, MoveDirection.Right); Assert.AreEqual(0, gridNode.Children.Count); }
public void gValue_getFvalueForChildNode_Equals20() { RsdGridSearchNode initialState = _basicWorld3.GetInitialSearchNode <RsdGridSearchNode>(); Assert.AreEqual(20, initialState.h); Assert.AreEqual(20, HelpMethods.GetCardinality(initialState.Reachable)); Assert.IsFalse(initialState.Reachable[0]); //(0,0) Assert.IsTrue(initialState.Reachable[1]); //(1,0) Assert.IsTrue(initialState.Reachable[2]); //(2,0) Assert.IsTrue(initialState.Reachable[3]); //(3,0) Assert.IsTrue(initialState.Reachable[4]); //(4,0) Assert.IsTrue(initialState.Reachable[5]); //(5,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); }
public void Children_NoChildrenOnBlockedLocations_ManuallyCheck() { RsdGridSearchNode initialSearchNode = _basicWorld3X3.GetInitialSearchNode <RsdGridSearchNode>(); //GoingToTheGoalPosition var gridNode = new RsdGridSearchNode(initialSearchNode, MoveDirection.Right); gridNode = new RsdGridSearchNode(gridNode, MoveDirection.Right); gridNode = new RsdGridSearchNode(gridNode, MoveDirection.Right); Assert.AreEqual(1, gridNode.Children.Count); var child = gridNode.Children.First.Value as RsdGridSearchNode; Assert.AreNotEqual(new Location(0, 4), child.HeadLocation); Assert.AreNotEqual(new Location(0, 2), child.HeadLocation); Assert.AreEqual(new Location(3, 1), child.HeadLocation); }
public void Children_AreAllwaysNearThierParents_DeltaDistanceAlways1() { RsdGridSearchNode initialSearchNode = _basicWorld3X3.GetInitialSearchNode <RsdGridSearchNode>(); //GoingToTheGoalPosition var gridNode = new RsdGridSearchNode(initialSearchNode, MoveDirection.Down); foreach (var NodeChild in gridNode.Children) { var gridNodeChild = NodeChild as RsdGridSearchNode; Assert.AreEqual(1, Math.Abs(gridNode.HeadLocation.X - gridNodeChild.HeadLocation.X) + Math.Abs(gridNode.HeadLocation.Y - gridNodeChild.HeadLocation.Y)); } var gridNode2 = new RsdGridSearchNode(gridNode, MoveDirection.Right); foreach (var nodeChild in gridNode2.Children) { var gridNodeChild = nodeChild as RsdGridSearchNode; Assert.AreEqual(1, Math.Abs(gridNode2.HeadLocation.X - gridNodeChild.HeadLocation.X) + Math.Abs(gridNode2.HeadLocation.Y - gridNodeChild.HeadLocation.Y)); } }
public void Children_GetChildrenList_RelavantChildrenReturned() { RsdGridSearchNode initialSearchNode = _basicWorld.GetInitialSearchNode <RsdGridSearchNode>(); var childs = initialSearchNode.Children; var sampledChild = initialSearchNode.Children.Last.Value; Assert.IsNotNull(childs); Assert.AreEqual(2, childs.Count); Assert.AreEqual(1, sampledChild.g); Assert.AreEqual(23, sampledChild.h); childs = sampledChild.Children; sampledChild = sampledChild.Children.Last.Value; Assert.IsNotNull(childs); Assert.AreEqual(2, childs.Count); Assert.AreEqual(2, sampledChild.g); Assert.AreEqual(22, sampledChild.h); childs = sampledChild.Children; sampledChild = sampledChild.Children.Last.Value; Assert.IsNotNull(childs); Assert.AreEqual(2, childs.Count); Assert.AreEqual(3, sampledChild.g); Assert.AreEqual(21, sampledChild.h); }
public void gValue_getFvalueForChildNode_Equals24b() { RsdGridSearchNode initialState = _basicWorld2.GetInitialSearchNode <RsdGridSearchNode>(); Assert.AreEqual(24, initialState.h); Assert.AreEqual(24, HelpMethods.GetCardinality(initialState.Reachable)); Assert.IsTrue(initialState.Reachable[0]); //(0,0) Assert.IsTrue(initialState.Reachable[1]); //(1,0) Assert.IsTrue(initialState.Reachable[2]); //(2,0) Assert.IsTrue(initialState.Reachable[3]); //(3,0) Assert.IsFalse(initialState.Reachable[4]); //(4,0) Assert.IsFalse(initialState.Reachable[5]); //(5,0) Assert.IsTrue(initialState.Reachable[6]); //(0,1) Assert.IsTrue(initialState.Reachable[7]); //(1,1) Assert.IsTrue(initialState.Reachable[8]); //(2,1) Assert.IsTrue(initialState.Reachable[9]); //(3,1) Assert.IsFalse(initialState.Reachable[10]); //(4,1) Assert.IsFalse(initialState.Reachable[11]); //(5,1) Assert.IsTrue(initialState.Reachable[12]); //(0,2) Assert.IsFalse(initialState.Reachable[13]); //(1,2) Assert.IsTrue(initialState.Reachable[14]); //(2,2) Assert.IsTrue(initialState.Reachable[15]); //(3,2) Assert.IsTrue(initialState.Reachable[16]); //(4,2) Assert.IsFalse(initialState.Reachable[17]); //(5,2) Assert.IsTrue(initialState.Reachable[18]); //(0,3) Assert.IsTrue(initialState.Reachable[19]); //(1,3) Assert.IsTrue(initialState.Reachable[20]); //(2,3) Assert.IsTrue(initialState.Reachable[21]); //(3,3) Assert.IsTrue(initialState.Reachable[22]); //(4,3) Assert.IsTrue(initialState.Reachable[23]); //(5,3) Assert.IsTrue(initialState.Reachable[24]); //(0,4) Assert.IsTrue(initialState.Reachable[25]); //(1,4) Assert.IsTrue(initialState.Reachable[26]); //(2,4) Assert.IsTrue(initialState.Reachable[27]); //(3,4) Assert.IsTrue(initialState.Reachable[28]); //(4,4) Assert.IsTrue(initialState.Reachable[29]); //(5,4) }
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)); }
public void fValue_getFvalueForNewNode_EqualsZero() { RsdGridSearchNode initialSearchNode = _basicWorld.GetInitialSearchNode <RsdGridSearchNode>(); Assert.AreEqual(0, initialSearchNode.g); }
public void Constructor_CreatesState_Created() { GridSearchNode searchNode = new RsdGridSearchNode(_basicWorld); Assert.IsNotNull(searchNode); }