Example #1
0
        public SinglePlan[] Solve()
        {
            A_Star_MDDs_Node currentNode;

            //A_Star_MDDs_Expander expander = new A_Star_MDDs_Expander();

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

                // Expand
                expanded++;  // TODO: don't count re-expansions as expansions?
                Expand(currentNode);
                //expander.Setup(currentNode);
                //Expand(expander);  // TODO: the expander just generates all children. EPEA* its ass!!
            }
            return(null);
        }
        private bool singleAgentAStar(AgentState agent)
        {
            AgentState.EquivalenceOverDifferentTimes = false;
            BinaryHeap <AgentState> openList   = new BinaryHeap <AgentState>(); // TODO: Safe to use OpenList here instead?
            HashSet <AgentState>    closedList = new HashSet <AgentState>();

            agent.h = this.problem.GetSingleAgentOptimalCost(agent);
            openList.Add(agent);
            AgentState node;

            this.initialEstimate += agent.h;
            TimedMove queryTimedMove = new TimedMove();

            while (openList.Count > 0)
            {
                if (this.runner.ElapsedMilliseconds() > Constants.MAX_TIME)
                {
                    return(false);
                }
                node = openList.Remove();
                if (node.h == 0)
                {
                    bool valid = true;
                    for (int i = node.lastMove.time; i <= maxPathCostSoFar; i++)
                    {
                        queryTimedMove.setup(node.lastMove.x, node.lastMove.y, Move.Direction.NO_DIRECTION, i);
                        if (reservationTable.Contains(queryTimedMove))
                        {
                            valid = false;
                        }
                    }
                    if (valid)
                    {
                        this.paths[agent.agent.agentNum] = new SinglePlan(node);
                        reservePath(node);
                        totalcost += node.lastMove.time;
                        parked.Add(new Move(node.lastMove.x, node.lastMove.y, Move.Direction.NO_DIRECTION), node.lastMove.time);
                        return(true);
                    }
                }
                expandNode(node, openList, closedList);
                expanded++;
            }
            return(false);
        }