/// <summary> /// Automatically calls Setup with the given costsNode /// </summary> /// <param name="problem"></param> /// <param name="costsNode">TODO: Maybe just pass the array of costs here?</param> /// <param name="runner"></param> public CostTreeNodeSolver(ProblemInstance problem, CostTreeNode costNode, Run runner) // Make sure agent numbers are in the correct order : this(problem, runner) { this.Setup(costNode); }
public CostTreeNodeSolverRepeatedMatching(ProblemInstance problem, Run runner) : base(problem, runner) { }
public CostTreeNodeSolverRepeatedMatching(ProblemInstance problem, CostTreeNode costNode, Run runner, int syncSize) : base(problem, costNode, runner) { this.syncSize = syncSize; }
public CostTreeNodeSolverKSimpleMatching(ProblemInstance problem, Run runner) : base(problem, runner) { }
public CostTreeNodeSolverKSimpleMatching(ProblemInstance problem, CostTreeNode costNode, Run runner, int maxGroupChecked) : base(problem, costNode, runner) { this.maxGroupChecked = maxGroupChecked; }
public static int matchCounter; // For debugging public CostTreeNodeSolver(ProblemInstance problem, Run runner) { this.runner = runner; this.problem = problem; this.allMDDs = new MDD[problem.GetNumOfAgents()]; }
public CostTreeNodeSolverDDBF(ProblemInstance problem, CostTreeNode costNode, Run runner) : base(problem, costNode, runner) { }
public override void Setup(ProblemInstance problemInstance, int minDepth, Run runner) { base.Setup(problemInstance, minDepth, runner); this.expandedFullStates = 0; this.generatedFullStates = 0; }
public override void Setup(ProblemInstance problemInstance, Run runner) { Setup(problemInstance, 0, runner); }
public virtual void Setup(ProblemInstance problemInstance, Run runner) { Setup(problemInstance, 0, runner); }
/// <summary> /// Runs a set of experiments. /// This function will generate a random instance (or load it from a file if it was already generated) /// </summary> public void RunExperimentSet(int[] gridSizes, int[] agentListSizes, int[] obstaclesProbs, int instances) { ProblemInstance instance; string instanceName; Run runner = new Run(); bool resultsFileExisted = File.Exists(RESULTS_FILE_NAME); runner.OpenResultsFile(RESULTS_FILE_NAME); if (resultsFileExisted == false) { runner.PrintResultsFileHeader(); } bool continueFromLastRun = false; string[] LastProblemDetails = null; string currentProblemFileName = Directory.GetCurrentDirectory() + "\\Instances\\current problem-" + Process.GetCurrentProcess().ProcessName; if (File.Exists(currentProblemFileName)) //if we're continuing running from last time { var lastProblemFile = new StreamReader(currentProblemFileName); LastProblemDetails = lastProblemFile.ReadLine().Split(','); //get the last problem lastProblemFile.Close(); continueFromLastRun = true; } for (int gs = 0; gs < gridSizes.Length; gs++) { for (int obs = 0; obs < obstaclesProbs.Length; obs++) { runner.ResetOutOfTimeCounters(); for (int ag = 0; ag < agentListSizes.Length; ag++) { if (gridSizes[gs] * gridSizes[gs] * (1 - obstaclesProbs[obs] / 100) < agentListSizes[ag]) // Probably not enough room for all agents { continue; } for (int i = 0; i < instances; i++) { if (continueFromLastRun) //set the latest problem { gs = int.Parse(LastProblemDetails[0]); obs = int.Parse(LastProblemDetails[1]); ag = int.Parse(LastProblemDetails[2]); i = int.Parse(LastProblemDetails[3]); for (int j = 4; j < LastProblemDetails.Length; j++) { runner.outOfTimeCounters[j - 4] = int.Parse(LastProblemDetails[j]); } continueFromLastRun = false; continue; // "current problem" file describes last solved problem, no need to solve it again } if (runner.outOfTimeCounters.Length != 0 && runner.outOfTimeCounters.Sum() == runner.outOfTimeCounters.Length * Constants.MAX_FAIL_COUNT) // All algs should be skipped { break; } instanceName = "Instance-" + gridSizes[gs] + "-" + obstaclesProbs[obs] + "-" + agentListSizes[ag] + "-" + i; try { instance = ProblemInstance.Import(Directory.GetCurrentDirectory() + "\\Instances\\" + instanceName); instance.instanceId = i; } catch (Exception importException) { if (onlyReadInstances) { Console.WriteLine("File " + instanceName + " dosen't exist"); return; } instance = runner.GenerateProblemInstance(gridSizes[gs], agentListSizes[ag], obstaclesProbs[obs] * gridSizes[gs] * gridSizes[gs] / 100); instance.ComputeSingleAgentShortestPaths(); instance.instanceId = i; instance.Export(instanceName); } runner.SolveGivenProblem(instance); // Save the latest problem if (File.Exists(currentProblemFileName)) { File.Delete(currentProblemFileName); } var lastProblemFile = new StreamWriter(currentProblemFileName); lastProblemFile.Write("{0},{1},{2},{3}", gs, obs, ag, i); for (int j = 0; j < runner.outOfTimeCounters.Length; j++) { lastProblemFile.Write("," + runner.outOfTimeCounters[j]); } lastProblemFile.Close(); } } } } runner.CloseResultsFile(); }
/// <summary> /// Dragon Age experiment /// </summary> /// <param name="numInstances"></param> /// <param name="mapFileNames"></param> public void RunDragonAgeExperimentSet(int numInstances, string[] mapFileNames) { ProblemInstance instance; string instanceName; Run runner = new Run(); bool resultsFileExisted = File.Exists(RESULTS_FILE_NAME); runner.OpenResultsFile(RESULTS_FILE_NAME); if (resultsFileExisted == false) { runner.PrintResultsFileHeader(); } // FIXME: Code dup with RunExperimentSet TextWriter output; // int[] agentListSizes = { 5, 10 }; int[] agentListSizes = { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 250, 300 }; bool continueFromLastRun = false; string[] lineParts = null; string currentProblemFileName = Directory.GetCurrentDirectory() + "\\Instances\\current problem-" + Process.GetCurrentProcess().ProcessName; if (File.Exists(currentProblemFileName)) //if we're continuing running from last time { TextReader input = new StreamReader(currentProblemFileName); lineParts = input.ReadLine().Split(','); //get the last problem input.Close(); continueFromLastRun = true; } int stopTimeMS = 1000 * 60 * 1; Stopwatch debugSW = new Stopwatch(); debugSW.Start(); for (int ag = 0; ag < agentListSizes.Length; ag++) { for (int i = 0; i < numInstances; i++) { for (int map = 0; map < mapFileNames.Length; map++) { /////@@@@@@@@@@@@ // if (map == 1) // { // i = 9; // } Debug.WriteLine($@"on start {ag},{i},{map}"); if (continueFromLastRun) //set the latest problem { ag = int.Parse(lineParts[0]); i = int.Parse(lineParts[1]); map = int.Parse(lineParts[2]); for (int j = 3; j < lineParts.Length; j++) { runner.outOfTimeCounters[j - 3] = int.Parse(lineParts[j]); } continueFromLastRun = false; continue; } if (runner.outOfTimeCounters.Sum() == runner.outOfTimeCounters.Length * 20) // All algs should be skipped { break; } string mapFileName = mapFileNames[map]; instanceName = Path.GetFileNameWithoutExtension(mapFileName) + "-" + agentListSizes[ag] + "-" + i; try { instance = ProblemInstance.Import(Directory.GetCurrentDirectory() + "\\Instances\\" + instanceName); } catch (Exception importException) { if (onlyReadInstances) { Console.WriteLine("File " + instanceName + " dosen't exist"); return; } instance = runner.GenerateDragonAgeProblemInstance(mapFileName, agentListSizes[ag]); instance.ComputeSingleAgentShortestPaths(); // Consider just importing the generated problem after exporting it to remove the duplication of this line from Import() instance.instanceId = i; instance.Export(instanceName); } runner.SolveGivenProblem(instance); //save the latest problem File.Delete(currentProblemFileName); output = new StreamWriter(currentProblemFileName); output.Write("{0},{1},{2}", ag, i, map); for (int j = 0; j < runner.outOfTimeCounters.Length; j++) { output.Write("," + runner.outOfTimeCounters[j]); } output.Close(); if (debugSW.ElapsedMilliseconds > stopTimeMS) { Debug.WriteLine("Stop"); break; } } if (debugSW.ElapsedMilliseconds > stopTimeMS) { break; } } if (debugSW.ElapsedMilliseconds > stopTimeMS) { break; } } runner.CloseResultsFile(); }