static void poolProcesses() { int[] waits = new int[] { 3, 9, 2, 1, 12, 14, 3, 5 }; string shellArgs = "python _testLS.py "; System.Diagnostics.Process[] processes = new System.Diagnostics.Process[waits.Length]; string workingDir = Application.dataPath + "/LKHProbs~"; CMDProcessPool pool = new CMDProcessPool(3); print("add jobs"); for (int i = 0; i < waits.Length; ++i) { string arg = shellArgs + waits[i]; pool.Add(new ProcessSettings { workingDirectory = workingDir, args = arg }); } print("will run"); pool.run(); print("done with pool"); }
public override IEnumerable <PenDrawingPath> generate() { CMDProcessPool pool = new CMDProcessPool(generatorConfig.MaxTSPThreads); TSPLibProblem[] tsps = new TSPLibProblem[pointSets.Count]; // // foreach list of points // make a tsp problem. // add it to the LKH job pool if no output file exists // for (int i = 0; i < pointSets.Count; ++i) { TSPLibProblem tsp = TSPLibProblem.FromPoints(pointSets[i].GetEnumerator(), BaseFileName + "." + i); if (!tsp.OutputFileExists()) { pool.Add(tsp.GetTSPCommand()); } tsps[i] = tsp; } pool.run(); // Output files should now exists for all tsp problems // create pen drawing paths from each of them for (int i = 0; i < pointSets.Count; ++i) { yield return(fromTSP(tsps[i], pointSets[i])); } }
void SolveTriTree(PenDrawingPath pdPath) { //CONSIDER: two passes // 1.) Dark very detailed // 2.) mid to light don't sweat the details as much //split tri tree leaves if not sufficiently populated if (generatorConfig.ShouldSplitUnderFilledTris) { triTree.root.SplitUnderPopulatedLeaves(generatorConfig.TriFilledThreshold, generatorConfig.MaxSplitToFillRecursionDepth); } triTree.root.CullDataWithMaxMean(bitMapPointGenerator.MaxGrayScale); List <IsoTriangle <PixelTriData> > subTrees; // split tree into max cities sub trees subTrees = triTree.root.NonEmptyChildrenWithMaxLeaves(generatorConfig.MaxTSPTriangleCities); //DEBUG var meshGO = MeshUtil.MakeGameObject(triTree.getMesh(), "CrosshatchTriTree"); var pool = new CMDProcessPool(generatorConfig.MaxTSPThreads); var subLeaves = new List <IsoTriangle <PixelTriData> > [subTrees.Count]; var tsps = new TSPLibProblem[subTrees.Count]; //DEBUG delete any previously generated files TSPLibProblem.GetDeleteAllCommand(BaseFileName + "*").ToCMDProcess().run(); for (int i = 0; i < subTrees.Count; ++i) { var tree = subTrees[i]; //get leaf centers var leaves = tree.GetLeaves(true); var centers = new List <Vector2f>(leaves.Count); for (int j = 0; j < leaves.Count; ++j) { centers.Add(leaves[j].center); } // solve each sub tree var tsp = TSPLibProblem.FromPoints(centers.GetEnumerator(), BaseFileName + ".tri." + i); if (!tsp.OutputFileExists()) { pool.Add(tsp.GetTSPCommand()); } subLeaves[i] = leaves; tsps[i] = tsp; } pool.run(); for (int i = 0; i < subTrees.Count; ++i) { // crosshatch sub trees var tsp = tsps[i]; if (!tsp.setIndicesFromOutputFile()) { Debug.LogWarning("no tsp indices"); continue; //TODO: handle more gracefully } var leaves = subLeaves[i]; TriCrosshatch <PixelTriData> tch = null, last = null; for (int j = 0; j < leaves.Count; ++j) { tch = new TriCrosshatch <PixelTriData>(this, leaves[tsp.indexAt(j)]); tch.last = last; tch.next = j == leaves.Count - 1 ? null : new TriCrosshatch <PixelTriData>(this, leaves[tsp.indexAt(j + 1)]); tch.AddDrawPoints(pdPath, viewBoxToPaperScale, (float)machineConfig.toolDiameterMM); last = tch; } } }