/// <summary> /// Adds the specified node to the open nodes collection. /// </summary> /// <param name="node">Node to be added.</param> /// <param name="gValue">Calculated distance from the start.</param> /// <param name="predecessor">Predecessor node.</param> /// <param name="appliedOperator">Predecessor operator.</param> protected override void AddToOpenNodes(ISearchNode node, int gValue, ISearchNode predecessor, IOperator appliedOperator) { if (gValue > LimitValue) { return; } NodeInfo nodeInfo; if (NodesInfo.TryGetValue(node, out nodeInfo)) { if (nodeInfo.GValue > gValue) { nodeInfo.GValue = gValue; nodeInfo.Predecessor = Tuple.Create(predecessor, appliedOperator); NodesInfo[node] = nodeInfo; double hValue = Heuristic.GetValue(node); OpenNodes.Add(gValue + hValue, node); } } else { double hValue = Heuristic.GetValue(node); double fValue = gValue + hValue; if (fValue > LimitValue) { LowestValueOverLimit = Math.Min(LowestValueOverLimit, fValue); return; } NodesInfo.Add(node, new NodeInfo(gValue, Tuple.Create(predecessor, appliedOperator))); OpenNodes.Add(fValue, node); } }
/// <summary> /// Adds the specified node to the open nodes collection. /// </summary> /// <param name="node">Node to be added.</param> /// <param name="gValue">Calculated distance from the start.</param> /// <param name="hValue">Heuristic distance to the goal.</param> /// <param name="predecessor">Predecessor node.</param> /// <param name="appliedOperator">Predecessor operator.</param> protected void AddToOpenNodes(ISearchNode node, int gValue, double hValue, ISearchNode predecessor, IOperator appliedOperator) { NodeInfo nodeInfo; if (NodesInfo.TryGetValue(node, out nodeInfo)) { if (nodeInfo.GValue > gValue) { nodeInfo.GValue = gValue; nodeInfo.Predecessor = Tuple.Create(predecessor, appliedOperator); NodesInfo[node] = nodeInfo; OpenNodes.Add(gValue + hValue, node); } } else { NodesInfo.Add(node, new NodeInfo(gValue, Tuple.Create(predecessor, appliedOperator))); OpenNodes.Add(gValue + hValue, node); } }