diff --git a/1024shop-manager/1024shop-manager/src/main/java/net/xdclass/shopmanager/controller/SubController.java b/1024shop-manager/1024shop-manager/src/main/java/net/xdclass/shopmanager/controller/SubController.java index 9b9b4e1..4a2f5f2 100644 --- a/1024shop-manager/1024shop-manager/src/main/java/net/xdclass/shopmanager/controller/SubController.java +++ b/1024shop-manager/1024shop-manager/src/main/java/net/xdclass/shopmanager/controller/SubController.java @@ -163,20 +163,23 @@ public class SubController { //循环板坯 plistSlab.forEach(p -> { - //二次分组 - SetGrpDataBySlab(p); + try { + //二次分组 + SetGrpDataBySlab(p); - logger.info("***二次分组数量*** " + gltGCalGrp.size()); + logger.info("***二次分组数量*** " + gltGCalGrp.size()); - if (gltGCalGrp.size() > 0) { + if (gltGCalGrp.size() > 0) { - SetGroupCalRslt(p); + SetGroupCalRslt(p); + } + if (gltGGrpCalRslt.size() > 0) { + SetSaveDate(p); + } + } catch (Exception e) { + logger.info(e.toString()); } - if(gltGGrpCalRslt.size()>0){ - SetSaveDate(p); - } - } ); @@ -1181,8 +1184,8 @@ public class SubController { //轧机最小长度 int intRollMinLen = plistPmPdConstBtDO.stream().filter(p -> p.getRollLineNo().equals("30")).findFirst().orElse(null).getHpmMinPLen().intValue(); -// gltGCalGrp.parallelStream().forEach(e->{ - gltGCalGrp.forEach(e -> { + //gltGCalGrp.parallelStream().forEach(e->{ + gltGCalGrp.parallelStream().forEach(e -> { //实例化计算结果数组 GGrpCalRslt GGCR = new GGrpCalRslt(); //可轧制最大长度 @@ -1195,17 +1198,16 @@ public class SubController { int intSlabLen = SInfo.getSlabActLen().intValue(); //判断可轧制最大长度 TODO:厚度计算Decimal取整计算,会有误差,后续判断误差值修正计算 - if ((BigDecimal.valueOf(intSlabLen).divide(intThk.multiply(BigDecimal.valueOf(intWid)), RoundingMode.HALF_UP)).compareTo(BigDecimal.valueOf(intRollMaxLen)) > 0) { + if ((SInfo.getSlabActLen().multiply(SInfo.getSlabActThk()).multiply(SInfo.getSlabActWid()).divide(intThk.multiply(BigDecimal.valueOf(intWid)), RoundingMode.HALF_UP)).compareTo(BigDecimal.valueOf(intRollMaxLen)) > 0) { intMaxLen = intRollMaxLen; } else { - intMaxLen = (BigDecimal.valueOf(intSlabLen).divide(intThk.multiply(BigDecimal.valueOf(intWid)), RoundingMode.HALF_UP)).intValue(); + intMaxLen = (SInfo.getSlabActLen().multiply(SInfo.getSlabActThk()).multiply(SInfo.getSlabActWid()).divide(intThk.multiply(BigDecimal.valueOf(intWid)), RoundingMode.HALF_UP)).intValue(); } //不能小于可轧制的最小长度 if (intMaxLen < intRollMinLen) { return; } - GGCR.setCal_Wid(intWid); GGCR.setCal_Thk(intThk); GGCR.setCal_Len(intMaxLen); @@ -1218,14 +1220,34 @@ public class SubController { // gltGGrpCalRslt.parallelStream().forEach(p -> { gltGGrpCalRslt.forEach(p -> { // 测试数据 + //处理数据多处理 + List ltValues= new ArrayList<>(); + List ltweights= new ArrayList<>(); + List ltOrder= new ArrayList<>(); + + logger.info( "订单总数量:" + p.getLtInfoGPreOrder().size()); + + //计算可处理数据最大值 + p.getLtInfoGPreOrder().forEach(e->{ + + int intOrdCount = p.getCal_Len()/e.getLen(); + + if(ltOrder.stream().filter(f->f.equals(e.getOrderNo())).count()==intOrdCount) + { + return; + } + ltOrder.add(e.getOrderNo());//添加订单号 + ltValues.add(e.getIDValue());//价值 + ltweights.add(e.getLen());//长度 + }); // 生成 values 和 weights 数组 - long[] values = new long[p.getLtInfoGPreOrder().size()]; - long[][] weights = new long[0][p.getLtInfoGPreOrder().size()]; + long[] values = new long[ltValues.size()]; + long[][] weights = new long[1][ltweights.size()]; - for (int i = 0; i < p.getLtInfoGPreOrder().size(); i++) { - values[i] = p.getLtInfoGPreOrder().get(i).getIDValue(); // 从订单中获取 value - weights[0][i] = (long) p.getLtInfoGPreOrder().get(i).getInfoPmProContProdAttrDO().getOrderLen() + 5; // 从订单中获取 weights + for (int i = 0; i < ltValues.size(); i++) { + values[i] =ltValues.get(i); // 从订单中获取 value + weights[0][i] = ltweights.get(i)+5; // 从订单中获取 weights } //是否展宽 @@ -1243,10 +1265,13 @@ public class SubController { && f.getPlateThickFrom().compareTo(p.getCal_Thk()) <= 0 && f.getPlateThickTo().compareTo(p.getCal_Thk()) >= 0 && f.getSlabThickFrom().compareTo(SInfo.getSlabActThk()) <= 0 - && f.getSlabThickFrom().compareTo(SInfo.getSlabActThk()) >= 0 + && f.getSlabThickTo().compareTo(SInfo.getSlabActThk()) >= 0 && f.getCombinePlateWidthFrom().compareTo(BigDecimal.valueOf(p.getCal_Wid())) <= 0 - && f.getCombinePlateWidthTo().compareTo(BigDecimal.valueOf(p.getCal_Wid())) <= 0 + && f.getCombinePlateWidthTo().compareTo(BigDecimal.valueOf(p.getCal_Wid())) >= 0 ).findFirst().orElse(null); + if (PPCLB == null) { + return; + } //切头 int intHead = PPCLB.getHeadCut().intValue(); //切尾 @@ -1259,17 +1284,22 @@ public class SubController { //初始化方案 Loader.loadNativeLibraries(); +// logger.info("values Size:{}", p.getLtInfoGPreOrder().size()); + for (int i = 0; i < ltweights.size(); i++) { + + logger.info("weights:{}", ltweights.get(i)); + + } + // 调用 solve 方法来解决问题 ArrayList ltInt = solve(values, weights, capacities); + //实例化实际订单号 + p.setLtActInfoGPreOrder(new ArrayList<>()); //循环返回的订单插入到实际数组中 for (int i = 0; i < ltInt.size(); i++) { - - //实例化实际订单号 - p.setLtActInfoGPreOrder(new ArrayList<>()); int indexi = i; p.getLtActInfoGPreOrder().add(p.getLtInfoGPreOrder().stream().filter(m -> m.getIDValue() == ltInt.get(indexi)).collect(Collectors.toList()).get(0)); - } //根据实际订单再计算 diff --git a/1024shop-manager/1024shop-manager/src/main/java/net/xdclass/shopmanager/util/Knapsack.java b/1024shop-manager/1024shop-manager/src/main/java/net/xdclass/shopmanager/util/Knapsack.java index f0c0666..39765d3 100644 --- a/1024shop-manager/1024shop-manager/src/main/java/net/xdclass/shopmanager/util/Knapsack.java +++ b/1024shop-manager/1024shop-manager/src/main/java/net/xdclass/shopmanager/util/Knapsack.java @@ -5,6 +5,7 @@ import com.google.ortools.Loader; import com.google.ortools.algorithms.KnapsackSolver; import java.util.ArrayList; +import java.util.Arrays; /** * Sample showing how to model using the knapsack solver. @@ -64,6 +65,8 @@ public class Knapsack { ArrayList packedWeights = new ArrayList<>(); int totalWeight = 0; + System.out.println("values = " + Arrays.stream(values).count()); + System.out.println("weights = " + Arrays.stream(values).count()); // 输出计算结果 System.out.println("Total value = " + computedValue); for (int i = 0; i < values.length; i++) {