private void CollectSon(ReducerOpenList <BFSNode> openList, BFSNode node, int x, int y) { BFSNode son = new BFSNode(new TimedMove(x, y, Move.Direction.NO_DIRECTION, 0), node); if (!openList.Contains(son)) { openList.Enqueue(son); } }
private void CollectSon(ReducerOpenList <NFReducerNode> openList, LinkedList <NFReducerNode> sons, int nodeTime, int x, int y) { NFReducerNode son = new NFReducerNode(nodeTime, x, y); if (openList.Contains(son)) { son = openList.Get(son); NFReducerNode.DecreaseIndexCounter(); } sons.AddLast(son); }
/// <summary> /// Creates an initial network flow problem reduced from the given problem /// </summary> private bool CreateNFProblem(CFMAStar.CostFunction costFunction) { this.superSink = new NFReducerNode(-1, -1, -1); NFNodes.Add(this.superSink); ReducerOpenList <NFReducerNode> openList = new ReducerOpenList <NFReducerNode>(); openList.Enqueue(new NFReducerNode(0, goalState.x, goalState.y)); while (openList.Count != 0) { //if (timer.ElapsedMilliseconds > Constants.MCMF_MAX_TIME) // return false; NFReducerNode node = openList.Dequeue(); LinkedList <NFReducerNode> nodeSons = new LinkedList <NFReducerNode>(); if (l == -1 || (l != -1 && node.nodeTime != T)) { nodeSons = GetSons(node, openList); } foreach (NFReducerNode son in nodeSons) { son.AddEdgeTo(node); node.AddEdgeFrom(son); if (!openList.Contains(son)) { openList.Enqueue(son); } if (l == -1 && IsStartPosition(son) && this.startPositionsDict[new KeyValuePair <int, int>(son.x, son.y)] == 1) { this.startPositionsDict[new KeyValuePair <int, int>(son.x, son.y)] = 0; startPositionsToDiscover--; } if (l == -1 && startPositionsToDiscover == 0) { l = son.nodeTime; if (costFunction == CFMAStar.CostFunction.SOC) { T = l + startPositions.Length - 1; } else { T = l; } } } if (!NFNodes.Contains(node)) { AddAfterDuplicationAndSinkConnection(node); } } return(true); }
internal void addNetworkLayer() { ReducerOpenList <NFReducerNode> openList = new ReducerOpenList <NFReducerNode>(); this.T++; foreach (NFReducerNode node in this.zeroLayer) { NFNodes.Remove(node); openList.Enqueue(node); } this.zeroLayer = new List <NFReducerNode>(); while (openList.Count != 0) { NFReducerNode node = openList.Dequeue(); LinkedList <NFReducerNode> nodeSons = new LinkedList <NFReducerNode>(); if (node.nodeTime != T) { nodeSons = GetSons(node, openList); } foreach (NFReducerNode son in nodeSons) { son.AddEdgeTo(node); node.AddEdgeFrom(son); if (!openList.Contains(son)) { openList.Enqueue(son); } } if (!NFNodes.Contains(node)) { AddAfterDuplicationAndSinkConnection(node); } } ImportToMCMFAlgorithm(); }