1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

add bad job list

This commit is contained in:
oblonski 2014-08-09 22:48:51 +02:00
parent 632a889c4b
commit 62331ccfd9
15 changed files with 167 additions and 117 deletions

View file

@ -93,6 +93,7 @@ public class SolutionPrinter {
System.out.format("+---------------+------------------------------------------+%n"); System.out.format("+---------------+------------------------------------------+%n");
System.out.format(leftAlignSolution, "costs",solution.getCost()); System.out.format(leftAlignSolution, "costs",solution.getCost());
System.out.format(leftAlignSolution, "nVehicles",solution.getRoutes().size()); System.out.format(leftAlignSolution, "nVehicles",solution.getRoutes().size());
System.out.format(leftAlignSolution, "badJobs", solution.getBadJobs().size());
System.out.format("+----------------------------------------------------------+%n"); System.out.format("+----------------------------------------------------------+%n");
if(print.equals(Print.VERBOSE)){ if(print.equals(Print.VERBOSE)){
@ -130,6 +131,10 @@ public class SolutionPrinter {
} }
System.out.format("+*:=PenaltyVehicle+%n"); System.out.format("+*:=PenaltyVehicle+%n");
System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n"); System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n");
System.out.format("+*:=badJobs+%n");
for(Job j : solution.getBadJobs()){
System.out.println(j.getId());
}
} }
private static String getVehicleString(VehicleRoute route) { private static String getVehicleString(VehicleRoute route) {

View file

@ -29,6 +29,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
@ -51,8 +52,8 @@ public final class InsertionInitialSolutionFactory implements InitialSolutionFac
logger.info("create initial solution."); logger.info("create initial solution.");
List<VehicleRoute> vehicleRoutes = new ArrayList<VehicleRoute>(); List<VehicleRoute> vehicleRoutes = new ArrayList<VehicleRoute>();
vehicleRoutes.addAll(vrp.getInitialVehicleRoutes()); vehicleRoutes.addAll(vrp.getInitialVehicleRoutes());
insertion.insertJobs(vehicleRoutes, getUnassignedJobs(vrp)); Collection<Job> badJobs = insertion.insertJobs(vehicleRoutes, getUnassignedJobs(vrp));
VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(vehicleRoutes, Double.MAX_VALUE); VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(vehicleRoutes, badJobs, Double.MAX_VALUE);
double costs = solutionCostsCalculator.getCosts(solution); double costs = solutionCostsCalculator.getCosts(solution);
solution.setCost(costs); solution.setCost(costs);
logger.info("creation done"); logger.info("creation done");

View file

@ -117,6 +117,7 @@ public class SearchStrategy {
* @param vrp the underlying vehicle routing problem * @param vrp the underlying vehicle routing problem
* @param solutions which will be modified * @param solutions which will be modified
* @return discoveredSolution * @return discoveredSolution
* @throws java.lang.IllegalStateException if selector cannot select any solution
*/ */
@SuppressWarnings("UnusedParameters") @SuppressWarnings("UnusedParameters")
public DiscoveredSolution run(VehicleRoutingProblem vrp, Collection<VehicleRoutingProblemSolution> solutions){ public DiscoveredSolution run(VehicleRoutingProblem vrp, Collection<VehicleRoutingProblemSolution> solutions){

View file

@ -16,15 +16,15 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.algorithm.listener.SearchStrategyListener;
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
import jsprit.core.util.RandomNumberGeneration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import jsprit.core.algorithm.listener.SearchStrategyListener;
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
import jsprit.core.util.RandomNumberGeneration;
public class SearchStrategyManager { public class SearchStrategyManager {
@ -55,8 +55,9 @@ public class SearchStrategyManager {
/** /**
* adds a new search strategy. the probability must be within [0,1]. * adds a new search strategy. the probability must be within [0,1].
* @param strategy * @param strategy strategy to be added
* @param probability * @param probability probability of corresponding strategy to be added
* @throws java.lang.IllegalStateException if strategy is null OR prob > 1. OR prob < 0.
*/ */
public void addStrategy(SearchStrategy strategy, double probability){ public void addStrategy(SearchStrategy strategy, double probability){
if(strategy == null){ if(strategy == null){
@ -76,6 +77,12 @@ public class SearchStrategyManager {
} }
} }
/**
* Returns search strategy that has been randomly selected.
*
* @return selected search strategy
* @throws java.lang.IllegalStateException if randomNumberGenerator is null OR no search strategy can be found
*/
public SearchStrategy getRandomStrategy() { public SearchStrategy getRandomStrategy() {
if(random == null) throw new IllegalStateException("randomizer is null. make sure you set random object correctly"); if(random == null) throw new IllegalStateException("randomizer is null. make sure you set random object correctly");
double randomFig = random.nextDouble(); double randomFig = random.nextDouble();

View file

@ -23,6 +23,7 @@ import jsprit.core.problem.solution.SolutionCostCalculator;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
import jsprit.core.problem.vehicle.Vehicle;
/** /**
* Default objective function which is the sum of all fixed vehicle and variable * Default objective function which is the sum of all fixed vehicle and variable
@ -49,10 +50,17 @@ public class VariablePlusFixedSolutionCostCalculatorFactory {
double c = 0.0; double c = 0.0;
for(VehicleRoute r : solution.getRoutes()){ for(VehicleRoute r : solution.getRoutes()){
c += stateManager.getRouteState(r, InternalStates.COSTS, Double.class); c += stateManager.getRouteState(r, InternalStates.COSTS, Double.class);
c += r.getVehicle().getType().getVehicleCostParams().fix; c += getFixedCosts(r.getVehicle());
} }
c += solution.getBadJobs().size() * c * .1;
return c; return c;
} }
private double getFixedCosts(Vehicle vehicle) {
if(vehicle == null) return 0.0;
if(vehicle.getType() == null) return 0.0;
return vehicle.getType().getVehicleCostParams().fix;
}
}; };
} }

View file

@ -16,10 +16,10 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.acceptor; package jsprit.core.algorithm.acceptor;
import java.util.Collection;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import java.util.Collection;
public class GreedyAcceptance implements SolutionAcceptor{ public class GreedyAcceptance implements SolutionAcceptor{
@ -48,12 +48,6 @@ public class GreedyAcceptance implements SolutionAcceptor{
if (worstSolution == null) worstSolution = s; if (worstSolution == null) worstSolution = s;
else if (s.getCost() > worstSolution.getCost()) worstSolution = s; else if (s.getCost() > worstSolution.getCost()) worstSolution = s;
} }
// if(newSolution.getRoutes().size() < worstSolution.getRoutes().size()){
// solutions.remove(worstSolution);
// solutions.add(newSolution);
// solutionAccepted = true;
// }
// else
if(newSolution.getCost() < worstSolution.getCost()){ if(newSolution.getCost() < worstSolution.getCost()){
solutions.remove(worstSolution); solutions.remove(worstSolution);
solutions.add(newSolution); solutions.add(newSolution);

View file

@ -620,24 +620,7 @@ public class VehicleRoutingAlgorithms {
} }
private static SolutionCostCalculator getDefaultCostCalculator(final StateManager stateManager) { private static SolutionCostCalculator getDefaultCostCalculator(final StateManager stateManager) {
SolutionCostCalculator calc = new SolutionCostCalculator() { return new VariablePlusFixedSolutionCostCalculatorFactory(stateManager).createCalculator();
@Override
public double getCosts(VehicleRoutingProblemSolution solution) {
double costs = 0.0;
for(VehicleRoute route : solution.getRoutes()){
costs += stateManager.getRouteState(route, InternalStates.COSTS, Double.class) + getFixedCosts(route.getVehicle());
}
return costs;
}
private double getFixedCosts(Vehicle vehicle) {
if(vehicle == null) return 0.0;
if(vehicle.getType() == null) return 0.0;
return vehicle.getType().getVehicleCostParams().fix;
}
};
return calc;
} }
private static VehicleFleetManager createFleetManager(final VehicleRoutingProblem vrp) { private static VehicleFleetManager createFleetManager(final VehicleRoutingProblem vrp) {

View file

@ -16,8 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.module; package jsprit.core.algorithm.module;
import java.util.Collection;
import jsprit.core.algorithm.SearchStrategyModule; import jsprit.core.algorithm.SearchStrategyModule;
import jsprit.core.algorithm.listener.SearchStrategyModuleListener; import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
import jsprit.core.algorithm.recreate.InsertionStrategy; import jsprit.core.algorithm.recreate.InsertionStrategy;
@ -27,6 +25,10 @@ import jsprit.core.algorithm.ruin.listener.RuinListener;
import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public class RuinAndRecreateModule implements SearchStrategyModule{ public class RuinAndRecreateModule implements SearchStrategyModule{
@ -46,7 +48,12 @@ public class RuinAndRecreateModule implements SearchStrategyModule{
@Override @Override
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
Collection<Job> ruinedJobs = ruin.ruin(vrpSolution.getRoutes()); Collection<Job> ruinedJobs = ruin.ruin(vrpSolution.getRoutes());
insertion.insertJobs(vrpSolution.getRoutes(), ruinedJobs); Set<Job> ruinedJobSet = new HashSet<Job>();
ruinedJobSet.addAll(ruinedJobs);
ruinedJobSet.addAll(vrpSolution.getBadJobs());
Collection<Job> badJobs = insertion.insertJobs(vrpSolution.getRoutes(), ruinedJobSet);
vrpSolution.getBadJobs().clear();
vrpSolution.getBadJobs().addAll(badJobs);
return vrpSolution; return vrpSolution;
} }

View file

@ -34,11 +34,11 @@ import java.util.*;
/** /**
* Best insertion that insert the job where additional costs are minimal.
* *
* @author stefan schroeder * @author stefan schroeder
* *
*/ */
final class BestInsertion implements InsertionStrategy{ final class BestInsertion implements InsertionStrategy{
class Insertion { class Insertion {
@ -79,8 +79,6 @@ final class BestInsertion implements InsertionStrategy{
private JobInsertionCostsCalculator bestInsertionCostCalculator; private JobInsertionCostsCalculator bestInsertionCostCalculator;
private boolean minVehiclesFirst = false;
public void setRandom(Random random) { public void setRandom(Random random) {
this.random = random; this.random = random;
} }
@ -99,8 +97,9 @@ final class BestInsertion implements InsertionStrategy{
} }
@Override @Override
public void insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) { public Collection<Job> insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
insertionsListeners.informInsertionStarts(vehicleRoutes,unassignedJobs); insertionsListeners.informInsertionStarts(vehicleRoutes,unassignedJobs);
List<Job> badJobs = new ArrayList<Job>(unassignedJobs.size());
List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs); List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs);
Collections.shuffle(unassignedJobList, random); Collections.shuffle(unassignedJobList, random);
for(Job unassignedJob : unassignedJobList){ for(Job unassignedJob : unassignedJobList){
@ -116,38 +115,17 @@ final class BestInsertion implements InsertionStrategy{
bestInsertionCost = iData.getInsertionCost(); bestInsertionCost = iData.getInsertionCost();
} }
} }
if(!minVehiclesFirst){
VehicleRoute newRoute = VehicleRoute.emptyRoute(); VehicleRoute newRoute = VehicleRoute.emptyRoute();
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost); InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
if(newIData.getInsertionCost() < bestInsertionCost){ if(newIData.getInsertionCost() < bestInsertionCost){
bestInsertion = new Insertion(newRoute,newIData); bestInsertion = new Insertion(newRoute,newIData);
vehicleRoutes.add(newRoute); vehicleRoutes.add(newRoute);
} }
} if(bestInsertion == null) badJobs.add(unassignedJob);
if(bestInsertion == null){ else inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
VehicleRoute newRoute = VehicleRoute.emptyRoute();
InsertionData bestI = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, Double.MAX_VALUE);
if(bestI instanceof InsertionData.NoInsertionFound){
throw new NoSolutionFoundException(getErrorMsg(unassignedJob));
}
else{
bestInsertion = new Insertion(newRoute,bestI);
vehicleRoutes.add(newRoute);
}
}
// logger.info("insert " + unassignedJob + " pickup@" + bestInsertion.getInsertionData().getPickupInsertionIndex() + " delivery@" + bestInsertion.getInsertionData().getDeliveryInsertionIndex());
inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
} }
insertionsListeners.informInsertionEndsListeners(vehicleRoutes); insertionsListeners.informInsertionEndsListeners(vehicleRoutes);
} return badJobs;
private String getErrorMsg(Job unassignedJob) {
return "given the vehicles, could not insert job\n" +
"\t" + unassignedJob +
"\n\tthis might have the following reasons:\n" +
"\t- no vehicle has the capacity to transport the job [check whether there is at least one vehicle that is capable to transport the job]\n" +
"\t- the time-window cannot be met, even in a commuter tour the time-window is missed [check whether it is possible to reach the time-window on the shortest path or make hard time-windows soft]\n" +
"\t- if you deal with finite vehicles, and the available vehicles are already fully employed, no vehicle can be found anymore to transport the job [add penalty-vehicles]";
} }
@Override @Override

View file

@ -114,7 +114,7 @@ final class BestInsertionConcurrent implements InsertionStrategy{
} }
@Override @Override
public void insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) { public Collection<Job> insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
insertionsListeners.informInsertionStarts(vehicleRoutes,unassignedJobs); insertionsListeners.informInsertionStarts(vehicleRoutes,unassignedJobs);
List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs); List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs);
Collections.shuffle(unassignedJobList, random); Collections.shuffle(unassignedJobList, random);
@ -184,6 +184,7 @@ final class BestInsertionConcurrent implements InsertionStrategy{
inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute()); inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
} }
insertionsListeners.informInsertionEndsListeners(vehicleRoutes); insertionsListeners.informInsertionEndsListeners(vehicleRoutes);
return null;
} }
private String getErrorMsg(Job unassignedJob) { private String getErrorMsg(Job unassignedJob) {

View file

@ -16,17 +16,16 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.recreate; package jsprit.core.algorithm.recreate;
import java.util.Collection;
import jsprit.core.algorithm.recreate.listener.InsertionListener; import jsprit.core.algorithm.recreate.listener.InsertionListener;
import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import java.util.Collection;
/** /**
* Basic interface for insertion strategies
* *
* @author stefan schroeder * @author stefan schroeder
* *
@ -35,12 +34,11 @@ import jsprit.core.problem.solution.route.VehicleRoute;
public interface InsertionStrategy { public interface InsertionStrategy {
/** /**
* Assigns the unassigned jobs to service-providers * Inserts unassigned jobs into vehicle routes.
* * @param vehicleRoutes existing vehicle routes
* @param vehicleRoutes * @param unassignedJobs jobs to be inserted
* @param unassignedJobs
*/ */
public void insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs); public Collection<Job> insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs);
public void addListener(InsertionListener insertionListener); public void addListener(InsertionListener insertionListener);

View file

@ -16,11 +16,12 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.problem.solution; package jsprit.core.problem.solution;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import jsprit.core.problem.solution.route.VehicleRoute;
/** /**
* Contains the solution of a vehicle routing problem and its corresponding costs. * Contains the solution of a vehicle routing problem and its corresponding costs.
@ -30,13 +31,11 @@ import jsprit.core.problem.solution.route.VehicleRoute;
*/ */
public class VehicleRoutingProblemSolution { public class VehicleRoutingProblemSolution {
public static double NO_COST_YET = -9999.0;
/** /**
* Makes a deep copy of the solution to be copied. * Makes a deep copy of the solution to be copied.
* *
* @param solution2copy * @param solution2copy solution to be copied
* @return * @return solution
*/ */
public static VehicleRoutingProblemSolution copyOf(VehicleRoutingProblemSolution solution2copy){ public static VehicleRoutingProblemSolution copyOf(VehicleRoutingProblemSolution solution2copy){
return new VehicleRoutingProblemSolution(solution2copy); return new VehicleRoutingProblemSolution(solution2copy);
@ -44,6 +43,8 @@ public class VehicleRoutingProblemSolution {
private final Collection<VehicleRoute> routes; private final Collection<VehicleRoute> routes;
private Collection<Job> badJobs = new ArrayList<Job>();
private double cost; private double cost;
private VehicleRoutingProblemSolution(VehicleRoutingProblemSolution solution){ private VehicleRoutingProblemSolution(VehicleRoutingProblemSolution solution){
@ -53,13 +54,14 @@ public class VehicleRoutingProblemSolution {
routes.add(route); routes.add(route);
} }
this.cost = solution.getCost(); this.cost = solution.getCost();
badJobs.addAll(solution.getBadJobs());
} }
/** /**
* Constructs a solution with a number of {@link VehicleRoute}s and their corresponding aggregate cost value. * Constructs a solution with a number of {@link VehicleRoute}s and their corresponding aggregate cost value.
* *
* @param routes * @param routes routes being part of the solution
* @param cost * @param cost total costs of solution
*/ */
public VehicleRoutingProblemSolution(Collection<VehicleRoute> routes, double cost) { public VehicleRoutingProblemSolution(Collection<VehicleRoute> routes, double cost) {
super(); super();
@ -67,6 +69,19 @@ public class VehicleRoutingProblemSolution {
this.cost = cost; this.cost = cost;
} }
/**
* Constructs a solution with a number of {@link VehicleRoute}s, bad jobs and their corresponding aggregate cost value.
*
* @param routes routes being part of the solution
* @param cost total costs of solution
*/
public VehicleRoutingProblemSolution(Collection<VehicleRoute> routes, Collection<Job> badJobs, double cost) {
super();
this.routes = routes;
this.badJobs = badJobs;
this.cost = cost;
}
/** /**
* Returns a collection of vehicle-routes. * Returns a collection of vehicle-routes.
* *
@ -88,10 +103,19 @@ public class VehicleRoutingProblemSolution {
/** /**
* Sets the costs of this solution. * Sets the costs of this solution.
* *
* @param cost * @param cost the cost to assigned to this solution
*/ */
public void setCost(double cost){ public void setCost(double cost){
this.cost = cost; this.cost = cost;
} }
/**
* Returns bad jobs, i.e. jobs that are not assigned to any vehicle route.
*
* @return bad jobs
*/
public Collection<Job> getBadJobs(){
return badJobs;
}
} }

View file

@ -18,14 +18,17 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.problem.solution; package jsprit.core.problem.solution;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import jsprit.core.problem.solution.route.VehicleRoute; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import org.junit.Test;
public class VehicleRoutingProblemSolutionTest { public class VehicleRoutingProblemSolutionTest {
@ -51,4 +54,42 @@ public class VehicleRoutingProblemSolutionTest {
assertEquals(20.0,sol.getCost(),0.01); assertEquals(20.0,sol.getCost(),0.01);
} }
@Test
public void sizeOfBadJobsShouldBeCorrect(){
Job badJob = mock(Job.class);
List<Job> badJobs = new ArrayList<Job>();
badJobs.add(badJob);
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.<VehicleRoute>emptyList(), badJobs, 10.0);
assertEquals(1,sol.getBadJobs().size());
}
@Test
public void sizeOfBadJobsShouldBeCorrect_2(){
Job badJob = mock(Job.class);
List<Job> badJobs = new ArrayList<Job>();
badJobs.add(badJob);
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.<VehicleRoute>emptyList(), 10.0);
sol.getBadJobs().addAll(badJobs);
assertEquals(1, sol.getBadJobs().size());
}
@Test
public void badJobsShouldBeCorrect(){
Job badJob = mock(Job.class);
List<Job> badJobs = new ArrayList<Job>();
badJobs.add(badJob);
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.<VehicleRoute>emptyList(), badJobs, 10.0);
assertEquals(badJob,sol.getBadJobs().iterator().next());
}
@Test
public void badJobsShouldBeCorrect_2() {
Job badJob = mock(Job.class);
List<Job> badJobs = new ArrayList<Job>();
badJobs.add(badJob);
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.<VehicleRoute>emptyList(), 10.0);
sol.getBadJobs().addAll(badJobs);
assertEquals(badJob, sol.getBadJobs().iterator().next());
}
} }

View file

@ -245,7 +245,7 @@ public class BicycleMessenger {
VehicleRoutingTransportCosts routingCosts = new CrowFlyCosts(problemBuilder.getLocations()); //which is the default VehicleRoutingTransportCosts in builder above VehicleRoutingTransportCosts routingCosts = new CrowFlyCosts(problemBuilder.getLocations()); //which is the default VehicleRoutingTransportCosts in builder above
problemBuilder.setRoutingCost(routingCosts); problemBuilder.setRoutingCost(routingCosts);
//finally build the problem //finally build the problem
problemBuilder.addPenaltyVehicles(20.0,50000); // problemBuilder.addPenaltyVehicles(20.0,50000);
VehicleRoutingProblem bicycleMessengerProblem = problemBuilder.build(); VehicleRoutingProblem bicycleMessengerProblem = problemBuilder.build();
/* /*
@ -272,10 +272,10 @@ public class BicycleMessenger {
vraBuilder.addDefaultCostCalculators(); vraBuilder.addDefaultCostCalculators();
vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); vraBuilder.setStateAndConstraintManager(stateManager, constraintManager);
VehicleRoutingAlgorithm algorithm = vraBuilder.build(); VehicleRoutingAlgorithm algorithm = vraBuilder.build();
algorithm.setNuOfIterations(2000); algorithm.setMaxIterations(2000);
VariationCoefficientTermination prematureAlgorithmTermination = new VariationCoefficientTermination(200, 0.001); VariationCoefficientTermination prematureAlgorithmTermination = new VariationCoefficientTermination(200, 0.001);
algorithm.setPrematureAlgorithmTermination(prematureAlgorithmTermination); // algorithm.setPrematureAlgorithmTermination(prematureAlgorithmTermination);
algorithm.addListener(prematureAlgorithmTermination); // algorithm.addListener(prematureAlgorithmTermination);
// algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); // algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
//search //search
@ -294,6 +294,7 @@ public class BicycleMessenger {
//and the problem as well as the solution //and the problem as well as the solution
Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions)); Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions));
plotter1.setLabel(Plotter.Label.ID);
plotter1.plotShipments(false); plotter1.plotShipments(false);
// plotter1.setBoundingBox(5000, 45500, 25000, 66500); // plotter1.setBoundingBox(5000, 45500, 25000, 66500);
plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMessenger"); plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMessenger");

View file

@ -59,7 +59,7 @@ public class MultipleDepotExampleWithPenaltyVehicles {
* *
* each with 14 vehicles each with a capacity of 500 and a maximum duration of 310 * each with 14 vehicles each with a capacity of 500 and a maximum duration of 310
*/ */
int nuOfVehicles = 14; int nuOfVehicles = 13;
int capacity = 500; int capacity = 500;
double maxDuration = 310; double maxDuration = 310;
Coordinate firstDepotCoord = Coordinate.newInstance(-33, 33); Coordinate firstDepotCoord = Coordinate.newInstance(-33, 33);
@ -68,7 +68,8 @@ public class MultipleDepotExampleWithPenaltyVehicles {
int depotCounter = 1; int depotCounter = 1;
for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){ for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){
for(int i=0;i<nuOfVehicles;i++){ for(int i=0;i<nuOfVehicles;i++){
VehicleType vehicleType = VehicleTypeImpl.Builder.newInstance(depotCounter + "_type").addCapacityDimension(0, capacity).setCostPerDistance(1.0).build(); VehicleType vehicleType = VehicleTypeImpl.Builder.newInstance(depotCounter + "_type")
.addCapacityDimension(0, capacity).setFixedCost(100.).setCostPerDistance(1.0).build();
String vehicleId = depotCounter + "_" + (i+1) + "_vehicle"; String vehicleId = depotCounter + "_" + (i+1) + "_vehicle";
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance(vehicleId); VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance(vehicleId);
vehicleBuilder.setStartLocationCoordinate(depotCoord); vehicleBuilder.setStartLocationCoordinate(depotCoord);
@ -83,7 +84,7 @@ public class MultipleDepotExampleWithPenaltyVehicles {
/* /*
* define penalty-type with the same id, but other higher fixed and variable costs * define penalty-type with the same id, but other higher fixed and variable costs
*/ */
vrpBuilder.addPenaltyVehicles(3, 50); // vrpBuilder.addPenaltyVehicles(3, 50);
/* /*
* define problem with finite fleet * define problem with finite fleet
@ -104,7 +105,7 @@ public class MultipleDepotExampleWithPenaltyVehicles {
* solve the problem * solve the problem
*/ */
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml"); VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml");
vra.setNuOfIterations(5000); vra.setMaxIterations(2000);
vra.getAlgorithmListeners().addListener(new StopWatch(),Priority.HIGH); vra.getAlgorithmListeners().addListener(new StopWatch(),Priority.HIGH);
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();