Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        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();
        }