Commit f366bb13 authored by Tong Li's avatar Tong Li

倒排配套

parent ff663b04
package com.aps.entity.Algorithm; package com.aps.entity.Algorithm;
import com.aps.common.util.FileHelper;
import com.aps.entity.Algorithm.IDAndChildID.GroupResult; import com.aps.entity.Algorithm.IDAndChildID.GroupResult;
import com.aps.entity.basic.Entry; import com.aps.entity.basic.Entry;
import com.aps.entity.basic.GlobalParam; import com.aps.entity.basic.GlobalParam;
...@@ -31,7 +32,7 @@ public class Chromosome { ...@@ -31,7 +32,7 @@ public class Chromosome {
/// <summary> /// <summary>
/// 机器选择部分(可选机器集中的顺序号) /// 机器选择部分(可选机器集中的顺序号)
/// </summary> /// </summary>
private List<Integer> machineSelection; private CopyOnWriteArrayList<Integer> machineSelection;
// 缓存标记 // 缓存标记
private transient boolean machineStrDirty = true; private transient boolean machineStrDirty = true;
...@@ -62,7 +63,7 @@ public class Chromosome { ...@@ -62,7 +63,7 @@ public class Chromosome {
public String getMachineStr() { public String getMachineStr() {
if (machineStrDirty) { if (machineStrDirty) {
machineStr = Optional.ofNullable(machineSelection) machineStr = Optional.ofNullable(machineSelection)
.orElse(Collections.emptyList()) .orElse(new CopyOnWriteArrayList<>(Collections.emptyList()))
.stream() .stream()
.map(String::valueOf) .map(String::valueOf)
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
...@@ -75,7 +76,7 @@ public class Chromosome { ...@@ -75,7 +76,7 @@ public class Chromosome {
public String getOperationStr() { public String getOperationStr() {
if (operationStrDirty) { if (operationStrDirty) {
operationStr = Optional.ofNullable(operationSequencing) operationStr = Optional.ofNullable(operationSequencing)
.orElse(Collections.emptyList()) .orElse(new CopyOnWriteArrayList<>(Collections.emptyList()))
.stream() .stream()
.map(String::valueOf) .map(String::valueOf)
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
...@@ -86,13 +87,13 @@ public class Chromosome { ...@@ -86,13 +87,13 @@ public class Chromosome {
} }
// 重写 setter 方法,在设置时标记为脏 // 重写 setter 方法,在设置时标记为脏
public void setMachineSelection(List<Integer> machineSelection) { public void setMachineSelection(CopyOnWriteArrayList<Integer> machineSelection) {
this.machineSelection = machineSelection; this.machineSelection = machineSelection;
this.machineStrDirty = true; this.machineStrDirty = true;
this.geneStrDirty = true; this.geneStrDirty = true;
} }
public void setOperationSequencing(List<Integer> operationSequencing) { public void setOperationSequencing(CopyOnWriteArrayList<Integer> operationSequencing) {
this.operationSequencing = operationSequencing; this.operationSequencing = operationSequencing;
this.operationStrDirty = true; this.operationStrDirty = true;
this.geneStrDirty = true; this.geneStrDirty = true;
...@@ -104,7 +105,7 @@ public class Chromosome { ...@@ -104,7 +105,7 @@ public class Chromosome {
/// <summary> /// <summary>
/// 工序排序部分(工件/订单ID) /// 工序排序部分(工件/订单ID)
/// </summary> /// </summary>
private List<Integer> operationSequencing; private CopyOnWriteArrayList<Integer> operationSequencing;
...@@ -117,7 +118,7 @@ public class Chromosome { ...@@ -117,7 +118,7 @@ public class Chromosome {
private List<GlobalOperationInfo> globalOpList = new ArrayList<>(); private CopyOnWriteArrayList<GlobalOperationInfo> globalOpList = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList<Entry> allOperations = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList<Entry> allOperations = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList<Order> orders = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList<Order> orders = new CopyOnWriteArrayList<>();
private List<Machine> InitMachines = new ArrayList<>(); private List<Machine> InitMachines = new ArrayList<>();
...@@ -249,4 +250,39 @@ public class Chromosome { ...@@ -249,4 +250,39 @@ public class Chromosome {
private List<KpiMetrics> kpiMetrics; private List<KpiMetrics> kpiMetrics;
/**
* 获取 Result 中工序ID不在 allOperations 里的调度结果列表
*
* @return 不在 allOperations 中的 GAScheduleResult 列表;若均存在则返回空列表
*/
public List<GAScheduleResult> getResultsNotInAllOperations() {
if (Result == null || Result.isEmpty()) {
return Collections.emptyList();
}
if (allOperations == null || allOperations.isEmpty()) {
return new ArrayList<>(Result);
}
Set<Integer> allOpIds = allOperations.stream()
.map(com.aps.entity.basic.Entry::getId)
.collect(Collectors.toSet());
List<GAScheduleResult> NotInAllOperations= Result.stream()
.filter(r -> !allOpIds.contains(r.getOperationId()))
.collect(Collectors.toList());
if(NotInAllOperations.size()>0)
{
FileHelper.writeLogFile("Result 中有工序ID不在 allOperations");
}
return NotInAllOperations;
}
/**
* 判断 Result 中是否存在工序ID不在 allOperations 里的调度结果
*
* @return 存在则返回 true,否则返回 false
*/
public boolean hasResultNotInAllOperations() {
return !getResultsNotInAllOperations().isEmpty();
}
} }
...@@ -16,8 +16,8 @@ public class ScheduleParams { ...@@ -16,8 +16,8 @@ public class ScheduleParams {
// 基础参数(自适应调整的基准值) // 基础参数(自适应调整的基准值)
private static final int MIN_POPULATION_SIZE = 10; private static final int MIN_POPULATION_SIZE = 10;
private static final int MAX_POPULATION_SIZE = 20; private static final int MAX_POPULATION_SIZE = 20;
private static final int MIN_MAX_ITERATIONS = 50; private static final int MIN_MAX_ITERATIONS = 10;
private static final int MAX_MAX_ITERATIONS = 100; private static final int MAX_MAX_ITERATIONS = 30;
private static final float MIN_CROSSOVER_PROB = 0.6f; private static final float MIN_CROSSOVER_PROB = 0.6f;
private static final float MAX_CROSSOVER_PROB = 0.9f; private static final float MAX_CROSSOVER_PROB = 0.9f;
private static final float MIN_MUTATION_PROB = 0.2f; private static final float MIN_MUTATION_PROB = 0.2f;
......
...@@ -17,6 +17,7 @@ import com.google.ortools.sat.Literal; ...@@ -17,6 +17,7 @@ import com.google.ortools.sat.Literal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* 基于 OR-Tools CP-SAT 的柔性作业车间调度(FJSP)建模器 * 基于 OR-Tools CP-SAT 的柔性作业车间调度(FJSP)建模器
...@@ -344,7 +345,7 @@ public class CpSatFjspModel { ...@@ -344,7 +345,7 @@ public class CpSatFjspModel {
chromo.setGsOrls(4); chromo.setGsOrls(4);
chromo.setGenerateType("CP-SAT"); chromo.setGenerateType("CP-SAT");
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
for (int i = 0; i < operationCount; i++) { for (int i = 0; i < operationCount; i++) {
Literal[] pres = presenceMatrix.get(i); Literal[] pres = presenceMatrix.get(i);
int selectedIdx = 0; int selectedIdx = 0;
...@@ -374,7 +375,7 @@ public class CpSatFjspModel { ...@@ -374,7 +375,7 @@ public class CpSatFjspModel {
.comparingInt(OpTimeRecord::getStartTime) .comparingInt(OpTimeRecord::getStartTime)
.thenComparingInt(OpTimeRecord::getMachineIdx)); .thenComparingInt(OpTimeRecord::getMachineIdx));
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
for (OpTimeRecord rec : records) { for (OpTimeRecord rec : records) {
os.add(rec.getGroupId()); os.add(rec.getGroupId());
} }
......
...@@ -10,6 +10,7 @@ import com.aps.entity.basic.Order; ...@@ -10,6 +10,7 @@ import com.aps.entity.basic.Order;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -207,8 +208,8 @@ public class CpSatInitializer { ...@@ -207,8 +208,8 @@ public class CpSatInitializer {
Random rnd = new Random(); Random rnd = new Random();
// 按全局顺序收集所有工序的 MS 和 OS // 按全局顺序收集所有工序的 MS 和 OS
List<Integer> fullMs = new ArrayList<>(); CopyOnWriteArrayList<Integer> fullMs = new CopyOnWriteArrayList<>();
List<Integer> fullOs = new ArrayList<>(); CopyOnWriteArrayList<Integer> fullOs = new CopyOnWriteArrayList<>();
int bottleneckIdx = 0; int bottleneckIdx = 0;
int nonBottleneckIdx = 0; int nonBottleneckIdx = 0;
......
...@@ -401,7 +401,7 @@ public class GeneticAlgorithm { ...@@ -401,7 +401,7 @@ public class GeneticAlgorithm {
chromosome.setMaterials(ProductionDeepCopyUtil.deepCopyTreeMap(materials, String.class,Material.class)); // 简单拷贝,实际可能需要深拷贝 chromosome.setMaterials(ProductionDeepCopyUtil.deepCopyTreeMap(materials, String.class,Material.class)); // 简单拷贝,实际可能需要深拷贝
chromosome.setAllOperations(ProductionDeepCopyUtil.deepCopyList(new CopyOnWriteArrayList<>(allOperations), Entry.class) ); // 简单拷贝,实际可能需要深拷贝 chromosome.setAllOperations(ProductionDeepCopyUtil.deepCopyList(new CopyOnWriteArrayList<>(allOperations), Entry.class) ); // 简单拷贝,实际可能需要深拷贝
chromosome.setGlobalOpList(ProductionDeepCopyUtil.deepCopyList(globalOpList, GlobalOperationInfo.class) ); // 简单拷贝,实际可能需要深拷贝 chromosome.setGlobalOpList(ProductionDeepCopyUtil.deepCopyList(new CopyOnWriteArrayList<>(globalOpList), GlobalOperationInfo.class) ); // 简单拷贝,实际可能需要深拷贝
//chromosome.setObjectiveWeights(_objectiveWeights); //chromosome.setObjectiveWeights(_objectiveWeights);
chromosome.setBaseTime(param.getBaseTime()); chromosome.setBaseTime(param.getBaseTime());
// chromosome.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝 // chromosome.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝
......
...@@ -220,8 +220,8 @@ public class GeneticDecoder { ...@@ -220,8 +220,8 @@ public class GeneticDecoder {
chromosome.setOperatRel(ProductionDeepCopyUtil.deepCopyList(cachedResult.getOperatRel(), GroupResult.class)); chromosome.setOperatRel(ProductionDeepCopyUtil.deepCopyList(cachedResult.getOperatRel(), GroupResult.class));
chromosome.setAllOperations(ProductionDeepCopyUtil.deepCopyList(cachedResult.getAllOperations(),Entry.class)); chromosome.setAllOperations(ProductionDeepCopyUtil.deepCopyList(cachedResult.getAllOperations(),Entry.class));
chromosome.setGlobalOpList(ProductionDeepCopyUtil.deepCopyList(cachedResult.getGlobalOpList(),GlobalOperationInfo.class)); chromosome.setGlobalOpList(ProductionDeepCopyUtil.deepCopyList(cachedResult.getGlobalOpList(),GlobalOperationInfo.class));
chromosome.setOperationSequencing(ProductionDeepCopyUtil.deepCopyList(cachedResult.getOperationSequencing())); chromosome.setOperationSequencing(ProductionDeepCopyUtil.deepCopyList(cachedResult.getOperationSequencing(), Integer.class));
chromosome.setMachineSelection(ProductionDeepCopyUtil.deepCopyList(cachedResult.getMachineSelection())); chromosome.setMachineSelection(ProductionDeepCopyUtil.deepCopyList(cachedResult.getMachineSelection(), Integer.class));
// Chromosome chromosomen= ProductionDeepCopyUtil.deepCopy(cachedResult); // Chromosome chromosomen= ProductionDeepCopyUtil.deepCopy(cachedResult);
// FileHelper.writeLogFile("解码-----------结束-------"+chromosome.getID()); // FileHelper.writeLogFile("解码-----------结束-------"+chromosome.getID());
...@@ -305,10 +305,10 @@ public class GeneticDecoder { ...@@ -305,10 +305,10 @@ public class GeneticDecoder {
return; return;
} }
List<Integer> oldSequence=chromosome.getOperationSequencing(); CopyOnWriteArrayList<Integer> oldSequence=chromosome.getOperationSequencing();
List<Integer> finalSequence = new ArrayList<>(); CopyOnWriteArrayList<Integer> finalSequence = new CopyOnWriteArrayList<>();
// 初始化两个结果数组 // 初始化两个结果数组
List<Integer> pfSequence = new ArrayList<>(); // 成品工序 CopyOnWriteArrayList<Integer> pfSequence = new CopyOnWriteArrayList<>(); // 成品工序
Map<Integer, List<Integer>> sfSequence = new HashMap<>(); // 半成品工序 Map<Integer, List<Integer>> sfSequence = new HashMap<>(); // 半成品工序
// 遍历原数组分类 // 遍历原数组分类
...@@ -439,7 +439,7 @@ public class GeneticDecoder { ...@@ -439,7 +439,7 @@ public class GeneticDecoder {
Map<Integer, Long> expectedCounts = allOperations.stream() Map<Integer, Long> expectedCounts = allOperations.stream()
.collect(Collectors.groupingBy(Entry::getGroupId, Collectors.counting())); .collect(Collectors.groupingBy(Entry::getGroupId, Collectors.counting()));
Map<Integer, Integer> actualCounts = new HashMap<>(); Map<Integer, Integer> actualCounts = new HashMap<>();
List<Integer> normalized = new ArrayList<>(); CopyOnWriteArrayList<Integer> normalized = new CopyOnWriteArrayList<>();
// 先保留原序列中的合法次数,超过真实工序数的重复 groupId 丢弃。 // 先保留原序列中的合法次数,超过真实工序数的重复 groupId 丢弃。
for (Integer groupId : operationSequencing) { for (Integer groupId : operationSequencing) {
......
...@@ -9,6 +9,7 @@ import com.aps.entity.basic.MachineOption; ...@@ -9,6 +9,7 @@ import com.aps.entity.basic.MachineOption;
import com.aps.entity.basic.Order; import com.aps.entity.basic.Order;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
...@@ -186,7 +187,7 @@ public class GeneticOperations { ...@@ -186,7 +187,7 @@ public class GeneticOperations {
// List<Chromosome> populationn= ProductionDeepCopyUtil.deepCopyList(tournamentSelection(population, param.getTournamentSize()),Chromosome.class); // List<Chromosome> populationn= ProductionDeepCopyUtil.deepCopyList(tournamentSelection(population, param.getTournamentSize()),Chromosome.class);
List<Chromosome> populationn= tournamentSelection2(population, param.getTournamentSize()); List<Chromosome> populationn= tournamentSelection2(population, param.getTournamentSize());
// populationn.parallelStream().forEach(t->DelOrder(t)); populationn.forEach(t->DelOrder(t));
return populationn; return populationn;
} }
...@@ -229,7 +230,7 @@ public class GeneticOperations { ...@@ -229,7 +230,7 @@ public class GeneticOperations {
} }
} }
List<Integer> child1Os, child2Os; CopyOnWriteArrayList<Integer> child1Os, child2Os;
// 根据是否允许打破优先级选择不同的生成策略 // 根据是否允许打破优先级选择不同的生成策略
if (_GlobalParam.isIsBreakPriority()) { if (_GlobalParam.isIsBreakPriority()) {
...@@ -247,8 +248,8 @@ public class GeneticOperations { ...@@ -247,8 +248,8 @@ public class GeneticOperations {
Map<Integer, Integer> parent1OpToMachine = buildOpToMachineMap(parent1); Map<Integer, Integer> parent1OpToMachine = buildOpToMachineMap(parent1);
Map<Integer, Integer> parent2OpToMachine = buildOpToMachineMap(parent2); Map<Integer, Integer> parent2OpToMachine = buildOpToMachineMap(parent2);
List<Integer> child1Ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> child1Ms = new CopyOnWriteArrayList<>();
List<Integer> child2Ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> child2Ms = new CopyOnWriteArrayList<>();
// 使用parent1的globalOpList作为基准(因为child1和child2都继承自parent1的orders/machines等) // 使用parent1的globalOpList作为基准(因为child1和child2都继承自parent1的orders/machines等)
for (GlobalOperationInfo opInfo : parent1.getGlobalOpList()) { for (GlobalOperationInfo opInfo : parent1.getGlobalOpList()) {
int opId = opInfo.getOp().getId(); int opId = opInfo.getOp().getId();
...@@ -287,16 +288,16 @@ public class GeneticOperations { ...@@ -287,16 +288,16 @@ public class GeneticOperations {
* @param seqLength 序列长度 * @param seqLength 序列长度
* @return 符合规则的子代序列 * @return 符合规则的子代序列
*/ */
private List<Integer> generateChildOsWithPriorityProtection( private CopyOnWriteArrayList<Integer> generateChildOsWithPriorityProtection(
Chromosome mainParent, Chromosome secondaryParent, Chromosome mainParent, Chromosome secondaryParent,
Set<Integer> jobset1Set, Map<Integer, Integer> maxAllowedCount, Set<Integer> jobset1Set, Map<Integer, Integer> maxAllowedCount,
int seqLength int seqLength
) { ) {
List<Integer> mainSeq = mainParent.getOperationSequencing(); CopyOnWriteArrayList<Integer> mainSeq = mainParent.getOperationSequencing();
List<Integer> secondarySeq = secondaryParent.getOperationSequencing(); CopyOnWriteArrayList<Integer> secondarySeq = secondaryParent.getOperationSequencing();
// 1. 首先按POX规则和次数限制收集候选序列 // 1. 首先按POX规则和次数限制收集候选序列
List<Integer> candidateSeq = new ArrayList<>(); CopyOnWriteArrayList<Integer> candidateSeq = new CopyOnWriteArrayList<>();
Map<Integer, Integer> childJobCount = new HashMap<>(); Map<Integer, Integer> childJobCount = new HashMap<>();
for (int i = 0; i < seqLength; i++) { for (int i = 0; i < seqLength; i++) {
...@@ -347,7 +348,7 @@ public class GeneticOperations { ...@@ -347,7 +348,7 @@ public class GeneticOperations {
}); });
// 构建最终的子序列 // 构建最终的子序列
List<Integer> childOs = new ArrayList<>(); CopyOnWriteArrayList<Integer> childOs = new CopyOnWriteArrayList<>();
for (IndexedOperation io : indexedOps) { for (IndexedOperation io : indexedOps) {
childOs.add(io.groupId); childOs.add(io.groupId);
} }
...@@ -399,14 +400,14 @@ public class GeneticOperations { ...@@ -399,14 +400,14 @@ public class GeneticOperations {
* @param seqLength 序列长度 * @param seqLength 序列长度
* @return 符合规则的子代序列 * @return 符合规则的子代序列
*/ */
private List<Integer> generateChildOsWithCountLimit( private CopyOnWriteArrayList<Integer> generateChildOsWithCountLimit(
Chromosome mainParent, Chromosome secondaryParent, Chromosome mainParent, Chromosome secondaryParent,
Set<Integer> jobset1Set, Map<Integer, Integer> maxAllowedCount, Set<Integer> jobset1Set, Map<Integer, Integer> maxAllowedCount,
int seqLength int seqLength
) { ) {
List<Integer> childOs = new ArrayList<>(); CopyOnWriteArrayList<Integer> childOs = new CopyOnWriteArrayList<>();
List<Integer> mainSeq = mainParent.getOperationSequencing(); CopyOnWriteArrayList<Integer> mainSeq = mainParent.getOperationSequencing();
List<Integer> secondarySeq = secondaryParent.getOperationSequencing(); CopyOnWriteArrayList<Integer> secondarySeq = secondaryParent.getOperationSequencing();
// 实时统计子代中每个工件的当前出现次数 // 实时统计子代中每个工件的当前出现次数
Map<Integer, Integer> childJobCount = new HashMap<>(); Map<Integer, Integer> childJobCount = new HashMap<>();
...@@ -509,7 +510,7 @@ public class GeneticOperations { ...@@ -509,7 +510,7 @@ public class GeneticOperations {
.findFirst().orElse(0); .findFirst().orElse(0);
List<Integer> MachineSelections= chromosome.getMachineSelection(); CopyOnWriteArrayList<Integer> MachineSelections= chromosome.getMachineSelection();
int machineSeq = MachineSelections.get(pos); int machineSeq = MachineSelections.get(pos);
...@@ -547,7 +548,7 @@ public class GeneticOperations { ...@@ -547,7 +548,7 @@ public class GeneticOperations {
int idx2 = os2.getIndex(); int idx2 = os2.getIndex();
// 交换位置 // 交换位置
List<Integer> os = chromosome.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = chromosome.getOperationSequencing();
Collections.swap(os, idx1, idx2); Collections.swap(os, idx1, idx2);
chromosome.setOperationSequencing(os); chromosome.setOperationSequencing(os);
} else { } else {
...@@ -564,7 +565,7 @@ public class GeneticOperations { ...@@ -564,7 +565,7 @@ public class GeneticOperations {
} }
// 执行反转 // 执行反转
List<Integer> os = chromosome.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = chromosome.getOperationSequencing();
for (int i = 0; i < (end - start + 1) / 2; i++) { for (int i = 0; i < (end - start + 1) / 2; i++) {
int pos1 = start + i; int pos1 = start + i;
int pos2 = end - i; int pos2 = end - i;
...@@ -595,59 +596,47 @@ public class GeneticOperations { ...@@ -595,59 +596,47 @@ public class GeneticOperations {
return indexWeights.get(CommonCalculator.getOsIndex(indexWeights)); return indexWeights.get(CommonCalculator.getOsIndex(indexWeights));
} }
public void DelOrder(Chromosome chromosome) { public void DelOrder(Chromosome chromosome) {
List<Entry> allOperations = chromosome.getAllOperations();
List<GlobalOperationInfo> globalOpList= chromosome.getGlobalOpList();
if(chromosome.getOrders()==null||chromosome.getOrders().size()==0) if(chromosome.getOrders()==null||chromosome.getOrders().size()==0)
return; return;
List<Order> orders = chromosome.getOrders(); List<Order> orders = chromosome.getOrders();
List<Integer> OperationSequencing= chromosome.getOperationSequencing();
List<Integer> newoorderids= orders.stream() List<Integer> newoorderids= orders.stream()
.filter(t->t.isNewSfCreate()) .filter(t->t.isNewSfCreate())
.map(Order::getId) .map(Order::getId)
.sorted(Comparator.reverseOrder()) .sorted(Comparator.reverseOrder())
.collect(Collectors.toList()); .collect(Collectors.toList());
if(newoorderids!=null&&newoorderids.size()>0) { if(newoorderids!=null&&newoorderids.size()>0) {
List<Entry> allOperations = chromosome.getAllOperations();
List<GlobalOperationInfo> globalOpList = chromosome.getGlobalOpList();
List<Integer> OperationSequencing = chromosome.getOperationSequencing();
// log(String.format("半成品订单-删除前,工序: %d,工序序列: %d,设备: %d,设备序列: %d",
// allOperations.size(), OperationSequencing.size(), globalOpList.size(), chromosome.getMachineSelection().size()), true);
for (Integer id : newoorderids) { for (Integer id : newoorderids) {
List<Entry> sourceOps = allOperations.stream() List<Entry> sourceOps = allOperations.stream()
.filter(o -> o.getGroupId() == id) .filter(o -> o.getGroupId()==id)
.sorted(Comparator.comparing(Entry::getSequence)) .sorted(Comparator.comparing(Entry::getSequence))
.collect(Collectors.toList()); .collect(Collectors.toList());
for (Entry entry : sourceOps) { for (Entry entry : sourceOps) {
OptionalInt index1 = IntStream.range(0, globalOpList.size()) OptionalInt index1 = IntStream.range(0, globalOpList.size())
.filter(h -> entry.getId() == globalOpList.get(h).getOp().getId()) .filter(h -> entry.getId()==globalOpList.get(h).getOp().getId())
.findFirst(); .findFirst();
globalOpList.remove((int) index1.orElse(0)); globalOpList.remove((int)index1.orElse(0));
chromosome.getMachineSelection().remove((int) index1.orElse(0)); chromosome.getMachineSelection().remove((int)index1.orElse(0));
} }
chromosome.getOperatRel().remove(id - 1); chromosome.getOperatRel().remove(id-1);
} }
allOperations.removeIf(t -> newoorderids.contains(t.getGroupId())); allOperations.removeIf(t ->newoorderids.contains(t.getGroupId()));
OperationSequencing.removeIf(t -> newoorderids.contains(t)); OperationSequencing.removeIf(t ->newoorderids.contains(t));
AtomicInteger globalOpId = new AtomicInteger(0); AtomicInteger globalOpId = new AtomicInteger(0);
globalOpList.forEach(t -> { globalOpList.forEach(t-> {
t.setGlobalOpId(globalOpId.getAndIncrement()); t.setGlobalOpId(globalOpId.getAndIncrement());
}); });
orders.removeIf(t -> newoorderids.contains(t.getId())); orders.removeIf(t ->newoorderids.contains(t.getId()));
// log(String.format("半成品订单-删除后,工序: %d,工序序列: %d,设备: %d,设备序列: %d",
// allOperations.size(), OperationSequencing.size(), globalOpList.size(), chromosome.getMachineSelection().size()), true);
//
} }
} }
private void log(String message, boolean enableLogging) { private void log(String message, boolean enableLogging) {
......
...@@ -585,7 +585,7 @@ public class HillClimbing { ...@@ -585,7 +585,7 @@ public class HillClimbing {
*/ */
private Chromosome swapAtDistance(Chromosome chromosome, int pos, int distance) { private Chromosome swapAtDistance(Chromosome chromosome, int pos, int distance) {
Chromosome neighbor = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> os = neighbor.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = neighbor.getOperationSequencing();
int targetPos = pos + distance; int targetPos = pos + distance;
if (targetPos >= 0 && targetPos < os.size() && pos >= 0 && pos < os.size()) { if (targetPos >= 0 && targetPos < os.size() && pos >= 0 && pos < os.size()) {
java.util.Collections.swap(os, pos, targetPos); java.util.Collections.swap(os, pos, targetPos);
...@@ -598,7 +598,7 @@ public class HillClimbing { ...@@ -598,7 +598,7 @@ public class HillClimbing {
*/ */
private Chromosome generateMachineChange(Chromosome chromosome, List<MachineOption> MachineOptions, int idx) { private Chromosome generateMachineChange(Chromosome chromosome, List<MachineOption> MachineOptions, int idx) {
Chromosome neighbor = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> ms = neighbor.getMachineSelection(); CopyOnWriteArrayList<Integer> ms = neighbor.getMachineSelection();
if (!ms.isEmpty()) { if (!ms.isEmpty()) {
......
...@@ -178,7 +178,9 @@ public class HybridAlgorithm { ...@@ -178,7 +178,9 @@ public class HybridAlgorithm {
Chromosome best=population.get(0); Chromosome best=population.get(0);
best = _simulatedAnnealing.search(best, _tabuSearch, _vns, sharedDecoder, machines); best = _simulatedAnnealing.search(best, _tabuSearch, _vns, sharedDecoder, machines);
best = _vns.search(best, sharedDecoder, machines); best = _vns.search(best, sharedDecoder, machines);
best = _tabuSearch.search(best, _vns, sharedDecoder, machines); best = _tabuSearch.search(best, _vns, sharedDecoder, machines);
return getBestChromosome(best, param.getBaseTime(), starttime); return getBestChromosome(best, param.getBaseTime(), starttime);
...@@ -211,7 +213,6 @@ public class HybridAlgorithm { ...@@ -211,7 +213,6 @@ public class HybridAlgorithm {
FileHelper.writeLogFile("迭代进化------"+iter+"-----开始-------"); FileHelper.writeLogFile("迭代进化------"+iter+"-----开始-------");
// 计算种群适应度标准差,微调参数 // 计算种群适应度标准差,微调参数
double fitnessStd = _fitnessCalculator.calculateFitnessStd(population); double fitnessStd = _fitnessCalculator.calculateFitnessStd(population);
param.fineTuneParams(iter, fitnessStd); param.fineTuneParams(iter, fitnessStd);
...@@ -438,7 +439,7 @@ public class HybridAlgorithm { ...@@ -438,7 +439,7 @@ public class HybridAlgorithm {
chromosome.setAllOperations(ProductionDeepCopyUtil.deepCopyList(new CopyOnWriteArrayList<>(allOperations), Entry.class) ); // 简单拷贝,实际可能需要深拷贝 chromosome.setAllOperations(ProductionDeepCopyUtil.deepCopyList(new CopyOnWriteArrayList<>(allOperations), Entry.class) ); // 简单拷贝,实际可能需要深拷贝
chromosome.setGlobalOpList(ProductionDeepCopyUtil.deepCopyList(globalOpList, GlobalOperationInfo.class) ); // 简单拷贝,实际可能需要深拷贝 chromosome.setGlobalOpList(ProductionDeepCopyUtil.deepCopyList(new CopyOnWriteArrayList<>(globalOpList), GlobalOperationInfo.class) ); // 简单拷贝,实际可能需要深拷贝
//chromosome.setObjectiveWeights(_objectiveWeights); //chromosome.setObjectiveWeights(_objectiveWeights);
chromosome.setBaseTime(param.getBaseTime()); chromosome.setBaseTime(param.getBaseTime());
// chromosome.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝 // chromosome.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝
......
...@@ -46,8 +46,8 @@ public class Initialization { ...@@ -46,8 +46,8 @@ public class Initialization {
/** /**
* 预生成全局工序列表(按“订单0→订单1→…+订单内工序1→2→…”排序,分配GlobalOpId) * 预生成全局工序列表(按“订单0→订单1→…+订单内工序1→2→…”排序,分配GlobalOpId)
*/ */
public List<GlobalOperationInfo> generateGlobalOpList() { public CopyOnWriteArrayList<GlobalOperationInfo> generateGlobalOpList() {
List<GlobalOperationInfo> globalOpList = new ArrayList<>(); CopyOnWriteArrayList<GlobalOperationInfo> globalOpList = new CopyOnWriteArrayList<>();
int globalOpId = 0; int globalOpId = 0;
for (Entry op : allOperations) { for (Entry op : allOperations) {
GlobalOperationInfo info = new GlobalOperationInfo(); GlobalOperationInfo info = new GlobalOperationInfo();
...@@ -134,8 +134,8 @@ public class Initialization { ...@@ -134,8 +134,8 @@ public class Initialization {
Map<Long, Double> machineLoad = new HashMap<>(); Map<Long, Double> machineLoad = new HashMap<>();
// int[] machineLoad = new int[machineCount + 1]; // 设备负载(1-based,设备ID从1开始) // int[] machineLoad = new int[machineCount + 1]; // 设备负载(1-based,设备ID从1开始)
List<Integer> ms = new ArrayList<>(); // MachineSelection(顺序=GlobalOpId顺序) CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>(); // MachineSelection(顺序=GlobalOpId顺序)
List<Integer> os = new ArrayList<>(); // OperationSequencing CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>(); // OperationSequencing
List<Integer> osp = new ArrayList<>(); // 相同优先级OperationSequencing List<Integer> osp = new ArrayList<>(); // 相同优先级OperationSequencing
double prevPriority =(double) -1; double prevPriority =(double) -1;
Random rnd = new Random(); Random rnd = new Random();
...@@ -211,8 +211,8 @@ public class Initialization { ...@@ -211,8 +211,8 @@ public class Initialization {
private Chromosome generateLSChromosome(Chromosome chromosome,List<GlobalOperationInfo> globalOpList) { private Chromosome generateLSChromosome(Chromosome chromosome,List<GlobalOperationInfo> globalOpList) {
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
Random rnd = new Random(); Random rnd = new Random();
int currentOrderId = -1; int currentOrderId = -1;
Map<Long, Double> machineLoad = new HashMap<>(); Map<Long, Double> machineLoad = new HashMap<>();
...@@ -291,8 +291,8 @@ public class Initialization { ...@@ -291,8 +291,8 @@ public class Initialization {
private Chromosome generateRSChromosome(Chromosome chromosome,List<GlobalOperationInfo> globalOpList) { private Chromosome generateRSChromosome(Chromosome chromosome,List<GlobalOperationInfo> globalOpList) {
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
Random rnd = new Random(); Random rnd = new Random();
List<Integer> osp = new ArrayList<>(); List<Integer> osp = new ArrayList<>();
double prevPriority = -1; double prevPriority = -1;
...@@ -410,11 +410,11 @@ public class Initialization { ...@@ -410,11 +410,11 @@ public class Initialization {
* SPT(最短加工时间) * SPT(最短加工时间)
*/ */
private Chromosome generateChromosomeByType(Chromosome chromosome,int sortType) { private Chromosome generateChromosomeByType(Chromosome chromosome,int sortType) {
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
Map<Long, Double> machineLoad = new HashMap<>(); Map<Long, Double> machineLoad = new HashMap<>();
Random rnd = new Random(); Random rnd = new Random();
List<GlobalOperationInfo> globalOpList = new ArrayList<>(); CopyOnWriteArrayList<GlobalOperationInfo> globalOpList = new CopyOnWriteArrayList<>();
// 1 SPT(最短加工时间) 2 LPT(最长加工时间) // 1 SPT(最短加工时间) 2 LPT(最长加工时间)
Map<Integer, LocalDateTime> dueDateMap = new HashMap<>(); Map<Integer, LocalDateTime> dueDateMap = new HashMap<>();
...@@ -537,11 +537,11 @@ public class Initialization { ...@@ -537,11 +537,11 @@ public class Initialization {
* 比率越小,优先级越高 * 比率越小,优先级越高
*/ */
private Chromosome generateCRChromosome(Chromosome chromosome) { private Chromosome generateCRChromosome(Chromosome chromosome) {
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
Map<Long, Double> machineLoad = new HashMap<>(); Map<Long, Double> machineLoad = new HashMap<>();
Random rnd = new Random(); Random rnd = new Random();
List<GlobalOperationInfo> globalOpList=new ArrayList<>(); CopyOnWriteArrayList<GlobalOperationInfo> globalOpList=new CopyOnWriteArrayList<>();
Map<Integer, Order> orderMap = new HashMap<>(); Map<Integer, Order> orderMap = new HashMap<>();
for (Order order : orders) { for (Order order : orders) {
...@@ -655,12 +655,12 @@ public class Initialization { ...@@ -655,12 +655,12 @@ public class Initialization {
* SST(最短准备时间)规则:优先选择准备时间最短的工序 * SST(最短准备时间)规则:优先选择准备时间最短的工序
*/ */
private Chromosome generateSSTChromosome(Chromosome chromosome) { private Chromosome generateSSTChromosome(Chromosome chromosome) {
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
Map<Long, Double> machineLoad = new HashMap<>(); Map<Long, Double> machineLoad = new HashMap<>();
Map<Long, List<RoutingDiscreteParam>> lastDiscreteParams = new HashMap<>(); Map<Long, List<RoutingDiscreteParam>> lastDiscreteParams = new HashMap<>();
Random rnd = new Random(); Random rnd = new Random();
List<GlobalOperationInfo> globalOpList=new ArrayList<>(); CopyOnWriteArrayList<GlobalOperationInfo> globalOpList=new CopyOnWriteArrayList<>();
List<Entry> sortedOps = new ArrayList<>(allOperations); List<Entry> sortedOps = new ArrayList<>(allOperations);
Map<Entry, Integer> randomIds = new HashMap<>(); Map<Entry, Integer> randomIds = new HashMap<>();
...@@ -778,11 +778,11 @@ public class Initialization { ...@@ -778,11 +778,11 @@ public class Initialization {
* EDD+SPT混合策略:先按截止日期,再按加工时间 * EDD+SPT混合策略:先按截止日期,再按加工时间
*/ */
private Chromosome generateEDDSPTChromosome(Chromosome chromosome) { private Chromosome generateEDDSPTChromosome(Chromosome chromosome) {
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
Map<Long, Double> machineLoad = new HashMap<>(); Map<Long, Double> machineLoad = new HashMap<>();
Random rnd = new Random(); Random rnd = new Random();
List<GlobalOperationInfo> globalOpList = new ArrayList<>(); CopyOnWriteArrayList<GlobalOperationInfo> globalOpList = new CopyOnWriteArrayList<>();
Map<Integer, LocalDateTime> dueDateMap = new HashMap<>(); Map<Integer, LocalDateTime> dueDateMap = new HashMap<>();
for (Order order : orders) { for (Order order : orders) {
...@@ -874,11 +874,11 @@ public class Initialization { ...@@ -874,11 +874,11 @@ public class Initialization {
* 瓶颈优先策略:优先安排预计为瓶颈的设备上的工序 * 瓶颈优先策略:优先安排预计为瓶颈的设备上的工序
*/ */
private Chromosome generateBottleneckFirstChromosome(Chromosome chromosome) { private Chromosome generateBottleneckFirstChromosome(Chromosome chromosome) {
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
Map<Long, Double> machineLoad = new HashMap<>(); Map<Long, Double> machineLoad = new HashMap<>();
Random rnd = new Random(); Random rnd = new Random();
List<GlobalOperationInfo> globalOpList = new ArrayList<>(); CopyOnWriteArrayList<GlobalOperationInfo> globalOpList = new CopyOnWriteArrayList<>();
Map<Entry, Integer> randomIds = new HashMap<>(); Map<Entry, Integer> randomIds = new HashMap<>();
List<Integer> indices = new ArrayList<>(); List<Integer> indices = new ArrayList<>();
...@@ -967,11 +967,11 @@ public class Initialization { ...@@ -967,11 +967,11 @@ public class Initialization {
* 随机 * 随机
*/ */
private Chromosome generateLsChromosome(Chromosome chromosome) { private Chromosome generateLsChromosome(Chromosome chromosome) {
List<Integer> ms = new ArrayList<>(); CopyOnWriteArrayList<Integer> ms = new CopyOnWriteArrayList<>();
List<Integer> os = new ArrayList<>(); CopyOnWriteArrayList<Integer> os = new CopyOnWriteArrayList<>();
Map<Long, Double> machineLoad = new HashMap<>(); Map<Long, Double> machineLoad = new HashMap<>();
Random rnd = new Random(); Random rnd = new Random();
List<GlobalOperationInfo> globalOpList = new ArrayList<>(); CopyOnWriteArrayList<GlobalOperationInfo> globalOpList = new CopyOnWriteArrayList<>();
// 按加工时间排序工序,加工时间相同时随机排序 // 按加工时间排序工序,加工时间相同时随机排序
List<Entry> sortedOps = new ArrayList<>(allOperations); List<Entry> sortedOps = new ArrayList<>(allOperations);
Map<Entry, Integer> randomIds = new HashMap<>(); Map<Entry, Integer> randomIds = new HashMap<>();
...@@ -1046,10 +1046,10 @@ public class Initialization { ...@@ -1046,10 +1046,10 @@ public class Initialization {
/** /**
* 按优先级加权打乱工序排序(高优先级订单的工序更可能靠前) * 按优先级加权打乱工序排序(高优先级订单的工序更可能靠前)
*/ */
private List<Integer> shuffleWithPriority(List<Integer> os) { private CopyOnWriteArrayList<Integer> shuffleWithPriority(List<Integer> os) {
if (!_globalParam.isIsBreakPriority()) { if (!_globalParam.isIsBreakPriority()) {
return new ArrayList<>(os); return new CopyOnWriteArrayList<>(os);
} }
Random rnd = new Random(); Random rnd = new Random();
...@@ -1070,7 +1070,7 @@ public class Initialization { ...@@ -1070,7 +1070,7 @@ public class Initialization {
.collect(Collectors.toList()); .collect(Collectors.toList());
// 按权重随机排序(权重越高,被选中的概率越大) // 按权重随机排序(权重越高,被选中的概率越大)
List<Integer> shuffled = new ArrayList<>(); CopyOnWriteArrayList<Integer> shuffled = new CopyOnWriteArrayList<>();
while (!weightedOs.isEmpty()) { while (!weightedOs.isEmpty()) {
double totalWeight = weightedOs.stream().mapToDouble(WeightedGroup::getWeight).sum(); double totalWeight = weightedOs.stream().mapToDouble(WeightedGroup::getWeight).sum();
int randomWeight = rnd.nextInt((int)totalWeight); int randomWeight = rnd.nextInt((int)totalWeight);
...@@ -1096,10 +1096,10 @@ public class Initialization { ...@@ -1096,10 +1096,10 @@ public class Initialization {
* 先用 CP-SAT 生成高质量种子,剩余用原有构造启发式补足 * 先用 CP-SAT 生成高质量种子,剩余用原有构造启发式补足
*/ */
public List<Chromosome> generateHybridInitialPopulation(ScheduleParams param) { public List<Chromosome> generateHybridInitialPopulation(ScheduleParams param) {
int populationSize = param.getPopulationSize(); int populationSize =param.getPopulationSize();
this.baseTime = param.getBaseTime(); this.baseTime = param.getBaseTime();
List<GlobalOperationInfo> sharedGlobalOpList = generateGlobalOpList(); CopyOnWriteArrayList<GlobalOperationInfo> sharedGlobalOpList = generateGlobalOpList();
List<Chromosome> population = new ArrayList<>(populationSize); List<Chromosome> population = new ArrayList<>(populationSize);
...@@ -1151,9 +1151,9 @@ public class Initialization { ...@@ -1151,9 +1151,9 @@ public class Initialization {
return population; return population;
} }
private List<GlobalOperationInfo> deepCopyGlobalOpList( private CopyOnWriteArrayList<GlobalOperationInfo> deepCopyGlobalOpList(
List<GlobalOperationInfo> source) { CopyOnWriteArrayList<GlobalOperationInfo> source) {
List<GlobalOperationInfo> copy = new ArrayList<>(source.size()); CopyOnWriteArrayList<GlobalOperationInfo> copy = new CopyOnWriteArrayList<>();
for (GlobalOperationInfo info : source) { for (GlobalOperationInfo info : source) {
GlobalOperationInfo newInfo = new GlobalOperationInfo(); GlobalOperationInfo newInfo = new GlobalOperationInfo();
newInfo.setGlobalOpId(info.getGlobalOpId()); newInfo.setGlobalOpId(info.getGlobalOpId());
......
...@@ -62,7 +62,7 @@ int newStartTime=0; ...@@ -62,7 +62,7 @@ int newStartTime=0;
.collect(Collectors.toList()); .collect(Collectors.toList());
Integer newMachineId1=newMachineId.intValue(); Integer newMachineId1=newMachineId.intValue();
List<Integer> OperationSequencing= chromosome.getOperationSequencing(); CopyOnWriteArrayList<Integer> OperationSequencing= chromosome.getOperationSequencing();
GAScheduleResult targetResult1=null; GAScheduleResult targetResult1=null;
Entry targetOp1=null; Entry targetOp1=null;
int targetopIndex1=0; int targetopIndex1=0;
...@@ -417,9 +417,9 @@ if(targetOp.getSequence()>1) { ...@@ -417,9 +417,9 @@ if(targetOp.getSequence()>1) {
} }
List<Integer> operationSequencing = newops.stream() CopyOnWriteArrayList<Integer> operationSequencing = newops.stream()
.map(OperationSort::getGroup) .map(OperationSort::getGroup)
.collect(Collectors.toList()); .collect(Collectors.toCollection(CopyOnWriteArrayList::new));
Collections.reverse(operationSequencing); Collections.reverse(operationSequencing);
chromosome.setOperationSequencing(operationSequencing); chromosome.setOperationSequencing(operationSequencing);
...@@ -776,7 +776,7 @@ if(targetOp.getSequence()>1) { ...@@ -776,7 +776,7 @@ if(targetOp.getSequence()>1) {
Map<Integer, Long> expectedCounts = allOperations.stream() Map<Integer, Long> expectedCounts = allOperations.stream()
.collect(Collectors.groupingBy(Entry::getGroupId, Collectors.counting())); .collect(Collectors.groupingBy(Entry::getGroupId, Collectors.counting()));
Map<Integer, Integer> actualCounts = new HashMap<>(); Map<Integer, Integer> actualCounts = new HashMap<>();
List<Integer> normalized = new ArrayList<>(); CopyOnWriteArrayList<Integer> normalized = new CopyOnWriteArrayList<>();
// 先保留原序列中的合法次数,超过真实工序数的重复 groupId 丢弃。 // 先保留原序列中的合法次数,超过真实工序数的重复 groupId 丢弃。
for (Integer groupId : operationSequencing) { for (Integer groupId : operationSequencing) {
...@@ -2077,7 +2077,7 @@ if(targetOp.getSequence()>1) { ...@@ -2077,7 +2077,7 @@ if(targetOp.getSequence()>1) {
List<Integer> operationSequencing = allOperations.stream() CopyOnWriteArrayList<Integer> operationSequencing = allOperations.stream()
.sorted((op1, op2) -> { .sorted((op1, op2) -> {
int time1 = opTimeMap.getOrDefault(op1.getId(), Integer.MAX_VALUE); int time1 = opTimeMap.getOrDefault(op1.getId(), Integer.MAX_VALUE);
int time2 = opTimeMap.getOrDefault(op2.getId(), Integer.MAX_VALUE); int time2 = opTimeMap.getOrDefault(op2.getId(), Integer.MAX_VALUE);
...@@ -2088,7 +2088,7 @@ if(targetOp.getSequence()>1) { ...@@ -2088,7 +2088,7 @@ if(targetOp.getSequence()>1) {
} }
}) })
.map(Entry::getGroupId) .map(Entry::getGroupId)
.collect(Collectors.toList()); .collect(Collectors.toCollection(CopyOnWriteArrayList::new));
chromosome.setOperationSequencing(operationSequencing); chromosome.setOperationSequencing(operationSequencing);
// 重新解码 // 重新解码
......
...@@ -243,7 +243,7 @@ public class SimulatedAnnealing { ...@@ -243,7 +243,7 @@ public class SimulatedAnnealing {
decode(decoder, current,machines); decode(decoder, current,machines);
Chromosome best = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome best = ProductionDeepCopyUtil.deepCopy(current, Chromosome.class);
writeKpi(best); writeKpi(best);
// 初始化解码 // 初始化解码
......
...@@ -1271,7 +1271,7 @@ public class VariableNeighborhoodSearch { ...@@ -1271,7 +1271,7 @@ public class VariableNeighborhoodSearch {
private Chromosome generateMachineChangeForSpecificOp(Chromosome chromosome, List<MachineOption> machineOptions, int idx) { private Chromosome generateMachineChangeForSpecificOp(Chromosome chromosome, List<MachineOption> machineOptions, int idx) {
Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> ms = neighbor.getMachineSelection(); CopyOnWriteArrayList<Integer> ms = neighbor.getMachineSelection();
if (!ms.isEmpty() && idx >= 0 && idx < ms.size()) { if (!ms.isEmpty() && idx >= 0 && idx < ms.size()) {
if (machineOptions.size() > 1) { if (machineOptions.size() > 1) {
int currentMachineSeq = ms.get(idx); int currentMachineSeq = ms.get(idx);
...@@ -1525,7 +1525,7 @@ public class VariableNeighborhoodSearch { ...@@ -1525,7 +1525,7 @@ public class VariableNeighborhoodSearch {
private Chromosome moveOperationForward(Chromosome chromosome, Map<Integer, Entry> originalPositionIndex,int pos, int steps) { private Chromosome moveOperationForward(Chromosome chromosome, Map<Integer, Entry> originalPositionIndex,int pos, int steps) {
geneticOperations.DelOrder(chromosome); geneticOperations.DelOrder(chromosome);
Chromosome neighbor = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor = ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> os = neighbor.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = neighbor.getOperationSequencing();
if (pos <= 0 || pos >= os.size()) { if (pos <= 0 || pos >= os.size()) {
return neighbor; return neighbor;
...@@ -1561,7 +1561,7 @@ public class VariableNeighborhoodSearch { ...@@ -1561,7 +1561,7 @@ public class VariableNeighborhoodSearch {
log("moveOperationBackward:originalPositionIndex"+originalPositionIndex.size()); log("moveOperationBackward:originalPositionIndex"+originalPositionIndex.size());
Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> os = neighbor.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = neighbor.getOperationSequencing();
if (pos < 0 || pos >= os.size() - 1) { if (pos < 0 || pos >= os.size() - 1) {
return neighbor; return neighbor;
...@@ -1598,7 +1598,7 @@ public class VariableNeighborhoodSearch { ...@@ -1598,7 +1598,7 @@ public class VariableNeighborhoodSearch {
log("insertOperationForward:originalPositionIndex"+originalPositionIndex.size()); log("insertOperationForward:originalPositionIndex"+originalPositionIndex.size());
Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> os = neighbor.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = neighbor.getOperationSequencing();
if (pos <= 0 || pos >= os.size()) { if (pos <= 0 || pos >= os.size()) {
return neighbor; return neighbor;
...@@ -1676,12 +1676,12 @@ public class VariableNeighborhoodSearch { ...@@ -1676,12 +1676,12 @@ public class VariableNeighborhoodSearch {
geneticOperations.DelOrder(chromosome); geneticOperations.DelOrder(chromosome);
Chromosome neighbor=new Chromosome(); Chromosome neighbor=new Chromosome();
neighbor.setID(UUID.randomUUID().toString()); neighbor.setID(UUID.randomUUID().toString());
neighbor.setOperationSequencing(new ArrayList<>(chromosome.getOperationSequencing())); neighbor.setOperationSequencing(chromosome.getOperationSequencing());
neighbor.setMachineSelection(new ArrayList<>(chromosome.getMachineSelection())); neighbor.setMachineSelection(chromosome.getMachineSelection());
neighbor.setScenarioID(chromosome.getScenarioID()); neighbor.setScenarioID(chromosome.getScenarioID());
neighbor.setBaseTime(chromosome.getBaseTime()); neighbor.setBaseTime(chromosome.getBaseTime());
neighbor.setFitnessLevel(chromosome.getFitnessLevel()); neighbor.setFitnessLevel(chromosome.getFitnessLevel());
neighbor.setGlobalOpList(new ArrayList<>(chromosome.getGlobalOpList())); neighbor.setGlobalOpList(chromosome.getGlobalOpList());
return neighbor; return neighbor;
} }
...@@ -1691,7 +1691,7 @@ public class VariableNeighborhoodSearch { ...@@ -1691,7 +1691,7 @@ public class VariableNeighborhoodSearch {
private Chromosome generateSwapNeighbor(Chromosome chromosome,Map<Integer, Entry> positionIndex,List<List<Integer>> positionByPriority) { private Chromosome generateSwapNeighbor(Chromosome chromosome,Map<Integer, Entry> positionIndex,List<List<Integer>> positionByPriority) {
log("generateSwapNeighbor"+positionIndex.size()); log("generateSwapNeighbor"+positionIndex.size());
Chromosome neighbor=copyChromosome(chromosome); Chromosome neighbor=copyChromosome(chromosome);
List<Integer> os = neighbor.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = neighbor.getOperationSequencing();
if (os.size() >= 2 && !positionByPriority.isEmpty()) { if (os.size() >= 2 && !positionByPriority.isEmpty()) {
int maxAttempts = 50; int maxAttempts = 50;
for (int attempt = 0; attempt < maxAttempts; attempt++) { for (int attempt = 0; attempt < maxAttempts; attempt++) {
...@@ -1744,7 +1744,7 @@ public class VariableNeighborhoodSearch { ...@@ -1744,7 +1744,7 @@ public class VariableNeighborhoodSearch {
log("generateReverseNeighbor"+positionIndex.size()); log("generateReverseNeighbor"+positionIndex.size());
Chromosome neighbor = copyChromosome(chromosome); //ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor = copyChromosome(chromosome); //ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> os = neighbor.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = neighbor.getOperationSequencing();
if (os.size() >= 2&&positionByPriority.size()>0) { if (os.size() >= 2&&positionByPriority.size()>0) {
// Map<Integer, Entry> positionIndex = buildPositionToEntryIndex(neighbor); // Map<Integer, Entry> positionIndex = buildPositionToEntryIndex(neighbor);
...@@ -1817,7 +1817,7 @@ public class VariableNeighborhoodSearch { ...@@ -1817,7 +1817,7 @@ public class VariableNeighborhoodSearch {
private Chromosome generateInsertNeighbor(Chromosome chromosome,Map<Integer, Entry> positionIndex,List<List<Integer>> positionByPriority) { private Chromosome generateInsertNeighbor(Chromosome chromosome,Map<Integer, Entry> positionIndex,List<List<Integer>> positionByPriority) {
Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
log("generateInsertNeighbor"+positionIndex.size()); log("generateInsertNeighbor"+positionIndex.size());
List<Integer> os = neighbor.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = neighbor.getOperationSequencing();
if (os.size() >= 2&&positionByPriority.size()>0) { if (os.size() >= 2&&positionByPriority.size()>0) {
// Map<Integer, Entry> positionIndex = buildPositionToEntryIndex(neighbor); // Map<Integer, Entry> positionIndex = buildPositionToEntryIndex(neighbor);
...@@ -1876,7 +1876,7 @@ public class VariableNeighborhoodSearch { ...@@ -1876,7 +1876,7 @@ public class VariableNeighborhoodSearch {
private Chromosome generateMachineChangeNeighbor(Chromosome chromosome) { private Chromosome generateMachineChangeNeighbor(Chromosome chromosome) {
log("generateMachineChangeNeighbor"); log("generateMachineChangeNeighbor");
Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> ms = neighbor.getMachineSelection(); CopyOnWriteArrayList<Integer> ms = neighbor.getMachineSelection();
if (!ms.isEmpty()) { if (!ms.isEmpty()) {
int idx = rnd.nextInt(ms.size()); int idx = rnd.nextInt(ms.size());
GlobalOperationInfo globalOp = chromosome.getGlobalOpList().get(idx); GlobalOperationInfo globalOp = chromosome.getGlobalOpList().get(idx);
...@@ -1922,8 +1922,8 @@ public class VariableNeighborhoodSearch { ...@@ -1922,8 +1922,8 @@ public class VariableNeighborhoodSearch {
//有问题 //有问题
log("generateSameMachineSwapNeighbor"+positionIndex.size()); log("generateSameMachineSwapNeighbor"+positionIndex.size());
Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class); Chromosome neighbor=copyChromosome(chromosome);// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
List<Integer> os = neighbor.getOperationSequencing(); CopyOnWriteArrayList<Integer> os = neighbor.getOperationSequencing();
List<Integer> ms = neighbor.getMachineSelection(); CopyOnWriteArrayList<Integer> ms = neighbor.getMachineSelection();
if (os.size() >= 2 && ms.size() >= 2) { if (os.size() >= 2 && ms.size() >= 2) {
......
...@@ -657,7 +657,7 @@ public class LockedOrderProcessorService { ...@@ -657,7 +657,7 @@ public class LockedOrderProcessorService {
// 5. 将锁定期订单添加到operationSequencing中,确保它们会被解码处理 // 5. 将锁定期订单添加到operationSequencing中,确保它们会被解码处理
if (!data.entries.isEmpty() && chromosome.getOperationSequencing() != null) { if (!data.entries.isEmpty() && chromosome.getOperationSequencing() != null) {
List<Integer> currentSequencing = new ArrayList<>(chromosome.getOperationSequencing()); CopyOnWriteArrayList<Integer> currentSequencing = new CopyOnWriteArrayList<>(chromosome.getOperationSequencing());
// 获取所有锁定期订单的ID // 获取所有锁定期订单的ID
Set<String> lockedOrderIds = data.entries.values().stream() Set<String> lockedOrderIds = data.entries.values().stream()
......
...@@ -285,7 +285,7 @@ public class PlanResultService { ...@@ -285,7 +285,7 @@ public class PlanResultService {
KpiCalculator kpiCalculator=new KpiCalculator(chromosome); KpiCalculator kpiCalculator=new KpiCalculator(chromosome);
kpiCalculator.calculatekpi(); kpiCalculator.calculatekpi();
// int NotInAllOperations= chromosome.getResultsNotInAllOperations().size();
// 添加锁定期工单到调度结果中 // 添加锁定期工单到调度结果中
...@@ -309,6 +309,8 @@ public class PlanResultService { ...@@ -309,6 +309,8 @@ public class PlanResultService {
} }
} }
// /** // /**
// * 添加锁定期工单到调度结果中 // * 添加锁定期工单到调度结果中
// * 从上一次排产结果中获取冻结期内的工单,保持时间、数量、设备、Entry等信息不变 // * 从上一次排产结果中获取冻结期内的工单,保持时间、数量、设备、Entry等信息不变
......
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