Commit c44201cc authored by Tong Li's avatar Tong Li

遗传算法-移动多工单,删除订单

parent b779f0fc
......@@ -78,7 +78,7 @@ public class GeneticDecoder {
chromosome.setTotalChangeoverTime(cachedResult.getTotalChangeoverTime());
chromosome.setMachineLoadStd(cachedResult.getMachineLoadStd());
chromosome.setDelayTime(cachedResult.getDelayTime());
chromosome.setResult(cachedResult.getResult());
chromosome.setResult(ProductionDeepCopyUtil.deepCopyList(cachedResult.getResult(),GAScheduleResult.class));
// Chromosome chromosomen= ProductionDeepCopyUtil.deepCopy(cachedResult);
return chromosome;
......
......@@ -63,7 +63,7 @@ public class GeneticOperations {
.findFirst()
// 处理空列表情况(避免NoSuchElementException)
.orElse(null);
selected.add(ProductionDeepCopyUtil.deepCopy(best));
selected.add(ProductionDeepCopyUtil.deepCopy(best,Chromosome.class));
}
return selected;
}
......
......@@ -29,20 +29,20 @@ public class ScheduleOperationService {
/**
* 移动工序方法
* @param chromosome 染色体对象
* @param opId 工序ID
* @param opIds 工序ID
* @param newStartTime 新开始时间
* @param newMachineId 新设备ID
*/
public void moveOperation(Chromosome chromosome, List<Integer> opIds, int newStartTime,
Long newMachineId, GlobalParam globalParam) {
List<Entry> allOperations = chromosome.getAllOperations();
int newStartTime1=newStartTime;
Map<Integer, Integer> opTimeMap = chromosome.getResult().stream()
.collect(Collectors.toMap(
GAScheduleResult::getOperationId,
r -> r.getStartTime()
));
Integer newMachineId1=newMachineId.intValue();
for (Integer opId:opIds) {
......@@ -57,28 +57,34 @@ public class ScheduleOperationService {
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
int machineOptionIndex = targetOp.getMachineOptions().stream()
.map(MachineOption::getMachineId)
.collect(Collectors.toList())
.indexOf(newMachineId) + 1;
if(newMachineId1!=0) {
int machineOptionIndex = targetOp.getMachineOptions().stream()
.map(MachineOption::getMachineId)
.collect(Collectors.toList())
.indexOf(newMachineId) + 1;
if (machineOptionIndex == 0) {
throw new NoSuchElementException("Machine not found: " + newMachineId);
}
if (machineOptionIndex == 0) {
throw new NoSuchElementException("Machine not found: " + newMachineId);
}
// 更新设备选择序列
int globalOpIndex = chromosome.getGlobalOpList().stream()
.filter(g -> g.getOp().getId() == opId)
.findFirst()
.map(GlobalOperationInfo::getGlobalOpId)
.orElseThrow(() -> new NoSuchElementException("Global operation not found: " + opId));
chromosome.getMachineSelection().set(globalOpIndex, machineOptionIndex);
targetResult.setForcedMachineId(newMachineId);
}else {
newMachineId1=(int)targetResult.getMachineId();
}
// 设置约束
targetResult.setDesignatedStartTime(newStartTime);
targetResult.setForcedMachineId(newMachineId);
// 更新设备选择序列
int globalOpIndex = chromosome.getGlobalOpList().stream()
.filter(g -> g.getOp().getId() == opId)
.findFirst()
.map(GlobalOperationInfo::getGlobalOpId)
.orElseThrow(() -> new NoSuchElementException("Global operation not found: " + opId));
chromosome.getMachineSelection().set(globalOpIndex, machineOptionIndex);
if(targetOp.getSequence()==1) {
opTimeMap.put(opId, newStartTime);
}else {
......@@ -98,8 +104,19 @@ public class ScheduleOperationService {
opTimeMap.put(opId, targetResult1.getStartTime()+1);
}
}
newStartTime=newStartTime+(int)targetResult.getProcessingTime();
newStartTime=newStartTime+1;
}
Long newMachineId2=newMachineId1.longValue();
GAScheduleResult FirstMachineResult = chromosome.getResult().stream()
.filter(r -> r.getMachineId() ==newMachineId2 && r.getStartTime() >= newStartTime1)
.findFirst()
.orElse(null);
if (FirstMachineResult != null) {
opTimeMap.put(FirstMachineResult.getOperationId(), newStartTime);
}
// 生成新的工序顺序
......@@ -238,7 +255,7 @@ public class ScheduleOperationService {
}
}else {
//不存在创建新的
Entry newOp = ProductionDeepCopyUtil.deepCopy(targetOp);
Entry newOp = ProductionDeepCopyUtil.deepCopy(targetOp,Entry.class);
newOp.setId(nodeInfo.getGlobalSerial());
newOp.setSequence(nodeInfo.getGroupSerial());
newOp.setExecId(nodeInfo.getOriginalId());
......@@ -320,7 +337,7 @@ public class ScheduleOperationService {
List<String> newChildIdList = new ArrayList<>();
for (int i = 1; i < splitCounts.length; i++) {
maxorderId++;
Order neworder = ProductionDeepCopyUtil.deepCopy(order);
Order neworder = ProductionDeepCopyUtil.deepCopy(order,Order.class);
neworder.setOrderId(UUID.randomUUID().toString().replace("-", ""));
if(splitCounts[0]!=0&&i==1) {// 数组第一个是0,为复制
order.setQuantity(splitCounts[0]);
......@@ -335,7 +352,7 @@ public class ScheduleOperationService {
}
String newId = UUID.randomUUID().toString().replace("-", "");
Entry newOp = ProductionDeepCopyUtil.deepCopy(entry);
Entry newOp = ProductionDeepCopyUtil.deepCopy(entry,Entry.class);
newOp.setExecId(newId);
newOp.setOrderId(neworder.getOrderId());
newOp.setGroupId(maxorderId);
......
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