This commit is contained in:
2023-07-21 17:59:56 +08:00
parent a65cb74daa
commit cfab5f1321
14 changed files with 609 additions and 140 deletions

View File

@@ -0,0 +1,34 @@
package cn.lihongjie.coal.service;
import cn.lihongjie.coal.dto.CoalBlendRequest;
import cn.lihongjie.coal.dto.CoalBlendResult;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
class CoalServiceTest {
@SneakyThrows
@Test
void testBlend() {
CoalService coalService = new CoalService();
InputStream stream = this.getClass().getClassLoader().getResourceAsStream(
"request1.json");
CoalBlendRequest coalBlendRequest = new ObjectMapper().readValue(stream, CoalBlendRequest.class);
for (int i = 0; i < 1; i++) {
CoalBlendResult result = coalService.blend(coalBlendRequest);
System.out.println(result.tableString());
}
}
}

View File

@@ -0,0 +1,39 @@
package cn.lihongjie.coal.service;
import com.google.ortools.Loader;
import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverStatus;
import com.google.ortools.sat.IntVar;
/** Minimal CP-SAT example to showcase calling the solver. */
public final class SimpleSatProgram {
public static void main(String[] args) throws Exception {
Loader.loadNativeLibraries();
// Create the model.
CpModel model = new CpModel();
// Create the variables.
int numVals = 3;
IntVar x = model.newIntVar(0, numVals - 1, "x");
IntVar y = model.newIntVar(0, numVals - 1, "y");
IntVar z = model.newIntVar(0, numVals - 1, "z");
// Create the constraints.
model.addDifferent(x, y);
// Create a solver and solve the model.
CpSolver solver = new CpSolver();
CpSolverStatus status = solver.solve(model);
if (status == CpSolverStatus.OPTIMAL || status == CpSolverStatus.FEASIBLE) {
System.out.println("x = " + solver.value(x));
System.out.println("y = " + solver.value(y));
System.out.println("z = " + solver.value(z));
} else {
System.out.println("No solution found.");
}
}
private SimpleSatProgram() {}
}

View File

@@ -0,0 +1,82 @@
{
"type": 1,
"maxTime": 100,
"constraints": [
{
"code": "param1",
"min": 1.5,
"max": 1.9,
"priority": 1,
"order": -1
},
{
"code": "param2",
"min": 2,
"max": 2.8,
"priority": 3,
"order": -1
},
{
"code": "param3",
"min": 3,
"max": 5,
"priority": 4,
"order": -1
}
],
"coals": [
{
"id": 1,
"name": "煤1",
"parameters": [
{
"code": "param1",
"value": 1
},
{
"code": "param2",
"value": 2
},
{
"code": "param3",
"value": 3
}
]
},
{
"id": 2,
"name": "煤2",
"parameters": [
{
"code": "param1",
"value": 2
},
{
"code": "param2",
"value": 3
},
{
"code": "param3",
"value": 5
}
]
},
{
"id": 3,
"name": "煤3",
"parameters": [
{
"code": "param1",
"value": 2
},
{
"code": "param2",
"value": 3
},
{
"code": "param3",
"value": 5
}
]
}]
}