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(); }
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 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); }