修改工单订单设备

parent 3c9b2b71
......@@ -974,4 +974,77 @@ Integer newMachineId1=newMachineId.intValue();
// }
}
public void editMachineOption(Chromosome chromosome,Entry operation,
Long newMachineId, GlobalParam globalParam) {
List<Entry> allOperations = chromosome.getAllOperations();
Map<Integer, Integer> opTimeMap = chromosome.getResult().stream()
.collect(Collectors.toMap(
GAScheduleResult::getOperationId,
r -> r.getStartTime()
));
Integer newMachineId1=newMachineId.intValue();
int opId = operation.getId();
// 获取目标结果和工序
GAScheduleResult targetResult = chromosome.getResult().stream()
.filter(r -> r.getOperationId() == opId)
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
Entry targetOp = allOperations.stream()
.filter(o -> o.getId() == opId)
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
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);
}
// 更新设备选择序列
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);
}
List<Integer> operationSequencing = allOperations.stream()
.sorted((op1, op2) -> {
int time1 = opTimeMap.getOrDefault(op1.getId(), Integer.MAX_VALUE);
int time2 = opTimeMap.getOrDefault(op2.getId(), Integer.MAX_VALUE);
if (time1 != time2) {
return Integer.compare(time1, time2);
} else {
return Integer.compare(op1.getSequence(), op2.getSequence());
}
})
.map(Entry::getGroupId)
.collect(Collectors.toList());
chromosome.setOperationSequencing(operationSequencing);
// 重新解码
redecode(chromosome, chromosome.getBaseTime(), globalParam);
}
}
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