Commit 05cfb647 by chamberone

feat: 字段调整,包名调整

1 parent e58666f4
...@@ -14,7 +14,7 @@ import lombok.Data; ...@@ -14,7 +14,7 @@ import lombok.Data;
@Data @Data
@PlanningSolution @PlanningSolution
public class VehicleRoutingSolution { public class DispatchSolution {
private String name; private String name;
...@@ -35,10 +35,10 @@ public class VehicleRoutingSolution { ...@@ -35,10 +35,10 @@ public class VehicleRoutingSolution {
@PlanningScore @PlanningScore
private HardSoftLongScore score; private HardSoftLongScore score;
public VehicleRoutingSolution() { public DispatchSolution() {
} }
public VehicleRoutingSolution(String name, List<Location> locationList, Depot depot, public DispatchSolution(String name, List<Location> locationList, Depot depot,
List<Technician> technicianList, List<Customer> customerList) { List<Technician> technicianList, List<Customer> customerList) {
this.name = name; this.name = name;
this.locationList = locationList; this.locationList = locationList;
......
...@@ -61,6 +61,7 @@ public class Technician { ...@@ -61,6 +61,7 @@ public class Technician {
/** /**
* @return route of the vehicle * @return route of the vehicle
*/ */
@JsonIgnore
public List<Location> getRoute() { public List<Location> getRoute() {
if (customerList.isEmpty()) { if (customerList.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
...@@ -72,7 +73,6 @@ public class Technician { ...@@ -72,7 +73,6 @@ public class Technician {
for (Customer customer : customerList) { for (Customer customer : customerList) {
route.add(customer.getLocation()); route.add(customer.getLocation());
} }
// route.add(depot.getLocation());
return route; return route;
} }
......
...@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory; ...@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider; import com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider;
import com.dituhui.pea.dispatch.pojo.VehicleRoutingSolution; import com.dituhui.pea.dispatch.pojo.DispatchSolution;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.dispatch.service.DispatchService; import com.dituhui.pea.dispatch.service.DispatchService;
import com.dituhui.pea.dispatch.pojo.Customer; import com.dituhui.pea.dispatch.pojo.Customer;
...@@ -68,13 +68,13 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -68,13 +68,13 @@ public class DispatchServiceImpl implements DispatchService {
Map<String, String> customerCodeSkillMap = loadCustomerCodeSkillMap(); Map<String, String> customerCodeSkillMap = loadCustomerCodeSkillMap();
Map<String, Map<String, Long>> preferredlocationDistanceMap =loadPreferredlocationDistanceMap(); Map<String, Map<String, Long>> preferredlocationDistanceMap =loadPreferredlocationDistanceMap();
Map<String, Integer> customerCodeServiceTimeMap = loadCustomerCodeServiceTimeMap(); Map<String, Integer> customerCodeServiceTimeMap = loadCustomerCodeServiceTimeMap();
VehicleRoutingSolution problem = createVehicleRoutingSolution(customerIndexMap, technicianIndexMap, DispatchSolution problem = createVehicleRoutingSolution(customerIndexMap, technicianIndexMap,
technicianCodeSkillsMap, customerCodeSkillMap, preferredlocationDistanceMap,customerCodeServiceTimeMap); technicianCodeSkillsMap, customerCodeSkillMap, preferredlocationDistanceMap,customerCodeServiceTimeMap);
// 创建求解器配置 // 创建求解器配置
// 创建 SolverConfig 对象,并设置求解器配置 // 创建 SolverConfig 对象,并设置求解器配置
SolverConfig solverConfig = new SolverConfig(); SolverConfig solverConfig = new SolverConfig();
solverConfig.setSolutionClass(VehicleRoutingSolution.class); solverConfig.setSolutionClass(DispatchSolution.class);
solverConfig.withEntityClassList(Arrays.asList(Technician.class, Customer.class));// 这里不能漏掉,否则约束不生效 solverConfig.withEntityClassList(Arrays.asList(Technician.class, Customer.class));// 这里不能漏掉,否则约束不生效
solverConfig.withTerminationSpentLimit(Duration.ofSeconds(60)); solverConfig.withTerminationSpentLimit(Duration.ofSeconds(60));
...@@ -82,9 +82,9 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -82,9 +82,9 @@ public class DispatchServiceImpl implements DispatchService {
solverConfig.withConstraintProviderClass(DispatchConstraintProvider.class); solverConfig.withConstraintProviderClass(DispatchConstraintProvider.class);
// 创建求解器 // 创建求解器
SolverFactory<VehicleRoutingSolution> solverFactory = SolverFactory.create(solverConfig); SolverFactory<DispatchSolution> solverFactory = SolverFactory.create(solverConfig);
Solver<VehicleRoutingSolution> solver = solverFactory.buildSolver(); Solver<DispatchSolution> solver = solverFactory.buildSolver();
VehicleRoutingSolution solution = solver.solve(problem); DispatchSolution solution = solver.solve(problem);
printSolution(solution, customerIndexMap, technicianIndexMap); printSolution(solution, customerIndexMap, technicianIndexMap);
...@@ -216,10 +216,10 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -216,10 +216,10 @@ public class DispatchServiceImpl implements DispatchService {
return customerIndexMap; return customerIndexMap;
} }
private static VehicleRoutingSolution createVehicleRoutingSolution(Map<Integer, String> customerIndexMap, private static DispatchSolution createVehicleRoutingSolution(Map<Integer, String> customerIndexMap,
Map<Integer, String> technicianIndexMap, Map<String, Set<String>> technicianCodeSkillsMap, Map<Integer, String> technicianIndexMap, Map<String, Set<String>> technicianCodeSkillsMap,
Map<String, String> customerCodeSkillMap, Map<String, Map<String, Long>> preferredlocationDistanceMap, Map<String, Integer> customerCodeServiceTimeMap) throws UncheckedIOException, FileNotFoundException { Map<String, String> customerCodeSkillMap, Map<String, Map<String, Long>> preferredlocationDistanceMap, Map<String, Integer> customerCodeServiceTimeMap) throws UncheckedIOException, FileNotFoundException {
VehicleRoutingSolution vehicleRoutingSolution = new VehicleRoutingSolution(); DispatchSolution vehicleRoutingSolution = new DispatchSolution();
// 翻转map // 翻转map
Map<String, Integer> customerIndexMap2 = customerIndexMap.entrySet().stream() Map<String, Integer> customerIndexMap2 = customerIndexMap.entrySet().stream()
...@@ -308,7 +308,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -308,7 +308,7 @@ public class DispatchServiceImpl implements DispatchService {
return vehicleRoutingSolution; return vehicleRoutingSolution;
} }
static void printSolution(VehicleRoutingSolution solution, Map<Integer, String> customerIndexMap, static void printSolution(DispatchSolution solution, Map<Integer, String> customerIndexMap,
Map<Integer, String> technicianIndexMap) { Map<Integer, String> technicianIndexMap) {
System.out.println("技能约束:"); System.out.println("技能约束:");
solution.getTechnicianList().forEach(technician -> { solution.getTechnicianList().forEach(technician -> {
......
...@@ -6,41 +6,41 @@ import org.optaplanner.core.api.domain.variable.VariableListener; ...@@ -6,41 +6,41 @@ import org.optaplanner.core.api.domain.variable.VariableListener;
import org.optaplanner.core.api.score.director.ScoreDirector; import org.optaplanner.core.api.score.director.ScoreDirector;
import com.dituhui.pea.dispatch.pojo.Customer; import com.dituhui.pea.dispatch.pojo.Customer;
import com.dituhui.pea.dispatch.pojo.VehicleRoutingSolution; import com.dituhui.pea.dispatch.pojo.DispatchSolution;
public class ArrivalTimeUpdatingVariableListener implements VariableListener<VehicleRoutingSolution, Customer> { public class ArrivalTimeUpdatingVariableListener implements VariableListener<DispatchSolution, Customer> {
@Override @Override
public void beforeEntityAdded(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { public void beforeEntityAdded(ScoreDirector<DispatchSolution> scoreDirector, Customer customer) {
// Do nothing // Do nothing
} }
@Override @Override
public void afterEntityAdded(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { public void afterEntityAdded(ScoreDirector<DispatchSolution> scoreDirector, Customer customer) {
updateArrivalTime(scoreDirector, customer); updateArrivalTime(scoreDirector, customer);
} }
@Override @Override
public void beforeVariableChanged(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { public void beforeVariableChanged(ScoreDirector<DispatchSolution> scoreDirector, Customer customer) {
// Do nothing // Do nothing
} }
@Override @Override
public void afterVariableChanged(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { public void afterVariableChanged(ScoreDirector<DispatchSolution> scoreDirector, Customer customer) {
updateArrivalTime(scoreDirector, customer); updateArrivalTime(scoreDirector, customer);
} }
@Override @Override
public void beforeEntityRemoved(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { public void beforeEntityRemoved(ScoreDirector<DispatchSolution> scoreDirector, Customer customer) {
// Do nothing // Do nothing
} }
@Override @Override
public void afterEntityRemoved(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { public void afterEntityRemoved(ScoreDirector<DispatchSolution> scoreDirector, Customer customer) {
updateArrivalTime(scoreDirector, customer); updateArrivalTime(scoreDirector, customer);
} }
protected void updateArrivalTime(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer sourceCustomer) { protected void updateArrivalTime(ScoreDirector<DispatchSolution> scoreDirector, Customer sourceCustomer) {
if (sourceCustomer.getTechnician() == null) { if (sourceCustomer.getTechnician() == null) {
if (sourceCustomer.getArrivalTime() != null) { if (sourceCustomer.getArrivalTime() != null) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!