public static void LoadTestScenario() { if (testScenarioFilePath == null) { return; } using (StreamReader file = new StreamReader(testScenarioFilePath)) { string line = file.ReadLine(); if (line != "[test_scenario_start]") { throw new FileNotFoundException("This is not a test scenario file", testScenarioFilePath); } while ((line = file.ReadLine()) != "[test_scenario_end]") { Console.WriteLine(line); if (line != null) { string[] data = line.Split(':'); switch (data[0]) { case "test_name": DataOutput.SaveFileName = data[1]; break; case "start_locomotive_location": Locomotive.CurrentLocationID = Convert.ToInt32(data[1]); break; case "max_carried_weight": Locomotive.MaxWeight = Convert.ToDouble(data[1]); break; case "max_waggon_count": Locomotive.MaxWaggonCount = Convert.ToInt32(data[1]); break; case "max_city_jumps": AlgorithmImplementation.MaxCityVisited = Convert.ToInt32(data[1]); break; case "algorithm_seed": AlgorithmImplementation.Seed = Convert.ToInt32(data[1]); break; case "city_route_loop_temperature": AlgorithmImplementation.MainLoopTemperature = Convert.ToDouble(data[1]); break; case "city_route_loop_alpha": AlgorithmImplementation.MainLoopAlpha = Convert.ToDouble(data[1]); break; case "contract_loop_temperature": AlgorithmImplementation.ContractLoopTemperature = Convert.ToDouble(data[1]); break; case "contract_loop_alpha": AlgorithmImplementation.ContractLoopAlpha = Convert.ToDouble(data[1]); break; case "number_of_cities": World.AddCities(Convert.ToInt32(data[1])); break; case "cities_connections_start": while ((line = file.ReadLine()) != "[start]") { if (line == "[test_scenario_end]") { return; } } while ((line = file.ReadLine()) != "[end]") { if (line == "[test_scenario_end]") { return; } if (line == null || line == "" || line.Contains("|")) { continue; } string[] values = line.Split(';'); World.AddConnection( Convert.ToInt32(values[0]), Convert.ToInt32(values[1]), Convert.ToDouble(values[2])); } break; case "contracts": while ((line = file.ReadLine()) != "[start]") { if (line == "[test_scenario_end]") { return; } } while ((line = file.ReadLine()) != "[end]") { if (line == "[test_scenario_end]") { return; } if (line == null || line == "" || line.Contains("|")) { continue; } string[] values = line.Split(';'); World.AddContractToCity( Convert.ToInt32(values[0]), DelieveryContractFactory.CreateContract( Convert.ToInt32(values[1]), Convert.ToDouble(values[2]), Convert.ToInt32(values[3]), Convert.ToDouble(values[4]))); } break; } } } file.Close(); } PrepCityAndContractCounters(); }
static void Main(string[] args) { Console.WriteLine("Press 'Enter' to skip test case selection, and start default test case\n" + "Press 'F' to start test case selection"); ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.F) { //LOADING Console.Write("\nPress 'Enter' to select test scenario file"); Console.ReadLine(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Text files|*.txt"; if (openFileDialog.ShowDialog() == DialogResult.OK) { DataInput.testScenarioFilePath = openFileDialog.FileName; } Console.Write("Selected test scenario: " + DataInput.testScenarioFilePath + "\n\n"); DataInput.LoadTestScenario(); //SAVEING Console.Write("Press 'Enter' to select save location for current test run"); Console.ReadLine(); FolderBrowserDialog b = new FolderBrowserDialog(); if (b.ShowDialog() == DialogResult.OK) { DataOutput.OutputPath = b.SelectedPath; } Console.Write("Selected save location: " + DataOutput.OutputPath + "\n\n"); ShowMatrix(); } else if (key.Key == ConsoleKey.S || key.Key == ConsoleKey.Enter) { #region preparationes #region Cities World.AddCities(5); #endregion #region Connections World.AddConnection(0, 1, 10); World.AddConnection(0, 2, 14); World.AddConnection(0, 3, 55); World.AddConnection(0, 4, 40); World.AddConnection(1, 0, 10); World.AddConnection(1, 2, 20); World.AddConnection(1, 3, 30); World.AddConnection(1, 4, 47); World.AddConnection(2, 1, 22); World.AddConnection(2, 3, 30); World.AddConnection(2, 4, 44); World.AddConnection(3, 1, 30); World.AddConnection(3, 2, 22); World.AddConnection(3, 4, 40); World.AddConnection(4, 0, 50); World.AddConnection(4, 2, 33); /* * 0;1;10; * 0;2;14; * 0;3;55; * 0;4;40; * 1;0;10; * 1;2;20; * 1;3;30; * 1;4;47; * 2;1;22; * 2;3;30; * 2;4;44; * 3;1;30; * 3;2;22; * 3;4;40; * 4;0;50; * 4;2;33; */ #endregion #region Contracts World.AddContractToCity(0, DelieveryContractFactory.CreateContract(1, 100, 10, 1000)); // 0 World.AddContractToCity(0, DelieveryContractFactory.CreateContract(2, 100, 20, 2000)); // 1 World.AddContractToCity(0, DelieveryContractFactory.CreateContract(3, 100, 30, 3000)); // 2 World.AddContractToCity(0, DelieveryContractFactory.CreateContract(1, 100, 10, 1000)); // 3 World.AddContractToCity(0, DelieveryContractFactory.CreateContract(2, 100, 20, 2000)); // 4 World.AddContractToCity(0, DelieveryContractFactory.CreateContract(3, 300, 30, 3000)); // 5 World.AddContractToCity(0, DelieveryContractFactory.CreateContract(1, 100, 10, 1000)); // 6 World.AddContractToCity(0, DelieveryContractFactory.CreateContract(2, 100, 20, 2000)); // 7 World.AddContractToCity(0, DelieveryContractFactory.CreateContract(3, 300, 30, 3000)); // 8 World.AddContractToCity(1, DelieveryContractFactory.CreateContract(4, 110, 10, 1011)); // 9 World.AddContractToCity(1, DelieveryContractFactory.CreateContract(2, 220, 23, 2022)); // 10 World.AddContractToCity(1, DelieveryContractFactory.CreateContract(4, 110, 10, 1011)); // 11 World.AddContractToCity(1, DelieveryContractFactory.CreateContract(2, 100, 23, 2022)); // 12 World.AddContractToCity(1, DelieveryContractFactory.CreateContract(4, 110, 10, 1011)); // 13 World.AddContractToCity(1, DelieveryContractFactory.CreateContract(2, 100, 23, 2022)); // 14 World.AddContractToCity(1, DelieveryContractFactory.CreateContract(4, 110, 10, 1011)); // 15 World.AddContractToCity(1, DelieveryContractFactory.CreateContract(2, 220, 23, 2022)); // 16 World.AddContractToCity(2, DelieveryContractFactory.CreateContract(1, 330, 44, 2242)); // 17 World.AddContractToCity(2, DelieveryContractFactory.CreateContract(0, 320, 14, 1242)); // 18 World.AddContractToCity(2, DelieveryContractFactory.CreateContract(0, 330, 44, 2242)); // 19 World.AddContractToCity(2, DelieveryContractFactory.CreateContract(4, 320, 14, 1242)); // 20 World.AddContractToCity(2, DelieveryContractFactory.CreateContract(3, 330, 44, 2242)); // 21 World.AddContractToCity(2, DelieveryContractFactory.CreateContract(3, 320, 14, 1242)); // 22 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(4, 222, 12, 1234)); // 23 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(2, 212, 33, 1554)); // 24 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(4, 222, 12, 1234)); // 25 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(4, 222, 12, 1234)); // 26 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(4, 222, 12, 1234)); // 27 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(4, 222, 12, 1234)); // 28 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(4, 222, 12, 1234)); // 29 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(4, 222, 12, 1234)); // 30 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(2, 212, 33, 1554)); // 31 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(2, 212, 33, 1554)); // 32 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(2, 212, 33, 1554)); // 33 World.AddContractToCity(3, DelieveryContractFactory.CreateContract(2, 212, 33, 1554)); // 34 World.AddContractToCity(4, DelieveryContractFactory.CreateContract(0, 242, 15, 9349)); // 35 World.AddContractToCity(4, DelieveryContractFactory.CreateContract(2, 782, 73, 9949)); // 36 /* * 0;1;100;10;1000; * 0;2;100;20;2000; * 0;3;100;30;3000; * 0;1;100;10;1000; * 0;2;100;20;2000; * 0;3;300;30;3000; * 0;1;100;10;1000; * 0;2;100;20;2000; * 0;3;300;30;3000; * 1;4;110;10;1011; * 1;2;220;23;2022; * 1;4;110;10;1011; * 1;2;100;23;2022; * 1;4;110;10;1011; * 1;2;100;23;2022; * 1;4;110;10;1011; * 1;2;220;23;2022; * 2;1;330;44;2242; * 2;0;320;14;1242; * 2;0;330;44;2242; * 2;2;320;14;1242; * 2;2;330;44;2242; * 2;2;320;14;1242; * 3;4;222;12;1234; * 3;2;212;33;1554; * 3;4;222;12;1234; * 3;4;222;12;1234; * 3;4;222;12;1234; * 3;4;222;12;1234; * 3;4;222;12;1234; * 3;4;222;12;1234; * 3;2;212;33;1554; * 3;2;212;33;1554; * 3;2;212;33;1554; * 3;2;212;33;1554; * 4;0;242;15;9349; * 4;2;782;73;9949; */ #endregion DataInput.PrepCityAndContractCounters(); #region Locomotive start parameters Locomotive.CurrentLocationID = 0; Locomotive.MaxWeight = 15_000; Locomotive.MaxWaggonCount = 112; #endregion #region Data output Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "tests"); DataOutput.OutputPath = AppDomain.CurrentDomain.BaseDirectory + "tests"; DataOutput.SaveFileName = "default_test_plan"; #endregion #region Algorythm parameters AlgorithmImplementation.MaxCityVisited = 4; AlgorithmImplementation.Seed = 69; AlgorithmImplementation.MainLoopTemperature = 100; AlgorithmImplementation.ContractLoopTemperature = 100; AlgorithmImplementation.MainLoopAlpha = 0.8; AlgorithmImplementation.ContractLoopAlpha = 0.8; #endregion #endregion ShowContracts(); ShowMatrix(); Console.WriteLine("Test plan data will be saved at " + DataOutput.OutputPath + "\n"); } Console.WriteLine("Press 'Enter' to start the algorithm"); Console.ReadLine(); // ============================== The M A G I C AlgorithmImplementation.Solve(); // ============================== Console.ReadLine(); }