Exemplo n.º 1
0
        /// <summary>
        /// Setup the relevant data structures for a run.
        /// </summary>
        public virtual void Setup(ProblemInstance problemInstance, int minDepth, Run runner)
        {
            minCAViolations  = int.MaxValue;
            passed           = 0;
            this.generatedHL = 1;
            this.expandedHL  = 1;
            this.generatedLL = 0;
            this.expandedLL  = 0;
            this.totalCost   = Constants.TIMEOUT_COST;

            // If there exists relevant previously solved subproblems - use their solution as a lower bound
            if (problemInstance.parameters.ContainsKey(CostTreeSearch.PARENT_GROUP1_KEY))
            {
                costA   = ((AgentsGroup)(problemInstance.parameters[CostTreeSearch.PARENT_GROUP1_KEY])).solutionCost;
                costB   = ((AgentsGroup)(problemInstance.parameters[CostTreeSearch.PARENT_GROUP2_KEY])).solutionCost;
                sizeOfA = ((AgentsGroup)(problemInstance.parameters[CostTreeSearch.PARENT_GROUP1_KEY])).Size();
            }
            else
            {
                costA   = problemInstance.m_vAgents[0].h;
                costB   = 0;
                sizeOfA = 1;
            }
            this.problem = problemInstance;
            this.runner  = runner;

            closedList = new HashSet <CostTreeNode>();
            openList   = new LinkedList <CostTreeNode>();
            int[]      costs = new int[problem.GetNumOfAgents()];
            AgentState temp;

            for (int i = 0; i < problem.GetNumOfAgents(); i++)
            {
                temp     = problem.m_vAgents[i];
                costs[i] = Math.Max(problem.GetSingleAgentOptimalCost(temp), minDepth);
            }

            openList.AddFirst(new CostTreeNode(costs));
            this.initialHeuristics = openList.First.Value.costs.Sum();

            // Store parameters used by Trevor's Independence Detection algorithm
            if (problemInstance.parameters.ContainsKey(Trevor.MAXIMUM_COST_KEY))
            {
                this.maxCost = (int)(problemInstance.parameters[Trevor.MAXIMUM_COST_KEY]);
            }
            else
            {
                this.maxCost = -1;
            }

            if (problemInstance.parameters.ContainsKey(Trevor.CONFLICT_AVOIDANCE))
            {
                ID_CAT = ((HashSet <TimedMove>)problemInstance.parameters[Trevor.CONFLICT_AVOIDANCE]);
            }
            if (problemInstance.parameters.ContainsKey(CBS_LocalConflicts.INTERNAL_CAT))
            {
                CBS_CAT = ((HashSet_U <TimedMove>)problemInstance.parameters[CBS_LocalConflicts.INTERNAL_CAT]);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Setup the relevant data structures for a run.
        /// </summary>
        /// <param name="problemInstance"></param>
        /// <param name="minDepth"></param>
        /// <param name="runner"></param>
        /// <param name="minCost">Not taken into account, just added to comply with ICbsSolver</param>
        public virtual void Setup(ProblemInstance problemInstance, int minDepth, Run runner, int minCost = -1)
        {
            this.minCAViolations        = int.MaxValue;
            CostTreeSearchSolver.passed = 0;
            this.generatedHL            = 1;
            this.expandedHL             = 1;
            this.generatedLL            = 0;
            this.expandedLL             = 0;
            this.totalCost = Constants.TIMEOUT_COST;

            // If there exists relevant previously solved subproblems - use their solution as a lower bound
            //if (problemInstance.parameters.ContainsKey(CostTreeSearch.PARENT_GROUP1_KEY))
            //{
            //    costA = ((AgentsGroup)(problemInstance.parameters[CostTreeSearch.PARENT_GROUP1_KEY])).solutionCost;
            //    costB = ((AgentsGroup)(problemInstance.parameters[CostTreeSearch.PARENT_GROUP2_KEY])).solutionCost;
            //    sizeOfA = ((AgentsGroup)(problemInstance.parameters[CostTreeSearch.PARENT_GROUP1_KEY])).Size();
            //}
            //else
            {
                costA   = problemInstance.GetSingleAgentOptimalCost(problemInstance.m_vAgents[0]);
                costB   = 0;
                sizeOfA = 1;
            }

            this.problem = problemInstance;
            this.runner  = runner;

            closedList = new HashSet <CostTreeNode>();
            openList   = new Queue <CostTreeNode>();
            int[] costs = new int[problem.GetNumOfAgents()];
            for (int i = 0; i < problem.GetNumOfAgents(); i++)
            {
                costs[i] = Math.Max(problem.GetSingleAgentOptimalCost(problem.m_vAgents[i]), minDepth);
            }

            openList.Enqueue(new CostTreeNode(costs)); // The root
            this.initialEstimate = openList.Peek().costs.Sum();

            // Store parameters used by IndependenceDetection's Independence Detection algorithm
            if (problemInstance.parameters.ContainsKey(IndependenceDetection.MAXIMUM_COST_KEY))
            {
                this.maxCost = (int)(problemInstance.parameters[IndependenceDetection.MAXIMUM_COST_KEY]);
            }
            else
            {
                this.maxCost = -1;
            }

            if (problemInstance.parameters.ContainsKey(IndependenceDetection.CONFLICT_AVOIDANCE))
            {
                ID_CAT = ((Dictionary <TimedMove, List <int> >)problemInstance.parameters[IndependenceDetection.CONFLICT_AVOIDANCE]);
            }

            if (problemInstance.parameters.ContainsKey(CBS_LocalConflicts.CAT))
            {
                CBS_CAT = ((Dictionary <TimedMove, List <int> >)problemInstance.parameters[CBS_LocalConflicts.CAT]);
            }
        }
Exemplo n.º 3
0
        public CFMAM_MCMF_Reducer(ProblemInstance problem, Move goalState)
        {
            this.problemGrid = problem.m_vGrid;

            startPositions          = new Move[problem.GetNumOfAgents()];
            this.startPositionsDict = new Dictionary <KeyValuePair <int, int>, int>();
            for (int i = 0; i < problem.m_vAgents.Length; i++)
            {
                startPositions[i] = problem.m_vAgents[i].lastMove;
                this.startPositionsDict.Add(new KeyValuePair <int, int>(startPositions[i].x, startPositions[i].y), 1);
            }

            startPositionsToDiscover = problem.GetNumOfAgents();

            this.goalState             = goalState;
            this.NFNodes               = new HashSet <NFReducerNode>();
            this.l                     = -1;
            this.T                     = -1;
            this.edgeCounter           = 0;
            this.outputProblem         = null;
            NFReducerNode.indexCounter = 0;
            this.zeroLayer             = new List <NFReducerNode>();
        }
Exemplo n.º 4
0
        public CostTreeNodeSolver(ProblemInstance problem, CostTreeNode costNode, Run runner) //make sure agent numbers are in the correct order
        {
            this.runner = runner;
            AgentState agent;

            maxCost          = 0;
            allMDDs          = new MDD[problem.GetNumOfAgents()];
            this.startingPos = problem.m_vAgents;
            this.costs       = costNode.costs;
            this.problem     = problem;

            maxCost = costNode.costs.Max();
            for (int i = 0; i < startingPos.Length; i++)
            {
                agent      = startingPos[i];
                allMDDs[i] = new MDD(i, agent.agent.agentNum, agent.lastMove, costNode.costs[i], maxCost, startingPos.Length, problem);
            }

            matchCounter = 0;
        }
Exemplo n.º 5
0
        public static int matchCounter; //debugging

        public CostTreeNodeSolver(ProblemInstance problem, Run runner)
        {
            this.runner  = runner;
            this.problem = problem;
            allMDDs      = new MDD[problem.GetNumOfAgents()];
        }
 public int GetNumberOfAgents()
 {
     return(instance.GetNumOfAgents());
 }
Exemplo n.º 7
0
        /// <summary>
        /// Solve given instance with a list of algorithms
        /// </summary>
        /// <param name="instance">The instance to solve</param>
        public bool SolveGivenProblem
        (
            ProblemInstance instance,
            HashSet <MMStarConstraint> constraints = null
        )
        {
            instanceId += 1;
            bool success = true;

            List <uint> agentList = Enumerable.Range(0, instance.m_vAgents.Length).Select <int, uint>(x => (uint)x).ToList <uint>(); // FIXME: Must the heuristics really receive a list of uints?

            // Solve using the different algorithms
            //Debug.WriteLine("Solving " + instance);

            MAM_AgentState[] vAgents = new MAM_AgentState[instance.GetNumOfAgents()];
            for (int agentIndex = 0; agentIndex < instance.GetNumOfAgents(); agentIndex++)
            {
                vAgents[agentIndex] = new MAM_AgentState(instance.m_vAgents[agentIndex]);
            }
            for (int i = 0; i < solvers.Count; i++)
            {
                solutionCost = -1;
                if (outOfTimeCounters[i] < Constants.MAX_FAIL_COUNT)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    preprocessingTime = 0;
                    if (solvers[i].GetHeuristicCalculator().GetName() == "FastMap H")
                    {
                        this.startTime = this.ElapsedMillisecondsTotal();
                        solvers[i].GetHeuristicCalculator().init(instance);
                        solvers[i].GetHeuristicCalculator().preprocessing();
                        preprocessingTime = this.ElapsedMilliseconds();
                        Console.WriteLine("Preprocessing time in milliseconds: {0}", preprocessingTime);
                    }

                    this.run(solvers[i], instance, constraints);
                    MAM_AgentState[] vAgents2 = new MAM_AgentState[vAgents.Count()];
                    for (int agentIndex = 0; agentIndex < vAgents.Count(); agentIndex++)
                    {
                        vAgents2[agentIndex] = new MAM_AgentState(vAgents[agentIndex]);
                    }
                    instance.m_vAgents = vAgents2;

                    if (solvers[i].GetCostFunction() == CostFunction.MakeSpan)
                    {
                        solutionCost = solvers[i].GetSolutionMakeSpanCost();
                    }
                    else if (solvers[i].GetCostFunction() == CostFunction.SOC)
                    {
                        solutionCost = solvers[i].GetSolutionSOCCost();
                    }

                    MAM_Plan plan = null;
                    if (solvers[i].IsSolved()) // Solved successfully
                    {
                        plan = solvers[i].GetPlan();
                        if (toPrint)
                        {
                            Console.WriteLine();
                            plan.ToString();
                            Console.WriteLine();
                        }
                        outOfTimeCounters[i] = 0;
                        //Console.WriteLine("+SUCCESS+ (:");
                        this.plan = plan;
                    }
                    else
                    {
                        outOfTimeCounters[i]++;
                        Console.WriteLine("-FAILURE- ):");
                    }
                    planningTime = elapsedTime;
                }
                else if (toPrint)
                {
                    PrintNullStatistics(solvers[i]);
                }
            }
            return(true);
        }
Exemplo n.º 8
0
        public int solveWithIMS(ProblemInstance instance)
        {
            int costConsistency = -1;

            MAM_AgentState[] vAgents = new MAM_AgentState[instance.GetNumOfAgents()];
            for (int agentIndex = 0; agentIndex < instance.GetNumOfAgents(); agentIndex++)
            {
                vAgents[agentIndex] = new MAM_AgentState(instance.m_vAgents[agentIndex]);
            }
            for (int i = 0; i < IMSSolvers.Count; i++)
            {
                solutionCost = -1;
                if (outOfTimeCounters[i] < Constants.MAX_FAIL_COUNT)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    preprocessingTime = 0;
                    if (IMSSolvers[i].GetHeuristicCalculator().GetName() == "FastMap H")
                    {
                        this.startTime = this.ElapsedMillisecondsTotal();
                        IMSSolvers[i].GetHeuristicCalculator().init(instance);
                        IMSSolvers[i].GetHeuristicCalculator().preprocessing();
                        preprocessingTime = this.ElapsedMilliseconds();
                        Console.WriteLine("Preprocessing time in milliseconds: {0}", preprocessingTime);
                    }

                    this.runIMS(IMSSolvers[i], instance);
                    MAM_AgentState[] vAgents2 = new MAM_AgentState[vAgents.Count()];
                    for (int agentIndex = 0; agentIndex < vAgents.Count(); agentIndex++)
                    {
                        vAgents2[agentIndex] = new MAM_AgentState(vAgents[agentIndex]);
                    }
                    instance.m_vAgents = vAgents2;

                    solutionCost = IMSSolvers[i].GetSolutionCost();

                    if (costConsistency == -1)
                    {
                        costConsistency = solutionCost;
                    }
                    else if (solutionCost != costConsistency)
                    {
                        throw new Exception("Inconsist Cost");
                    }

                    String plan = null;
                    if (IMSSolvers[i].IsSolved()) // Solved successfully
                    {
                        plan = IMSSolvers[i].GetPlan();
                        if (toPrint)
                        {
                            Console.WriteLine();
                            Console.WriteLine(plan);
                            Console.WriteLine();
                        }
                        outOfTimeCounters[i] = 0;
                        Console.WriteLine("+SUCCESS+ (:");
                    }
                    else
                    {
                        outOfTimeCounters[i]++;
                        Console.WriteLine("-FAILURE- ):");
                    }
                    planningTime = elapsedTime;
                    WriteGivenIMSProblem(instance, IMSSolvers[i], plan);
                }
                else if (toPrint)
                {
                    PrintNullStatistics(IMSSolvers[i]);
                }
                Console.WriteLine();
            }
            return(costConsistency);
        }
Exemplo n.º 9
0
        private int solveWithCFMCBS(ProblemInstance instance)
        {
            int costConsistency = -1;

            MAM_AgentState[] vAgents = new MAM_AgentState[instance.GetNumOfAgents()];
            for (int agentIndex = 0; agentIndex < instance.GetNumOfAgents(); agentIndex++)
            {
                vAgents[agentIndex] = new MAM_AgentState(instance.m_vAgents[agentIndex]);
            }
            for (int i = 0; i < CFMCBSSolvers.Count; i++)
            {
                solutionCost = -1;
                if (outOfTimeCounters[i] < Constants.MAX_FAIL_COUNT)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    this.runCFMCBS(CFMCBSSolvers[i], instance);
                    MAM_AgentState[] vAgents2 = new MAM_AgentState[vAgents.Count()];
                    for (int agentIndex = 0; agentIndex < vAgents.Count(); agentIndex++)
                    {
                        vAgents2[agentIndex] = new MAM_AgentState(vAgents[agentIndex]);
                    }
                    instance.m_vAgents = vAgents2;

                    solutionCost = CFMCBSSolvers[i].GetSolutionCost();

                    if (costConsistency == -1)
                    {
                        costConsistency = solutionCost;
                    }
                    else if (solutionCost != costConsistency)
                    {
                        throw new Exception("Inconsist Cost");
                    }

                    String plan = null;
                    if (CFMCBSSolvers[i].isSolved()) // Solved successfully
                    {
                        plan = CFMCBSSolvers[i].GetPlan();
                        if (toPrint)
                        {
                            Console.WriteLine();
                            Console.WriteLine(plan);
                            Console.WriteLine();
                        }
                        outOfTimeCounters[i] = 0;
                        Console.WriteLine("+SUCCESS+ (:");
                    }
                    else
                    {
                        outOfTimeCounters[i]++;
                        Console.WriteLine("-FAILURE- ):");
                    }
                    planningTime = elapsedTime;
                    WriteGivenCFMCBSProblem(instance, CFMCBSSolvers[i], plan);
                }
                else if (toPrint)
                {
                    PrintNullStatistics(IMSSolvers[i]);
                }
                Console.WriteLine();
            }
            return(costConsistency);
        }