//Single sigma version private void evolution(int p_i, string logfile) { int[] parent = new int[lambda]; int allpopulationsize = lambda + M;//lambda + M strategy esvariable[] tmppopulation = new esvariable[allpopulationsize]; //Copy parents to the tmppopulation if (!allsearch) { for (int i = 0; i < M; i++) { esvariable prt = new esvariable(size, parents[i].getx(), l, u, wh, numberoforders, computing, routingSolver, mysocketservers);//re-evaluate parents since numberoforders might have changed tmppopulation[i] = prt; } ; } else { for (int i = 0; i < M; i++) { tmppopulation[i] = parents[i]; } ; } //Create lambda number of children from their parents for (int i = 0; i < lambda; i++) { //bool infeasibledesign = true; int index = M + i; parent[i] = Convert.ToInt32(i * M / lambda);//Select each parent in a deterministic way double[] x = new double[size]; esvariable child = null; { //Create this part only p for (int k = 0; k < l.Count(); k++) { x[k] = parents[parent[i]].getx()[k] + normalDist(0, sigma, rnd1[i]); //Single sigma is used } setx(x); //Check if they are out of bounds and correct them, this has to be done in here before creating aisles randomly for (int k = l.Count(); k < size; k++) //It won't enter this loop unless it is new encoding { int indexencodingprobability = k - (this.size - l.Count()); if (x[indexencodingprobability] == 1) { x[k] = 1; } else if (x[indexencodingprobability] == 0) { x[k] = 0; } else { if (uniformrandom(0, 1, rnd1[i]) < x[indexencodingprobability])//If random number is lower than the probability of creating that aisle than instance is 0 { x[k] = 0; } else { x[k] = 1; } } } child = new esvariable(size, x, l, u, wh, numberoforders, computing, routingSolver, mysocketservers); //writeLog(logfile, child); } tmppopulation[index] = child; if (!usenft)//Do not use Near Feasibility Threshold { //If created child is better than parent then increase counter if (child.getCost() < parents[parent[i]].getCost()) { numberofsuccessfulchildrencreated++; numberofsuccessfulchildrencreatedperiteration++; } } else//Use Near Feasibility Threshold { //If created child is better than parent then increase counter if (child.getCost(p_i + 1, nft0, nftlambda) < parents[parent[i]].getCost(p_i + 1, nft0, nftlambda)) { numberofsuccessfulchildrencreated++; numberofsuccessfulchildrencreatedperiteration++; } } numberofchildrencreated++; } if (!usenft) { tmppopulation = sortPopulation(tmppopulation);//Sort lambda + M } else { tmppopulation = sortPopulation(tmppopulation, p_i); } for (int i = 0; i < M; i++)//Select best M individuals as new parents { parents[i] = tmppopulation[i]; } }
/// <summary> /// Write each solution (each child) to a log file /// </summary> /// <param name="p_logfile">Location of the log file</param> /// <param name="p_esvar">ES solution</param> private void writeLog(string p_logfile, esvariable p_esvar) { csvexport myexcel = new csvexport(); myexcel.addRow(); myexcel["Cost"] = ""; myexcel["Locs"] = ""; myexcel["SR"] = ""; myexcel["Width"] = p_esvar.getWarehouse().getWidth().ToString(); myexcel["Depth"] = p_esvar.getWarehouse().getDepth().ToString(); myexcel["Area"] = p_esvar.getWarehouse().area.ToString(); myexcel["Ratio"] = p_esvar.getx()[0].ToString(); myexcel["E1"] = p_esvar.getx()[1].ToString(); myexcel["E2"] = p_esvar.getx()[2].ToString(); myexcel["E3"] = p_esvar.getx()[3].ToString(); myexcel["E4"] = p_esvar.getx()[4].ToString(); myexcel["I1X"] = p_esvar.getx()[5].ToString(); myexcel["I1Y"] = p_esvar.getx()[6].ToString(); myexcel["PD"] = p_esvar.getx()[7].ToString(); myexcel["Angle1"] = (180 * p_esvar.getx()[8]).ToString(); myexcel["Angle2"] = (180 * p_esvar.getx()[9]).ToString(); myexcel["Angle3"] = (180 * p_esvar.getx()[10]).ToString(); myexcel["Angle4"] = (180 * p_esvar.getx()[11]).ToString(); myexcel["Angle5"] = (180 * p_esvar.getx()[12]).ToString(); myexcel["Angle6"] = (180 * p_esvar.getx()[13]).ToString(); myexcel["Angle7"] = (180 * p_esvar.getx()[14]).ToString(); myexcel["Angle8"] = (180 * p_esvar.getx()[15]).ToString(); myexcel["Adjuster1"] = p_esvar.getx()[16].ToString(); myexcel["Adjuster2"] = p_esvar.getx()[17].ToString(); myexcel["Adjuster3"] = p_esvar.getx()[18].ToString(); myexcel["Adjuster4"] = p_esvar.getx()[19].ToString(); myexcel["Adjuster5"] = p_esvar.getx()[20].ToString(); myexcel["Adjuster6"] = p_esvar.getx()[21].ToString(); myexcel["Adjuster7"] = p_esvar.getx()[22].ToString(); myexcel["Adjuster8"] = p_esvar.getx()[23].ToString(); myexcel["PickAdjuster1"] = p_esvar.getx()[24].ToString(); myexcel["PickAdjuster2"] = p_esvar.getx()[25].ToString(); myexcel["PickAdjuster3"] = p_esvar.getx()[26].ToString(); myexcel["PickAdjuster4"] = p_esvar.getx()[27].ToString(); myexcel["PickAdjuster5"] = p_esvar.getx()[28].ToString(); myexcel["PickAdjuster6"] = p_esvar.getx()[29].ToString(); myexcel["PickAdjuster7"] = p_esvar.getx()[30].ToString(); myexcel["PickAdjuster8"] = p_esvar.getx()[31].ToString(); myexcel["PC12"] = p_esvar.getx()[32].ToString(); myexcel["PC13"] = p_esvar.getx()[33].ToString(); myexcel["PC14"] = p_esvar.getx()[34].ToString(); myexcel["PC15"] = p_esvar.getx()[35].ToString(); myexcel["PC23"] = p_esvar.getx()[36].ToString(); myexcel["PC24"] = p_esvar.getx()[37].ToString(); myexcel["PC25"] = p_esvar.getx()[38].ToString(); myexcel["PC34"] = p_esvar.getx()[39].ToString(); myexcel["PC35"] = p_esvar.getx()[40].ToString(); myexcel["PC45"] = p_esvar.getx()[41].ToString(); myexcel["C12"] = p_esvar.getx()[42].ToString(); myexcel["C13"] = p_esvar.getx()[43].ToString(); myexcel["C14"] = p_esvar.getx()[44].ToString(); myexcel["C15"] = p_esvar.getx()[45].ToString(); myexcel["C23"] = p_esvar.getx()[46].ToString(); myexcel["C24"] = p_esvar.getx()[47].ToString(); myexcel["C25"] = p_esvar.getx()[48].ToString(); myexcel["C34"] = p_esvar.getx()[49].ToString(); myexcel["C35"] = p_esvar.getx()[50].ToString(); myexcel["C45"] = p_esvar.getx()[51].ToString(); myexcel.appendToFile(p_logfile); }
/// <summary> /// Creates initial population for ES /// </summary> public void createInitialParentPopulation() { parents = new esvariable[M]; for (int i = 0; i < this.M; i++) { double[] x = new double[this.size]; for (int j = 0; j < l.Count(); j++) { if (l[j] != u[j]) { x[j] = uniformrandom(l[j], u[j], rnd[i]); } else { x[j] = l[j]; } } //This part is for connection instances part of the encoding for (int j = l.Count(); j < this.size; j++) { int indexencodingprobability = j - (this.size - l.Count()); if (x[indexencodingprobability] == 1) { x[j] = 1; } else if (x[indexencodingprobability] == 0) { x[j] = 0; } else { if (uniformrandom(0, 1, rnd1[i]) < x[indexencodingprobability])//If random number is lower than the probability of creating that aisle than instance is 0 { x[j] = 0; } else { x[j] = 1; } } } numberofgaps = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(iteration) / Convert.ToDouble(this.counter))); if (allsearch) { numberoforders = wh.getOrders().Count(); } else { numberoforders = Convert.ToInt32(1 / Convert.ToDouble(numberofgaps) * wh.getOrders().Count()); } //string logfile = "log.csv"; esvariable p = new esvariable(size, x, l, u, wh, numberoforders, computing, routingSolver, mysocketservers); //writeLog(logfile, p); if (p.isInfeasible() == false) { parents[i] = p;//add to population } else { i--;//Do this iteration again } } if (!usenft)//Without Near Feasibility Threshold { parents = sortPopulation(parents); } else//With Near Feasibility Threshold { parents = sortPopulation(parents, 0); } }