Commit 138726ae authored by Tong Li's avatar Tong Li

拖动

parent df2cb5cb
package com.aps.entity.Algorithm;
import lombok.Data;
/**
* 作者:佟礼
* 时间:2026-01-15
*/
@Data
public class OperationSort {
int id;
int time;
int group;
/**
* 工序顺序
*/
public int sequence;
public OperationSort(int id, int time, int group, int sequence) {
this.id = id;
this.time = time;
this.group = group;
this.sequence = sequence;
}
}
......@@ -36,11 +36,18 @@ public class ScheduleOperationService {
Long newMachineId, GlobalParam globalParam,int lockStartTime) {
List<Entry> allOperations = chromosome.getAllOperations();
int newStartTime1=newStartTime;
Map<Integer, Integer> opTimeMap = chromosome.getResult().stream()
.collect(Collectors.toMap(
GAScheduleResult::getOperationId,
r -> r.getStartTime()
));
List<OperationSort> opGroupMap = allOperations.stream()
.map(data -> new OperationSort(data.getId(), 0,data.getGroupId(),data.getSequence())) // 再提取字段
.collect(Collectors.toList());
Integer newMachineId1=newMachineId.intValue();
for (Integer opId:opIds) {
......@@ -55,6 +62,21 @@ Integer newMachineId1=newMachineId.intValue();
.filter(o -> o.getId() == opId)
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
if(targetOp.getSequence()>1) {
Entry targetOp1 = allOperations.stream()
.filter(o -> o.getGroupId() == targetOp.getGroupId()
&& o.getSequence() == targetOp.getSequence() - 1)
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
GAScheduleResult targetResult1 = chromosome.getResult().stream()
.filter(r -> r.getOperationId() == targetOp1.getId())
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
if (targetResult1.getEndTime() < newStartTime)
{
throw new RuntimeException("不能早于前一工序的结束时间");
}
}
if(newMachineId1!=0) {
int machineOptionIndex = targetOp.getMachineOptions().stream()
......@@ -85,25 +107,25 @@ Integer newMachineId1=newMachineId.intValue();
targetResult.setLockStartTime(lockStartTime);
if(targetOp.getSequence()==1) {
opTimeMap.put(opId, newStartTime);
}else {
Entry targetOp1 = allOperations.stream()
.filter(o -> o.getGroupId() == targetOp.getGroupId()
&&o.getSequence()==targetOp.getSequence()-1)
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
GAScheduleResult targetResult1 = chromosome.getResult().stream()
.filter(r -> r.getOperationId() == targetOp1.getId())
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
if(targetResult1.getStartTime()<newStartTime)
{
opTimeMap.put(opId, newStartTime);
}else {
opTimeMap.put(opId, targetResult1.getStartTime()+1);
}
}
// if(targetOp.getSequence()==1) {
// opTimeMap.put(opId, newStartTime);
// }else {
// Entry targetOp1 = allOperations.stream()
// .filter(o -> o.getGroupId() == targetOp.getGroupId()
// &&o.getSequence()==targetOp.getSequence()-1)
// .findFirst()
// .orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
// GAScheduleResult targetResult1 = chromosome.getResult().stream()
// .filter(r -> r.getOperationId() == targetOp1.getId())
// .findFirst()
// .orElseThrow(() -> new NoSuchElementException("Operation not found: " + opId));
// if(targetResult1.getStartTime()<newStartTime)
// {
// opTimeMap.put(opId, newStartTime);
// }else {
// opTimeMap.put(opId, targetResult1.getStartTime()+1);
// }
// }
newStartTime=newStartTime+1;
}
......@@ -126,19 +148,58 @@ Integer newMachineId1=newMachineId.intValue();
List<Integer> operationSequencing = allOperations.stream()
opGroupMap.forEach(t->t.setTime(opTimeMap.get(t.getId())));
opGroupMap = opGroupMap.stream()
.sorted(Comparator.comparingLong(OperationSort::getTime))
.collect(Collectors.toList());
opGroupMap = opGroupMap.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());
}
return Integer.compare(op2.getTime(), op1.getTime());
})
.map(Entry::getGroupId)
.collect(Collectors.toList());
Map<Integer, Integer> groupMap=new HashMap<>();
Map<Integer, Integer> opidMap=new HashMap<>();
Map<Integer, OperationSort> outtimeMap=new HashMap<>();
List<OperationSort> newops=new ArrayList<>();
for (OperationSort op:opGroupMap) {
if(groupMap.containsKey(op.getGroup()))
{
if(groupMap.get(op.getGroup())<=op.getSequence())
{
outtimeMap.put(op.getId(),op);
}else {
opidMap.put(op.getGroup(),op.getSequence());
newops.add(op);
}
}else {
groupMap.put(op.getGroup(),op.getSequence());
opidMap.put(op.getGroup(),op.getId());
newops.add(op);
}
}
for (OperationSort op:outtimeMap.values()) {
int opid=(int) opidMap.get(op.getGroup());
OptionalInt index = IntStream.range(0, newops.size())
.filter(j -> opid==newops.get(j).getId())
.findFirst();
int opSeq =index.orElse(0) ;
newops.add(opSeq,op);
opidMap.put(op.getGroup(),op.getId());
}
List<Integer> operationSequencing = newops.stream()
.map(OperationSort::getGroup)
.collect(Collectors.toList());
Collections.reverse(operationSequencing);
chromosome.setOperationSequencing(operationSequencing);
// 重新解码
redecode(chromosome, chromosome.getBaseTime(), globalParam);
......
......@@ -439,7 +439,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
WriteScheduleSummary(chromosome);
// WriteScheduleSummary(chromosome);
ScheduleOperation.moveOperation(chromosome,opId, (int)ChronoUnit.SECONDS.between(chromosome.getBaseTime(), newStartTime),newMachineId, globalParam, lockStartTime);
// WriteScheduleSummary(chromosome);
......
......@@ -39,11 +39,11 @@ public class PlanResultServiceTest {
// nsgaiiUtils.Test();
//planResultService.execute2("C5FB5EF2A7334A0A92F826F4937E1008");
// planResultService.execute2("726D4C1A712B4B1393175BD44B775B66");
planResultService.execute2("265F24B6DF3C40E4B17D193B0CC8AAF2");
// LocalDateTime t= LocalDateTime.of(2025, 11, 15, 6, 51, 11);
// List<Integer> opids=new ArrayList<>();BCA6FA43FFA444D3952CF8F6E1EA291B
// opids.add(1);
// planResultService.Move("B571EF6682DB463AB2977B1055A74112",opids,t,3403L);
// planResultService.execute2("265F24B6DF3C40E4B17D193B0CC8AAF2");
LocalDateTime t= LocalDateTime.of(2026, 02, 14, 1, 25, 52);
List<Integer> opids=new ArrayList<>();//BCA6FA43FFA444D3952CF8F6E1EA291B
opids.add(9);
planResultService.Move("27065EA0ECD14A81B7FAAFEF52273F93",opids,t,1265l,0);
// planResultService.Redecode("12345679");
// MaintenanceWindow maintenanceWindow=new MaintenanceWindow();
// maintenanceWindow.setStartTime(LocalDateTime.of(2025, 10, 21, 0, 0, 0));
......
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