public void launchWorkers(NestItem[] parts) { background.ResponseAction = ResponseProcessor; if (ga == null) { List <NFP> adam = new List <NFP>(); var id = 0; for (int i = 0; i < parts.Count(); i++) { if (!parts[i].IsSheet) { for (int j = 0; j < parts[i].Quanity; j++) { var poly = cloneTree(parts[i].Polygon); // deep copy poly.id = id; // id is the unique id of all parts that will be nested, including cloned duplicates poly.source = i; // source is the id of each unique part from the main part list adam.Add(poly); id++; } } } adam = adam.OrderByDescending(z => Math.Abs(GeometryUtil.polygonArea(z))).ToList(); /*List<NFP> shuffle = new List<NFP>(); * Random r = new Random(DateTime.Now.Millisecond); * while (adam.Any()) * { * var rr = r.Next(adam.Count); * shuffle.Add(adam[rr]); * adam.RemoveAt(rr); * } * adam = shuffle;*/ /*#region special case * var temp = adam[1]; * adam.RemoveAt(1); * adam.Insert(9, temp); * #endregion*/ ga = new GeneticAlgorithm(adam.ToArray(), Config); } individual = null; // check if current generation is finished var finished = true; for (int i = 0; i < ga.population.Count; i++) { if (ga.population[i].fitness == null) { finished = false; break; } } if (finished) { //console.log('new generation!'); // all individuals have been evaluated, start next generation ga.generation(); } var running = ga.population.Where((p) => { return(p.processing != null); }).Count(); List <NFP> sheets = new List <NFP>(); List <int> sheetids = new List <int>(); List <int> sheetsources = new List <int>(); List <List <NFP> > sheetchildren = new List <List <NFP> >(); var sid = 0; for (int i = 0; i < parts.Count(); i++) { if (parts[i].IsSheet) { var poly = parts[i].Polygon; for (int j = 0; j < parts[i].Quanity; j++) { var cln = cloneTree(poly); cln.id = sid; // id is the unique id of all parts that will be nested, including cloned duplicates cln.source = poly.source; // source is the id of each unique part from the main part list sheets.Add(cln); sheetids.Add(sid); sheetsources.Add(i); sheetchildren.Add(poly.children); sid++; } } } for (int i = 0; i < ga.population.Count; i++) { //if(running < config.threads && !GA.population[i].processing && !GA.population[i].fitness){ // only one background window now... if (running < 1 && ga.population[i].processing == null && ga.population[i].fitness == null) { ga.population[i].processing = true; // hash values on arrays don't make it across ipc, store them in an array and reassemble on the other side.... List <int> ids = new List <int>(); List <int> sources = new List <int>(); List <List <NFP> > children = new List <List <NFP> >(); for (int j = 0; j < ga.population[i].placements.Count; j++) { var id = ga.population[i].placements[j].id; var source = ga.population[i].placements[j].source; var child = ga.population[i].placements[j].children; //ids[j] = id; ids.Add(id); //sources[j] = source; sources.Add(source.Value); //children[j] = child; children.Add(child); } DataInfo data = new DataInfo() { index = i, sheets = sheets, sheetids = sheetids.ToArray(), sheetsources = sheetsources.ToArray(), sheetchildren = sheetchildren, individual = ga.population[i], config = Config, ids = ids.ToArray(), sources = sources.ToArray(), children = children }; background.BackgroundStart(data); //ipcRenderer.send('background-start', { index: i, sheets: sheets, sheetids: sheetids, sheetsources: sheetsources, sheetchildren: sheetchildren, individual: GA.population[i], config: config, ids: ids, sources: sources, children: children}); running++; } } }