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); }
/// <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); }
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); }