static void Main(string[] args) { string directoryPath = AppDomain.CurrentDomain.BaseDirectory; string sTopologyFile = directoryPath + @"Dane\dd.net"; string sRoutesFile = @"Dane\d.PAT"; string sSlotsFile = @"Dane\d1.spec"; string sRequestFile = @"Dane\51.dem"; CGlobalManager _manager = new CGlobalManager(); CGlobalManager.LoadLinks(sTopologyFile); CGlobalManager.LoadRoutes(sRoutesFile); CGlobalManager.LoadRequests(sRequestFile); CGlobalManager.LoadRouteSlotMappings(sSlotsFile); AnnealingAlgorithm alg = new AnnealingAlgorithm(); Solution sol = alg.CalculateSolution(); Console.WriteLine("---------------------------------------------------------------"); sol.PrintSolution(99999); Console.ReadKey(); }
//loading links to global manager public static void LoadLinks(string topologyFilePath){ if (GlobalLinkList.Count == 0) { CGlobalManager manager = new CGlobalManager(); using (StreamReader topologyFile = new StreamReader(topologyFilePath)) { int nodeQuantity = 0; int linkQuantity = 0; int lineCounter = 0; string line; while ((line = topologyFile.ReadLine()) != null) { if (lineCounter == 0) { Int32.TryParse(line, out nodeQuantity); lineCounter++; } else if (lineCounter == 1) { Int32.TryParse(line, out linkQuantity); lineCounter++; } else { List<int> _line = line.Split('\t').Select(Int32.Parse).ToList(); int nodeA = lineCounter - 2; List<CLink> linkList = manager.CalculateLinksFromLine(nodeA, _line); foreach (var link in linkList) { GlobalLinkList.Add(link); } lineCounter++; } } } } }
//Loading routes to global manager public static void LoadRoutes(string routeFilePath) { if (GlobalRoutesList.Count == 0) { CGlobalManager _manager = new CGlobalManager(); using (StreamReader routeFile = new StreamReader(routeFilePath)) { int routesQuantity = 0; //propably useless information int lineCounter = 0; int startNodeNumber = 0; int endNodeNumber = 1; string line; while ((line = routeFile.ReadLine()) != null) { if (lineCounter == 0) { Int32.TryParse(line, out routesQuantity); lineCounter++; } else { List<int> list = line.Split(' ').Select(Int32.Parse).ToList(); List<int> linkIndexes = _manager.CalculateRouteFromBinary(list); if (startNodeNumber == endNodeNumber) { endNodeNumber++; } GlobalRoutesList.Add(new CRoute(lineCounter - 1, startNodeNumber, endNodeNumber, linkIndexes)); if (lineCounter % 30 == 0) { endNodeNumber++; } if (lineCounter % 390 == 0) { startNodeNumber++; endNodeNumber = 0; } lineCounter++; } } } } }