in prototype/dispatch/order-dispatcher/src/main/java/com/aws/proto/dispatching/api/v1/DispatcherResource.java [251:298]
public DispatcherResult stopSolving(@PathParam("problemId") String id) {
UUID problemId = UUID.fromString(id);
// get from in-mem map
SolutionState<DispatchingSolution, UUID> state = this.solutionMap.get(problemId);
// doesn't exist
if (state == null) {
return new DispatcherResult(problemId, "", Timestamp.valueOf(LocalDateTime.now()).getTime(), null, null, "NOT_SOLVING", null);
}
// terminate solution
this.solverManager.terminateEarly(problemId);
// this.solutionRepository.updateStatus(problemId, SolutionStatus.TERMINATED);
logger.info("Dispatch solver terminated after {}", state.solverJob.getSolvingDuration());
List<DispatcherResult.AssignedOrders> assignedOrders = new ArrayList<>();
for(PlanningDriver driver : state.problem.getPlanningDrivers()) {
Set<String> orderIds = new HashSet<>();
List<DispatcherResult.Visit> route = new ArrayList<>();
PlanningVisit visit = driver.getNextPlanningVisit();
if(visit == null) {
continue;
}
while(visit != null) {
orderIds.add(visit.getOrder().getOrderId());
route.add(new DispatcherResult.Visit(
visit.getLocationType(), visit.getLocation().getId(),
visit.getLocation().getCoordinates().latitude().doubleValue(),
visit.getLocation().getCoordinates().longitude().doubleValue()));
visit = visit.getNextPlanningVisit();
}
assignedOrders.add(
new DispatcherResult.AssignedOrders(
driver.getId(), driver.getDriverIdentity(), driver.getLocation(), new ArrayList<>(orderIds), route));
}
DispatcherResult result = new DispatcherResult(problemId, "execId-1234", Timestamp.valueOf(LocalDateTime.now()).getTime(), assignedOrders, new ArrayList<>(), "TERMINATED", state.problem.getScore().toString());
this.solutionMap.remove(problemId);
return result;
}