private Map<Job, VehicleRoute> map(Collection<VehicleRoute> vehicleRoutes) { Map<Job, VehicleRoute> map = new HashMap<Job, VehicleRoute>(vrp.getJobs().size()); for (VehicleRoute r : vehicleRoutes) { for (Job j : r.getTourActivities().getJobs()) { map.put(j, r); } } return map; }
@Override public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) { for (VehicleRoutingProblemSolution solution : solutions) { Set<Job> jobsInSolution = new HashSet<Job>(); for (VehicleRoute route : solution.getRoutes()) { jobsInSolution.addAll(route.getTourActivities().getJobs()); } if (jobsInSolution.size() != problem.getJobs().size()) { throw new IllegalStateException("we are at the end of the algorithm and still have not found a valid solution." + "This cannot be."); } } }
private List<LocationWrapper> getLocationWrappers(VehicleRoute route) { List<LocationWrapper> locations = new ArrayList<LocationWrapper>(route.getTourActivities().getJobs().size()); Map<Job, List<Location>> jobs2locations = new HashMap<Job, List<Location>>(); for (TourActivity act : route.getActivities()) { if (act instanceof TourActivity.JobActivity) { Job job = ((TourActivity.JobActivity) act).getJob(); if (!jobs2locations.containsKey(job)) { jobs2locations.put(job, new ArrayList<Location>()); } jobs2locations.get(job).add(act.getLocation()); } } for (Job j : jobs2locations.keySet()) { locations.add(new LocationWrapper(j, jobs2locations.get(j))); } return locations; }
private void verify(VehicleRoutingProblemSolution solution) { Set<Job> allJobs = new HashSet<Job>(problem.getJobs().values()); allJobs.removeAll(solution.getUnassignedJobs()); for (VehicleRoute route : solution.getRoutes()) { allJobs.removeAll(route.getTourActivities().getJobs()); if (route.getVehicle().getIndex() == 0) throw new IllegalStateException("vehicle used in initial solution has no index. probably a vehicle is used that has not been added to the " + " the VehicleRoutingProblem. only use vehicles that have already been added to the problem."); for (TourActivity act : route.getActivities()) { if (act.getIndex() == 0) throw new IllegalStateException("act in initial solution has no index. activities are created and associated to their job in VehicleRoutingProblem\n." + " thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" + " VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" + " then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem"); } } solution.getUnassignedJobs().addAll(allJobs); solution.setCost(getObjectiveFunction().getCosts(solution)); // if (nuJobs != problem.getJobs().values().size()) { // logger.warn("number of jobs in initial solution ({}) is not equal nuJobs in vehicle routing problem ({})" + // "\n this might yield unintended effects, e.g. initial solution cannot be improved anymore.", nuJobs, problem.getJobs().values().size()); // } }
jobs.addAll(vrp.getJobs().values()); for (VehicleRoute r : vrp.getInitialVehicleRoutes()) { jobs.addAll(r.getTourActivities().getJobs());
void insertionStarts(VehicleRoute route) { Capacity loadAtDepot = Capacity.Builder.newInstance().build(); Capacity loadAtEnd = Capacity.Builder.newInstance().build(); for (Job j : route.getTourActivities().getJobs()) { if (j instanceof Delivery) { loadAtDepot = Capacity.addup(loadAtDepot, j.getSize()); } else if (j instanceof Pickup || j instanceof Service) { loadAtEnd = Capacity.addup(loadAtEnd, j.getSize()); } } stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_BEGINNING, loadAtDepot); stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_END, loadAtEnd); }
private void retrieveActivities(VehicleRoutingProblem vrp) throws NoLocationFoundException { activities = new XYSeries("activities", false, true); for (Vehicle v : vrp.getVehicles()) { Coordinate start_coordinate = getCoordinate(v.getStartLocation().getCoordinate()); if (start_coordinate == null) throw new NoLocationFoundException(); XYDataItem item = new XYDataItem(start_coordinate.getX() * scalingFactor, start_coordinate.getY() * scalingFactor); markItem(item, Activity.START); activities.add(item); if (!v.getStartLocation().getId().equals(v.getEndLocation().getId())) { Coordinate end_coordinate = getCoordinate(v.getEndLocation().getCoordinate()); if (end_coordinate == null) throw new NoLocationFoundException(); XYDataItem end_item = new XYDataItem(end_coordinate.getX() * scalingFactor, end_coordinate.getY() * scalingFactor); markItem(end_item, Activity.END); activities.add(end_item); } } for (Job job : vrp.getJobs().values()) { addJob(activities, job); } for (VehicleRoute r : vrp.getInitialVehicleRoutes()) { for (Job job : r.getTourActivities().getJobs()) { addJob(activities, job); } } }
private Map<Job, VehicleRoute> map(Collection<VehicleRoute> vehicleRoutes) { Map<Job, VehicleRoute> map = new HashMap<Job, VehicleRoute>(vrp.getJobs().size()); for (VehicleRoute r : vehicleRoutes) { for (Job j : r.getTourActivities().getJobs()) { map.put(j, r); } } return map; }
@Override public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) { for (VehicleRoutingProblemSolution solution : solutions) { Set<Job> jobsInSolution = new HashSet<Job>(); for (VehicleRoute route : solution.getRoutes()) { jobsInSolution.addAll(route.getTourActivities().getJobs()); } if (jobsInSolution.size() != problem.getJobs().size()) { throw new IllegalStateException("we are at the end of the algorithm and still have not found a valid solution." + "This cannot be."); } } }
private List<LocationWrapper> getLocationWrappers(VehicleRoute route) { List<LocationWrapper> locations = new ArrayList<LocationWrapper>(route.getTourActivities().getJobs().size()); Map<Job, List<Location>> jobs2locations = new HashMap<Job, List<Location>>(); for (TourActivity act : route.getActivities()) { if (act instanceof TourActivity.JobActivity) { Job job = ((TourActivity.JobActivity) act).getJob(); if (!jobs2locations.containsKey(job)) { jobs2locations.put(job, new ArrayList<Location>()); } jobs2locations.get(job).add(act.getLocation()); } } for (Job j : jobs2locations.keySet()) { locations.add(new LocationWrapper(j, jobs2locations.get(j))); } return locations; }
private void verify(VehicleRoutingProblemSolution solution) { int nuJobs = 0; for (VehicleRoute route : solution.getRoutes()) { nuJobs += route.getTourActivities().getJobs().size(); if (route.getVehicle().getIndex() == 0) throw new IllegalStateException("vehicle used in initial solution has no index. probably a vehicle is used that has not been added to the " + " the VehicleRoutingProblem. only use vehicles that have already been added to the problem."); for (TourActivity act : route.getActivities()) { if (act.getIndex() == 0) { throw new IllegalStateException("act in initial solution has no index. activities are created and associated to their job in VehicleRoutingProblem\n." + " thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" + " VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" + " then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem"); } } } // if (nuJobs != problem.getJobs().values().size()) { // logger.warn("number of jobs in initial solution ({}) is not equal nuJobs in vehicle routing problem ({})" + // "\n this might yield unintended effects, e.g. initial solution cannot be improved anymore.", nuJobs, problem.getJobs().values().size()); // } }
jobs.addAll(vrp.getJobs().values()); for (VehicleRoute r : vrp.getInitialVehicleRoutes()) { jobs.addAll(r.getTourActivities().getJobs());
void insertionStarts(VehicleRoute route) { Capacity loadAtDepot = Capacity.Builder.newInstance().build(); Capacity loadAtEnd = Capacity.Builder.newInstance().build(); for (Job j : route.getTourActivities().getJobs()) { if (j instanceof Delivery) { loadAtDepot = Capacity.addup(loadAtDepot, j.getSize()); } else if (j instanceof Pickup || j instanceof Service) { loadAtEnd = Capacity.addup(loadAtEnd, j.getSize()); } } stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_BEGINNING, loadAtDepot); stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_END, loadAtEnd); }
private void retrieveActivities(VehicleRoutingProblem vrp) throws NoLocationFoundException { activities = new XYSeries("activities", false, true); for (Vehicle v : vrp.getVehicles()) { Coordinate start_coordinate = getCoordinate(v.getStartLocation().getCoordinate()); if (start_coordinate == null) throw new NoLocationFoundException(); XYDataItem item = new XYDataItem(start_coordinate.getX() * scalingFactor, start_coordinate.getY() * scalingFactor); markItem(item, Activity.START); activities.add(item); if (!v.getStartLocation().getId().equals(v.getEndLocation().getId())) { Coordinate end_coordinate = getCoordinate(v.getEndLocation().getCoordinate()); if (end_coordinate == null) throw new NoLocationFoundException(); XYDataItem end_item = new XYDataItem(end_coordinate.getX() * scalingFactor, end_coordinate.getY() * scalingFactor); markItem(end_item, Activity.END); activities.add(end_item); } } for (Job job : vrp.getJobs().values()) { addJob(activities, job); } for (VehicleRoute r : vrp.getInitialVehicleRoutes()) { for (Job job : r.getTourActivities().getJobs()) { addJob(activities, job); } } }