static void Main(string[] args) { //Dependency injection setup beigns // create service collection var serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection); // create service provider var serviceProvider = serviceCollection.BuildServiceProvider(); //Dependency injection setup ends var filename = "ColorTattooPNGFile"; var png = new PngFile(filename); var svg = new SvgFile("S1000Z0point8NoOverlapColorTattooPNGFile"); var tsp = new TspFile(filename); var tspSol = new TspSolFile("S1000Z0point8NoOverlapColorTattooPNGFile"); tsp.Dimension = 1000; //var stipplerServices = serviceProvider.GetRequiredService<IStippler>(); //Console.WriteLine(stipplerServices.CallStippler(png, 1000, 0.8)); var tspServices = serviceProvider.GetRequiredService <IGcodeCreator>(); //Console.WriteLine(tspServices.ConvertCircleSVGtoTSP(svg)); //Console.WriteLine(tspServices.ReorderSVGAccordingtoTSPsol(svg, tspSol, tsp)); Console.Read(); }
public string ReorderSVGAccordingtoTSPsol(string tspSolFile, string FileToReorder) { var tspSolfile = new TspSolFile(tspSolFile); var oldSvgFile = new SvgFile(FileToReorder); try { using (StreamReader oldSvgReader = new StreamReader($"{Constants.INPUTOUTPUT_FOLDER_RELATIVE_PATH}{oldSvgFile.FullFileName}")) { var reorderedSvgFile = new SvgFile($"Reordered{oldSvgFile.FullFileName}"); using (StreamWriter reorderedSvgWriter = new StreamWriter($"{Constants.INPUTOUTPUT_FOLDER_RELATIVE_PATH}{reorderedSvgFile.FullFileName}")) { List <int> tspSolOrder = GetTspSolLineOrder(tspSolfile); if (tspSolOrder.Count > 1) { int numberOfCities = tspSolOrder[0]; tspSolOrder.RemoveAt(0); string line; var lineorder = currentLineOrder(oldSvgFile); var count = 0; while ((line = oldSvgReader.ReadLine()) != null) { if (!line.Contains("circle")) { reorderedSvgWriter.WriteLine(line); } else { var correctOrder = tspSolOrder[count]; reorderedSvgWriter.WriteLine(lineorder[correctOrder]); count++; } } return($"{Constants.SUCCESS}-The file {reorderedSvgFile.FullFileName} has been created."); } return(Constants.FAILURE); } } } catch (Exception e) { Console.WriteLine(e.Message); return($"{Constants.FAILURE}- {e.Message}"); } }
/*Example beginning of a tspSolFile * *** *** * * * *** You chose the Concorde(CPLEX) solver *** *** *** *** *** Cities are numbered 0..n-1 and each line shows a leg from one city to the next ***followed by the distance rounded to integers*** *** ***1000 1000 ***0 586 22 //Begins with city 0, travel to city 586, which is a distance of 22 units ***586 15 18 ***15 477 22 *** *** ***PDF of optimal tour***unzip this file*** *** *** *** ***Additional Output: https://neos-server.org/neos/jobs/5750000/5754106-lLSnsAIU-solver-output.zip */ //returns a list of integers. First is the number of cities considered. The rest of the numbers are the order of the optimal city tour, where each number represents a city in the original .tsp file private static List <int> GetTspSolLineOrder(TspSolFile tspSolFile) { var tspSolOrder = new List <int>(); string line; int firstTspCity, secondTspCity, tspDistance; try { using (StreamReader tspSolReader = new StreamReader($"{Constants.INPUTOUTPUT_FOLDER_RELATIVE_PATH}{tspSolFile.FullFileName}")) { while ((line = tspSolReader.ReadLine()) != null) { var linesplit = line.Split(null); if (linesplit.Length == 2) { int.TryParse((line.Split(null))[0], out firstTspCity);//split at whitespace, take first part and attempt to parse to int int.TryParse((line.Split(null))[1], out secondTspCity); if (firstTspCity == secondTspCity && firstTspCity != 0)// eg: 5 5 { tspSolOrder.Add(firstTspCity); } } else if (linesplit.Length == 3) { int.TryParse((line.Split(null))[0], out firstTspCity);//split at whitespace, take first part and attempt to parse to int int.TryParse((line.Split(null))[1], out secondTspCity); int.TryParse((line.Split(null))[2], out tspDistance); if (tspDistance != 0 && (firstTspCity != 0 || secondTspCity != 0))//eg: 0 2 433 { tspSolOrder.Add(firstTspCity); } } } return(tspSolOrder); } } catch (Exception e) { Console.WriteLine(e.Message); return(tspSolOrder); } }