소스 검색

排程优化-退火合并优化

fangpy 7 달 전
부모
커밋
7597eb533d

+ 4 - 1
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/listener/TaskStartTimeListener.java

@@ -228,7 +228,10 @@ public class TaskStartTimeListener implements VariableListener<ApsSolution, Prod
                 if(process.getPreviousProcesses().size()>1){
                     for (ProductionProcesses previousProcess : process.getPreviousProcesses()) {
                         if(previousProcess.getEndTime() == null){
-                            int a = 1;
+                            log.error("preProcess:"+preProcess.getId()+" OrderMark:"+preProcess.getOrderMark());
+                            log.error("preProcess-blankid:"+preProcess.getProduceOrder().get(0).getId());
+                            log.error("process:"+process.getId()+" OrderMark:"+process.getOrderMark());
+                            log.error("process-blankid:"+process.getProduceOrder().get(0).getId());
                         }
                         if(previousProcess.getEndTime().compareTo(preProcess.getEndTime())>0){
                             preProcess = previousProcess;

+ 22 - 0
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/service/impl/ApsServiceImpl.java

@@ -673,6 +673,10 @@ public class ApsServiceImpl implements ApsService {
             Map<String,Integer> sortMap = new HashMap<>();
             sortMap.put("sortInt",mergePro.getOrderMark());
             setPreOrderMark(mergePro.getPreviousProcesses(),sortMap);
+
+            Map<String,Integer> nextsortMap = new HashMap<>();
+            nextsortMap.put("sortInt",mergePro.getOrderMark());
+            setNextOrderMark(mergePro.getNextProcesses(),nextsortMap);
         }
 
         return mergePro;
@@ -894,6 +898,24 @@ public class ApsServiceImpl implements ApsService {
         }
     }
 
+    private void setNextOrderMark(List<ProductionProcesses> nexts,Map<String,Integer> sortMap){
+        List<ProductionProcesses> nextpros = new ArrayList<>();
+        if(nexts != null && nexts.size()>0){
+            for (ProductionProcesses nextpro : nexts) {
+                sortMap.put("sortInt",sortMap.get("sortInt")+1);
+                if(nextpro.getOrderMark() != null && nextpro.getOrderMark()<sortMap.get("sortInt")){
+                    nextpro.setOrderMark(sortMap.get("sortInt"));
+                }
+                if(nextpro.getNextProcesses() != null && nextpro.getNextProcesses().size()>0){
+                    nextpros.addAll(nextpro.getNextProcesses());
+                }
+            }
+        }
+        if(nextpros != null && nextpros.size()>0){
+            setNextOrderMark(nextpros,sortMap);
+        }
+    }
+
     /**
      * 求解器初始化
      * @param productionScheduleVo

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

@@ -2,6 +2,7 @@ package com.rongwei.rwapsserver.aps.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import com.rongwei.rwapsserver.aps.domain.*;
 import com.rongwei.rwapsserver.aps.score.ApsConstraintProvider;
 import com.rongwei.rwapsserver.aps.service.ApsService;
@@ -193,7 +194,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
         // 退火提前排序
         Map<String,List<String>> ordergrous = new HashMap<>();
         apsService.tuihuoApsSch(apsSolution,otherThproces,otherNotZzFirstProces,productionScheduleVo,ordergrous);
-
+        log.info("退火提前合并排程结束,合并订单列表:"+JSONUtil.toJsonStr(ordergrous));
         /*if(1 == 1){
             return null;
         }*/
@@ -215,8 +216,10 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
 //        }
         apsSolution.setProcessesList(notLocks);
 
+        List<String> exOrderIds = new ArrayList<>();
         // 按照退火组炉分批排程
         List<CommonJavaBean> orderMerges = produceOrderMerge(ordergrous,apsSolution);
+        log.info("退火组炉分批排程:"+ JSONUtil.toJsonStr(orderMerges));
         Collections.sort(orderMerges, (pro1, pro2) -> {return pro2.getMaxVolumeWidth().compareTo(pro1.getMaxVolumeWidth());});
         ApsSolution solvedBalance = new ApsSolution();
         solvedBalance.setProcessesList(new ArrayList<>());
@@ -238,7 +241,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                                     .withSolutionClass(ApsSolution.class)
                                     .withEntityClasses(ProductionProcesses.class)
                                     .withConstraintProviderClass(ApsConstraintProvider.class)
-                                    .withTerminationConfig(new TerminationConfig().withUnimprovedSecondsSpentLimit(120L))
+                                    .withTerminationConfig(new TerminationConfig().withUnimprovedSecondsSpentLimit(60L))
 //                                .withTerminationSpentLimit(Duration.ofSeconds(runPlanSeconds))
                                     .withMoveThreadCount(cores)
                     );
@@ -295,6 +298,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                     // 排程结束的数据手动添加到设备占用列表中
                     setEqRunTimes(solvedBalance1.getProcessesList());
                 }catch (Exception e){
+                    exOrderIds.addAll(v);
                     if(productionScheduleRetVo.getMsg() == null){
                         productionScheduleRetVo.setMsg("排程异常,");
                     }
@@ -335,7 +339,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                                         .withSolutionClass(ApsSolution.class)
                                         .withEntityClasses(ProductionProcesses.class)
                                         .withConstraintProviderClass(ApsConstraintProvider.class)
-                                        .withTerminationConfig(new TerminationConfig().withUnimprovedSecondsSpentLimit(120L))
+                                        .withTerminationConfig(new TerminationConfig().withUnimprovedSecondsSpentLimit(60L))
 //                                    .withTerminationSpentLimit(Duration.ofSeconds(runPlanSeconds))
                                         .withMoveThreadCount(cores)
                         );
@@ -391,6 +395,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                         // 排程结束的数据手动添加到设备占用列表中
                         setEqRunTimes(solvedBalance1.getProcessesList());
                     }catch (Exception e){
+                        exOrderIds.add(k);
                         if(productionScheduleRetVo.getMsg() == null){
                             productionScheduleRetVo.setMsg("排程异常,");
                         }
@@ -485,7 +490,6 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
         productionScheduleRetVo.setScoreResult(explain2.toString());
         softExplain(explain2,solvedBalance.getProcessesList());*/
 
-        productionScheduleRetVo.setProcesses(solvedBalance.getProcessesList());
         // 循环引用ProductionProcesses置空
 //        solvedBalance.getProcessesList().addAll(solvedBalance1.getProcessesList());
         solvedBalance.getProcessesList().addAll(hasLocks);
@@ -620,6 +624,14 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
         solvedBalance.getProcessesList().addAll(otherThproces);
         solvedBalance.getProcessesList().addAll(sers);
 //        solvedBalance.getProcessesList().addAll(otherNotThproces);
+        // 过滤异常数据
+        if(exOrderIds != null && exOrderIds.size()>0){
+            List<ProductionProcesses> processes = solvedBalance.getProcessesList().stream().filter(v ->
+                    !exOrderIds.contains(v.getProduceOrder().get(0).getId()) && v.getEquipment() != null)
+                    .collect(Collectors.toList());
+            solvedBalance.setProcessesList(processes);
+        }
+
         for (ProductionProcesses productionProcesses : solvedBalance.getProcessesList()) {
             productionProcesses.setPreviousProcesses(null);
             productionProcesses.setRooprocess(null);
@@ -666,6 +678,8 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                 });
             }
         }
+
+        productionScheduleRetVo.setProcesses(solvedBalance.getProcessesList());
         return productionScheduleRetVo;
     }
 
@@ -701,6 +715,16 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                         syids.add(iids);
                     }
                 }
+                List<List<String>> syids1 = new ArrayList<>();
+                for (List<String> syid : syids) {
+                    boolean bl = CollUtil.containsAny(fids, syid);
+                    if(bl){
+                        CollUtil.addAllIfNotContains(fids,syid);
+                    }else{
+                        syids1.add(syid);
+                    }
+                }
+                syids = syids1;
                 cjb.setOrderids(fids);
                 BigDecimal maxVolumeWidth = null;
                 for (String orderid : cjb.getOrderids()) {

+ 40 - 5
rw-aps-server/src/test/java/com/rongwei/rwapsserver/RwApsServerApplicationTests.java

@@ -1,9 +1,11 @@
 package com.rongwei.rwapsserver;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.json.JSONUtil;
 import com.rongwei.rwapsserver.aps.domain.ProductionProcesses;
 import org.drools.util.DateUtils;
 import org.junit.jupiter.api.Test;
@@ -12,9 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
+import java.util.*;
 
 @SpringBootTest
 class RwApsServerApplicationTests {
@@ -56,9 +56,44 @@ class RwApsServerApplicationTests {
 //        System.out.println(new BigDecimal("20").divide(new BigDecimal("0.352"),0, BigDecimal.ROUND_HALF_UP).intValue());
 //        System.out.println(new BigDecimal("15").divide(new BigDecimal("57"),2, BigDecimal.ROUND_HALF_UP).setScale(0, RoundingMode.CEILING).intValue());
 
+        /*Map<String,List<String>> ordergrous = new HashMap<>();
         List<String> a = new ArrayList<>();
-        a.add("12");a.add("34");a.add("56");
-        System.out.println("测试数据:"+a);
+        a.add("1111");a.add("2222");
+        ordergrous.put("aaaaaa",a);
+        System.out.println("测试数据:"+ JSONUtil.toJsonStr(ordergrous));*/
+
+        /*List<List<String>> allIds = new ArrayList<>();
+        List<String> a = new ArrayList<>();
+        a.add("1");
+        List<String> b = new ArrayList<>();
+        b.add("2");
+        List<String> c = new ArrayList<>();
+        c.add("1");c.add("2");
+        allIds.add(a);allIds.add(b);allIds.add(c);
+
+        List<String> fids = allIds.get(0);
+        List<List<String>> syids = new ArrayList<>();
+        for (int i = 1; i < allIds.size(); i++) {
+            List<String> iids = allIds.get(i);
+            boolean bl = CollUtil.containsAny(fids, iids);
+            if(bl){
+                CollUtil.addAllIfNotContains(fids,iids);
+            }else{
+                syids.add(iids);
+            }
+        }
+        List<List<String>> syids1 = new ArrayList<>();
+        for (List<String> syid : syids) {
+            boolean bl = CollUtil.containsAny(fids, syid);
+            if(bl){
+                CollUtil.addAllIfNotContains(fids,syid);
+            }else{
+                syids1.add(syid);
+            }
+        }
+        syids = syids1;*/
+        String apsPlanStartDateStr = DateUtil.formatDateTime(new Date());
+        System.out.println(apsPlanStartDateStr);
     }
 
 }