Commit 653269ef authored by Tong Li's avatar Tong Li

订单配套

parent 9e01001a
...@@ -116,25 +116,9 @@ public class ResourceGanttController { ...@@ -116,25 +116,9 @@ public class ResourceGanttController {
} }
@GetMapping("/getScene")
@Operation(summary = "获取所有场景ID", description = "获取所有场景ID")
public Chromosome getScene() {
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome scheduleChromosomes = planResultService.execute1();
// 提取所有场景ID
return scheduleChromosomes;
}
@GetMapping("/getScene2")
@Operation(summary = "获取所有场景ID", description = "获取所有场景ID")
public Chromosome getScene2() {
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome scheduleChromosomes = planResultService.execute2("B571EF6682DB463AB2977B1055A74112");
// 提取所有场景ID
return scheduleChromosomes;
}
@GetMapping("/SyncMaterials") @GetMapping("/SyncMaterials")
@Operation(summary = "更新物料信息缓存", description = "更新物料信息缓存") @Operation(summary = "更新物料信息缓存", description = "更新物料信息缓存")
......
...@@ -15,7 +15,7 @@ private Long lastmodifieruserid; ...@@ -15,7 +15,7 @@ private Long lastmodifieruserid;
private Long isdeleted; private Long isdeleted;
private LocalDateTime deletiontime; private LocalDateTime deletiontime;
private Long deleteruserid; private Long deleteruserid;
private Long routingHeaderId; private Integer routingHeaderId;
private Long routingDetailId; private Long routingDetailId;
private String materialId; private String materialId;
private String materialType; private String materialType;
......
...@@ -52,6 +52,5 @@ private List<Integer> FinishOrderId ; ...@@ -52,6 +52,5 @@ private List<Integer> FinishOrderId ;
private List<Integer> TargetFinishedOperationId; private List<Integer> TargetFinishedOperationId;
private double delayHours;//延迟时间 private double delayHours;//延迟时间
//物料需求
private List<OrderMaterialRequirement> materialRequirementList;
} }
\ No newline at end of file
...@@ -44,8 +44,10 @@ public class GeneticAlgorithm { ...@@ -44,8 +44,10 @@ public class GeneticAlgorithm {
private SceneService _sceneService; private SceneService _sceneService;
private String sceneId;
public GeneticAlgorithm(GlobalParam globalParam,List<Machine> machines, List<Order> orders, public GeneticAlgorithm(GlobalParam globalParam,List<Machine> machines, List<Order> orders,
List<Material> materials, MachineSchedulerService machineScheduler,List<GroupResult> entryRel,MaterialRequirementService _materialRequirementService,SceneService sceneService) { List<Material> materials, MachineSchedulerService machineScheduler,List<GroupResult> entryRel,MaterialRequirementService _materialRequirementService,SceneService sceneService,String _sceneId) {
this.machines = machines; this.machines = machines;
this.orders = orders; this.orders = orders;
this.materials = materials; this.materials = materials;
...@@ -54,7 +56,7 @@ public class GeneticAlgorithm { ...@@ -54,7 +56,7 @@ public class GeneticAlgorithm {
_entryRel=entryRel; _entryRel=entryRel;
materialRequirementService=_materialRequirementService; materialRequirementService=_materialRequirementService;
_sceneService=sceneService; _sceneService=sceneService;
sceneId=_sceneId;
} }
public void Init(double[] customWeights, boolean pureNSGAIIMode) { public void Init(double[] customWeights, boolean pureNSGAIIMode) {
...@@ -299,19 +301,15 @@ public class GeneticAlgorithm { ...@@ -299,19 +301,15 @@ public class GeneticAlgorithm {
FileHelper.writeLogFile(String.format("排产-----------方案数量---%d-------",0 )); FileHelper.writeLogFile(String.format("排产-----------方案数量---%d-------",0 ));
return population; return population;
} }
population = population.stream()
.collect(Collectors.toMap(
Chromosome::getGeneStr, // key:去重的字段(GeneStr)
u -> u, // value:Chromosome对象
// population = population.stream() (u1, u2) -> u1 // 重复时保留第一个元素
// .collect(Collectors.toMap( ))
// Chromosome::getGeneStr, // key:去重的字段(GeneStr) .values() // 获取去重后的
// u -> u, // value:Chromosome对象 .stream()
// (u1, u2) -> u1 // 重复时保留第一个元素 .collect(Collectors.toList());
// ))
// .values() // 获取去重后的
// .stream()
// .collect(Collectors.toList());
return population; return population;
} }
...@@ -372,7 +370,7 @@ return population; ...@@ -372,7 +370,7 @@ return population;
{ {
FileHelper.writeLogFile("解码---------------"+population.size() ); FileHelper.writeLogFile("解码---------------"+population.size() );
GeneticDecoder decoder = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler,orderMaterials); GeneticDecoder decoder = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler,materialRequirementService, sceneId);
boolean ismore=true; boolean ismore=true;
if(ismore) { if(ismore) {
CompletableFuture.allOf(population.stream() CompletableFuture.allOf(population.stream()
......
...@@ -47,13 +47,17 @@ public class GeneticDecoder { ...@@ -47,13 +47,17 @@ public class GeneticDecoder {
private GlobalParam _globalParam; private GlobalParam _globalParam;
private MachineCalculator machineCalculator; private MachineCalculator machineCalculator;
private List<OrderMaterialRequirement> orderMaterials; private MaterialRequirementService materialRequirementService;
private DiscreteParameterMatrixService discreteParameterMatrixService; private DiscreteParameterMatrixService discreteParameterMatrixService;
private String sceneId;
public GeneticDecoder(GlobalParam globalParam,LocalDateTime baseTime, List<Machine> machines, List<Order> orders, public GeneticDecoder(GlobalParam globalParam,LocalDateTime baseTime, List<Machine> machines, List<Order> orders,
List<Material> materials, MachineSchedulerService machineScheduler, List<OrderMaterialRequirement> _orderMaterials) { List<Material> materials, MachineSchedulerService machineScheduler, MaterialRequirementService _materialRequirementService,String _sceneId) {
this.baseTime = baseTime; this.baseTime = baseTime;
this.machines = machines; this.machines = machines;
this.orders = orders; this.orders = orders;
...@@ -62,7 +66,8 @@ public class GeneticDecoder { ...@@ -62,7 +66,8 @@ public class GeneticDecoder {
this.machineScheduler = machineScheduler; this.machineScheduler = machineScheduler;
_globalParam=globalParam; _globalParam=globalParam;
machineCalculator=new MachineCalculator(baseTime,machines,machineScheduler); machineCalculator=new MachineCalculator(baseTime,machines,machineScheduler);
orderMaterials=_orderMaterials; materialRequirementService=_materialRequirementService;
sceneId=_sceneId;
// this.orderMaxID = orders.stream().mapToInt(Order::getId).max().orElse(0); // this.orderMaxID = orders.stream().mapToInt(Order::getId).max().orElse(0);
} }
...@@ -71,6 +76,10 @@ public class GeneticDecoder { ...@@ -71,6 +76,10 @@ public class GeneticDecoder {
// FileHelper.writeLogFile("解码-----------开始-------"+chromosome.getID()+":"+cacheKey ); // FileHelper.writeLogFile("解码-----------开始-------"+chromosome.getID()+":"+cacheKey );
_allOperations=chromosome.getAllOperations(); _allOperations=chromosome.getAllOperations();
List<OrderMaterialRequirement> orderMaterials = materialRequirementService.buildMultiLevelRequirementNetwork(sceneId, baseTime);
if(orderMaterials!=null&&orderMaterials.size()>0&&_globalParam.isIsCheckSf()) { if(orderMaterials!=null&&orderMaterials.size()>0&&_globalParam.isIsCheckSf()) {
CreateNewOpSequence(chromosome); CreateNewOpSequence(chromosome);
} }
...@@ -619,6 +628,7 @@ if(finishedOrder==null||finishedOrder.size()==0) ...@@ -619,6 +628,7 @@ if(finishedOrder==null||finishedOrder.size()==0)
private int getOperationBOMTime(Entry currentOp, Chromosome chromosome) { private int getOperationBOMTime(Entry currentOp, Chromosome chromosome) {
List<OrderMaterialRequirement> orderMaterials= chromosome.getOrderMaterials();
if(orderMaterials==null) if(orderMaterials==null)
{ {
return 0; return 0;
......
...@@ -1181,7 +1181,7 @@ if(targetOp.getSequence()>1) { ...@@ -1181,7 +1181,7 @@ if(targetOp.getSequence()>1) {
chromosome.setMachines(ProductionDeepCopyUtil.deepCopyList(chromosome.getInitMachines(),Machine.class) ); chromosome.setMachines(ProductionDeepCopyUtil.deepCopyList(chromosome.getInitMachines(),Machine.class) );
GeneticDecoder decoder = new GeneticDecoder(globalParam,baseTime, chromosome.getMachines(), GeneticDecoder decoder = new GeneticDecoder(globalParam,baseTime, chromosome.getMachines(),
chromosome.getOrders(), null, machineScheduler,chromosome.getOrderMaterials()); chromosome.getOrders(), null, machineScheduler,null,chromosome.getScenarioID());
chromosome.setResultOld(ProductionDeepCopyUtil.deepCopyList(chromosome.getResult(),GAScheduleResult.class)); chromosome.setResultOld(ProductionDeepCopyUtil.deepCopyList(chromosome.getResult(),GAScheduleResult.class));
chromosome.getResult().clear(); chromosome.getResult().clear();
......
...@@ -128,124 +128,8 @@ public class PlanResultService { ...@@ -128,124 +128,8 @@ public class PlanResultService {
public Chromosome execute1() {
try {
//List<ScheduleResultDetail> details=new ArrayList<>();
// ScheduleResultDetail detail1=new ScheduleResultDetail();
//
// detail1.setOneTime(100);//单件工时
//
//
// ScheduleResultDetail detail2=new ScheduleResultDetail();
//
// detail2.setOneTime(200);//单件工时
// details.add(detail1);
// details.add(detail2);
// mergeSegmentsWithDifferentOneTime(details, 50);
// 1. 读取数据
List<Machine> machines = loadData("machines.json", Machine.class);
List<Product> products = loadData("products.json", Product.class);
List<Order> orders = loadData("orders.json", Order.class);
// 设置机器信息到班次中
for (Machine machine : machines) {
if (machine.getShifts() != null) {
for (Shift shift : machine.getShifts()) {
shift.setMachineId(machine.getId());
shift.setMachineName(machine.getName());
}
}
// 调试:打印机器和班次信息
System.out.println("Machine: " + machine.getId() + ", Name: " + machine.getName());
if (machine.getShifts() != null) {
for (Shift shift : machine.getShifts()) {
System.out.println(" Shift: " + shift.getStartTime() + " - " + shift.getEndTime() +
", Status: " + shift.getStatus() +
", MachineId: " + shift.getMachineId() +
", MachineName: " + shift.getMachineName());
}
}
}
ScheduleParams param = new ScheduleParams();
param.setBaseTime(LocalDateTime.of(2025, 11, 1, 0, 0, 0));
// List<MesHoliday> holidays= _MesHolidayService.list();
// 创建节假日
// 将节假日添加到所有设备中
// addHolidaysToAllMachines(machines);
// 3. 创建调度服务
MachineSchedulerService machineScheduler = new MachineSchedulerService(
param.getBaseTime());
// 4. 初始化机器时间线
for (Machine machine : machines) {
MachineTimeline timeline = machineScheduler.getOrCreateTimeline(machine);
machine.setAvailability(timeline.getSegments());
}
// 3. 构建订单-工序数据
List<Entry> allOperations = new ArrayList<>();
Random rnd = new Random(); // 注意:此处变量声明但未使用,可根据实际需求保留或移除
int id = 1;
for (Order order : orders) {
order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
// 假设products是一个List<Product>,根据Product的Id查找对应的产品
Product product = products.stream()
.filter(p -> p.getId() == order.getProductId())
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("未找到对应产品: " + order.getProductId()));
int sequence = 1;
for (Operation o : product.getOperations()) { // 假设Product类有getOperations()方法返回工序列表
Entry entry = new Entry();
entry.setId(id);
// entry.setGroupId(order.getId());
entry.setSequence(sequence);
entry.setMachineOptions(o.getMachineOptions()); // 假设Operation类有获取机器选项的方法
entry.setPriority(order.getPriority());
entry.setQuantity(order.getQuantity());
// entry.setMaterialRequirements(o.getMaterialRequirements()); // 假设Operation类有获取物料需求的方法
if (sequence != 1) {
OperationDependency od=new OperationDependency();
od.setPrevOperationId(id - 1);
entry.getPrevEntryIds().add(od); // 假设Entry类有getPrevEntryIds()返回List<Integer>
}
allOperations.add(entry);
sequence++;
id++;
}
}
GlobalParam globalParam=new GlobalParam();
// 5. 执行调度算法
param.initAdaptiveParams(allOperations.size());
GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,null,machineScheduler,null,materialRequirementService,_sceneService); //new GeneticAlgorithm(products, machines, orders, machineScheduler);
Chromosome Chromosomes =scheduler.Run(param,allOperations);
WriteScheduleSummary(Chromosomes);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
LocalDateTime ds= LocalDateTime.of(2025, 12, 7, 23, 59);
// ScheduleOperation.moveOperation(Chromosomes,3, (int)ChronoUnit.SECONDS.between(param.getBaseTime(), ds),(Long)2,param.getBaseTime(), globalParam);
WriteScheduleSummary(Chromosomes);
return Chromosomes;
} catch (Exception e) {
throw new RuntimeException("调度执行失败", e);
}
}
public Chromosome execute2(String SceneId) { public Chromosome execute2(String SceneId) {
try { try {
...@@ -284,14 +168,14 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -284,14 +168,14 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
List<GroupResult> entryRel=(List<GroupResult>)list.get(2); List<GroupResult> entryRel=(List<GroupResult>)list.get(2);
Map<Long,Double> machineIds=(Map<Long,Double>)list.get(3); Map<Long,Double> machineIds=(Map<Long,Double>)list.get(3);
Map<Integer,Object> reslte=materialRequirementService.preloadRoutingCache(SceneId,orders,Materials,globalParam.isIsCheckSf());
List<Long> equipIDs=(List<Long>) reslte.get(1);
// List<Long> equipIDs= materialRequirementService.preloadRoutingCache(SceneId,orders,Materials,globalParam.isIsCheckSf()); List<Long> machineIds1=machineIds.keySet().stream().collect(Collectors.toList());
if(equipIDs!=null&&equipIDs.size()>0)
Set machineIds1=machineIds.keySet(); {
// if(equipIDs!=null&&equipIDs.size()>0) machineIds1.addAll(equipIDs);
// { }
// machineIds1.addAll(equipIDs);
// }
machines= machines.stream().filter(t->machineIds1.contains(t.getId())).collect(Collectors.toList()); machines= machines.stream().filter(t->machineIds1.contains(t.getId())).collect(Collectors.toList());
...@@ -313,7 +197,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -313,7 +197,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
// 5. 执行调度算法 // 5. 执行调度算法
GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,Materials,machineScheduler,entryRel,materialRequirementService,_sceneService); //new GeneticAlgorithm(products, machines, orders, machineScheduler); GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,Materials,machineScheduler,entryRel,materialRequirementService,_sceneService,SceneId); //new GeneticAlgorithm(products, machines, orders, machineScheduler);
param.initAdaptiveParams(entrys.size()); param.initAdaptiveParams(entrys.size());
double[] customWeights = new double[] { 0.4, 0.1, 0.1, 0.1, 0.3 }; // 延迟时间权重提升到0.5 double[] customWeights = new double[] { 0.4, 0.1, 0.1, 0.1, 0.3 }; // 延迟时间权重提升到0.5
//完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间 //完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间
...@@ -866,7 +750,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0)); ...@@ -866,7 +750,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
machines= machines.stream().filter(t->machineIds.contains(t.getId())).collect(Collectors.toList()); machines= machines.stream().filter(t->machineIds.contains(t.getId())).collect(Collectors.toList());
// 5. 执行调度算法 // 5. 执行调度算法
GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,Materials,machineScheduler,entryRel,materialRequirementService,_sceneService); //new GeneticAlgorithm(products, machines, orders, machineScheduler); GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,Materials,machineScheduler,entryRel,materialRequirementService,_sceneService,SceneId); //new GeneticAlgorithm(products, machines, orders, machineScheduler);
param.initAdaptiveParams(entrys.size()); param.initAdaptiveParams(entrys.size());
double[] customWeights = new double[] { 0.4, 0.1, 0.1, 0.1, 0.3 }; // 延迟时间权重提升到0.5 double[] customWeights = new double[] { 0.4, 0.1, 0.1, 0.1, 0.3 }; // 延迟时间权重提升到0.5
//完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间 //完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间
......
...@@ -37,7 +37,7 @@ public class PlanResultServiceTest { ...@@ -37,7 +37,7 @@ public class PlanResultServiceTest {
// NSGAIIUtils nsgaiiUtils=new NSGAIIUtils(); // NSGAIIUtils nsgaiiUtils=new NSGAIIUtils();
// nsgaiiUtils.Test(); // nsgaiiUtils.Test();
planResultService.execute2("0DCB1301C57C48B68154789B0FAB8B98"); planResultService.execute2("83D729F5E0694F25A71614B1991D7457");
// planResultService.execute2("726D4C1A712B4B1393175BD44B775B66"); // planResultService.execute2("726D4C1A712B4B1393175BD44B775B66");
// planResultService.execute2("265F24B6DF3C40E4B17D193B0CC8AAF2"); // planResultService.execute2("265F24B6DF3C40E4B17D193B0CC8AAF2");
// LocalDateTime t= LocalDateTime.of(2026, 02, 14, 1, 25, 52); // LocalDateTime t= LocalDateTime.of(2026, 02, 14, 1, 25, 52);
......
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