Commit ceaf4e51 by chamberone
1 parent d8211205
......@@ -101,7 +101,9 @@ public class PrepareController {
}
DispatchSolution solution = solver.solve(problem);
log.info("getCustomerList size: {}", solution.getTechnicianList().get(0).getCustomerList().size());
DispatchSolutionUtils.removeHardConstraintCustomer(solution, solverFactory);
log.info("getCustomerList size: {}", solution.getTechnicianList().get(0).getCustomerList().size());
solveService.saveSolutionWrp(solution);
extractService.extractDispatchToOrder(groupId, batchNo, false);
......
......@@ -8,6 +8,8 @@ import com.dituhui.pea.dispatch.pojo.Technician;
import com.dituhui.pea.dispatch.service.BatchService;
import com.dituhui.pea.dispatch.service.ExtractService;
import com.dituhui.pea.dispatch.service.SolveService;
import com.dituhui.pea.dispatch.utils.DispatchSolutionUtils;
import lombok.extern.slf4j.Slf4j;
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.api.solver.SolverFactory;
......@@ -19,7 +21,6 @@ import org.springframework.stereotype.Component;
import org.springframework.scheduling.annotation.Scheduled;
import java.io.File;
import java.sql.SQLException;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
......@@ -48,6 +49,7 @@ public class BatchScheduler {
@Autowired
ExtractService extractService;
private SolverFactory<DispatchSolution> solverFactory;
private Solver<DispatchSolution> solver;
public BatchScheduler() {
......@@ -57,7 +59,7 @@ public class BatchScheduler {
solverConfig.withConstraintProviderClass(DispatchConstraintProvider.class);
solverConfig.withTerminationSpentLimit(Duration.ofSeconds(60 * 5));
SolverFactory<DispatchSolution> solverFactory = SolverFactory.create(solverConfig);
solverFactory = SolverFactory.create(solverConfig);
solver = solverFactory.buildSolver();
}
......@@ -108,6 +110,7 @@ public class BatchScheduler {
}
log.info("dispatchRun prepare done, group:{}, day:{}, batch:{}, problemId:{}", groupId, currDay, batchNo, problemId);
DispatchSolution solution = solver.solve(problem);
DispatchSolutionUtils.removeHardConstraintCustomer(solution, solverFactory);
log.info("dispatchRun solve done, group:{}, day:{}, batch:{}, problemId:{}, score:{}", groupId, currDay, batchNo, problemId, solution.getScore().toShortString());
this.solveService.saveSolutionWrp(solution);
this.extractService.extractDispatchToOrder(groupId, batchNo, false);
......
......@@ -55,6 +55,7 @@ public class DispatchServiceImpl implements DispatchService {
solver.addEventListener(new DispatchSolverEventListener());
// 求解
DispatchSolution solution = solver.solve(problem);
DispatchSolutionUtils.removeHardConstraintCustomer(solution, solverFactory);
return Result.success(solution.getTechnicianList());
}
......
......@@ -15,6 +15,8 @@ import com.dituhui.pea.dispatch.entity.OrgGroup;
import com.dituhui.pea.dispatch.pojo.*;
import com.dituhui.pea.dispatch.service.ExtractService;
import com.dituhui.pea.dispatch.service.SolveService;
import com.dituhui.pea.dispatch.utils.DispatchSolutionUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.util.FileUtil;
import org.optaplanner.core.api.solver.Solver;
......@@ -217,6 +219,7 @@ public class SolveServiceImpl implements SolveService {
log.info("调用引擎处理-开始, groupId:{}, batchNo:{}", groupId, batchNo);
Solver<DispatchSolution> solver = solverFactory.buildSolver();
DispatchSolution solution = solver.solve(problem);
DispatchSolutionUtils.removeHardConstraintCustomer(solution, solverFactory);
log.info("调用引擎处理-结束, groupId:{}, batchNo:{}, score:{}", groupId, batchNo, solution.getScore());
JacksonSolutionFileIO<DispatchSolution> exporter = new JacksonSolutionFileIO<DispatchSolution>(
......
......@@ -9,6 +9,8 @@ import com.dituhui.pea.dispatch.pojo.Technician;
import com.dituhui.pea.dispatch.service.BatchService;
import com.dituhui.pea.dispatch.service.ExtractService;
import com.dituhui.pea.dispatch.service.SolveService;
import com.dituhui.pea.dispatch.utils.DispatchSolutionUtils;
import lombok.extern.slf4j.Slf4j;
import org.drools.commands.fluent.Batch;
import org.junit.jupiter.api.Test;
......@@ -43,6 +45,7 @@ class SolveServiceTest {
String day = "2023-03-20";
private SolverManager<DispatchSolution, UUID> solverManager;
private SolverFactory<DispatchSolution> solverFactory;
private Solver<DispatchSolution> solver;
public SolveServiceTest() {
......@@ -52,7 +55,7 @@ class SolveServiceTest {
solverConfig.withConstraintProviderClass(DispatchConstraintProvider.class);
solverConfig.withTerminationSpentLimit(Duration.ofSeconds(10));
SolverFactory<DispatchSolution> solverFactory = SolverFactory.create(solverConfig);
solverFactory = SolverFactory.create(solverConfig);
solver = solverFactory.buildSolver();
solverManager = SolverManager.create(solverConfig, new SolverManagerConfig());
}
......@@ -74,6 +77,7 @@ class SolveServiceTest {
}
DispatchSolution solution = solver.solve(problem);
DispatchSolutionUtils.removeHardConstraintCustomer(solution, solverFactory);
solveService.saveSolutionWrp(solution);
extractService.extractDispatchToOrder(groupId, batchNo, false);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!