/// <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); }
public List <List <TimedMove> > bfsToStartPositions(Move goalState) { ReducerOpenList <BFSNode> openList = new ReducerOpenList <BFSNode>(); HashSet <BFSNode> closedList = new HashSet <BFSNode>(); List <List <TimedMove> > paths = new List <List <TimedMove> >(); openList.Enqueue(new BFSNode(goalState)); int startPositionsFound = 0; while (openList.Count != 0) { BFSNode node = openList.Dequeue(); if (closedList.Contains(node)) { continue; } if (findStartPosition(node.position) != null) { addPath(instance, paths, node); startPositionsFound++; if (startPositionsFound == this.instance.m_vAgents.Length) { break; } } GetSons(node, openList, instance); closedList.Add(node); } return(paths); }
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); } }
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(); }