Commit dd36e456 authored by Tong Li's avatar Tong Li

优化非分配排序

parent 4965288c
......@@ -110,12 +110,12 @@ public class GeneticAlgorithm {
FileHelper.writeLogFile("初始化批量解码-----------开始-------");
Chromosomedecode(param,allOperations,globalOpList,population);
FileHelper.writeLogFile("初始化批量解码-----------结束-------");
List<List<Chromosome>> fronts = _nsgaIIUtils.parallelFastNonDominatedSort(population);
List<List<Chromosome>> combinedFronts = _nsgaIIUtils.parallelFastNonDominatedSort(population);
int ordercount = globalOpList.stream()
.mapToInt(GlobalOperationInfo::getGroupId)
.max()
.orElse(0);
Chromosome best=GetBest(fronts,"初始");
Chromosome best=GetBest(combinedFronts,"初始");
// best=fronts.get(0).stream()
// .max(Comparator.comparingDouble(Chromosome::getFitness))
......@@ -165,6 +165,7 @@ public class GeneticAlgorithm {
List<Chromosome> nextPopulation = new ArrayList<>();
for (int i = 0; i < selected.size(); i += 2) {
if (i + 1 >= selected.size()) {
selected.get(i).setID(UUID.randomUUID().toString());
nextPopulation.add(selected.get(i));
break;
}
......@@ -188,6 +189,7 @@ public class GeneticAlgorithm {
for (Chromosome chromosome : nextPopulation) {
if (rnd.nextDouble() < param.getMutationProb()) {
Chromosome chromosome1= ProductionDeepCopyUtil.deepCopy(chromosome,Chromosome.class);
chromosome1.setID(UUID.randomUUID().toString());
geneticOps.mutate(chromosome1, globalOpList);
nextPopulation1.add(chromosome1);
}
......@@ -209,12 +211,15 @@ public class GeneticAlgorithm {
// List<Chromosome> elites = population1.subList(0, param.getElitismCount());
List<Chromosome> newPopulation = new ArrayList<>();
newPopulation.addAll(population);
//保留一定数量的上一代
List<Chromosome> populationcopy = _nsgaIIUtils.selectNextPopulation(combinedFronts, param.getPopulationSize()/5);
newPopulation.addAll(populationcopy);
newPopulation.addAll(nextPopulation);
newPopulation= chromosomeDistinct1(newPopulation);
FileHelper.writeLogFile("非支配排序-----------开始-------");
// 2.7 非支配排序
List<List<Chromosome>> combinedFronts = _nsgaIIUtils.parallelFastNonDominatedSort(newPopulation);
combinedFronts = _nsgaIIUtils.parallelFastNonDominatedSort(newPopulation);
FileHelper.writeLogFile("非支配排序-----------结束-------");
// 2.8 选择下一代种群
population = _nsgaIIUtils.selectNextPopulation(combinedFronts, param.getPopulationSize());
......@@ -291,14 +296,9 @@ return population;
}
FileHelper.writeLogFile(String.format("排产-----------方案数量---%d-------",population.size() ));
List<Chromosome> population1 = population.stream().filter(t->t.getGeneStr()==null).collect(Collectors.toList());
if(population1!=null&&population1.size()>0)
{
FileHelper.writeLogFile(String.format("排产-----------方案GeneStrnull数量---%d-------",population1.size() ));
}
population = population.stream()
.collect(Collectors.toMap(
Chromosome::getGeneStr, // key:去重的字段(GeneStr)
......@@ -308,7 +308,6 @@ if(population1!=null&&population1.size()>0)
.values() // 获取去重后的
.stream()
.collect(Collectors.toList());
FileHelper.writeLogFile(String.format("排产-----------方案数量---%d-------",population.size() ));
return population;
}
......@@ -321,14 +320,9 @@ if(population1!=null&&population1.size()>0)
}
FileHelper.writeLogFile(String.format("排产-----------方案数量---%d-------",population.size() ));
List<Chromosome> population1 = population.stream().filter(t->t.getGeneStr()==null).collect(Collectors.toList());
if(population1!=null&&population1.size()>0)
{
FileHelper.writeLogFile(String.format("排产-----------方案GeneStrnull数量---%d-------",population1.size() ));
}
population = population.stream()
.collect(Collectors.toMap(
Chromosome::getGeneStr, // key:去重的字段(GeneStr)
......@@ -338,7 +332,6 @@ if(population1!=null&&population1.size()>0)
.values() // 获取去重后的
.stream()
.collect(Collectors.toList());
FileHelper.writeLogFile(String.format("排产-----------方案数量---%d-------",population.size() ));
return population;
}
......
......@@ -39,7 +39,7 @@ public class PlanResultServiceTest {
// nsgaiiUtils.Test();
//planResultService.execute2("C5FB5EF2A7334A0A92F826F4937E1008");
// planResultService.execute2("726D4C1A712B4B1393175BD44B775B66");
planResultService.execute2("13CC1CF783CE40D7AE3264D09FAA6378");
planResultService.execute2("265F24B6DF3C40E4B17D193B0CC8AAF2");
// LocalDateTime t= LocalDateTime.of(2025, 11, 15, 6, 51, 11);
// List<Integer> opids=new ArrayList<>();BCA6FA43FFA444D3952CF8F6E1EA291B
// opids.add(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment