class RouteOptimizerImpl implements RouteOptimizer {

    @Override
    public void addLocation(Location domainLocation, DistanceMatrixRow distanceMatrixRow) {
        PlanningLocation location = PlanningLocationFactory.fromDomain(
                domainLocation,
                new DistanceMapImpl(distanceMatrixRow));
        // Unfortunately can't start solver with an empty solution (see https://issues.redhat.com/browse/PLANNER-776)
        if (depot == null) {
            depot = new PlanningDepot(location);
            publishSolution();
        } else {
            PlanningVisit visit = PlanningVisitFactory.fromLocation(location);
            visits.add(visit);
            if (vehicles.isEmpty()) {
                publishSolution();
            } else if (visits.size() == 1) {
                solverManager.startSolver(SolutionFactory.solutionFromVisits(vehicles, depot, visits));
            } else {
                solverManager.addVisit(visit);
            }
        }
    }

    @Autowired  RouteOptimizerImpl(SolverManager solverManager, RouteChangedEventPublisher routeChangedEventPublisher);

}