Commit 2e356235 authored by Tong Li's avatar Tong Li

物料需求

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