Explorar el Código

链式变量模型

fangpy hace 6 meses
padre
commit
0eabda332b

+ 1 - 1
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/controller/ApsSchedulingController.java

@@ -40,7 +40,7 @@ public class ApsSchedulingController {
     public ProductionScheduleRetVo productionSchedule(@RequestBody ProductionScheduleVo productionScheduleVo) throws Exception{
         ProductionScheduleRetVo productionScheduleRetVo = null;
         try{
-            productionScheduleRetVo = productionScheduleService.productionSchedule(productionScheduleVo);
+            productionScheduleRetVo = productionScheduleService.productionLxSchedule(productionScheduleVo);
             productionScheduleRetVo.setCode("200");
         }catch(ApsException ae){
             productionScheduleRetVo = new ProductionScheduleRetVo();

+ 29 - 0
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/domain/ApsTypeVo.java

@@ -0,0 +1,29 @@
+package com.rongwei.rwapsserver.aps.domain;
+
+import lombok.Data;
+
+@Data
+public class ApsTypeVo {
+
+    /**
+     * 是否混排:
+     * default:分批排程(默认排程)
+     * mix:混合排程
+     */
+    private String mixIf;
+
+    /**
+     * 是否退火提前合并:
+     * thMergeBf:退火提前合并
+     * notThMergeBf:退火不提前合并
+     */
+    private String thMergeMode;
+
+    /**
+     * 约束优先级:
+     * lz:冷轧优先
+     * th:退火优先
+     */
+    private String constraintMode;
+
+}

+ 189 - 4
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/service/impl/ProductionScheduleServiceImpl.java

@@ -49,6 +49,15 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
         List<ProductionProcesses> otherThproces = new ArrayList<>();
         List<ProductionProcesses> otherNotThproces = new ArrayList<>();
         ApsSolution apsSolution = getPreApsSolution(productionScheduleVo,otherThproces);
+
+        // 全量排程数据备份
+        List<ProductionProcesses> allToApsProcess = new ArrayList<>();
+        allToApsProcess.addAll(apsSolution.getProcessesList());
+        Map<String,ProductionProcesses> allToApsProcesMaps = new HashMap<>();
+        for (ProductionProcesses toApsProcess : allToApsProcess) {
+            allToApsProcesMaps.put(toApsProcess.getId(),toApsProcess);
+        }
+
         // 退火合并
         List<ProductionProcesses> thList = apsService.thProcessMerge(productionScheduleVo,apsSolution,otherThproces);
         apsSolution.setProcessesList(thList);
@@ -58,6 +67,21 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
         List<ProductionProcesses> otherSerProces = new ArrayList<>();
         List<ProductionProcesses> otherSerProcesMerges = apsService.seriesLzBzMerge(processesList, otherSerProces);
         apsSolution.setProcessesList(otherSerProcesMerges);
+
+        // 去掉锁定工序
+        List<ProductionProcesses> notLocks = new ArrayList<>();
+        List<ProductionProcesses> hasLocks = new ArrayList<>();
+        if(apsSolution.getProcessesList() != null && apsSolution.getProcessesList().size()>0){
+            for (ProductionProcesses productionProcesses : apsSolution.getProcessesList()) {
+                if(!productionProcesses.getIfLock()){
+                    notLocks.add(productionProcesses);
+                }else{
+                    hasLocks.add(productionProcesses);
+                }
+            }
+        }
+        apsSolution.setProcessesList(notLocks);
+
         // 排程作业排序
         sortProcess(apsSolution.getProcessesList(),1);
         String cores = Runtime.getRuntime().availableProcessors() + "";
@@ -66,7 +90,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                         .withSolutionClass(ApsSolution.class)
                         .withEntityClasses(ProductionProcesses.class, Equipment.class)
                         .withConstraintProviderClass(ApsConstraintProvider.class)
-                        .withTerminationConfig(new TerminationConfig().withUnimprovedSecondsSpentLimit(180L))
+                        .withTerminationConfig(new TerminationConfig().withUnimprovedSecondsSpentLimit(60L))
 //                    .withTerminationSpentLimit(Duration.ofSeconds(runPlanSeconds))
                         .withMoveThreadCount(cores)
         );
@@ -105,7 +129,10 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                 }
             }
         });
-
+        List<Equipment> allequipmentList = apsSolution.getEquipmentList();
+        List<Equipment> equipments = allequipmentList.stream().filter(v -> v.getId().equals(apsSolution.getProcessesList().get(0).getOptionalEquipments().get(0))).collect(Collectors.toList());
+        equipments.get(0).setTasks(apsSolution.getProcessesList());
+        apsSolution.setEquipmentList(equipments);
         ApsSolution solvedBalance  = solver.solve(apsSolution);
         log.info("**************排程评分分析***************");
         SolutionManager<ApsSolution, HardSoftScore> scoreManager = SolutionManager.create(solverFactory);
@@ -116,7 +143,165 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
         // 得分分析
         softExplain(explain,solvedBalance.getProcessesList());
 
-        return null;
+        solvedBalance.getProcessesList().addAll(hasLocks);
+        // 退火合并工序排程完拆分
+        if(otherThproces != null && otherThproces.size()>0){
+            List<ProductionProcesses> otherThproce1 = new ArrayList<>();
+            for (ProductionProcesses otherThproce : otherThproces) {
+                if(StrUtil.isNotBlank(otherThproce.getMergeThMainId())){
+                    ProductionProcesses thpro = null;
+                    for (ProductionProcesses productionProcesses : solvedBalance.getProcessesList()) {
+                        if(productionProcesses.getId().equals(otherThproce.getMergeThMainId())){
+                            thpro = productionProcesses;
+                            break;
+                        }
+                    }
+                    if(thpro != null){
+                        otherThproce.setStartTime(thpro.getStartTime());
+                        otherThproce.setEndTime(thpro.getEndTime());
+                        otherThproce.setEquipmentId(thpro.getEquipmentId());
+                        otherThproce.setEquipment(thpro.getEquipment());
+                        otherThproce.setConflictRoptions(thpro.getConflictRoptions());
+
+                        thpro.setOpeProducePcNum(1);
+                        if(thpro.getPreviousProcessesIds() != null && thpro.getPreviousProcessesIds().size()>0){
+                            List<String> preids = new ArrayList<>();
+                            preids.add(thpro.getPreviousProcessesIds().get(0));
+                            thpro.setPreviousProcessesIds(preids);
+                        }
+
+                        if(thpro.getNextProcessesIds() != null && thpro.getNextProcessesIds().size()>0){
+                            for (String nextProcessesId : otherThproce.getNextProcessesIds()) {
+                                int i = thpro.getNextProcessesIds().indexOf(nextProcessesId);
+                                if(i>=0){
+                                    thpro.getNextProcessesIds().remove(i);
+                                }
+                            }
+                        }
+                        if(thpro.getProcessType().equals("小卷成退")){
+                            thpro.setMinThPcNum(thpro.getMinThPcNum()-otherThproce.getMinThPcNum());
+                        }
+                    }else{
+                        otherThproce1.add(otherThproce);
+                    }
+                }
+            }
+            if(otherThproce1 != null && otherThproce1.size()>0){
+                for (ProductionProcesses otherThproce : otherThproce1) {
+                    if(StrUtil.isNotBlank(otherThproce.getMergeThMainId())){
+                        ProductionProcesses thpro = null;
+                        for (ProductionProcesses productionProcesses : otherThproces) {
+                            if(productionProcesses.getId().equals(otherThproce.getMergeThMainId())){
+                                thpro = productionProcesses;
+                                break;
+                            }
+                        }
+                        if(thpro != null){
+                            otherThproce.setStartTime(thpro.getStartTime());
+                            otherThproce.setEndTime(thpro.getEndTime());
+                            otherThproce.setEquipmentId(thpro.getEquipmentId());
+                            otherThproce.setEquipment(thpro.getEquipment());
+                            otherThproce.setConflictRoptions(thpro.getConflictRoptions());
+
+                            thpro.setOpeProducePcNum(1);
+                            if(thpro.getProcessType().equals("小卷成退")){
+                                thpro.setMinThPcNum(thpro.getMinThPcNum()-otherThproce.getMinThPcNum());
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        // 非退火合并拆分
+        List<ProductionProcesses> sers = new ArrayList<>();
+        for (ProductionProcesses productionProcesses : solvedBalance.getProcessesList()) {
+            if(productionProcesses.getMergeProOrders() != null && productionProcesses.getMergeProOrders().size()>0 && !"铸轧".equals(productionProcesses.getProcessType())){
+                List<String> mergeProOrders = productionProcesses.getMergeProOrders();
+                ProductionProcesses lastpo = allToApsProcesMaps.get(mergeProOrders.get(mergeProOrders.size()-1));
+                boolean hasreplacenextLock = false;
+                for (int i = mergeProOrders.size()-1; i > 0; i--) {
+                    ProductionProcesses po = allToApsProcesMaps.get(mergeProOrders.get(i));
+                    po.setStartTime(productionProcesses.getEndTime().minusMinutes(po.getUnitProduceTime()));
+                    po.setEndTime(productionProcesses.getEndTime());
+                    po.setEquipmentId(productionProcesses.getEquipmentId());
+                    po.setEquipment(productionProcesses.getEquipment());
+//                    po.setConflictRoptions(productionProcesses.getConflictRoptions());
+                    if(productionProcesses.getConflictDes() != null && productionProcesses.getConflictDes().contains("与下道工序开始时间不符合规则")){
+                        if(po.getUniqueBsProcessesId().equals(lastpo.getUniqueBsProcessesId())){
+                            if(StrUtil.isBlank(po.getConflictDes())){
+                                po.setConflictDes("与下道工序开始时间不符合规则");
+                            }else{
+                                po.setConflictDes(po.getConflictDes() + "与下道工序开始时间不符合规则");
+                            }
+                            po.setHasConflict("y");
+                            hasreplacenextLock = true;
+                        }
+                    }
+                    productionProcesses.setOpeProducePcNum(1);
+                    productionProcesses.setProduceTime(productionProcesses.getProduceTime()-po.getUnitProduceTime());
+                    productionProcesses.setEndTime(productionProcesses.getEndTime().minusMinutes(po.getUnitProduceTime()));
+
+                    sers.add(po);
+                }
+                if(hasreplacenextLock){
+                    productionProcesses.setConflictDes(productionProcesses.getConflictDes().replaceAll("与下道工序开始时间不符合规则",""));
+                }
+            }
+        }
+
+        solvedBalance.getProcessesList().addAll(otherThproces);
+        solvedBalance.getProcessesList().addAll(sers);
+
+        for (ProductionProcesses productionProcesses : solvedBalance.getProcessesList()) {
+            productionProcesses.setPreviousProcesses(null);
+            productionProcesses.setRooprocess(null);
+            productionProcesses.setNextProcesses(null);
+            productionProcesses.getEquipment().setProcessesList(null);
+            productionProcesses.getEquipment().setEquipmentRunTimes(null);
+            productionProcesses.setPreviousStep(null);
+            productionProcesses.setOptionalProviderEquipments(null);
+            productionProcesses.setEquass(null);
+            productionProcesses.setMergeRooprocess(null);
+            productionProcesses.setOpeProducePcNum(1);
+            if(productionProcesses.getApsOverallConfig() != null){
+                productionProcesses.getApsOverallConfig().setFurnaceInstallations(null);
+                productionProcesses.getApsOverallConfig().setMergeFurnaces(null);
+            }
+            if(productionProcesses.getOldNextProcessesIds() != null){
+                productionProcesses.setNextProcessesIds(productionProcesses.getOldNextProcessesIds());
+            }
+            if(productionProcesses.getOldPreviousProcessesIds() != null){
+                productionProcesses.setPreviousProcessesIds(productionProcesses.getOldPreviousProcessesIds());
+            }
+            // 冲突约束补充处理
+            if(productionProcesses.getConflictRoptions() != null && productionProcesses.getConflictRoptions().size()>0){
+                productionProcesses.getConflictRoptions().forEach((k,v)->{
+                    if(StrUtil.isBlank(productionProcesses.getHasConflict())){
+                        productionProcesses.setHasConflict("y");
+                    }
+                    // 强制约束
+                    if(k.indexOf("hard") == 0){
+                        if(StrUtil.isBlank(productionProcesses.getConflictDes())){
+                            productionProcesses.setConflictDes(v);
+                        }else{
+                            productionProcesses.setConflictDes(productionProcesses.getConflictDes()+";"+v);
+                        }
+                    }
+                    // 非强制约束
+                    else if (k.indexOf("soft") == 0) {
+                        if(StrUtil.isBlank(productionProcesses.getSoftconflictdes())){
+                            productionProcesses.setSoftconflictdes(v);
+                        }else{
+                            productionProcesses.setSoftconflictdes(productionProcesses.getSoftconflictdes()+";"+v);
+                        }
+                    }
+                });
+            }
+        }
+
+        productionScheduleRetVo.setProcesses(solvedBalance.getProcessesList());
+        return productionScheduleRetVo;
     }
 
     /**
@@ -270,7 +455,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
         // 异常坯料计划ID
         List<String> exOrderIds = new ArrayList<>();
         // 混合排程
-        if("2".equals(productionScheduleVo.getScheduleType())){
+        if("mix".equals(productionScheduleVo.getScheduleType().getMixIf())){
             // optaplanner 求解器配置实例化
             SolverFactory<ApsSolution> solverFactory = SolverFactory.create(new SolverConfig()
                     .withEnvironmentMode(mode)

+ 1 - 1
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/vo/ProductionScheduleVo.java

@@ -30,7 +30,7 @@ public class ProductionScheduleVo {
      * default:分批排程(默认排程)
      * mix:混合排程
      */
-    private String scheduleType;
+    private ApsTypeVo scheduleType;
 
     /**
      * 生产工序集合