mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'bad-job-list'
This commit is contained in:
commit
264dafd06a
31 changed files with 528 additions and 460 deletions
|
|
@ -30,8 +30,10 @@ import jsprit.core.problem.vehicle.PenaltyVehicleType;
|
||||||
* Printer to print the details of a vehicle-routing-problem solution.
|
* Printer to print the details of a vehicle-routing-problem solution.
|
||||||
*
|
*
|
||||||
* @author stefan schroeder
|
* @author stefan schroeder
|
||||||
|
* @deprecated use jsprit.core.reporting.SolutionPrinter instead
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class SolutionPrinter {
|
public class SolutionPrinter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -93,6 +95,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, "unassignedJobs", solution.getUnassignedJobs().size());
|
||||||
System.out.format("+----------------------------------------------------------+%n");
|
System.out.format("+----------------------------------------------------------+%n");
|
||||||
|
|
||||||
if(print.equals(Print.VERBOSE)){
|
if(print.equals(Print.VERBOSE)){
|
||||||
|
|
@ -130,6 +133,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.getUnassignedJobs()){
|
||||||
|
System.out.println(j.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getVehicleString(VehicleRoute route) {
|
private static String getVehicleString(VehicleRoute route) {
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 3.0 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
******************************************************************************/
|
|
||||||
package jsprit.core.algorithm;
|
|
||||||
|
|
||||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
|
||||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
|
||||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
|
||||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
|
||||||
import jsprit.core.util.*;
|
|
||||||
import org.apache.commons.math.stat.descriptive.moment.Mean;
|
|
||||||
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
|
|
||||||
class NeighborhoodThresholdInitialiser implements AlgorithmStartsListener{
|
|
||||||
|
|
||||||
private static Logger log = LogManager.getLogger(NeighborhoodThresholdInitialiser.class);
|
|
||||||
|
|
||||||
private NeighborhoodImpl neighborhood;
|
|
||||||
|
|
||||||
private VehicleRoutingAlgorithmFactory routingAlgorithmFactory = new VehicleRoutingAlgorithmFactory() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) {
|
|
||||||
VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "resources/config.xml");
|
|
||||||
return algorithm;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private int crowFlySpeed = 20;
|
|
||||||
|
|
||||||
public NeighborhoodThresholdInitialiser(NeighborhoodImpl neighborhood) {
|
|
||||||
this.neighborhood = neighborhood;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param crowFlySpeed the crowFlySpeed to set
|
|
||||||
*/
|
|
||||||
public void setCrowFlySpeed(int crowFlySpeed) {
|
|
||||||
this.crowFlySpeed = crowFlySpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param routingAlgorithmFactory the routingAlgorithm to set
|
|
||||||
*/
|
|
||||||
public void setRoutingAlgorithmFactory(VehicleRoutingAlgorithmFactory routingAlgorithmFactory) {
|
|
||||||
this.routingAlgorithmFactory = routingAlgorithmFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise(VehicleRoutingProblem problem){
|
|
||||||
informAlgorithmStarts(problem, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection<VehicleRoutingProblemSolution> solutions) {
|
|
||||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
|
||||||
builder.addAllJobs(problem.getJobs().values());
|
|
||||||
builder.addAllVehicles(problem.getVehicles());
|
|
||||||
CrowFlyCosts crowFly = new CrowFlyCosts(builder.getLocations());
|
|
||||||
crowFly.speed = crowFlySpeed;
|
|
||||||
builder.setRoutingCost(crowFly);
|
|
||||||
VehicleRoutingProblem pblm = builder.build();
|
|
||||||
|
|
||||||
VehicleRoutingAlgorithm algo = routingAlgorithmFactory.createAlgorithm(pblm);
|
|
||||||
Collection<VehicleRoutingProblemSolution> mySolutions = algo.searchSolutions();
|
|
||||||
|
|
||||||
double threshold = determineThreshold(pblm,builder.getLocations(), mySolutions);
|
|
||||||
neighborhood.setThreshold(threshold);
|
|
||||||
neighborhood.initialise();
|
|
||||||
}
|
|
||||||
|
|
||||||
private double determineThreshold(VehicleRoutingProblem pblm, Locations locations, Collection<VehicleRoutingProblemSolution> mySolutions) {
|
|
||||||
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(mySolutions);
|
|
||||||
double[] distances = new double[bestSolution.getRoutes().size()+pblm.getJobs().size()];
|
|
||||||
getDistances(distances,bestSolution,locations);
|
|
||||||
Mean mean = new Mean();
|
|
||||||
double meanValue = mean.evaluate(distances);
|
|
||||||
StandardDeviation dev = new StandardDeviation();
|
|
||||||
double devValue = dev.evaluate(distances, meanValue);
|
|
||||||
log.info("mean="+meanValue+", dev="+devValue);
|
|
||||||
return meanValue + devValue;
|
|
||||||
// + 2*devValue;
|
|
||||||
// return Double.MAX_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getDistances(double[] distances, VehicleRoutingProblemSolution bestSolution, Locations locations) {
|
|
||||||
int index = 0;
|
|
||||||
for(VehicleRoute route : bestSolution.getRoutes()){
|
|
||||||
TourActivity prev = null;
|
|
||||||
for(TourActivity act : route.getTourActivities().getActivities()){
|
|
||||||
if(prev == null){ prev = act; continue; }
|
|
||||||
double dist = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(prev.getLocationId()), locations.getCoord(act.getLocationId()));
|
|
||||||
// log.info("dist="+dist);
|
|
||||||
distances[index] = dist;
|
|
||||||
index++;
|
|
||||||
prev = act;
|
|
||||||
}
|
|
||||||
// double dist = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(prev.getLocationId()), locations.getCoord(route.getEnd().getLocationId()));
|
|
||||||
// distances[index] = dist;
|
|
||||||
// index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -117,7 +117,8 @@ 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){
|
||||||
VehicleRoutingProblemSolution solution = solutionSelector.selectSolution(solutions);
|
VehicleRoutingProblemSolution solution = solutionSelector.selectSolution(solutions);
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -43,16 +44,23 @@ public class VariablePlusFixedSolutionCostCalculatorFactory {
|
||||||
|
|
||||||
public SolutionCostCalculator createCalculator(){
|
public SolutionCostCalculator createCalculator(){
|
||||||
return new SolutionCostCalculator() {
|
return new SolutionCostCalculator() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||||
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.getUnassignedJobs().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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -620,25 +620,8 @@ 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) {
|
||||||
if(vrp.getFleetSize().equals(FleetSize.INFINITE)){
|
if(vrp.getFleetSize().equals(FleetSize.INFINITE)){
|
||||||
|
|
|
||||||
|
|
@ -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.getUnassignedJobs());
|
||||||
|
Collection<Job> unassignedJobs = insertion.insertJobs(vrpSolution.getRoutes(), ruinedJobSet);
|
||||||
|
vrpSolution.getUnassignedJobs().clear();
|
||||||
|
vrpSolution.getUnassignedJobs().addAll(unassignedJobs);
|
||||||
return vrpSolution;
|
return vrpSolution;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,9 +97,10 @@ 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> unassignedJobList = new ArrayList<Job>(unassignedJobs);
|
List<Job> badJobs = new ArrayList<Job>(unassignedJobs.size());
|
||||||
|
List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs);
|
||||||
Collections.shuffle(unassignedJobList, random);
|
Collections.shuffle(unassignedJobList, random);
|
||||||
for(Job unassignedJob : unassignedJobList){
|
for(Job unassignedJob : unassignedJobList){
|
||||||
Insertion bestInsertion = null;
|
Insertion bestInsertion = null;
|
||||||
|
|
@ -116,41 +115,20 @@ 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);
|
||||||
}
|
else inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
|
||||||
if(bestInsertion == null){
|
}
|
||||||
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) {
|
@Override
|
||||||
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
|
|
||||||
public void removeListener(InsertionListener insertionListener) {
|
public void removeListener(InsertionListener insertionListener) {
|
||||||
insertionsListeners.removeListener(insertionListener);
|
insertionsListeners.removeListener(insertionListener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,12 +85,8 @@ final class BestInsertionConcurrent implements InsertionStrategy{
|
||||||
|
|
||||||
private JobInsertionCostsCalculator bestInsertionCostCalculator;
|
private JobInsertionCostsCalculator bestInsertionCostCalculator;
|
||||||
|
|
||||||
private boolean minVehiclesFirst = false;
|
|
||||||
|
|
||||||
private int nuOfBatches;
|
private int nuOfBatches;
|
||||||
|
|
||||||
private ExecutorService executor;
|
|
||||||
|
|
||||||
private ExecutorCompletionService<Insertion> completionService;
|
private ExecutorCompletionService<Insertion> completionService;
|
||||||
|
|
||||||
public void setRandom(Random random) {
|
public void setRandom(Random random) {
|
||||||
|
|
@ -100,11 +96,10 @@ final class BestInsertionConcurrent implements InsertionStrategy{
|
||||||
public BestInsertionConcurrent(JobInsertionCostsCalculator jobInsertionCalculator, ExecutorService executorService, int nuOfBatches, VehicleRoutingProblem vehicleRoutingProblem) {
|
public BestInsertionConcurrent(JobInsertionCostsCalculator jobInsertionCalculator, ExecutorService executorService, int nuOfBatches, VehicleRoutingProblem vehicleRoutingProblem) {
|
||||||
super();
|
super();
|
||||||
this.insertionsListeners = new InsertionListeners();
|
this.insertionsListeners = new InsertionListeners();
|
||||||
this.executor = executorService;
|
|
||||||
this.nuOfBatches = nuOfBatches;
|
this.nuOfBatches = nuOfBatches;
|
||||||
inserter = new Inserter(insertionsListeners, vehicleRoutingProblem);
|
inserter = new Inserter(insertionsListeners, vehicleRoutingProblem);
|
||||||
bestInsertionCostCalculator = jobInsertionCalculator;
|
bestInsertionCostCalculator = jobInsertionCalculator;
|
||||||
completionService = new ExecutorCompletionService<Insertion>(executor);
|
completionService = new ExecutorCompletionService<Insertion>(executorService);
|
||||||
logger.info("initialise " + this);
|
logger.info("initialise " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,19 +109,16 @@ 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> badJobs = new ArrayList<Job>(unassignedJobs.size());
|
||||||
|
List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs);
|
||||||
Collections.shuffle(unassignedJobList, random);
|
Collections.shuffle(unassignedJobList, random);
|
||||||
|
List<Batch> batches = distributeRoutes(vehicleRoutes,nuOfBatches);
|
||||||
List<Batch> batches = distributeRoutes(vehicleRoutes,nuOfBatches);
|
for(final Job unassignedJob : unassignedJobList){
|
||||||
|
Insertion bestInsertion = null;
|
||||||
for(final Job unassignedJob : unassignedJobList){
|
|
||||||
|
|
||||||
Insertion bestInsertion = null;
|
|
||||||
double bestInsertionCost = Double.MAX_VALUE;
|
double bestInsertionCost = Double.MAX_VALUE;
|
||||||
|
for(final Batch batch : batches){
|
||||||
for(final Batch batch : batches){
|
|
||||||
completionService.submit(new Callable<Insertion>() {
|
completionService.submit(new Callable<Insertion>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -135,21 +127,18 @@ final class BestInsertionConcurrent implements InsertionStrategy{
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
try {
|
||||||
|
for (int i = 0; i < batches.size(); i++) {
|
||||||
try{
|
Future<Insertion> futureIData = completionService.take();
|
||||||
for(int i=0;i<batches.size();i++){
|
Insertion insertion = futureIData.get();
|
||||||
Future<Insertion> futureIData = completionService.take();
|
if (insertion == null) continue;
|
||||||
Insertion insertion = futureIData.get();
|
if (insertion.getInsertionData().getInsertionCost() < bestInsertionCost) {
|
||||||
if(insertion == null) continue;
|
bestInsertion = insertion;
|
||||||
if(insertion.getInsertionData().getInsertionCost() < bestInsertionCost){
|
bestInsertionCost = insertion.getInsertionData().getInsertionCost();
|
||||||
bestInsertion = insertion;
|
}
|
||||||
bestInsertionCost = insertion.getInsertionData().getInsertionCost();
|
}
|
||||||
}
|
} catch(InterruptedException e){
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(InterruptedException e){
|
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
catch (ExecutionException e) {
|
catch (ExecutionException e) {
|
||||||
|
|
@ -157,42 +146,18 @@ final class BestInsertionConcurrent implements InsertionStrategy{
|
||||||
logger.error(e.getCause().toString());
|
logger.error(e.getCause().toString());
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
||||||
if(!minVehiclesFirst){
|
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
||||||
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
if(newIData.getInsertionCost() < bestInsertionCost){
|
||||||
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
bestInsertion = new Insertion(newRoute,newIData);
|
||||||
if(newIData.getInsertionCost() < bestInsertionCost){
|
vehicleRoutes.add(newRoute);
|
||||||
bestInsertion = new Insertion(newRoute,newIData);
|
batches.get(random.nextInt(batches.size())).routes.add(newRoute);
|
||||||
bestInsertionCost = newIData.getInsertionCost();
|
}
|
||||||
vehicleRoutes.add(newRoute);
|
if(bestInsertion == null) badJobs.add(unassignedJob);
|
||||||
batches.get(random.nextInt(batches.size())).routes.add(newRoute);
|
else inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(bestInsertion == null){
|
|
||||||
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 IllegalStateException(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
|
||||||
|
|
|
||||||
|
|
@ -16,18 +16,17 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
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,14 +34,13 @@ 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 Collection<Job> insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs);
|
||||||
public void insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs);
|
|
||||||
|
public void addListener(InsertionListener insertionListener);
|
||||||
public void addListener(InsertionListener insertionListener);
|
|
||||||
|
|
||||||
public void removeListener(InsertionListener insertionListener);
|
public void removeListener(InsertionListener insertionListener);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -526,7 +526,9 @@ public class VehicleRoutingProblem {
|
||||||
*
|
*
|
||||||
* @param penaltyFactor penaltyFactor of penaltyVehicle
|
* @param penaltyFactor penaltyFactor of penaltyVehicle
|
||||||
* @return this builder
|
* @return this builder
|
||||||
|
* @deprecated since 1.3.2-SNAPSHOT bad job list replaces penalty vehicles
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder addPenaltyVehicles(double penaltyFactor){
|
public Builder addPenaltyVehicles(double penaltyFactor){
|
||||||
this.addPenaltyVehicles = true;
|
this.addPenaltyVehicles = true;
|
||||||
this.penaltyFactor = penaltyFactor;
|
this.penaltyFactor = penaltyFactor;
|
||||||
|
|
@ -543,7 +545,9 @@ public class VehicleRoutingProblem {
|
||||||
* @param penaltyFactor the penaltyFactor of penaltyVehicle
|
* @param penaltyFactor the penaltyFactor of penaltyVehicle
|
||||||
* @param penaltyFixedCosts which is an absolute penaltyValue (in contrary to penaltyFactor)
|
* @param penaltyFixedCosts which is an absolute penaltyValue (in contrary to penaltyFactor)
|
||||||
* @return this builder
|
* @return this builder
|
||||||
|
* @deprecated since 1.3.2-SNAPSHOT bad job list replaces penalty vehicles
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder addPenaltyVehicles(double penaltyFactor, double penaltyFixedCosts){
|
public Builder addPenaltyVehicles(double penaltyFactor, double penaltyFixedCosts){
|
||||||
this.addPenaltyVehicles = true;
|
this.addPenaltyVehicles = true;
|
||||||
this.penaltyFactor = penaltyFactor;
|
this.penaltyFactor = penaltyFactor;
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,7 @@ import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||||
import jsprit.core.problem.driver.Driver;
|
import jsprit.core.problem.driver.Driver;
|
||||||
import jsprit.core.problem.driver.DriverImpl;
|
import jsprit.core.problem.driver.DriverImpl;
|
||||||
import jsprit.core.problem.job.Delivery;
|
import jsprit.core.problem.job.*;
|
||||||
import jsprit.core.problem.job.Pickup;
|
|
||||||
import jsprit.core.problem.job.Service;
|
|
||||||
import jsprit.core.problem.job.Shipment;
|
|
||||||
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.activity.TimeWindow;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
|
|
@ -304,7 +301,16 @@ public class VrpXMLReader{
|
||||||
}
|
}
|
||||||
routes.add(routeBuilder.build());
|
routes.add(routeBuilder.build());
|
||||||
}
|
}
|
||||||
VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, cost);
|
VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, cost);
|
||||||
|
List<HierarchicalConfiguration> unassignedJobConfigs = solutionConfig.configurationsAt("unassignedJobs.job");
|
||||||
|
for(HierarchicalConfiguration unassignedJobConfig : unassignedJobConfigs){
|
||||||
|
String jobId = unassignedJobConfig.getString("[@id]");
|
||||||
|
Job job = getShipment(jobId);
|
||||||
|
if(job == null) job = getService(jobId);
|
||||||
|
if(job == null) throw new IllegalStateException("cannot find unassignedJob with id " + jobId);
|
||||||
|
solution.getUnassignedJobs().add(job);
|
||||||
|
}
|
||||||
|
|
||||||
solutions.add(solution);
|
solutions.add(solution);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,11 @@ public class VrpXMLWriter {
|
||||||
xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").end", route.getEnd().getArrTime());
|
xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").end", route.getEnd().getArrTime());
|
||||||
routeCounter++;
|
routeCounter++;
|
||||||
}
|
}
|
||||||
|
int unassignedJobCounter = 0;
|
||||||
|
for(Job unassignedJob : solution.getUnassignedJobs()){
|
||||||
|
xmlConfig.setProperty(solutionPath + "(" + counter + ").unassignedJobs.job(" + unassignedJobCounter + ")[@id]", unassignedJob.getId());
|
||||||
|
unassignedJobCounter++;
|
||||||
|
}
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -29,14 +30,12 @@ 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> unassignedJobs = 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();
|
||||||
|
unassignedJobs.addAll(solution.getUnassignedJobs());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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,21 @@ 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 unassignedJobs jobs that could not be assigned to any vehicle
|
||||||
|
* @param cost total costs of solution
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public VehicleRoutingProblemSolution(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs, double cost) {
|
||||||
|
super();
|
||||||
|
this.routes = routes;
|
||||||
|
this.unassignedJobs = unassignedJobs;
|
||||||
|
this.cost = cost;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a collection of vehicle-routes.
|
* Returns a collection of vehicle-routes.
|
||||||
*
|
*
|
||||||
|
|
@ -88,10 +105,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> getUnassignedJobs(){
|
||||||
|
return unassignedJobs;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,10 +77,10 @@ public class SolutionPrinter {
|
||||||
System.out.printf("| indicator | value |%n");
|
System.out.printf("| indicator | value |%n");
|
||||||
System.out.format("+---------------+----------+%n");
|
System.out.format("+---------------+----------+%n");
|
||||||
|
|
||||||
System.out.format(leftAlign, "nJobs", problem.getJobs().values().size());
|
System.out.format(leftAlign, "noJobs", problem.getJobs().values().size());
|
||||||
Jobs jobs = getNuOfJobs(problem);
|
Jobs jobs = getNuOfJobs(problem);
|
||||||
System.out.format(leftAlign, "nServices",jobs.nServices);
|
System.out.format(leftAlign, "noServices",jobs.nServices);
|
||||||
System.out.format(leftAlign, "nShipments",jobs.nShipments);
|
System.out.format(leftAlign, "noShipments",jobs.nShipments);
|
||||||
System.out.format(leftAlign, "fleetsize",problem.getFleetSize().toString());
|
System.out.format(leftAlign, "fleetsize",problem.getFleetSize().toString());
|
||||||
System.out.format("+--------------------------+%n");
|
System.out.format("+--------------------------+%n");
|
||||||
|
|
||||||
|
|
@ -92,7 +92,8 @@ public class SolutionPrinter {
|
||||||
System.out.printf("| indicator | value |%n");
|
System.out.printf("| indicator | value |%n");
|
||||||
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, "noVehicles",solution.getRoutes().size());
|
||||||
|
System.out.format(leftAlignSolution, "unassgndJobs", solution.getUnassignedJobs().size());
|
||||||
System.out.format("+----------------------------------------------------------+%n");
|
System.out.format("+----------------------------------------------------------+%n");
|
||||||
|
|
||||||
if(print.equals(Print.VERBOSE)){
|
if(print.equals(Print.VERBOSE)){
|
||||||
|
|
@ -130,6 +131,14 @@ public class SolutionPrinter {
|
||||||
}
|
}
|
||||||
System.out.format("+*:=PenaltyVehicle+%n");
|
System.out.format("+*:=PenaltyVehicle+%n");
|
||||||
System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n");
|
System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n");
|
||||||
|
System.out.format("+----------------+%n");
|
||||||
|
System.out.format("| unassignedJobs |%n");
|
||||||
|
System.out.format("+----------------+%n");
|
||||||
|
String unassignedJobAlgin = "| %-14s |%n";
|
||||||
|
for(Job j : solution.getUnassignedJobs()){
|
||||||
|
System.out.format(unassignedJobAlgin,j.getId());
|
||||||
|
}
|
||||||
|
System.out.format("+----------------+%n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getVehicleString(VehicleRoute route) {
|
private static String getVehicleString(VehicleRoute route) {
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,18 @@
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:sequence>
|
<xs:element name="unassignedJobs" minOccurs="0" maxOccurs="1">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="job" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="id" type="xs:string" use="required"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package jsprit.core.algorithm;
|
||||||
|
|
||||||
|
import jsprit.core.algorithm.box.GreedySchrimpfFactory;
|
||||||
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
|
import jsprit.core.problem.job.Service;
|
||||||
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
|
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||||
|
import jsprit.core.util.Coordinate;
|
||||||
|
import jsprit.core.util.Solutions;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class UnassignedJobListTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void job2ShouldBeInBadJobList_dueToTimeWindow(){
|
||||||
|
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
builder.addVehicle(VehicleImpl.Builder.newInstance("v1").setEarliestStart(0).setLatestArrival(12).setStartLocationCoordinate(Coordinate.newInstance(1, 1)).build());
|
||||||
|
Service job1 = Service.Builder.newInstance("job1").setCoord(Coordinate.newInstance(0, 0)).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build();
|
||||||
|
builder.addJob(job1);
|
||||||
|
Service job2 = Service.Builder.newInstance("job2").setCoord(Coordinate.newInstance(2, 2)).setTimeWindow(TimeWindow.newInstance(12, 24)).setServiceTime(1).build();
|
||||||
|
builder.addJob(job2);
|
||||||
|
|
||||||
|
VehicleRoutingProblem vrp = builder.build();
|
||||||
|
VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
|
||||||
|
algorithm.setMaxIterations(10);
|
||||||
|
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
|
||||||
|
|
||||||
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||||
|
assertTrue(!solution.getUnassignedJobs().contains(job1));
|
||||||
|
assertTrue(solution.getUnassignedJobs().contains(job2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void job2ShouldBeInBadJobList_dueToSize(){
|
||||||
|
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
builder.addVehicle(VehicleImpl.Builder.newInstance("v1").setEarliestStart(0).setLatestArrival(12).setStartLocationCoordinate(Coordinate.newInstance(1, 1)).build());
|
||||||
|
Service job1 = Service.Builder.newInstance("job1").setCoord(Coordinate.newInstance(0, 0)).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build();
|
||||||
|
builder.addJob(job1);
|
||||||
|
Service job2 = Service.Builder.newInstance("job2").setCoord(Coordinate.newInstance(2, 2)).addSizeDimension(0,10).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build();
|
||||||
|
builder.addJob(job2);
|
||||||
|
|
||||||
|
VehicleRoutingProblem vrp = builder.build();
|
||||||
|
VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
|
||||||
|
algorithm.setMaxIterations(10);
|
||||||
|
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
|
||||||
|
|
||||||
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||||
|
assertTrue(!solution.getUnassignedJobs().contains(job1));
|
||||||
|
assertTrue(solution.getUnassignedJobs().contains(job2));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -16,12 +16,6 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.algorithm.io;
|
package jsprit.core.algorithm.io;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import jsprit.core.algorithm.SearchStrategy;
|
import jsprit.core.algorithm.SearchStrategy;
|
||||||
import jsprit.core.algorithm.SearchStrategyModule;
|
import jsprit.core.algorithm.SearchStrategyModule;
|
||||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||||
|
|
@ -42,11 +36,16 @@ import jsprit.core.problem.io.VrpXMLReader;
|
||||||
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 jsprit.core.problem.solution.route.VehicleRoute;
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
|
|
||||||
import org.apache.commons.configuration.ConfigurationException;
|
import org.apache.commons.configuration.ConfigurationException;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
public class TestAlgorithmReader {
|
public class TestAlgorithmReader {
|
||||||
|
|
||||||
|
|
@ -242,5 +241,19 @@ public class TestAlgorithmReader {
|
||||||
}
|
}
|
||||||
assertEquals(3, nOfModules);
|
assertEquals(3, nOfModules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readerTest_whenReadingAlgoWithSchemaValidation_itReadsCorrectly(){
|
||||||
|
AlgorithmConfig algoConfig = new AlgorithmConfig();
|
||||||
|
new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig.xml");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readerTest_whenReadingAlgoWithSchemaValidationWithoutIterations_itReadsCorrectly(){
|
||||||
|
AlgorithmConfig algoConfig = new AlgorithmConfig();
|
||||||
|
new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig_withoutIterations.xml");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 3.0 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
******************************************************************************/
|
|
||||||
package jsprit.core.problem.io;
|
|
||||||
|
|
||||||
import jsprit.core.algorithm.io.AlgorithmConfig;
|
|
||||||
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class AlgorithmReaderTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void readerTest_whenReadingAlgoWithSchemaValidation_itReadsCorrectly(){
|
|
||||||
AlgorithmConfig algoConfig = new AlgorithmConfig();
|
|
||||||
new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig.xml");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void readerTest_whenReadingAlgoWithSchemaValidationWithoutIterations_itReadsCorrectly(){
|
|
||||||
AlgorithmConfig algoConfig = new AlgorithmConfig();
|
|
||||||
new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig_withoutIterations.xml");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 3.0 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
******************************************************************************/
|
|
||||||
package jsprit.core.problem.io;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
|
||||||
import jsprit.core.problem.VehicleRoutingProblem.Builder;
|
|
||||||
import jsprit.core.problem.io.VrpXMLReader;
|
|
||||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
|
||||||
import jsprit.core.problem.solution.route.activity.DeliverShipment;
|
|
||||||
import jsprit.core.problem.solution.route.activity.PickupService;
|
|
||||||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
|
|
||||||
public class ReaderTest {
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRead_ifReaderIsCalled_itReadsSuccessfully(){
|
|
||||||
new VrpXMLReader(VehicleRoutingProblem.Builder.newInstance(), new ArrayList<VehicleRoutingProblemSolution>()).read("src/test/resources/lui-shen-solution.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRead_ifReaderIsCalled_itReadsSuccessfullyV2(){
|
|
||||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
|
||||||
ArrayList<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
|
||||||
new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml");
|
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
|
||||||
assertEquals(3,vrp.getJobs().size());
|
|
||||||
assertEquals(1,solutions.size());
|
|
||||||
|
|
||||||
assertEquals(1,solutions.get(0).getRoutes().size());
|
|
||||||
List<TourActivity> activities = solutions.get(0).getRoutes().iterator().next().getTourActivities().getActivities();
|
|
||||||
assertEquals(4,activities.size());
|
|
||||||
assertTrue(activities.get(0) instanceof PickupService);
|
|
||||||
assertTrue(activities.get(1) instanceof PickupService);
|
|
||||||
assertTrue(activities.get(2) instanceof PickupShipment);
|
|
||||||
assertTrue(activities.get(3) instanceof DeliverShipment);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
* License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
* version 3.0 of the License, or (at your option) any later version.
|
* version 3.0 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
@ -21,7 +21,13 @@ import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||||
import jsprit.core.problem.job.Job;
|
import jsprit.core.problem.job.Job;
|
||||||
import jsprit.core.problem.job.Service;
|
import jsprit.core.problem.job.Service;
|
||||||
import jsprit.core.problem.job.Shipment;
|
import jsprit.core.problem.job.Shipment;
|
||||||
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
|
import jsprit.core.problem.solution.route.activity.DeliverShipment;
|
||||||
|
import jsprit.core.problem.solution.route.activity.PickupService;
|
||||||
|
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||||
|
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
import jsprit.core.problem.vehicle.Vehicle;
|
import jsprit.core.problem.vehicle.Vehicle;
|
||||||
|
import jsprit.core.util.Solutions;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
@ -570,5 +576,47 @@ public class VrpXMLReaderTest {
|
||||||
assertEquals(2,vrp.getInitialVehicleRoutes().iterator().next().getActivities().size());
|
assertEquals(2,vrp.getInitialVehicleRoutes().iterator().next().getActivities().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRead_ifReaderIsCalled_itReadsSuccessfullyV2(){
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
ArrayList<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml");
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
assertEquals(4,vrp.getJobs().size());
|
||||||
|
assertEquals(1,solutions.size());
|
||||||
|
|
||||||
|
assertEquals(1,solutions.get(0).getRoutes().size());
|
||||||
|
List<TourActivity> activities = solutions.get(0).getRoutes().iterator().next().getTourActivities().getActivities();
|
||||||
|
assertEquals(4,activities.size());
|
||||||
|
assertTrue(activities.get(0) instanceof PickupService);
|
||||||
|
assertTrue(activities.get(1) instanceof PickupService);
|
||||||
|
assertTrue(activities.get(2) instanceof PickupShipment);
|
||||||
|
assertTrue(activities.get(3) instanceof DeliverShipment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRead_ifReaderIsCalled_itReadsSuccessfully(){
|
||||||
|
new VrpXMLReader(VehicleRoutingProblem.Builder.newInstance(), new ArrayList<VehicleRoutingProblemSolution>()).read("src/test/resources/lui-shen-solution.xml");
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unassignedJobShouldBeRead(){
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
ArrayList<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml");
|
||||||
|
|
||||||
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||||
|
assertEquals(1,solution.getUnassignedJobs().size());
|
||||||
|
assertEquals("4",solution.getUnassignedJobs().iterator().next().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// public void solutionListShouldBeEmpty(){
|
||||||
|
// VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
// ArrayList<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
// new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpforReaderTest.xml");
|
||||||
|
// assertTrue(solutions.isEmpty());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,20 @@ import jsprit.core.problem.VehicleRoutingProblem.Builder;
|
||||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||||
import jsprit.core.problem.job.Service;
|
import jsprit.core.problem.job.Service;
|
||||||
import jsprit.core.problem.job.Shipment;
|
import jsprit.core.problem.job.Shipment;
|
||||||
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import jsprit.core.problem.vehicle.Vehicle;
|
import jsprit.core.problem.vehicle.Vehicle;
|
||||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
|
import jsprit.core.util.Solutions;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
|
@ -865,4 +870,68 @@ public class VrpXMLWriterTest {
|
||||||
assertEquals(2,newVrp.getInitialVehicleRoutes().iterator().next().getActivities().size());
|
assertEquals(2,newVrp.getInitialVehicleRoutes().iterator().next().getActivities().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void solutionWithoutUnassignedJobsShouldBeWrittenCorrectly(){
|
||||||
|
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
|
||||||
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build();
|
||||||
|
VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||||
|
builder.addVehicle(v1);
|
||||||
|
|
||||||
|
Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||||
|
Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||||
|
|
||||||
|
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||||
|
|
||||||
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v1).addService(s1).addService(s2).build();
|
||||||
|
List<VehicleRoute> routes = new ArrayList<VehicleRoute>();
|
||||||
|
routes.add(route);
|
||||||
|
VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes,10.);
|
||||||
|
List<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
solutions.add(solution);
|
||||||
|
|
||||||
|
new VrpXMLWriter(vrp, solutions).write(infileName);
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
List<VehicleRoutingProblemSolution> solutionsToRead = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
new VrpXMLReader(vrpToReadBuilder, solutionsToRead).read(infileName);
|
||||||
|
|
||||||
|
assertEquals(1, solutionsToRead.size());
|
||||||
|
assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(),0.01);
|
||||||
|
assertTrue(Solutions.bestOf(solutionsToRead).getUnassignedJobs().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void solutionWithUnassignedJobsShouldBeWrittenCorrectly(){
|
||||||
|
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
|
||||||
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build();
|
||||||
|
VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||||
|
builder.addVehicle(v1);
|
||||||
|
|
||||||
|
Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||||
|
Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||||
|
|
||||||
|
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||||
|
|
||||||
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v1).addService(s1).build();
|
||||||
|
List<VehicleRoute> routes = new ArrayList<VehicleRoute>();
|
||||||
|
routes.add(route);
|
||||||
|
VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes,10.);
|
||||||
|
solution.getUnassignedJobs().add(s2);
|
||||||
|
List<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
solutions.add(solution);
|
||||||
|
|
||||||
|
new VrpXMLWriter(vrp, solutions).write(infileName);
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
List<VehicleRoutingProblemSolution> solutionsToRead = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
new VrpXMLReader(vrpToReadBuilder, solutionsToRead).read(infileName);
|
||||||
|
|
||||||
|
assertEquals(1, solutionsToRead.size());
|
||||||
|
assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(),0.01);
|
||||||
|
assertEquals(1, Solutions.bestOf(solutionsToRead).getUnassignedJobs().size());
|
||||||
|
assertEquals("2", Solutions.bestOf(solutionsToRead).getUnassignedJobs().iterator().next().getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.getUnassignedJobs().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.getUnassignedJobs().addAll(badJobs);
|
||||||
|
assertEquals(1, sol.getUnassignedJobs().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.getUnassignedJobs().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.getUnassignedJobs().addAll(badJobs);
|
||||||
|
assertEquals(badJob, sol.getUnassignedJobs().iterator().next());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,19 @@
|
||||||
</timeWindow>
|
</timeWindow>
|
||||||
</timeWindows>
|
</timeWindows>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<service id="4" type="service">
|
||||||
|
<locationId>i(3,9)</locationId>
|
||||||
|
<coord x="10.0" y="10.0"/>
|
||||||
|
<capacity-demand>1</capacity-demand>
|
||||||
|
<duration>0.0</duration>
|
||||||
|
<timeWindows>
|
||||||
|
<timeWindow>
|
||||||
|
<start>0.0</start>
|
||||||
|
<end>4000.0</end>
|
||||||
|
</timeWindow>
|
||||||
|
</timeWindows>
|
||||||
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
<shipments>
|
<shipments>
|
||||||
|
|
@ -143,6 +156,9 @@
|
||||||
<end>100.0</end>
|
<end>100.0</end>
|
||||||
</route>
|
</route>
|
||||||
</routes>
|
</routes>
|
||||||
|
<unassignedJobs>
|
||||||
|
<job id="4"/>
|
||||||
|
</unassignedJobs>
|
||||||
</solution>
|
</solution>
|
||||||
</solutions>
|
</solutions>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,13 @@
|
||||||
</problemType>
|
</problemType>
|
||||||
<vehicles>
|
<vehicles>
|
||||||
<vehicle>
|
<vehicle>
|
||||||
<id>v</id>
|
<id>v1</id>
|
||||||
<typeId>type</typeId>
|
<typeId>vehType</typeId>
|
||||||
<startLocation>
|
<startLocation>
|
||||||
<id>startLoc</id>
|
<id>loc</id>
|
||||||
<coord x="1.0" y="2.0"/>
|
|
||||||
</startLocation>
|
</startLocation>
|
||||||
<endLocation>
|
<endLocation>
|
||||||
<id>endLoc</id>
|
<id>loc</id>
|
||||||
<coord x="4.0" y="5.0"/>
|
|
||||||
</endLocation>
|
</endLocation>
|
||||||
<timeSchedule>
|
<timeSchedule>
|
||||||
<start>0.0</start>
|
<start>0.0</start>
|
||||||
|
|
@ -25,19 +23,9 @@
|
||||||
</vehicles>
|
</vehicles>
|
||||||
<vehicleTypes>
|
<vehicleTypes>
|
||||||
<type>
|
<type>
|
||||||
<id>type</id>
|
<id>vehType</id>
|
||||||
<capacity-dimensions>
|
<capacity-dimensions>
|
||||||
<dimension index="0">100</dimension>
|
<dimension index="0">20</dimension>
|
||||||
<dimension index="1">1000</dimension>
|
|
||||||
<dimension index="2">0</dimension>
|
|
||||||
<dimension index="3">0</dimension>
|
|
||||||
<dimension index="4">0</dimension>
|
|
||||||
<dimension index="5">0</dimension>
|
|
||||||
<dimension index="6">0</dimension>
|
|
||||||
<dimension index="7">0</dimension>
|
|
||||||
<dimension index="8">0</dimension>
|
|
||||||
<dimension index="9">0</dimension>
|
|
||||||
<dimension index="10">10000</dimension>
|
|
||||||
</capacity-dimensions>
|
</capacity-dimensions>
|
||||||
<costs>
|
<costs>
|
||||||
<fixed>0.0</fixed>
|
<fixed>0.0</fixed>
|
||||||
|
|
@ -46,4 +34,53 @@
|
||||||
</costs>
|
</costs>
|
||||||
</type>
|
</type>
|
||||||
</vehicleTypes>
|
</vehicleTypes>
|
||||||
|
<services>
|
||||||
|
<service id="2" type="service">
|
||||||
|
<locationId>loc2</locationId>
|
||||||
|
<capacity-dimensions>
|
||||||
|
<dimension index="0">1</dimension>
|
||||||
|
</capacity-dimensions>
|
||||||
|
<duration>4.0</duration>
|
||||||
|
<timeWindows>
|
||||||
|
<timeWindow>
|
||||||
|
<start>0.0</start>
|
||||||
|
<end>1.7976931348623157E308</end>
|
||||||
|
</timeWindow>
|
||||||
|
</timeWindows>
|
||||||
|
</service>
|
||||||
|
<service id="1" type="service">
|
||||||
|
<locationId>loc</locationId>
|
||||||
|
<capacity-dimensions>
|
||||||
|
<dimension index="0">1</dimension>
|
||||||
|
</capacity-dimensions>
|
||||||
|
<duration>2.0</duration>
|
||||||
|
<timeWindows>
|
||||||
|
<timeWindow>
|
||||||
|
<start>0.0</start>
|
||||||
|
<end>1.7976931348623157E308</end>
|
||||||
|
</timeWindow>
|
||||||
|
</timeWindows>
|
||||||
|
</service>
|
||||||
|
</services>
|
||||||
|
<solutions>
|
||||||
|
<solution>
|
||||||
|
<cost>10.0</cost>
|
||||||
|
<routes>
|
||||||
|
<route>
|
||||||
|
<driverId>noDriver</driverId>
|
||||||
|
<vehicleId>v1</vehicleId>
|
||||||
|
<start>0.0</start>
|
||||||
|
<act type="service">
|
||||||
|
<serviceId>1</serviceId>
|
||||||
|
<arrTime>0.0</arrTime>
|
||||||
|
<endTime>0.0</endTime>
|
||||||
|
</act>
|
||||||
|
<end>0.0</end>
|
||||||
|
</route>
|
||||||
|
</routes>
|
||||||
|
<unassignedJobs>
|
||||||
|
<job id="2"/>
|
||||||
|
</unassignedJobs>
|
||||||
|
</solution>
|
||||||
|
</solutions>
|
||||||
</problem>
|
</problem>
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -269,13 +269,14 @@ public class BicycleMessenger {
|
||||||
|
|
||||||
//create your algorithm
|
//create your algorithm
|
||||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(bicycleMessengerProblem,"input/algorithmConfig_open.xml");
|
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(bicycleMessengerProblem,"input/algorithmConfig_open.xml");
|
||||||
|
// vraBuilder.setNuOfThreads(2);
|
||||||
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(5000);
|
||||||
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,7 +295,8 @@ 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.plotShipments(false);
|
plotter1.setLabel(Plotter.Label.ID);
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.examples;
|
package jsprit.examples;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener;
|
import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener;
|
||||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||||
import jsprit.analysis.toolbox.Plotter;
|
import jsprit.analysis.toolbox.Plotter;
|
||||||
|
|
@ -34,6 +32,8 @@ import jsprit.instance.reader.VrphGoldenReader;
|
||||||
import jsprit.instance.reader.VrphGoldenReader.VrphType;
|
import jsprit.instance.reader.VrphGoldenReader.VrphType;
|
||||||
import jsprit.util.Examples;
|
import jsprit.util.Examples;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows how to benchmark the algorithm on different classical HVRP and FSM instances.
|
* Shows how to benchmark the algorithm on different classical HVRP and FSM instances.
|
||||||
*
|
*
|
||||||
|
|
@ -57,7 +57,7 @@ public class HVRPBenchmarkExample {
|
||||||
//read modified Golden-instance, you can find all relevant instances in jsprit-instances/instances/vrph
|
//read modified Golden-instance, you can find all relevant instances in jsprit-instances/instances/vrph
|
||||||
//you can build various problems, see VrphType doc for more details
|
//you can build various problems, see VrphType doc for more details
|
||||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPFD).read("input/cn_14mix.txt");
|
new VrphGoldenReader(vrpBuilder, VrphType.HVRPFD).read("input/cn_14mix.txt");
|
||||||
vrpBuilder.addPenaltyVehicles(10.0);
|
// vrpBuilder.addPenaltyVehicles(10.0);
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
//try also input//jsprit-examples/input/algorithmConfig_considerFixedCosts_routeLevel.xml
|
//try also input//jsprit-examples/input/algorithmConfig_considerFixedCosts_routeLevel.xml
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.examples;
|
package jsprit.examples;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||||
import jsprit.analysis.toolbox.SolutionPrinter.Print;
|
import jsprit.analysis.toolbox.SolutionPrinter.Print;
|
||||||
|
|
@ -35,6 +33,8 @@ import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
import jsprit.core.util.Solutions;
|
import jsprit.core.util.Solutions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* customers (id,x,y,demand)
|
* customers (id,x,y,demand)
|
||||||
* 1 22 22 18
|
* 1 22 22 18
|
||||||
|
|
@ -113,7 +113,7 @@ public class HVRPExample {
|
||||||
vrpBuilder.addVehicle(vehicle3_1);
|
vrpBuilder.addVehicle(vehicle3_1);
|
||||||
|
|
||||||
//add penaltyVehicles to allow invalid solutions temporarily
|
//add penaltyVehicles to allow invalid solutions temporarily
|
||||||
vrpBuilder.addPenaltyVehicles(5, 1000);
|
// vrpBuilder.addPenaltyVehicles(5, 1000);
|
||||||
|
|
||||||
//set fleetsize finite
|
//set fleetsize finite
|
||||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.examples;
|
package jsprit.examples;
|
||||||
|
|
||||||
import jsprit.analysis.toolbox.*;
|
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||||
import jsprit.analysis.toolbox.SolutionPrinter.Print;
|
import jsprit.analysis.toolbox.Plotter;
|
||||||
|
import jsprit.analysis.toolbox.StopWatch;
|
||||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority;
|
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority;
|
||||||
|
|
@ -28,6 +29,7 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||||
import jsprit.core.problem.vehicle.VehicleType;
|
import jsprit.core.problem.vehicle.VehicleType;
|
||||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||||
|
import jsprit.core.reporting.SolutionPrinter;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
import jsprit.core.util.Solutions;
|
import jsprit.core.util.Solutions;
|
||||||
import jsprit.util.Examples;
|
import jsprit.util.Examples;
|
||||||
|
|
@ -59,7 +61,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 +70,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 +86,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,12 +107,12 @@ 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(1);
|
||||||
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();
|
||||||
|
|
||||||
SolutionPrinter.print(vrp,Solutions.bestOf(solutions),Print.VERBOSE);
|
SolutionPrinter.print(vrp, Solutions.bestOf(solutions), jsprit.core.reporting.SolutionPrinter.Print.VERBOSE);
|
||||||
|
|
||||||
new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p08_solution.png", "p08");
|
new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p08_solution.png", "p08");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue