支持原煤配煤

This commit is contained in:
2024-01-13 19:10:03 +08:00
parent c91d364c16
commit 64cea704b2
3 changed files with 93 additions and 33 deletions

View File

@@ -60,6 +60,18 @@ public class CoalBlendEntity extends OrgCommonEntity {
+ " and i.code = blend_type)")
private String blendTypeName;
@Comment("煤类型")
private String coalType;
@Formula(
"(select i.name\n"
+ "from t_dictionary d,\n"
+ " t_dictionary_item i\n"
+ "where d.id = i.dictionary_id\n"
+ " and d.code = 'coalBlend.coalType'\n"
+ " and i.code = coal_type)")
private String coalTypeName;
@Comment("结果个数")
private Integer count = 20;
@@ -282,52 +294,83 @@ public class CoalBlendEntity extends OrgCommonEntity {
});
IntVar[] percentValArr = percentVal.toJavaArray(IntVar[]::new);
// 各个煤累加和 100
model.addEquality(LinearExpr.sum(percentValArr), 100);
boolean isJM = StringUtils.isEmpty(coalType) || StringUtils.equalsIgnoreCase(coalType, "0");
boolean isYM = StringUtils.equalsIgnoreCase(coalType, "2");
if (isJM) {
// 各个煤累加和 100
model.addEquality(LinearExpr.sum(percentValArr), 100);
} else {
if (isYM) {
// 原煤配煤比例小于等于 100
model.addLessOrEqual(LinearExpr.sum(percentValArr), 100);
}
}
addBaseConstrain(model, percentValArr);
IntVar gcd = model.newIntVar(2, 100, "gcd");
Stream<IntVar> gcdVal = null;
if (Objects.equals(blendType, "2")) {
if (isJM) {
gcdVal =
Stream.ofAll(coals)
.zipWithIndex(
(c, i) ->
model.newIntVar(
c.getMinPercent(),
c.getMaxPercent(),
"gcdX" + i));
percentVal.zip(gcdVal).forEach(t -> model.addDivisionEquality(t._2, t._1, gcd));
percentVal
.zip(gcdVal)
.forEach(t -> model.addModuloEquality(LinearExpr.constant(0), t._1, gcd));
if (Objects.equals(blendType, "2")) {
model.addLessOrEqual(
LinearExpr.sum(gcdVal.toJavaArray(IntVar[]::new)), type2PercentSum);
}
gcdVal =
Stream.ofAll(coals)
.zipWithIndex(
(c, i) ->
model.newIntVar(
c.getMinPercent(),
c.getMaxPercent(),
"gcdX" + i));
percentVal.zip(gcdVal).forEach(t -> model.addDivisionEquality(t._2, t._1, gcd));
percentVal
.zip(gcdVal)
.forEach(t -> model.addModuloEquality(LinearExpr.constant(0), t._1, gcd));
if (StringUtils.isNotEmpty(targetParam)) {
if (targetOrder == -1) {
model.addLessOrEqual(
LinearExpr.sum(gcdVal.toJavaArray(IntVar[]::new)), type2PercentSum);
}
model.maximize(
LinearExpr.weightedSum(
percentValArr,
coals.stream()
.mapToLong(x -> (long) (x.getParam(targetParam) * 100))
.toArray()));
if (StringUtils.isNotEmpty(targetParam)) {
if (targetOrder == -1) {
} else {
model.maximize(
LinearExpr.weightedSum(
percentValArr,
coals.stream()
.mapToLong(x -> (long) (x.getParam(targetParam) * 100))
.toArray()));
model.minimize(
LinearExpr.weightedSum(
percentValArr,
coals.stream()
.mapToLong(x -> (long) (x.getParam(targetParam) * 100))
.toArray()));
} else {
model.minimize(
LinearExpr.weightedSum(
percentValArr,
coals.stream()
.mapToLong(x -> (long) (x.getParam(targetParam) * 100))
.toArray()));
}
}
}
if (isYM){
int coalSize = coals.size();
long[] weightArr = new long[coalSize];
for (int i = 0; i < coalSize; i++) {
weightArr[i] = (long) (Math.pow(100, coalSize - i));
}
model.maximize(LinearExpr.weightedSum(percentValArr, weightArr));
}
stopWatch.stop();
stopWatch.start("CpSolver");

View File

@@ -1930,6 +1930,22 @@
]
},
{
"code": "coalBlend.coalType",
"name": "配煤-煤类型",
"item": [
{
"code": "0",
"name": "精煤"
},
{
"code": "2",
"name": "原煤"
}
]
},
{
"code": "inventoryCheck.type",
"name": "库存盘点类型",

View File

@@ -0,0 +1 @@
update t_coal_blend set coal_type = '0' where coal_type is null;