Commit fa7cf28d authored by Tong Li's avatar Tong Li

Merge remote-tracking branch 'origin/tl'

parents a46c938c 2e356235
...@@ -2756,4 +2756,49 @@ public class GeneticDecoder { ...@@ -2756,4 +2756,49 @@ public class GeneticDecoder {
// return machineStr + "_" + operationStr; // return machineStr + "_" + operationStr;
} }
public void DelOrder(Chromosome chromosome) {
List<Entry> allOperations = chromosome.getAllOperations();
List<GlobalOperationInfo> globalOpList= chromosome.getGlobalOpList();
if(chromosome.getOrders()==null||chromosome.getOrders().size()==0)
return;
List<Order> orders = chromosome.getOrders();
List<Integer> OperationSequencing= chromosome.getOperationSequencing();
List<Integer> newoorderids= orders.stream()
.filter(t->t.isNewSfCreate())
.map(Order::getId)
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
if(newoorderids!=null&&newoorderids.size()>0) {
for (Integer id : newoorderids) {
List<Entry> sourceOps = allOperations.stream()
.filter(o -> o.getGroupId()==id)
.sorted(Comparator.comparing(Entry::getSequence))
.collect(Collectors.toList());
for (Entry entry : sourceOps) {
OptionalInt index1 = IntStream.range(0, globalOpList.size())
.filter(h -> entry.getId()==globalOpList.get(h).getOp().getId())
.findFirst();
globalOpList.remove((int)index1.orElse(0));
chromosome.getMachineSelection().remove((int)index1.orElse(0));
}
chromosome.getOperatRel().remove(id-1);
}
allOperations.removeIf(t ->newoorderids.contains(t.getGroupId()));
OperationSequencing.removeIf(t ->newoorderids.contains(t));
AtomicInteger globalOpId = new AtomicInteger(0);
globalOpList.forEach(t-> {
t.setGlobalOpId(globalOpId.getAndIncrement());
});
orders.removeIf(t ->newoorderids.contains(t.getId()));
}
}
} }
...@@ -74,6 +74,7 @@ public class HillClimbing { ...@@ -74,6 +74,7 @@ public class HillClimbing {
*/ */
public Chromosome searchAll(Chromosome chromosome, List<Machine> machines, GeneticDecoder decoder) { public Chromosome searchAll(Chromosome chromosome, List<Machine> machines, GeneticDecoder decoder) {
Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
decoder.DelOrder(current);
Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
...@@ -116,6 +117,7 @@ public class HillClimbing { ...@@ -116,6 +117,7 @@ public class HillClimbing {
positionIndex = buildPositionIndex(current); positionIndex = buildPositionIndex(current);
entryIndex = buildEntryIndex(current, entrys); entryIndex = buildEntryIndex(current, entrys);
MachinePositionIndex = buildEntryMachinePositionIndex(current); MachinePositionIndex = buildEntryMachinePositionIndex(current);
decoder.DelOrder(current);
break; break;
} }
} }
...@@ -235,6 +237,7 @@ public class HillClimbing { ...@@ -235,6 +237,7 @@ public class HillClimbing {
current =ProductionDeepCopyUtil.deepCopy(best, Chromosome.class); current =ProductionDeepCopyUtil.deepCopy(best, Chromosome.class);
positionIndex = buildPositionIndex(current); positionIndex = buildPositionIndex(current);
entryIndex = buildEntryIndex(current, entrys); entryIndex = buildEntryIndex(current, entrys);
decoder.DelOrder(current);
} }
} }
} }
...@@ -243,6 +246,7 @@ public class HillClimbing { ...@@ -243,6 +246,7 @@ public class HillClimbing {
public Chromosome search(Chromosome chromosome, GeneticDecoder decoder , List<Machine> machines) { public Chromosome search(Chromosome chromosome, GeneticDecoder decoder , List<Machine> machines) {
Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
decoder.DelOrder(current);
Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
...@@ -289,6 +293,7 @@ public class HillClimbing { ...@@ -289,6 +293,7 @@ public class HillClimbing {
MachinePositionIndex = buildEntryMachinePositionIndex(current); MachinePositionIndex = buildEntryMachinePositionIndex(current);
break; break;
} }
decoder.DelOrder(current);
} }
} }
if (improved) break; if (improved) break;
...@@ -353,6 +358,7 @@ public class HillClimbing { ...@@ -353,6 +358,7 @@ public class HillClimbing {
noImproveCount=0; noImproveCount=0;
positionIndex = buildPositionIndex(current); positionIndex = buildPositionIndex(current);
entryIndex = buildEntryIndex(current, entrys); entryIndex = buildEntryIndex(current, entrys);
decoder.DelOrder(current);
break; break;
} }
} }
...@@ -382,6 +388,7 @@ public class HillClimbing { ...@@ -382,6 +388,7 @@ public class HillClimbing {
noImproveCount=0; noImproveCount=0;
positionIndex = buildPositionIndex(current); positionIndex = buildPositionIndex(current);
entryIndex = buildEntryIndex(current, entrys); entryIndex = buildEntryIndex(current, entrys);
decoder.DelOrder(current);
break; break;
} }
} }
......
...@@ -140,9 +140,11 @@ int opcount=allOperations.size(); ...@@ -140,9 +140,11 @@ int opcount=allOperations.size();
// return getBestChromosome(population.get(0), param.getBaseTime(), starttime); // return getBestChromosome(population.get(0), param.getBaseTime(), starttime);
// 步骤2:对初始种群进行爬山法局部优化 // 步骤2:对初始种群进行爬山法局部优化
if(opcount<100 ) { if(opcount<100 ) {
Chromosome best=population.get(0); Chromosome best=population.get(0);
geneticOps.DelOrder(best);
FileHelper.writeLogFile("爬山法局部优化-----------开始-------"); FileHelper.writeLogFile("爬山法局部优化-----------开始-------");
GeneticDecoder hillClimbingDecoder = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler, materialRequirementService, sceneId); GeneticDecoder hillClimbingDecoder = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler, materialRequirementService, sceneId);
...@@ -164,7 +166,7 @@ int opcount=allOperations.size(); ...@@ -164,7 +166,7 @@ int opcount=allOperations.size();
if(opcount<800 ) { if(opcount<800 ) {
Chromosome best=population.get(0); Chromosome best=population.get(0);
geneticOps.DelOrder(best);
FileHelper.writeLogFile("模拟退火+爬山法优化-----------开始-------"); FileHelper.writeLogFile("模拟退火+爬山法优化-----------开始-------");
Chromosome saHcOptimized = _simulatedAnnealing.searchWithHillClimbing(best,_vns, saDecoder1, machines); Chromosome saHcOptimized = _simulatedAnnealing.searchWithHillClimbing(best,_vns, saDecoder1, machines);
FileHelper.writeLogFile("模拟退火+爬山法优化-----------结束-------"); FileHelper.writeLogFile("模拟退火+爬山法优化-----------结束-------");
...@@ -173,7 +175,7 @@ int opcount=allOperations.size(); ...@@ -173,7 +175,7 @@ int opcount=allOperations.size();
} }
if(opcount>=800 ) { if(opcount>=800 ) {
Chromosome best=population.get(0); Chromosome best=population.get(0);
geneticOps.DelOrder(best);
best = _simulatedAnnealing.search(best, _tabuSearch, _vns, saDecoder1, machines); best = _simulatedAnnealing.search(best, _tabuSearch, _vns, saDecoder1, machines);
best = _vns.search(best, vnsDecoder1, machines); best = _vns.search(best, vnsDecoder1, machines);
best = _tabuSearch.search(best, _vns, tabuDecoder1, machines); best = _tabuSearch.search(best, _vns, tabuDecoder1, machines);
......
...@@ -100,6 +100,7 @@ public class SimulatedAnnealing { ...@@ -100,6 +100,7 @@ public class SimulatedAnnealing {
log("模拟退火+爬山法 - 开始执行",true); log("模拟退火+爬山法 - 开始执行",true);
Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
decoder.DelOrder(current);
Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
writeKpi(best); writeKpi(best);
...@@ -167,6 +168,7 @@ public class SimulatedAnnealing { ...@@ -167,6 +168,7 @@ public class SimulatedAnnealing {
log(String.format("模拟退火+爬山法 - 迭代%d:找到更优解(微小),fitness=%.4f", totalIterations, best.getFitness()),true); log(String.format("模拟退火+爬山法 - 迭代%d:找到更优解(微小),fitness=%.4f", totalIterations, best.getFitness()),true);
} }
} }
decoder.DelOrder(current);
} }
if (!improved) { if (!improved) {
...@@ -238,6 +240,7 @@ public class SimulatedAnnealing { ...@@ -238,6 +240,7 @@ public class SimulatedAnnealing {
Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
decode(decoder, current,machines); decode(decoder, current,machines);
decoder.DelOrder(current);
Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
writeKpi(best); writeKpi(best);
// 初始化解码 // 初始化解码
...@@ -314,6 +317,7 @@ public class SimulatedAnnealing { ...@@ -314,6 +317,7 @@ public class SimulatedAnnealing {
log(String.format("模拟退火 - 迭代%d:找到更优解(微小),fitness=%.4f", totalIterations, best.getFitness())); log(String.format("模拟退火 - 迭代%d:找到更优解(微小),fitness=%.4f", totalIterations, best.getFitness()));
} }
} }
decoder.DelOrder(current);
} }
if (!improved) { if (!improved) {
......
...@@ -66,6 +66,7 @@ public class TabuSearch { ...@@ -66,6 +66,7 @@ public class TabuSearch {
log("禁忌搜索 - 开始执行",true); log("禁忌搜索 - 开始执行",true);
Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
decoder.DelOrder(current);
Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
this.bestFitness = best.getFitnessLevel().clone(); this.bestFitness = best.getFitnessLevel().clone();
writeKpi(best); writeKpi(best);
...@@ -180,6 +181,7 @@ public class TabuSearch { ...@@ -180,6 +181,7 @@ public class TabuSearch {
// 没有改进 // 没有改进
noImprovementCount++; noImprovementCount++;
} }
decoder.DelOrder(current);
} else { } else {
// 不接受,无改进计数+1 // 不接受,无改进计数+1
noImprovementCount++; noImprovementCount++;
......
...@@ -299,9 +299,10 @@ public class VariableNeighborhoodSearch { ...@@ -299,9 +299,10 @@ public class VariableNeighborhoodSearch {
*/ */
public Chromosome search(Chromosome chromosome, GeneticDecoder decoder, List<Machine> machines) { public Chromosome search(Chromosome chromosome, GeneticDecoder decoder, List<Machine> machines) {
log("变邻域搜索 - 开始执行",true); log("变邻域搜索 - 开始执行",true);
geneticOperations.DelOrder(chromosome);
// 深拷贝当前染色体 // 深拷贝当前染色体
Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome current = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
geneticOperations.DelOrder(current);
Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
writeKpi(best); writeKpi(best);
...@@ -359,7 +360,7 @@ public class VariableNeighborhoodSearch { ...@@ -359,7 +360,7 @@ public class VariableNeighborhoodSearch {
boolean success = isBetter(localBest, best); boolean success = isBetter(localBest, best);
boolean isSignificant = isSignificantImprovement(localBest, best); boolean isSignificant = isSignificantImprovement(localBest, best);
if (success) { if (success) {
best = localBest; best =ProductionDeepCopyUtil.deepCopy(localBest, Chromosome.class); ;
writeKpi(best); writeKpi(best);
current = localBest; current = localBest;
totalImprovements++; totalImprovements++;
...@@ -373,6 +374,7 @@ public class VariableNeighborhoodSearch { ...@@ -373,6 +374,7 @@ public class VariableNeighborhoodSearch {
// 微小改进也接受,但不重置计数,继续尝试 // 微小改进也接受,但不重置计数,继续尝试
log(String.format("变邻域搜索 - 邻域成功(微小): %s", neighborhood.name),true); log(String.format("变邻域搜索 - 邻域成功(微小): %s", neighborhood.name),true);
} }
geneticOperations.DelOrder(current);
} else { } else {
k++; // 尝试下一个邻域 k++; // 尝试下一个邻域
// 检查是否完成一轮 // 检查是否完成一轮
......
...@@ -199,10 +199,7 @@ public class PlanResultService { ...@@ -199,10 +199,7 @@ public class PlanResultService {
for (Machine machine : machines){ for (Machine machine : machines){
Long machineId=machine.getId(); Long machineId=machine.getId();
if(machineId==2406)
{
int i=0;
}
if(machineIds.get(machineId)!=null&&machineIds.get(machineId)>3600*24*200) { if(machineIds.get(machineId)!=null&&machineIds.get(machineId)>3600*24*200) {
int day = (int) (machineIds.get(machineId) / 3600 / 24)+100; int day = (int) (machineIds.get(machineId) / 3600 / 24)+100;
......
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