public void assignDrivers()

in prototype/dispatch/order-dispatcher/src/main/java/com/aws/proto/dispatching/api/v2/DispatcherService.java [106:166]


    public void assignDrivers(UUID problemId, AssignDriversRequest req) {
        long createdAt = Timestamp.valueOf(LocalDateTime.now()).getTime();
        String executionId = req.executionId;

        List<PlanningDelivery> planningDeliveries = new ArrayList<>();

        List<Coordinates> locationsForDriverQuery = new ArrayList<>();
        for (AssignDriversRequest.Order inputOrder : req.orders) {
            locationsForDriverQuery.add(Coordinates.valueOf(inputOrder.restaurant.lat, inputOrder.restaurant.lon));
        }

        List<PlanningDriverBase> drivers = driverQueryManager.retrieveDriversAroundLocations(locationsForDriverQuery);
//        List<PlanningDriverBase> drivers = driverQueryManager.retrieveDriversWithExtendingRadius(
//          Coordinates.valueOf(req.centroid.lat, req.centroid.lon), req.orders.length);

        if(drivers.size() == 0) {
            DispatcherRequestResult result = new DispatcherRequestResult(problemId.toString());
            result.error = "No drivers present in the system";

            List<String> unassignedOrderIds = Arrays.stream(req.orders).map(o -> o.orderId).collect(Collectors.toList());
            assignmentService.saveAssignment(new DispatcherResult(problemId, executionId, createdAt, new ArrayList<>(), unassignedOrderIds, "NO_DRIVERS", "NA"));

            return;
        }

        List<LocationBase> allLocations = new ArrayList<>();

        for (AssignDriversRequest.Order inputOrder : req.orders) {
            Order order = new Order(inputOrder.orderId, inputOrder.createdAt, inputOrder.state, inputOrder.restaurant.preparationTimeInMins);
            RestaurantLocation restaurantLocation = new RestaurantLocation(inputOrder.restaurant.id, Coordinates.valueOf(inputOrder.restaurant.lat, inputOrder.restaurant.lon));
            CustomerLocation customerLocation = new CustomerLocation(inputOrder.customer.id, Coordinates.valueOf(inputOrder.customer.lat, inputOrder.customer.lon));

            PlanningDelivery delivery = new PlanningDelivery(order, restaurantLocation, customerLocation);
            planningDeliveries.add(delivery);

            allLocations.add(restaurantLocation);
            allLocations.add(customerLocation);
        }

        // save locations to _all_ locations
        drivers.forEach(d -> allLocations.add(d.getLocation()));

        assignmentService.saveAssignment(new DispatcherResult(problemId, executionId, createdAt, new ArrayList<>(), new ArrayList<>(), "ENQUEUED", "NA"));

        // build distance matrix
        DistanceMatrix distanceMatrix = DistanceMatrix.generate(allLocations, this.graphhopperRouter);
        logger.trace(distanceMatrix.toString());
        for (LocationBase loc : allLocations) {
            loc.setDistanceMatrix(distanceMatrix);
        }

        List<PlanningDriver> planningDrivers = drivers.stream().map(PlanningDriver::new).collect(Collectors.toList());

        DispatchingSolution problem = new DispatchingSolution(problemId, "DispatchingSolution", createdAt, executionId, planningDrivers, planningDeliveries);
//        SolverJob<DispatchingSolution, UUID> solverJob = this.solverManager.solveAndListen(problemId, this::problemFinder, this::consumeSolution);

        SolverJob<DispatchingSolution, UUID> solverJob = this.solverManager.solve(problemId, this::problemFinder, this::finalBestSolutionConsumer);

        this.solutionMap.put(problemId, new SolutionState<>(solverJob, problem, System.currentTimeMillis()));
        assignmentService.saveAssignment(new DispatcherResult(problemId, executionId, problem.getCreatedAt(), solverJob.getSolverStatus()));
    }