Commit 8423472d authored by DESKTOP-VKRD9QF\Administration's avatar DESKTOP-VKRD9QF\Administration
parents 343f8a88 cfcaec50
This diff is collapsed.
...@@ -15,13 +15,11 @@ import io.swagger.v3.oas.annotations.tags.Tag; ...@@ -15,13 +15,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -136,14 +134,64 @@ public class ResourceGanttController { ...@@ -136,14 +134,64 @@ public class ResourceGanttController {
} }
@GetMapping("/Move") @GetMapping("/Move")
public Chromosome Move(String SceneId,int opid,LocalDateTime newStartTime,
Long newMachineId) {
// opid=1;
// newStartTime= LocalDateTime.of(2025, 12, 7, 0, 0);
// newMachineId=3402L;
// SceneId="B571EF6682DB463AB2977B1055A74112";
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome scheduleChromosomes = planResultService.Move(SceneId,opid,newStartTime,newMachineId);
// 提取所有场景ID
return scheduleChromosomes;
}
@PostMapping("/SpiltOperation")
public Chromosome SpiltOperation(@RequestParam String SceneId,
@RequestParam int opid,
@RequestBody List<Double> splitCounts) {
opid=1;
// newStartTime= LocalDateTime.of(2025, 12, 7, 0, 0);
// newMachineId=3402L;
splitCounts=new ArrayList<>();
splitCounts.add(20000d);
splitCounts.add(30000d);
SceneId="B571EF6682DB463AB2977B1055A74112";
public Chromosome Move() {
// 调用 PlanResultService 获取 ScheduleChromosome 列表 // 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome scheduleChromosomes = planResultService.Move("B571EF6682DB463AB2977B1055A74112"); Chromosome scheduleChromosomes = planResultService.SpiltOperation(SceneId,opid,splitCounts.toArray(new Double[0]));
// 提取所有场景ID // 提取所有场景ID
return scheduleChromosomes; return scheduleChromosomes;
} }
@PostMapping("/delOperation")
public Chromosome DelOperation(@RequestParam String SceneId,
@RequestParam int opid) {
opid=1;
SceneId="B571EF6682DB463AB2977B1055A74112";
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome scheduleChromosomes = planResultService.DelOperation(SceneId,opid);
// 提取所有场景ID
return scheduleChromosomes;
}
@PostMapping("/LockedOperation")
public Chromosome LockedOperation(@RequestParam String SceneId,
@RequestParam int opid,@RequestParam boolean isLocked) {
opid=1;
SceneId="B571EF6682DB463AB2977B1055A74112";
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome scheduleChromosomes = planResultService.LockOperation(SceneId,opid,isLocked);
// 提取所有场景ID
return scheduleChromosomes;
}
/** /**
* 将 ScheduleChromosome 转换为 ResourceGanttVO 列表 * 将 ScheduleChromosome 转换为 ResourceGanttVO 列表
......
...@@ -27,7 +27,8 @@ public class GAScheduleResult { ...@@ -27,7 +27,8 @@ public class GAScheduleResult {
private double Quantity; // 批次大小(订单可拆分) private double Quantity; // 批次大小(订单可拆分)
private List<ScheduleResultDetail> GeneDetails; // 时间详情 private List<ScheduleResultDetail> GeneDetails; // 时间详情
private int designatedStartTime = -1; // 设计开始时间(默认-1) private int designatedStartTime = -1; // 设计开始时间(默认-1)
private int forcedMachineId = -1; // 强制分配的设备ID(-1表示无强制) private Long forcedMachineId =-1L; // 强制分配的设备ID(-1表示无强制)
private boolean IsLocked=false;
private double OneTime; // 单件工时 private double OneTime; // 单件工时
private double ProcessingTime; // 绝对处理时间(分钟) private double ProcessingTime; // 绝对处理时间(分钟)
private int ChangeoverTime; private int ChangeoverTime;
......
...@@ -25,15 +25,26 @@ public class Entry { ...@@ -25,15 +25,26 @@ public class Entry {
public int GroupId ; public int GroupId ;
/** /**
* 所属组ID 需要按照前后顺序生产的工单给一组 * 原订单ID
*/ */
public String OrderId ; public String OrderId ;
private Long routingDetailId;
private Long taskSeq;
private String routingDetailName;
private String productId; private String productId;
/** /**
* 工单ID * 工单ID
*/ */
public String ExecId ; public String ExecId ;
/**
* 工单ID
*/
public String MainId;
/** /**
* 离散参数 * 离散参数
*/ */
...@@ -64,6 +75,11 @@ public class Entry { ...@@ -64,6 +75,11 @@ public class Entry {
*/ */
public List<Integer> NextEntryIds ;//后工序 public List<Integer> NextEntryIds ;//后工序
/**
* 数据状态 1 拆分 2 新建
*/
public Integer state ;
/** /**
* 是否可中断,间缝插针 * 是否可中断,间缝插针
*/ */
......
...@@ -131,7 +131,7 @@ public class GeneticAlgorithm { ...@@ -131,7 +131,7 @@ public class GeneticAlgorithm {
break; break;
} }
} }
best.setBaseTime(param.getBaseTime());
best.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines)); best.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines));
best.setOrders(orders); best.setOrders(orders);
// 步骤3:返回最优解 // 步骤3:返回最优解
......
...@@ -168,6 +168,16 @@ public class GeneticDecoder { ...@@ -168,6 +168,16 @@ public class GeneticDecoder {
Entry currentOp = orderOps.get(scheduledCount); Entry currentOp = orderOps.get(scheduledCount);
int opSequence = currentOp.getSequence(); int opSequence = currentOp.getSequence();
GAScheduleResult existingResult = chromosome.getResultOld().stream()
.filter(r-> r.getOperationId() == currentOp.Id)
.findFirst().orElse(null);
if(existingResult!=null) {
if(existingResult.isIsLocked())
{
continue;
}
}
// 从映射表中获取机器和加工时间 // 从映射表中获取机器和加工时间
OpMachine machineOption=opMachineMap.stream() OpMachine machineOption=opMachineMap.stream()
.filter(m -> m.getGroupId() == groupId&&m.getSequence()==opSequence) .filter(m -> m.getGroupId() == groupId&&m.getSequence()==opSequence)
...@@ -356,6 +366,7 @@ public class GeneticDecoder { ...@@ -356,6 +366,7 @@ public class GeneticDecoder {
result.setTeardownTime(teardownTime); result.setTeardownTime(teardownTime);
if(existingResult!=null) { if(existingResult!=null) {
result.setDesignatedStartTime(existingResult.getDesignatedStartTime()); result.setDesignatedStartTime(existingResult.getDesignatedStartTime());
} }
result.setOneTime(processingTime); result.setOneTime(processingTime);
......
...@@ -215,7 +215,7 @@ public class IdGroupingWithDualSerial { ...@@ -215,7 +215,7 @@ public class IdGroupingWithDualSerial {
* @return 更新后的结果 * @return 更新后的结果
*/ */
public static List<GroupResult> addNode(List<GroupResult> existingResults, int targetGroupIndex, public static List<GroupResult> addNode(List<GroupResult> existingResults, int targetGroupIndex,
String newId, List<Integer> newParentIds, List<Integer> newChildIds) { String newId, List<Integer> newParentIds, List<Integer> newChildIds,String insertAfterOriginalId) {
// 1. 空值安全检查 // 1. 空值安全检查
if (existingResults == null || existingResults.isEmpty() || targetGroupIndex < 0 || targetGroupIndex >= existingResults.size()) { if (existingResults == null || existingResults.isEmpty() || targetGroupIndex < 0 || targetGroupIndex >= existingResults.size()) {
throw new IllegalArgumentException("无效的现有结果或目标分组索引"); throw new IllegalArgumentException("无效的现有结果或目标分组索引");
...@@ -244,12 +244,26 @@ public class IdGroupingWithDualSerial { ...@@ -244,12 +244,26 @@ public class IdGroupingWithDualSerial {
newGlobalSerial++; newGlobalSerial++;
} }
// 5. 找到新节点的插入位置(父节点之后)
// 5. 找到插入位置:优先插入到指定节点之后,否则插入到父节点之后
int insertIndex = 0; int insertIndex = 0;
for (int i = 0; i < nodeList.size(); i++) { // 定位要插入到其后的节点(如"20")
NodeInfo node = nodeList.get(i); if (insertAfterOriginalId != null && !insertAfterOriginalId.trim().isEmpty()) {
if (newParentIds.contains(node.getGlobalSerial())) { for (int i = 0; i < nodeList.size(); i++) {
insertIndex = i + 1; // 插入到最后一个父节点之后 NodeInfo node = nodeList.get(i);
if (insertAfterOriginalId.equals(node.getOriginalId())) {
insertIndex = i + 1; // 插入到指定节点之后
break;
}
}
}
// 若未找到指定节点,回退到父节点之后的逻辑
if (insertIndex == 0) {
for (int i = 0; i < nodeList.size(); i++) {
NodeInfo node = nodeList.get(i);
if (newParentIds.contains(node.getGlobalSerial())) {
insertIndex = i + 1;
}
} }
} }
...@@ -528,7 +542,7 @@ public class IdGroupingWithDualSerial { ...@@ -528,7 +542,7 @@ public class IdGroupingWithDualSerial {
int targetGroupIndex = 1; // 分组2的索引 int targetGroupIndex = 1; // 分组2的索引
// 添加新节点 // 添加新节点
results = addNode(results, targetGroupIndex, newId, newParentIds, newChildIds); results = addNode(results, targetGroupIndex, newId, newParentIds, newChildIds,"");
List<String> newIdList = Arrays.asList("20", "21", "24"); List<String> newIdList = Arrays.asList("20", "21", "24");
...@@ -540,6 +554,7 @@ public class IdGroupingWithDualSerial { ...@@ -540,6 +554,7 @@ public class IdGroupingWithDualSerial {
results = deleteNodeByGlobalSerial(results, 13); results = deleteNodeByGlobalSerial(results, 13);
// 输出结果 // 输出结果
for (int i = 0; i < results.size(); i++) { for (int i = 0; i < results.size(); i++) {
GroupResult groupResult = results.get(i); GroupResult groupResult = results.get(i);
......
...@@ -31,6 +31,7 @@ import java.time.format.DateTimeFormatter; ...@@ -31,6 +31,7 @@ import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Service @Service
public class PlanResultService { public class PlanResultService {
...@@ -66,7 +67,7 @@ public class PlanResultService { ...@@ -66,7 +67,7 @@ public class PlanResultService {
@Autowired @Autowired
private ProdOrderProcessService _prodOrderProcessService; private ProdOrderProcessService _prodOrderProcessService;
private final LocalDateTime baseTime = LocalDateTime.of(2025, 10, 1, 0, 0, 0); private LocalDateTime baseTime = LocalDateTime.of(2025, 11, 1, 0, 0, 0);
public List<ScheduleChromosome> execute() { public List<ScheduleChromosome> execute() {
try { try {
...@@ -229,7 +230,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -229,7 +230,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
WriteScheduleSummary(Chromosomes); WriteScheduleSummary(Chromosomes);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(); ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
LocalDateTime ds= LocalDateTime.of(2025, 12, 7, 23, 59); LocalDateTime ds= LocalDateTime.of(2025, 12, 7, 23, 59);
ScheduleOperation.moveOperation(Chromosomes,3, (int)ChronoUnit.SECONDS.between(param.getBaseTime(), ds),2,param.getBaseTime(), globalParam); // ScheduleOperation.moveOperation(Chromosomes,3, (int)ChronoUnit.SECONDS.between(param.getBaseTime(), ds),(Long)2,param.getBaseTime(), globalParam);
WriteScheduleSummary(Chromosomes); WriteScheduleSummary(Chromosomes);
return Chromosomes; return Chromosomes;
...@@ -297,24 +298,112 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -297,24 +298,112 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
throw new RuntimeException("调度执行失败", e); throw new RuntimeException("调度执行失败", e);
} }
} }
public Chromosome Move(String SceneId) {
public Chromosome EditOperation(String SceneId,Entry operation) {
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
if (chromosome == null || chromosome.getAllOperations() == null) {
return chromosome; // 直接返回,空值由上层处理
}
List<Entry> operations = chromosome.getAllOperations();
// 直接查找匹配元素的索引(避免先找元素再查索引的冗余)
int position = IntStream.range(0, operations.size())
.filter(i -> {
Entry t = operations.get(i);
return t.getId()==operation.getId();
})
.findFirst()
.orElse(-1);
// 索引有效时替换
if (position != -1) {
operations.set(position, operation);
}
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleParams param = new ScheduleParams(); ScheduleParams param = new ScheduleParams();
param.setBaseTime(LocalDateTime.of(2025, 11, 1, 0, 0, 0)); param.setBaseTime(LocalDateTime.of(2025, 11, 1, 0, 0, 0));
GlobalParam globalParam=new GlobalParam();
ScheduleOperation.redecode(chromosome,param.getBaseTime(), globalParam);
return chromosome;
}
public Chromosome Move(String SceneId,int opId, LocalDateTime newStartTime,
Long newMachineId) {
GlobalParam globalParam=new GlobalParam(); GlobalParam globalParam=new GlobalParam();
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId); Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperation.moveOperation(chromosome,opId, (int)ChronoUnit.SECONDS.between(chromosome.getBaseTime(), newStartTime),newMachineId, globalParam);
// WriteScheduleSummary(chromosome);
_sceneService.saveChromosomeToFile(chromosome, SceneId);
return chromosome;
}
public Chromosome SpiltOperation(String SceneId,int opId,Double[] splitCounts) {
GlobalParam globalParam=new GlobalParam();
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperation.SpiltOperation(chromosome,opId,splitCounts, globalParam);
WriteScheduleSummary(chromosome); WriteScheduleSummary(chromosome);
_sceneService.saveChromosomeToFile(chromosome, SceneId);
return chromosome;
}
public Chromosome DelOperation(String SceneId,int opId) {
GlobalParam globalParam=new GlobalParam();
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperation.DelOperation(chromosome,opId, globalParam);
WriteScheduleSummary(chromosome);
_sceneService.saveChromosomeToFile(chromosome, SceneId);
return chromosome;
}
public Chromosome LockOperation(String SceneId,int opId,boolean isLocked) {
GlobalParam globalParam=new GlobalParam();
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(); ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
LocalDateTime ds= LocalDateTime.of(2025, 12, 7, 23, 59);
ScheduleOperation.moveOperation(chromosome,2, (int)ChronoUnit.SECONDS.between(param.getBaseTime(), ds),2,param.getBaseTime(), globalParam); ScheduleOperation.LockOperation(chromosome,opId,isLocked, globalParam);
WriteScheduleSummary(chromosome); WriteScheduleSummary(chromosome);
// _sceneService.saveChromosomeToFile(chromosome, SceneId); _sceneService.saveChromosomeToFile(chromosome, SceneId);
return chromosome; return chromosome;
} }
public Chromosome schedule(String SceneId) {
public Chromosome schedule(String SceneId) {
try { try {
ScheduleParams param = new ScheduleParams(); ScheduleParams param = new ScheduleParams();
...@@ -401,11 +490,9 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -401,11 +490,9 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
.collect(Collectors.toList()); .collect(Collectors.toList());
for (GAScheduleResult job : sortedJobs) { for (GAScheduleResult job : sortedJobs) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(String.format( sb.append(String.format(
"[%d-%d]:[%s-%s] Order %d, Machine %d, Operation %d, Batch %d, processingTime %d", "[%d-%d]:[%s-%s] Order %d, Machine %d, Operation %d, Batch %.1f, processingTime %%.1f",
job.getStartTime(), job.getStartTime(),
job.getEndTime(), job.getEndTime(),
ConvertTime(job.getStartTime()), ConvertTime(job.getStartTime()),
...@@ -437,7 +524,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -437,7 +524,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
} }
} }
private String ConvertTime(int minute) { private String ConvertTime(int minute) {
return baseTime.plusMinutes(minute).format(java.time.format.DateTimeFormatter.ofPattern("MM-dd HH:mm")); return baseTime.plusSeconds(minute).format(java.time.format.DateTimeFormatter.ofPattern("MM-dd HH:mm"));
} }
/** /**
...@@ -667,6 +754,9 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -667,6 +754,9 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
{ {
entry.setOrderId(op.getOrderId()); entry.setOrderId(op.getOrderId());
entry.setQuantity(op.getPlanQty()); entry.setQuantity(op.getPlanQty());
entry.setRoutingDetailId(op.getRoutingDetailId());
entry.setTaskSeq(op.getTaskSeq());
entry.setRoutingDetailName(op.getRoutingDetailName());
ProdLaunchOrder order = ProdLaunchOrders.stream() ProdLaunchOrder order = ProdLaunchOrders.stream()
.filter(t -> t.getOrderId().equals(op.getOrderId())) .filter(t -> t.getOrderId().equals(op.getOrderId()))
.findFirst().orElse(null); .findFirst().orElse(null);
...@@ -682,8 +772,10 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -682,8 +772,10 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
MachineOption mo = new MachineOption(); MachineOption mo = new MachineOption();
mo.setMachineId(e.getEquipId()); mo.setMachineId(e.getEquipId());
mo.setProcessingTime(e.getSpeed()); mo.setProcessingTime(e.getSpeed());
// mo.setContantTime(op.getConstTime()); mo.setContantTime(op.getConstTime());
// mo.setTeardownTime(op.getPostprocessingTime()); mo.setSetupTime(op.getChangeLineTime());
mo.setTeardownTime(op.getPostprocessingTime());
mo.setPreTime(e.getSetupTime());
mos.add(mo); mos.add(mo);
} }
......
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