/// <summary> /// The returned plan wasn't constructed considering a CAT, so it's possible there's an alternative plan with the same cost and less collisions. /// </summary> /// <param name="agentState"></param> /// <returns></returns> public SinglePlan GetSingleAgentOptimalPlan(AgentState agentState, out Dictionary <int, int> conflictCountPerAgent, out Dictionary <int, List <int> > conflictTimesPerAgent, out Dictionary <int, List <int> > conflictTimesBiasPerAgent, int conflictRange = 0) { LinkedList <Move> moves = new LinkedList <Move>(); int agentNum = agentState.agent.agentNum; var conflictCounts = new Dictionary <int, int>(); var conflictTimes = new Dictionary <int, List <int> >(); var conflictTimesBias = new Dictionary <int, List <int> >(); var conflictProbability = new Dictionary <int, List <double> >(); IReadOnlyDictionary <TimedMove, List <int> > CAT; if (this.parameters.ContainsKey(CBS_LocalConflicts.CAT)) // TODO: Add support for IndependenceDetection's CAT { CAT = ((IReadOnlyDictionary <TimedMove, List <int> >) this.parameters[CBS_LocalConflicts.CAT]); } else { CAT = new Dictionary <TimedMove, List <int> >(); } //for(int tempTime = 0 ; tempTime < agentState.) TimedMove current = agentState.lastMove; // The starting position int time = current.time; int timeWithoutDelays = 0; while (true) { moves.AddLast(current); if (current.direction != Move.Direction.NO_DIRECTION && current.direction != Move.Direction.Wait) { timeWithoutDelays++; } // Count conflicts: current.UpdateConflictCounts(CAT, conflictCounts, conflictTimes, conflictTimesBias, conflictRange); if (agentState.agent.Goal.Equals(current)) { break; } // Get next optimal move time++; Move optimal = this.singleAgentOptimalMoves[agentNum][this.GetCardinality(current)]; current = new TimedMove(optimal, time); } conflictCountPerAgent = conflictCounts; conflictTimesPerAgent = conflictTimes; conflictTimesBiasPerAgent = conflictTimesBias; return(new SinglePlan(moves, agentNum)); }
/// <summary> /// The returned plan wasn't constructed considering a CAT, so it's possible there's an alternative plan with the same cost and less collisions. /// </summary> /// <param name="agentState"></param> /// <returns></returns> public SinglePlan GetSingleAgentOptimalPlan(AgentState agentState, out Dictionary <int, int> conflictCountPerAgent, out Dictionary <int, List <int> > conflictTimesPerAgent) { LinkedList <Move> moves = new LinkedList <Move>(); int agentNum = agentState.agent.agentNum; var conflictCounts = new Dictionary <int, int>(); var conflictTimes = new Dictionary <int, List <int> >(); IReadOnlyDictionary <TimedMove, List <int> > CAT; if (this.parameters.ContainsKey(CBS.CAT)) // TODO: Add support for IndependenceDetection's CAT { CAT = ((IReadOnlyDictionary <TimedMove, List <int> >) this.parameters[CBS.CAT]); } else { CAT = new Dictionary <TimedMove, List <int> >(); } TimedMove current = agentState.lastMove; // The starting position int time = current.time; while (true) { moves.AddLast(current); // Count conflicts: current.UpdateConflictCounts(CAT, conflictCounts, conflictTimes); if (agentState.agent.Goal.Equals(current)) { break; } // Get next optimal move time++; Move optimal = this.singleAgentOptimalMoves[agentNum][this.GetCardinality(current)]; current = new TimedMove(optimal, time); } conflictCountPerAgent = conflictCounts; conflictTimesPerAgent = conflictTimes; return(new SinglePlan(moves, agentNum)); }