sunhao 3 days ago
parent b95da6eaef
commit c3f82d4b7b

@ -163,6 +163,7 @@ public class SubController {
//循环板坯 //循环板坯
plistSlab.forEach(p -> { plistSlab.forEach(p -> {
try {
//二次分组 //二次分组
SetGrpDataBySlab(p); SetGrpDataBySlab(p);
@ -176,7 +177,9 @@ public class SubController {
if (gltGGrpCalRslt.size() > 0) { if (gltGGrpCalRslt.size() > 0) {
SetSaveDate(p); SetSaveDate(p);
} }
} catch (Exception e) {
logger.info(e.toString());
}
} }
); );
@ -1182,7 +1185,7 @@ public class SubController {
int intRollMinLen = plistPmPdConstBtDO.stream().filter(p -> p.getRollLineNo().equals("30")).findFirst().orElse(null).getHpmMinPLen().intValue(); int intRollMinLen = plistPmPdConstBtDO.stream().filter(p -> p.getRollLineNo().equals("30")).findFirst().orElse(null).getHpmMinPLen().intValue();
//gltGCalGrp.parallelStream().forEach(e->{ //gltGCalGrp.parallelStream().forEach(e->{
gltGCalGrp.forEach(e -> { gltGCalGrp.parallelStream().forEach(e -> {
//实例化计算结果数组 //实例化计算结果数组
GGrpCalRslt GGCR = new GGrpCalRslt(); GGrpCalRslt GGCR = new GGrpCalRslt();
//可轧制最大长度 //可轧制最大长度
@ -1195,17 +1198,16 @@ public class SubController {
int intSlabLen = SInfo.getSlabActLen().intValue(); int intSlabLen = SInfo.getSlabActLen().intValue();
//判断可轧制最大长度 TODO厚度计算Decimal取整计算会有误差后续判断误差值修正计算 //判断可轧制最大长度 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; intMaxLen = intRollMaxLen;
} else { } 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) { if (intMaxLen < intRollMinLen) {
return; return;
} }
GGCR.setCal_Wid(intWid); GGCR.setCal_Wid(intWid);
GGCR.setCal_Thk(intThk); GGCR.setCal_Thk(intThk);
GGCR.setCal_Len(intMaxLen); GGCR.setCal_Len(intMaxLen);
@ -1218,14 +1220,34 @@ public class SubController {
// gltGGrpCalRslt.parallelStream().forEach(p -> { // gltGGrpCalRslt.parallelStream().forEach(p -> {
gltGGrpCalRslt.forEach(p -> { gltGGrpCalRslt.forEach(p -> {
// 测试数据 // 测试数据
//处理数据多处理
List<Integer> ltValues= new ArrayList<>();
List<Integer> ltweights= new ArrayList<>();
List<String> 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 数组 // 生成 values 和 weights 数组
long[] values = new long[p.getLtInfoGPreOrder().size()]; long[] values = new long[ltValues.size()];
long[][] weights = new long[0][p.getLtInfoGPreOrder().size()]; long[][] weights = new long[1][ltweights.size()];
for (int i = 0; i < p.getLtInfoGPreOrder().size(); i++) { for (int i = 0; i < ltValues.size(); i++) {
values[i] = p.getLtInfoGPreOrder().get(i).getIDValue(); // 从订单中获取 value values[i] =ltValues.get(i); // 从订单中获取 value
weights[0][i] = (long) p.getLtInfoGPreOrder().get(i).getInfoPmProContProdAttrDO().getOrderLen() + 5; // 从订单中获取 weights weights[0][i] = ltweights.get(i)+5; // 从订单中获取 weights
} }
//是否展宽 //是否展宽
@ -1243,10 +1265,13 @@ public class SubController {
&& f.getPlateThickFrom().compareTo(p.getCal_Thk()) <= 0 && f.getPlateThickFrom().compareTo(p.getCal_Thk()) <= 0
&& f.getPlateThickTo().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.getSlabThickFrom().compareTo(SInfo.getSlabActThk()) >= 0 && f.getSlabThickTo().compareTo(SInfo.getSlabActThk()) >= 0
&& f.getCombinePlateWidthFrom().compareTo(BigDecimal.valueOf(p.getCal_Wid())) <= 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); ).findFirst().orElse(null);
if (PPCLB == null) {
return;
}
//切头 //切头
int intHead = PPCLB.getHeadCut().intValue(); int intHead = PPCLB.getHeadCut().intValue();
//切尾 //切尾
@ -1259,17 +1284,22 @@ public class SubController {
//初始化方案 //初始化方案
Loader.loadNativeLibraries(); Loader.loadNativeLibraries();
// logger.info("values Size:{}", p.getLtInfoGPreOrder().size());
for (int i = 0; i < ltweights.size(); i++) {
logger.info("weights:{}", ltweights.get(i));
}
// 调用 solve 方法来解决问题 // 调用 solve 方法来解决问题
ArrayList<Long> ltInt = solve(values, weights, capacities); ArrayList<Long> ltInt = solve(values, weights, capacities);
//循环返回的订单插入到实际数组中
for (int i = 0; i < ltInt.size(); i++) {
//实例化实际订单号 //实例化实际订单号
p.setLtActInfoGPreOrder(new ArrayList<>()); p.setLtActInfoGPreOrder(new ArrayList<>());
//循环返回的订单插入到实际数组中
for (int i = 0; i < ltInt.size(); i++) {
int indexi = i; int indexi = i;
p.getLtActInfoGPreOrder().add(p.getLtInfoGPreOrder().stream().filter(m -> m.getIDValue() == ltInt.get(indexi)).collect(Collectors.toList()).get(0)); p.getLtActInfoGPreOrder().add(p.getLtInfoGPreOrder().stream().filter(m -> m.getIDValue() == ltInt.get(indexi)).collect(Collectors.toList()).get(0));
} }
//根据实际订单再计算 //根据实际订单再计算

@ -5,6 +5,7 @@ import com.google.ortools.Loader;
import com.google.ortools.algorithms.KnapsackSolver; import com.google.ortools.algorithms.KnapsackSolver;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
/** /**
* Sample showing how to model using the knapsack solver. * Sample showing how to model using the knapsack solver.
@ -64,6 +65,8 @@ public class Knapsack {
ArrayList<Long> packedWeights = new ArrayList<>(); ArrayList<Long> packedWeights = new ArrayList<>();
int totalWeight = 0; 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); System.out.println("Total value = " + computedValue);
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {

Loading…
Cancel
Save