mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
回滚原煤配煤
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -365,7 +365,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.ortools</groupId>
|
||||
<artifactId>ortools-java</artifactId>
|
||||
<version>9.6.2534</version>
|
||||
<version>9.8.3296</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
@@ -48,30 +48,30 @@ public class CoalBlendEntity extends OrgCommonEntity {
|
||||
@OneToMany(mappedBy = "coal", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<CoalBlendResultInfoEntity> results;
|
||||
|
||||
@Comment("配煤类型")
|
||||
private String blendType;
|
||||
|
||||
@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 = 'coal.blendType'\n"
|
||||
+ " 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)")
|
||||
+ "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 String blendType;
|
||||
|
||||
@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 = 'coal.blendType'\n"
|
||||
+ " and i.code = blend_type)")
|
||||
private String blendTypeName;
|
||||
|
||||
@Comment("结果个数")
|
||||
private Integer count = 20;
|
||||
|
||||
@@ -294,83 +294,52 @@ public class CoalBlendEntity extends OrgCommonEntity {
|
||||
});
|
||||
|
||||
IntVar[] percentValArr = percentVal.toJavaArray(IntVar[]::new);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 各个煤累加和 100
|
||||
model.addEquality(LinearExpr.sum(percentValArr), 100);
|
||||
addBaseConstrain(model, percentValArr);
|
||||
|
||||
IntVar gcd = model.newIntVar(2, 100, "gcd");
|
||||
Stream<IntVar> gcdVal = null;
|
||||
|
||||
if (isJM) {
|
||||
if (Objects.equals(blendType, "2")) {
|
||||
|
||||
if (Objects.equals(blendType, "2")) {
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
model.addLessOrEqual(
|
||||
LinearExpr.sum(gcdVal.toJavaArray(IntVar[]::new)), type2PercentSum);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(targetParam)) {
|
||||
if (targetOrder == -1) {
|
||||
|
||||
model.maximize(
|
||||
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()));
|
||||
}
|
||||
}
|
||||
model.addLessOrEqual(
|
||||
LinearExpr.sum(gcdVal.toJavaArray(IntVar[]::new)), type2PercentSum);
|
||||
}
|
||||
|
||||
if (isYM){
|
||||
if (StringUtils.isNotEmpty(targetParam)) {
|
||||
if (targetOrder == -1) {
|
||||
|
||||
model.maximize(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(x -> (long) (x.getParam(targetParam) * 100))
|
||||
.toArray()));
|
||||
|
||||
int coalSize = coals.size();
|
||||
long[] weightArr = new long[coalSize];
|
||||
} else {
|
||||
|
||||
for (int i = 0; i < coalSize; i++) {
|
||||
|
||||
|
||||
weightArr[i] = (long) (Math.pow(100, coalSize - i));
|
||||
|
||||
model.minimize(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(x -> (long) (x.getParam(targetParam) * 100))
|
||||
.toArray()));
|
||||
}
|
||||
|
||||
model.maximize(LinearExpr.weightedSum(percentValArr, weightArr));
|
||||
}
|
||||
|
||||
stopWatch.stop();
|
||||
stopWatch.start("CpSolver");
|
||||
|
||||
@@ -429,283 +398,283 @@ public class CoalBlendEntity extends OrgCommonEntity {
|
||||
if (param1.get())
|
||||
vo.setParam1(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam1()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam1()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param2.get())
|
||||
vo.setParam2(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam2()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam2()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param3.get())
|
||||
vo.setParam3(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam3()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam3()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param4.get())
|
||||
vo.setParam4(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam4()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam4()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param5.get())
|
||||
vo.setParam5(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam5()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam5()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param6.get())
|
||||
vo.setParam6(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam6()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam6()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param7.get())
|
||||
vo.setParam7(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam7()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam7()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param8.get())
|
||||
vo.setParam8(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam8()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam8()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param9.get())
|
||||
vo.setParam9(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam9()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam9()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param10.get())
|
||||
vo.setParam10(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam10()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam10()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param11.get())
|
||||
vo.setParam11(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam11()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam11()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param12.get())
|
||||
vo.setParam12(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam12()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam12()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param13.get())
|
||||
vo.setParam13(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam13()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam13()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param14.get())
|
||||
vo.setParam14(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam14()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam14()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param15.get())
|
||||
vo.setParam15(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam15()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam15()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param16.get())
|
||||
vo.setParam16(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam16()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam16()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param17.get())
|
||||
vo.setParam17(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam17()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam17()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param18.get())
|
||||
vo.setParam18(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam18()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam18()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param19.get())
|
||||
vo.setParam19(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam19()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam19()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
if (param20.get())
|
||||
vo.setParam20(
|
||||
value(
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam20()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
LinearExpr.weightedSum(
|
||||
percentValArr,
|
||||
coals.stream()
|
||||
.mapToLong(
|
||||
x ->
|
||||
(long)
|
||||
(x
|
||||
.getParam20()
|
||||
* 100))
|
||||
.toArray()))
|
||||
/ 10000.0);
|
||||
|
||||
CoalBlendEntity.this.results.add(vo);
|
||||
|
||||
|
||||
@@ -22,4 +22,14 @@ public class CoalPercentVo {
|
||||
|
||||
@Comment("煤的铲车配煤比例")
|
||||
private Double type2Percent;
|
||||
|
||||
|
||||
|
||||
@Comment("原煤比例")
|
||||
private Double ymPercent;
|
||||
public CoalPercentVo(String name, Double percent, Double type2Percent) {
|
||||
this.name = name;
|
||||
this.percent = percent;
|
||||
this.type2Percent = type2Percent;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user