fangpy 10 mēneši atpakaļ
vecāks
revīzija
59a94dd011

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

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

+ 5 - 2
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/score/ApsConstraintProvider.java

@@ -1557,7 +1557,7 @@ public class ApsConstraintProvider implements ConstraintProvider {
      */
     private Constraint deliveryDate(ConstraintFactory constraintFactory) {
         return constraintFactory.forEach(ProductionProcesses.class)
-                .filter(productionProcesses -> productionProcesses.getNextProcesses() == null)
+//                .filter(productionProcesses -> productionProcesses.getNextProcesses() == null)
                 .filter(productionProcesses -> {
                     /*
                         获取最后一步工步的结束时间(最后一步工步的结束时间即此产品生产的实际结束时间)
@@ -1609,7 +1609,7 @@ public class ApsConstraintProvider implements ConstraintProvider {
      */
     private Constraint expecteddays(ConstraintFactory constraintFactory) {
         return constraintFactory.forEach(ProductionProcesses.class)
-                .filter(productionProcesses -> productionProcesses.getNextProcesses() == null || productionProcesses.getNextProcesses().size() == 0)
+//                .filter(productionProcesses -> productionProcesses.getNextProcesses() == null || productionProcesses.getNextProcesses().size() == 0)
                 .filter(productionProcesses -> {
                     // 非最后一道工序或者最后一道工序没有排程时间的工序直接跳过
                     if(productionProcesses.getEndTime() == null){
@@ -1652,6 +1652,9 @@ public class ApsConstraintProvider implements ConstraintProvider {
                 startTime = rooprocess.getNextProcesses().get(0).getStartTime();
             }else{
                 startTime = rooprocess.getStartTime();
+                if(startTime == null){
+                    return 0L;
+                }
             }
         }else{
             return 0L;

+ 2 - 0
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/service/ApsService.java

@@ -12,6 +12,8 @@ public interface ApsService {
 
     ApsSolution tuihuoAps(ApsSolution apsSolution);
 
+    void tuihuoApsSch(ApsSolution apsSolution);
+
     SolverFactory<ApsSolution> solverInit(ProductionScheduleVo productionScheduleVo);
 
     List<ProductionProcesses> thProcessMerge(ProductionScheduleVo productionScheduleVo,ApsSolution apsSolution,List<ProductionProcesses> otherThproces);

+ 2 - 1
rw-aps-server/src/main/java/com/rongwei/rwapsserver/aps/service/ProductionScheduleService.java

@@ -1,5 +1,6 @@
 package com.rongwei.rwapsserver.aps.service;
 
+import com.rongwei.rwapsserver.aps.domain.ApsSolution;
 import com.rongwei.rwapsserver.aps.vo.ProductionScheduleRetVo;
 import com.rongwei.rwapsserver.aps.vo.ProductionScheduleVo;
 
@@ -7,6 +8,6 @@ public interface ProductionScheduleService {
 
     ProductionScheduleRetVo productionSchedule(ProductionScheduleVo productionScheduleVo) throws Exception;
 
-    ProductionScheduleRetVo tuiHuoSchedule(ProductionScheduleVo productionScheduleVo) throws Exception;
+    ProductionScheduleRetVo tuiHuoSchedule(ProductionScheduleVo productionScheduleVo, ApsSolution apsSolution) throws Exception;
 
 }

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

@@ -66,7 +66,11 @@ public class ApsServiceImpl implements ApsService {
                     // 全局配置
                     ApsOverallConfig apsOverallConfig = new ApsOverallConfig();
                     BeanUtil.copyProperties(process.getApsOverallConfig(),apsOverallConfig);
-                    apsOverallConfig.setStartTime(process.getApsOverallConfig().getStartTime().plusMinutes(totaltime));
+                    if(process.getRooprocess() != null && process.getRooprocess().getStartTime() != null){
+                        apsOverallConfig.setStartTime(process.getRooprocess().getStartTime().plusMinutes(totaltime));
+                    }else{
+                        apsOverallConfig.setStartTime(process.getApsOverallConfig().getStartTime().plusMinutes(totaltime));
+                    }
                     // 开始时间设置
                     process.setApsOverallConfig(apsOverallConfig);
                     // 前后道工序置空
@@ -82,6 +86,48 @@ public class ApsServiceImpl implements ApsService {
         return apsSolutionTuihuo;
     }
 
+    /**
+     * 退火
+     * @param apsSolution
+     */
+    @Override
+    public void tuihuoApsSch(ApsSolution apsSolution){
+        ApsSolution apsSolutionTh = tuihuoAps(apsSolution);
+        // 退火工序求解器运行
+        int processNum1 = apsSolutionTh.getProcessesList().size();
+        int runPlanSeconds1 = (processNum1)*30;
+        // CPU核数
+        String cores = Runtime.getRuntime().availableProcessors() + "";
+        SolverFactory<ApsSolution> solverFactory1 = SolverFactory.create(new SolverConfig()
+                .withEnvironmentMode(EnvironmentMode.REPRODUCIBLE)
+                .withSolutionClass(ApsSolution.class)
+                .withEntityClasses(ProductionProcesses.class)
+                .withConstraintProviderClass(ApsConstraintProvider.class)
+                .withTerminationSpentLimit(Duration.ofSeconds(runPlanSeconds1))
+                .withMoveThreadCount(cores)
+        );
+        Solver<ApsSolution> solver1 = solverFactory1.buildSolver();
+        ApsSolution solvedBalance1 = solver1.solve(apsSolutionTh);
+        log.info("**************退火排程评分分析***************");
+        SolutionManager<ApsSolution, HardSoftScore> scoreManager1 = SolutionManager.create(solverFactory1);
+        ScoreExplanation<ApsSolution, HardSoftScore> explain1 = scoreManager1.explain(solvedBalance1);
+        log.info(explain1.toString());
+        log.info("**************退火排程评分分析***************");
+
+        // 锁定退火工序
+        for (ProductionProcesses process : apsSolution.getProcessesList()) {
+            List<ProductionProcesses> collect = solvedBalance1.getProcessesList().stream().filter(v -> v.getId().equals(process.getId())).collect(Collectors.toList());
+            if(collect != null && collect.size()>0){
+                process.setStartTime(collect.get(0).getStartTime());
+                process.setEndTime(collect.get(0).getEndTime());
+                process.setEquipmentId(collect.get(0).getEquipmentId());
+                process.setEquipment(collect.get(0).getEquipment());
+                process.setDelay(collect.get(0).getDelay());
+                process.setIfLock(true);
+            }
+        }
+    }
+
     /**
      * 获取所有前道工序的时间总和
      * @param process

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

@@ -180,6 +180,8 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
                 }
             }
         }
+        // 退火提前排序
+        apsService.tuihuoApsSch(apsSolution);
         // 去掉锁定工序
         List<ProductionProcesses> notLocks = new ArrayList<>();
         List<ProductionProcesses> hasLocks = new ArrayList<>();
@@ -1323,7 +1325,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
      * @param productionScheduleVo
      * @return
      */
-    public ProductionScheduleRetVo tuiHuoSchedule(ProductionScheduleVo productionScheduleVo) throws Exception{
+    public ProductionScheduleRetVo tuiHuoSchedule(ProductionScheduleVo productionScheduleVo,ApsSolution apsSolution) throws Exception{
         // 排程结果对象
         ProductionScheduleRetVo productionScheduleRetVo = new ProductionScheduleRetVo();
         // 排程运行时长
@@ -1345,7 +1347,7 @@ public class ProductionScheduleServiceImpl implements ProductionScheduleService
             mode = EnvironmentMode.FULL_ASSERT;
         }
         List<ProductionProcesses> otherThproces = new ArrayList<>();
-        ApsSolution apsSolution = getPreApsSolution(productionScheduleVo,otherThproces);
+//        ApsSolution apsSolution = getPreApsSolution(productionScheduleVo,otherThproces);
         // 退火提前排序
         ApsSolution apsSolutionTh = apsService.tuihuoAps(apsSolution);
         if(apsSolutionTh.getProcessesList() != null && apsSolutionTh.getProcessesList().size()>0){