Exemple #1
0
        /// <summary>
        /// Discovers all of the neighbors of a given node
        /// </summary>
        /// <param name="node"> Node to discover neighbors to </param>
        /// <param name="openList"> linked list containing all of the unhandled nodes. recieved to check that neighboor is not already discovered </param>
        /// <returns> List of all node neighboors </returns>
        private LinkedList <NFReducerNode> GetSons(NFReducerNode node, ReducerOpenList <NFReducerNode> openList)
        {
            LinkedList <NFReducerNode> sons = new LinkedList <NFReducerNode>();

            CollectSon(openList, sons, node.nodeTime + 1, node.x, node.y);

            if (node.x != this.problemGrid.Length - 1 && !problemGrid[node.x + 1][node.y])
            {
                CollectSon(openList, sons, node.nodeTime + 1, node.x + 1, node.y);
            }
            if (node.x != 0 && !problemGrid[node.x - 1][node.y])
            {
                CollectSon(openList, sons, node.nodeTime + 1, node.x - 1, node.y);
            }
            if (node.y != this.problemGrid[node.x].Length - 1 && !problemGrid[node.x][node.y + 1])
            {
                CollectSon(openList, sons, node.nodeTime + 1, node.x, node.y + 1);
            }
            if (node.y != 0 && !problemGrid[node.x][node.y - 1])
            {
                CollectSon(openList, sons, node.nodeTime + 1, node.x, node.y - 1);
            }

            return(sons);
        }
        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);
            }
        }
Exemple #4
0
        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);
        }
Exemple #5
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);
        }
        private void GetSons(BFSNode node, ReducerOpenList <BFSNode> openList, ProblemInstance problem)
        {
            bool[][] problemGrid = problem.m_vGrid;

            if (node.position.x != problemGrid.Length - 1 && !problemGrid[node.position.x + 1][node.position.y])
            {
                CollectSon(openList, node, node.position.x + 1, node.position.y);
            }
            if (node.position.x != 0 && !problemGrid[node.position.x - 1][node.position.y])
            {
                CollectSon(openList, node, node.position.x - 1, node.position.y);
            }
            if (node.position.y != problemGrid[node.position.x].Length - 1 && !problemGrid[node.position.x][node.position.y + 1])
            {
                CollectSon(openList, node, node.position.x, node.position.y + 1);
            }
            if (node.position.y != 0 && !problemGrid[node.position.x][node.position.y - 1])
            {
                CollectSon(openList, node, node.position.x, node.position.y - 1);
            }
        }
Exemple #7
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();
        }