Exemple #1
0
        public SinglePlan[] Solve()
        {
            MDDStep      currentNode;
            ExpandedNode toExpand = new ExpandedNode();

            while (openList.Count > 0)
            {
                if (runner.ElapsedMilliseconds() > Constants.MAX_TIME)
                {
                    return(null);
                }
                currentNode = (MDDStep)openList.Remove();
                // Check if node is the goal
                if (this.GoalTest(currentNode))
                {
                    conflictAvoidanceViolations = currentNode.conflicts;
                    return(GetAnswer(currentNode));
                }

                // Expand
                expanded++;
                toExpand.Setup(currentNode);
                Expand(toExpand);
            }
            return(null);
        }
Exemple #2
0
        private bool singleAgentA_Star(AgentState agent)
        {
            BinaryHeap           openList   = new BinaryHeap(); // TODO: Safe to use OpenList here instead?
            HashSet <AgentState> closedList = new HashSet <AgentState>();

            openList.Add(agent);
            AgentState temp = agent;
            bool       valid;

            while (openList.Count > 0)
            {
                if (this.runner.ElapsedMilliseconds() > 120000)
                {
                    return(false);
                }
                temp = (AgentState)openList.Remove();
                if (temp.h == 0)
                {
                    valid = true;
                    for (int i = temp.lastMove.time; i <= maxPathCost; i++)
                    {
                        if (RT.Contains(new TimedMove(temp.lastMove.x, temp.lastMove.y, Move.Direction.NO_DIRECTION, i)))
                        {
                            valid = false;
                        }
                    }
                    if (valid)
                    {
                        reservePath(temp);
                        totalTime += temp.lastMove.time;
                        //printPath(temp);
                        parked.Add(new Move(temp.lastMove.x, temp.lastMove.y, Move.Direction.NO_DIRECTION), temp.lastMove.time);
                        return(true);
                    }
                }
                expanded++;
                expendNode(temp, openList, closedList);
            }
            return(false);
        }