示例#1
0
文件: Silver.cs 项目: kylevedder/mapf
        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);
        }
示例#2
0
        public AStarMDD(MDD[] problem, Run runner, Dictionary <TimedMove, List <int> > conflicts, Dictionary <TimedMove, List <int> > CBS_CAT)
        {
            this.expanded  = 0;
            this.generated = 0;
            MDDStep root;

            this.problem    = problem;
            this.runner     = runner;
            this.ID_CAT     = conflicts;
            this.CBS_CAT    = CBS_CAT;
            this.closedList = new Dictionary <MDDStep, MDDStep>();
            this.openList   = new BinaryHeap();
            MDDNode[] sRoot = new MDDNode[problem.Length];
            for (int i = 0; i < problem.Length; i++)
            {
                sRoot[i]       = problem[i].levels[0].First.Value;
                sRoot[i].legal = true;
            }
            root = new MDDStep(sRoot, null);
            openList.Add(root);
            closedList.Add(root, root); // There will never be a hit. This is only done for consistancy
            conflictAvoidanceViolations = 0;
        }
示例#3
0
        public AStarMDD(MDD[] problem, Run runner, HashSet <TimedMove> conflicts, HashSet_U <TimedMove> CBS_CAT)
        {
            this.expanded  = 0;
            this.generated = 0;
            MDDStep root;

            this.problem    = problem;
            this.runner     = runner;
            this.ID_CAT     = conflicts;
            this.CBS_CAT    = CBS_CAT;
            this.closedList = new Dictionary <MDDStep, MDDStep>();
            this.openList   = new BinaryHeap();
            MDDNode[] sRoot = new MDDNode[problem.Length];
            for (int i = 0; i < problem.Length; i++)
            {
                sRoot[i]       = problem[i].levels[0].First.Value;
                sRoot[i].legal = true;
            }
            root = new MDDStep(sRoot, null);
            openList.Add(root);
            // Not adding it automatically to the closed list here?
            conflictAvoidanceViolations = 0;
        }
示例#4
0
文件: Silver.cs 项目: kylevedder/mapf
 private void expendNode(AgentState node, BinaryHeap openList, HashSet <AgentState> closedList)
 {
     foreach (TimedMove move in node.lastMove.GetNextMoves())
     {
         if (isValidMove(move))
         {
             AgentState temp   = new AgentState(node);
             AgentState tempCL = temp;
             temp.prev = node;
             if (move.time > maxPathCost)
             {
                 tempCL = new AgentState(temp);
                 tempCL.lastMove.time = maxPathCost;
             }
             if (!closedList.Contains(tempCL))
             {
                 closedList.Add(tempCL);
                 temp.lastMove.time = move.time;
                 openList.Add(temp);
                 generated++;
             }
         }
     }
 }