public CityTSM() { IList <City> cities = new List <City>(); cities.Add(new City("Dresden", 51.050407, 13.737262)); cities.Add(new City("Freiburg", 47.997791, 7.842609)); cities.Add(new City("Grimma", 51.236443, 12.720231)); cities.Add(new City("Gera", 50.884842, 12.079811)); cities.Add(new City("Bremen", 53.073635, 8.806422)); cities.Add(new City("Darmstadt", 49.878708, 8.646927)); cities.Add(new City("Berlin", 52.520008, 13.404954)); cities.Add(new City("Munich", 48.137154, 11.576124)); IProblem <City> problem = new ProblemBuilder <City>() .Locations(cities) .Distances((City c1, City c2) => DistFrom(c1.lat, c1.lon, c2.lat, c2.lon)) .FixedFirstLocation(0) .BuildIntegerArray(); //ISolver<City> solver = new NearestNeighborSolver<City>(problem) ISolver <City> solver = new ParallelBranchBoundSolver <City>(problem); IPath <City> path = solver.Solve(); System.Console.Out.WriteLine(solver.ToString()); System.Console.Out.WriteLine("\tbest=" + path); }
public void Run(string filename) { Dictionary <string, Pin> startPins = new Dictionary <string, Pin>(); Dictionary <string, List <Pin> > pinMap = new Dictionary <string, List <Pin> >(); FileInfo file = new FileInfo(filename); using (ExcelPackage excel = new ExcelPackage(file)) { //foreach (ExcelWorksheet worksheet in excel.Workbook.Worksheets.) ExcelWorksheet worksheet = excel.Workbook.Worksheets["Datensatz1"]; { for (int l = 2; l <= worksheet.Dimension.End.Row; l++) { double xPos = GetValue(worksheet.Cells[l, 1].Value); double yPos = GetValue(worksheet.Cells[l, 2].Value); double zPos = GetValue(worksheet.Cells[l, 3].Value); string pinType = (string)worksheet.Cells[l, 4].Value; string circuit = (string)worksheet.Cells[l, 5].Value; Pin pin = new Pin(pinType, circuit, xPos, yPos, zPos); Match match = Regex.Match(circuit, "(.*) (F\\d+)", RegexOptions.IgnoreCase); if (match.Success) { string parentCircuit = match.Groups[1].Value; List <Pin> pins = null; if (pinMap.ContainsKey(circuit)) { pins = pinMap[circuit]; } else { pins = new List <Pin>(); pinMap.Add(circuit, pins); } pins.Add(pin); } else { startPins.Add(circuit, pin); } Debug.WriteLine(circuit + " - " + xPos + ":" + yPos + ":" + zPos); } } } foreach (KeyValuePair <string, List <Pin> > entry in pinMap) { string circuit = entry.Key; List <Pin> pins = entry.Value; Pin startPin = null; Match match = Regex.Match(circuit, "(.*) (F\\d+)", RegexOptions.IgnoreCase); if (match.Success) { string key = match.Groups[1].Value; startPin = startPins[match.Groups[1].Value]; } IProblem <Pin> problem = new ProblemBuilder <Pin>() .Locations(pins) .Distances((Pin p1, Pin p2) => CalcDistance(p1, p2)) .FixedFirstLocation(startPin) .BuildIntegerArray(); ISolver <Pin> solverNN = new NearestNeighborSolver <Pin>(problem); ISolver <Pin> solverPBB = new ParallelBranchBoundSolver <Pin>(problem); Stopwatch stopWatch = new Stopwatch(); System.Console.Out.WriteLine("Circuit: " + circuit); System.Console.Out.WriteLine("\tNN = " + solverNN.Solve()); stopWatch.Start(); System.Console.Out.WriteLine("\tPBB= " + solverPBB.Solve()); stopWatch.Stop(); System.Console.Out.WriteLine("\t\t time = " + stopWatch.Elapsed); } }