public override bool InitStates(INode Start, INode Goal) { startNode = new ANode(Start); goalNode = new ANode(Goal); startNode.G = 0; startNode.H = hCalc.Calculate(startNode, goalNode); openList.AddValue(startNode); return(true); }
public abstrA() { expansions = 0; foundGoalNode = null; startNode = null; goalNode = null; timeAvaliable = 5000; rewards = new Dictionary <double, double>(); openList = new NodeTable <ANode>(Comparer); closedList = new NodeTable <ANode>(Comparer); }
private double fvalue(ANode node) { return(node.G + node.H); }
public bool winA(double TimeAvaliable) { currentLvl = -1; while (stopwatch.Elapsed.TotalMilliseconds < TimeAvaliable && !stopped) { if (openList.Count == 0) { return(false); } ANode currentNode = openList.Min; openList.RemoveValue(currentNode); closedList.AddValue(currentNode); if (foundGoalNode != null && fvalue(currentNode) > fvalue(foundGoalNode)) { return(false); } if (currentNode.Level <= currentLvl - winSize) { closedList.RemoveValue(currentNode); suspendList.AddValue(currentNode); continue; } if (currentNode.Level > currentLvl) { currentLvl = currentNode.Level; } if (currentNode.Equals(goalNode)) { foundGoalNode = currentNode; rewards.Add(stopwatch.Elapsed.TotalMilliseconds, currentNode.G); return(true); } IEnumerable <ANode> successorNodes = succGen.Generate(currentNode); expansions++; nodesGenerated += successorNodes.Count(); foreach (ANode successorNode in successorNodes) { ANode node1; ANode node2; ANode node3; if (openList.TryGetValue(successorNode, out node1)) { if (node1.G > successorNode.G) { successorNode.H = hCalc.Calculate(successorNode, goalNode); successorNode.Level = currentNode.Level + 1; openList.RemoveValue(node1); openList.AddValue(successorNode); } } else if (suspendList.TryGetValue(successorNode, out node3)) { if (node3.G > successorNode.G) { successorNode.H = hCalc.Calculate(successorNode, goalNode); successorNode.Level = currentNode.Level + 1; suspendList.RemoveValue(node3); suspendList.AddValue(successorNode); } } else if (closedList.TryGetValue(successorNode, out node2)) { if (node2.G > successorNode.G) { closedList.RemoveValue(node2); successorNode.H = hCalc.Calculate(successorNode, goalNode); successorNode.Level = currentNode.Level + 1; openList.AddValue(successorNode); } } else { successorNode.Parent = currentNode; successorNode.H = hCalc.Calculate(successorNode, goalNode); successorNode.Level = currentNode.Level + 1; openList.AddValue(successorNode); } } } return(false); }
private double fvalue(ANode n) { return(n.G + n.H); }
private double fvalue2(ANode n) { return(n.G + w * n.H); }
public override void Execute() { stopwatch.Restart(); while (stopwatch.Elapsed.TotalMilliseconds < timeAvaliable && !stopped) { if (openList.Count == 0) { isOptimalFound = true; stopwatch.Stop(); return; } ANode currentNode = openList.Min; openList.RemoveValue(currentNode); if (currentNode.Equals(goalNode)) { foundGoalNode = currentNode; rewards.Add(stopwatch.Elapsed.TotalMilliseconds, currentNode.G); continue; } if (foundGoalNode == null || fvalue(currentNode) < foundGoalNode.G) { closedList.AddValue(currentNode); IEnumerable <ANode> successorNodes = succGen.Generate(currentNode); expansions++; nodesGenerated = nodesGenerated + successorNodes.Count(); foreach (ANode successorNode in successorNodes) { if (foundGoalNode == null || successorNode.G + hCalc.Calculate(successorNode, goalNode) < foundGoalNode.G) { ANode node1; ANode node2; bool InOpen; bool InClosed; if (InOpen = openList.TryGetValue(successorNode, out node1)) { if (node1.G > successorNode.G) { successorNode.H = hCalc.Calculate(successorNode, goalNode); openList.RemoveValue(node1); openList.AddValue(successorNode); } } else if (InClosed = closedList.TryGetValue(successorNode, out node2)) { if (node2.G > successorNode.G) { closedList.RemoveValue(node2); successorNode.H = hCalc.Calculate(successorNode, goalNode); openList.AddValue(successorNode); } } else { successorNode.H = hCalc.Calculate(successorNode, goalNode); openList.AddValue(successorNode); } } } } } stopwatch.Stop(); }
private bool Search(double timeAvaliable) { while (stopwatch.Elapsed.TotalMilliseconds < timeAvaliable && !stopped) { if (openList.Count == 0) { isOptimalFound = true; return(true); } ANode currentNode = openList.Min; openList.RemoveValue(currentNode); if (currentNode.Equals(goalNode)) { foundGoalNode = currentNode; isOptimalFound = true; rewards.Add(stopwatch.Elapsed.TotalMilliseconds, currentNode.G); return(false); } closedList.AddValue(currentNode); IEnumerable <ANode> successorNodes = succGen.Generate(currentNode); expansions++; nodesGenerated = nodesGenerated + successorNodes.Count(); foreach (ANode successorNode in successorNodes) { ANode node1; ANode node2; bool InOpen; bool InClosed; if (InOpen = openList.TryGetValue(successorNode, out node1)) { if (node1.G > successorNode.G) { successorNode.H = hCalc.Calculate(successorNode, goalNode); openList.RemoveValue(node1); openList.AddValue(successorNode); } } else if (InClosed = closedList.TryGetValue(successorNode, out node2)) { if (node2.G > successorNode.G) { closedList.RemoveValue(node2); successorNode.H = hCalc.Calculate(successorNode, goalNode); openList.AddValue(successorNode); } } else { successorNode.H = hCalc.Calculate(successorNode, goalNode); openList.AddValue(successorNode); } } } return(false); }