mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
完善
This commit is contained in:
34
src/test/java/cn/lihongjie/coal/service/CoalServiceTest.java
Normal file
34
src/test/java/cn/lihongjie/coal/service/CoalServiceTest.java
Normal 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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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() {}
|
||||
}
|
||||
82
src/test/resources/request1.json
Normal file
82
src/test/resources/request1.json
Normal 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
|
||||
}
|
||||
]
|
||||
}]
|
||||
}
|
||||
Reference in New Issue
Block a user