/// <summary> /// Solve given instance with a list of algorithms /// </summary> /// <param name="instance">The instance to solve</param> public void SolveGivenProblem(ProblemInstance instance) { // Preparing a list of agent indices (not agent nums) for the heuristics' Init() method 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); this.PrintProblemStatistics(instance); //double cr0 = instance.getConflictRation(0); //double cr1 = instance.getConflictRation(1); //Debug.WriteLine("Conflict ratio (first order): " + cr0); //Debug.WriteLine("Conflict ratio (second order): " + cr1); //this.resultsWriter.Write(cr0 + RESULTS_DELIMITER); //this.resultsWriter.Write(cr1 + RESULTS_DELIMITER); // Initializing all heuristics, whereever they're used for (int i = 0; i < heuristics.Count; i++) { heuristics[i].init(instance, agentList); } for (int i = 0; i < solvers.Count; i++) { if (outOfTimeCounters[i] < Constants.MAX_FAIL_COUNT) // After "MAX_FAIL_COUNT" consecutive failures of a given algorithm we stop running it. // Assuming problem difficulties are non-decreasing, if it consistently failed on several problems it won't suddenly succeed in solving the next problem. { GC.Collect(); GC.WaitForPendingFinalizers(); this.run(solvers[i], instance); Console.WriteLine(); if (solvers[i].GetSolutionCost() >= 0) // Solved successfully { Plan plan = solvers[i].GetPlan(); int planSize = plan.GetSize(); if (planSize < 200) { plan.PrintPlan(); } else { Console.WriteLine("Plan is too long to print (" + planSize + " steps)."); } outOfTimeCounters[i] = 0; // Validate solution: if (i != 0 && solvers[0].GetSolutionCost() >= 0) { Debug.Assert(solvers[0].GetSolutionCost() == solvers[i].GetSolutionCost(), solvers[0] + " solution cost is different than that of " + solvers[i]); // Assuming algs are supposed to find an optimal solution, this is an error. //Debug.Assert(solvers[0].GetExpanded() == solvers[i].GetExpanded(), "Different Expanded"); //Debug.Assert(solvers[0].GetGenerated() == solvers[i].GetGenerated(), "Different Generated"); //Debug.Assert(solvers[0].GetSolutionDepth() == solvers[i].GetSolutionDepth(), "Depth Bug " + solvers[i]); } Console.WriteLine("+SUCCESS+ (:"); } else { outOfTimeCounters[i]++; Console.WriteLine("-FAILURE- ):"); } } else { PrintNullStatistics(solvers[i]); } Console.WriteLine(); } this.ContinueToNextLine(); }