Commit 27bcdacf by chamberone

feat: 调整算法工具

1 parent 42a53b83
package com.dituhui.pea.dispatch.scheduler; package com.dituhui.pea.dispatch.scheduler;
import com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider; import java.io.File;
import com.dituhui.pea.dispatch.entity.DispatchBatch; import java.time.LocalDate;
import com.dituhui.pea.dispatch.pojo.Customer; import java.time.format.DateTimeFormatter;
import com.dituhui.pea.dispatch.pojo.DispatchSolution; import java.util.UUID;
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.Solver;
import org.optaplanner.core.api.solver.SolverFactory; import org.optaplanner.core.impl.solver.DefaultSolverFactory;
import org.optaplanner.core.config.solver.SolverConfig;
import org.optaplanner.persistence.jackson.impl.domain.solution.JacksonSolutionFileIO; import org.optaplanner.persistence.jackson.impl.domain.solution.JacksonSolutionFileIO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.File; import com.dituhui.pea.dispatch.pojo.DispatchSolution;
import java.time.Duration; import com.dituhui.pea.dispatch.service.BatchService;
import java.time.LocalDate; import com.dituhui.pea.dispatch.service.ExtractService;
import java.time.LocalDateTime; import com.dituhui.pea.dispatch.service.SolveService;
import java.time.LocalTime; import com.dituhui.pea.dispatch.utils.DispatchSolutionUtils;
import java.time.format.DateTimeFormatter;
import java.util.Arrays; import lombok.extern.slf4j.Slf4j;
import java.util.UUID;
@Slf4j @Slf4j
@Component @Component
...@@ -49,17 +41,11 @@ public class BatchScheduler { ...@@ -49,17 +41,11 @@ public class BatchScheduler {
@Autowired @Autowired
ExtractService extractService; ExtractService extractService;
private SolverFactory<DispatchSolution> solverFactory; private DefaultSolverFactory<DispatchSolution> solverFactory;
private Solver<DispatchSolution> solver; private Solver<DispatchSolution> solver;
public BatchScheduler() { public BatchScheduler() {
solverFactory = DispatchSolutionUtils.getSolverFactory(30, 60 * 5);
SolverConfig solverConfig = new SolverConfig().withSolutionClass(DispatchSolution.class);
solverConfig.withEntityClassList(Arrays.asList(Technician.class, Customer.class));// 这里不能漏掉,否则约束不生效
solverConfig.withConstraintProviderClass(DispatchConstraintProvider.class);
solverConfig.withTerminationSpentLimit(Duration.ofSeconds(60 * 5));
solverFactory = SolverFactory.create(solverConfig);
solver = solverFactory.buildSolver(); solver = solverFactory.buildSolver();
} }
...@@ -74,8 +60,8 @@ public class BatchScheduler { ...@@ -74,8 +60,8 @@ public class BatchScheduler {
String currDay = LocalDate.now().plusDays(i).format(DateTimeFormatter.ISO_LOCAL_DATE); String currDay = LocalDate.now().plusDays(i).format(DateTimeFormatter.ISO_LOCAL_DATE);
log.info("dispatchRun begin----- group:{}, day:{}", groupId, currDay); log.info("dispatchRun begin----- group:{}, day:{}", groupId, currDay);
LocalTime currentTime = LocalTime.now(); // LocalTime currentTime = LocalTime.now();
LocalTime cutoffTime = LocalTime.parse("18:00:00", DateTimeFormatter.ISO_LOCAL_TIME); // LocalTime cutoffTime = LocalTime.parse("18:00:00", DateTimeFormatter.ISO_LOCAL_TIME);
// 明天单才有cutoff // 明天单才有cutoff
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!