/// <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, 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; } for (int ag = 0; ag < agentListSizes.Length; ag++) { for (int i = 0; i < numInstances; i++) { for (int map = 0; map < mapFileNames.Length; 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(); } } } runner.CloseResultsFile(); }