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

migrated from log4j1x to log4j2

This commit is contained in:
oblonski 2014-07-25 09:57:40 +02:00
parent 64f0829e4a
commit 42570d69ac
47 changed files with 480 additions and 437 deletions

View file

@ -18,9 +18,6 @@
package jsprit.core.algorithm; package jsprit.core.algorithm;
import java.util.ArrayList;
import java.util.List;
import jsprit.core.algorithm.recreate.InsertionStrategy; import jsprit.core.algorithm.recreate.InsertionStrategy;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Job;
@ -28,15 +25,16 @@ import jsprit.core.problem.solution.InitialSolutionFactory;
import jsprit.core.problem.solution.SolutionCostCalculator; 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 org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.ArrayList;
import java.util.List;
public final class InsertionInitialSolutionFactory implements InitialSolutionFactory { public final class InsertionInitialSolutionFactory implements InitialSolutionFactory {
private static final Logger logger = Logger.getLogger(InsertionInitialSolutionFactory.class); private static final Logger logger = LogManager.getLogger(InsertionInitialSolutionFactory.class);
private final InsertionStrategy insertion; private final InsertionStrategy insertion;

View file

@ -16,28 +16,24 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import java.util.Collection;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.algorithm.listener.AlgorithmStartsListener; import jsprit.core.algorithm.listener.AlgorithmStartsListener;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
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.TourActivity; import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.util.CrowFlyCosts; import jsprit.core.util.*;
import jsprit.core.util.EuclideanDistanceCalculator;
import jsprit.core.util.Locations;
import jsprit.core.util.NeighborhoodImpl;
import jsprit.core.util.Solutions;
import org.apache.commons.math.stat.descriptive.moment.Mean; import org.apache.commons.math.stat.descriptive.moment.Mean;
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collection;
class NeighborhoodThresholdInitialiser implements AlgorithmStartsListener{ class NeighborhoodThresholdInitialiser implements AlgorithmStartsListener{
private static Logger log = Logger.getLogger(NeighborhoodThresholdInitialiser.class); private static Logger log = LogManager.getLogger(NeighborhoodThresholdInitialiser.class);
private NeighborhoodImpl neighborhood; private NeighborhoodImpl neighborhood;

View file

@ -16,22 +16,18 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import jsprit.core.algorithm.acceptor.SolutionAcceptor; import jsprit.core.algorithm.acceptor.SolutionAcceptor;
import jsprit.core.algorithm.listener.SearchStrategyModuleListener; import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
import jsprit.core.algorithm.selector.SolutionSelector; import jsprit.core.algorithm.selector.SolutionSelector;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.solution.SolutionCostCalculator; import jsprit.core.problem.solution.SolutionCostCalculator;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class SearchStrategy { public class SearchStrategy {
@ -62,7 +58,7 @@ public class SearchStrategy {
} }
private static Logger logger = Logger.getLogger(SearchStrategy.class); private static Logger logger = LogManager.getLogger(SearchStrategy.class);
private Collection<SearchStrategyModule> searchStrategyModules = new ArrayList<SearchStrategyModule>(); private Collection<SearchStrategyModule> searchStrategyModules = new ArrayList<SearchStrategyModule>();

View file

@ -16,23 +16,18 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import java.util.ArrayList;
import java.util.Collection;
import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution; import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
import jsprit.core.algorithm.listener.AlgorithmEndsListener; import jsprit.core.algorithm.listener.*;
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
import jsprit.core.algorithm.listener.IterationEndsListener;
import jsprit.core.algorithm.listener.IterationStartsListener;
import jsprit.core.algorithm.listener.SearchStrategyListener;
import jsprit.core.algorithm.listener.SearchStrategyModuleListener;
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListener;
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners;
import jsprit.core.algorithm.termination.PrematureAlgorithmTermination; import jsprit.core.algorithm.termination.PrematureAlgorithmTermination;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
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.activity.TourActivity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.ArrayList;
import java.util.Collection;
/** /**
@ -47,7 +42,7 @@ public class VehicleRoutingAlgorithm {
private final String name; private final String name;
private long counter = 0; private long counter = 0;
private long nextCounter = 1; private long nextCounter = 1;
private static final Logger log = Logger.getLogger(Counter.class); private static final Logger log = LogManager.getLogger(Counter.class);
public Counter(final String name) { public Counter(final String name) {
this.name = name; this.name = name;
@ -70,9 +65,7 @@ public class VehicleRoutingAlgorithm {
} }
} }
public static final int NOBREAK = Integer.MAX_VALUE; private static Logger logger = LogManager.getLogger(VehicleRoutingAlgorithm.class);
private static Logger logger = Logger.getLogger(VehicleRoutingAlgorithm.class);
private VehicleRoutingProblem problem; private VehicleRoutingProblem problem;
@ -112,16 +105,40 @@ public class VehicleRoutingAlgorithm {
/** /**
* Adds solution to the collection of initial solutions. * Adds solution to the collection of initial solutions.
* *
* @param solution * @param solution the solution to be added
*/ */
public void addInitialSolution(VehicleRoutingProblemSolution solution){ public void addInitialSolution(VehicleRoutingProblemSolution solution){
verify(solution);
initialSolutions.add(solution); initialSolutions.add(solution);
} }
private void verify(VehicleRoutingProblemSolution solution) {
int nuJobs = 0;
for(VehicleRoute route : solution.getRoutes()){
nuJobs += route.getTourActivities().getJobs().size();
if(route.getVehicle().getIndex() == 0)
throw new IllegalStateException("vehicle used in initial solution has no index. probably a vehicle is used that has not been added to the " +
" the VehicleRoutingProblem. only use vehicles that have already been added to the problem.");
for(TourActivity act : route.getActivities()) {
if (act.getIndex() == 0) {
throw new IllegalStateException("act in initial solution has no index. activities are created and associated to their job in VehicleRoutingProblem\n." +
" thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" +
" VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" +
" then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem");
}
}
}
if(nuJobs != problem.getJobs().values().size()){
logger.warn("number of jobs in initial solution (" + nuJobs + ") is not equal nuJobs in vehicle routing problem (" + problem.getJobs().values().size() + ")" +
"\n this might yield unintended effects, e.g. initial solution cannot be improved anymore.");
}
}
/** /**
* Sets premature termination. * Sets premature termination.
* *
* @param prematureAlgorithmTermination * @param prematureAlgorithmTermination the termination criterion
*/ */
public void setPrematureAlgorithmTermination(PrematureAlgorithmTermination prematureAlgorithmTermination){ public void setPrematureAlgorithmTermination(PrematureAlgorithmTermination prematureAlgorithmTermination){
this.prematureAlgorithmTermination = prematureAlgorithmTermination; this.prematureAlgorithmTermination = prematureAlgorithmTermination;

View file

@ -16,9 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.acceptor; package jsprit.core.algorithm.acceptor;
import java.net.URL;
import java.util.Collection;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.io.AlgorithmConfig; import jsprit.core.algorithm.io.AlgorithmConfig;
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader; import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
@ -30,16 +27,17 @@ import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.util.Resource; import jsprit.core.util.Resource;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.net.URL;
import java.util.Collection;
public class ExperimentalSchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener{ public class ExperimentalSchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener{
private static Logger logger = Logger.getLogger(ExperimentalSchrimpfAcceptance.class); final static Logger logger = LogManager.getLogger(ExperimentalSchrimpfAcceptance.class.getName());
private final double alpha; private final double alpha;

View file

@ -16,9 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.acceptor; package jsprit.core.algorithm.acceptor;
import java.net.URL;
import java.util.Collection;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.io.AlgorithmConfig; import jsprit.core.algorithm.io.AlgorithmConfig;
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader; import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
@ -30,9 +27,12 @@ import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.util.Resource; import jsprit.core.util.Resource;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.net.URL;
import java.util.Collection;
/** /**
@ -77,7 +77,7 @@ import org.apache.log4j.Logger;
*/ */
public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener{ public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener{
private static Logger logger = Logger.getLogger(SchrimpfAcceptance.class); private static Logger logger = LogManager.getLogger(SchrimpfAcceptance.class.getName());
private final double alpha; private final double alpha;

View file

@ -18,12 +18,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.acceptor; package jsprit.core.algorithm.acceptor;
import java.net.URL;
import java.util.Collection;
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.apache.log4j.Logger;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.io.AlgorithmConfig; import jsprit.core.algorithm.io.AlgorithmConfig;
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader; import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
@ -34,10 +28,16 @@ import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.util.Resource; import jsprit.core.util.Resource;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.net.URL;
import java.util.Collection;
public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListener { public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListener {
private static Logger logger = Logger.getLogger(SchrimpfInitialThresholdGenerator.class); private static Logger logger = LogManager.getLogger(SchrimpfInitialThresholdGenerator.class.getName());
private SchrimpfAcceptance schrimpfAcceptance; private SchrimpfAcceptance schrimpfAcceptance;

View file

@ -16,22 +16,22 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.io; package jsprit.core.algorithm.io;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import jsprit.core.util.Resource; import jsprit.core.util.Resource;
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class AlgorithmConfigXmlReader { public class AlgorithmConfigXmlReader {
private static Logger log = Logger.getLogger(AlgorithmConfigXmlReader.class); private static Logger log = LogManager.getLogger(AlgorithmConfigXmlReader.class.getName());
private AlgorithmConfig algorithmConfig; private AlgorithmConfig algorithmConfig;

View file

@ -16,10 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.io; package jsprit.core.algorithm.io;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener; import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
import jsprit.core.algorithm.recreate.BestInsertionBuilder; import jsprit.core.algorithm.recreate.BestInsertionBuilder;
import jsprit.core.algorithm.recreate.InsertionStrategy; import jsprit.core.algorithm.recreate.InsertionStrategy;
@ -28,14 +24,18 @@ import jsprit.core.algorithm.state.StateManager;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.constraint.ConstraintManager; import jsprit.core.problem.constraint.ConstraintManager;
import jsprit.core.problem.vehicle.VehicleFleetManager; import jsprit.core.problem.vehicle.VehicleFleetManager;
import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
class InsertionFactory { class InsertionFactory {
private static Logger log = Logger.getLogger(InsertionFactory.class); private static Logger log = LogManager.getLogger(InsertionFactory.class.getName());
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config, public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config,

View file

@ -58,7 +58,8 @@ import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleFleetManager; import jsprit.core.problem.vehicle.VehicleFleetManager;
import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration; import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.Thread.UncaughtExceptionHandler; import java.lang.Thread.UncaughtExceptionHandler;
import java.net.URL; import java.net.URL;
@ -354,7 +355,7 @@ public class VehicleRoutingAlgorithms {
} }
private static Logger log = Logger.getLogger(VehicleRoutingAlgorithms.class); private static Logger log = LogManager.getLogger(VehicleRoutingAlgorithms.class.getName());
private VehicleRoutingAlgorithms(){} private VehicleRoutingAlgorithms(){}

View file

@ -25,7 +25,8 @@ import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.util.RandomNumberGeneration; import jsprit.core.util.RandomNumberGeneration;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*; import java.util.*;
@ -62,7 +63,7 @@ final class BestInsertion implements InsertionStrategy{
} }
private static Logger logger = Logger.getLogger(BestInsertion.class); private static Logger logger = LogManager.getLogger(BestInsertion.class);
private Random random = RandomNumberGeneration.getRandom(); private Random random = RandomNumberGeneration.getRandom();

View file

@ -25,7 +25,8 @@ import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.util.RandomNumberGeneration; import jsprit.core.util.RandomNumberGeneration;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
@ -68,7 +69,7 @@ final class BestInsertionConcurrent implements InsertionStrategy{
} }
private static Logger logger = Logger.getLogger(BestInsertionConcurrent.class); private static Logger logger = LogManager.getLogger(BestInsertionConcurrent.class);
private Random random = RandomNumberGeneration.getRandom(); private Random random = RandomNumberGeneration.getRandom();

View file

@ -16,22 +16,21 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.recreate; package jsprit.core.algorithm.recreate;
import java.util.ArrayList;
import java.util.List;
import jsprit.core.problem.driver.Driver; import jsprit.core.problem.driver.Driver;
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 jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.ArrayList;
import java.util.List;
class CalculatesServiceInsertionWithTimeScheduling implements JobInsertionCostsCalculator{ class CalculatesServiceInsertionWithTimeScheduling implements JobInsertionCostsCalculator{
private static Logger log = Logger.getLogger(CalculatesServiceInsertionWithTimeScheduling.class); private static Logger log = LogManager.getLogger(CalculatesServiceInsertionWithTimeScheduling.class);
private JobInsertionCostsCalculator jic; private JobInsertionCostsCalculator jic;

View file

@ -27,11 +27,12 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
import jsprit.core.problem.solution.route.state.StateFactory; import jsprit.core.problem.solution.route.state.StateFactory;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCostsCalculator, SoftRouteConstraint{ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCostsCalculator, SoftRouteConstraint{
private static final Logger logger = Logger.getLogger(JobInsertionConsideringFixCostsCalculator.class); private static final Logger logger = LogManager.getLogger(JobInsertionConsideringFixCostsCalculator.class);
private final JobInsertionCostsCalculator standardServiceInsertion; private final JobInsertionCostsCalculator standardServiceInsertion;

View file

@ -30,7 +30,8 @@ import jsprit.core.problem.solution.route.activity.Start;
import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.util.CalculationUtils; import jsprit.core.util.CalculationUtils;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/** /**
* Calculator that calculates the best insertion position for a {@link Service}. * Calculator that calculates the best insertion position for a {@link Service}.
@ -40,7 +41,7 @@ import org.apache.log4j.Logger;
*/ */
final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{
private static final Logger logger = Logger.getLogger(ServiceInsertionCalculator.class); private static final Logger logger = LogManager.getLogger(ServiceInsertionCalculator.class);
private HardRouteStateLevelConstraint hardRouteLevelConstraint; private HardRouteStateLevelConstraint hardRouteLevelConstraint;

View file

@ -35,7 +35,8 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
import jsprit.core.problem.solution.route.state.StateFactory; import jsprit.core.problem.solution.route.state.StateFactory;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*; import java.util.*;
@ -44,7 +45,7 @@ import java.util.*;
final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsCalculator{ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsCalculator{
private static final Logger logger = Logger.getLogger(ServiceInsertionOnRouteLevelCalculator.class); private static final Logger logger = LogManager.getLogger(ServiceInsertionOnRouteLevelCalculator.class);
private final VehicleRoutingTransportCosts transportCosts; private final VehicleRoutingTransportCosts transportCosts;

View file

@ -31,7 +31,8 @@ import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
import jsprit.core.util.CalculationUtils; import jsprit.core.util.CalculationUtils;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List; import java.util.List;
@ -40,7 +41,7 @@ import java.util.List;
final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
private static final Logger logger = Logger.getLogger(ShipmentInsertionCalculator.class); private static final Logger logger = LogManager.getLogger(ShipmentInsertionCalculator.class);
private HardRouteStateLevelConstraint hardRouteLevelConstraint; private HardRouteStateLevelConstraint hardRouteLevelConstraint;

View file

@ -16,11 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.recreate; package jsprit.core.algorithm.recreate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound; import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.driver.Driver; import jsprit.core.problem.driver.Driver;
@ -29,13 +24,18 @@ import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleFleetManager; import jsprit.core.problem.vehicle.VehicleFleetManager;
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCostsCalculator{ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCostsCalculator{
private Logger logger = Logger.getLogger(VehicleTypeDependentJobInsertionCalculator.class); private Logger logger = LogManager.getLogger(VehicleTypeDependentJobInsertionCalculator.class);
private final VehicleFleetManager fleetManager; private final VehicleFleetManager fleetManager;

View file

@ -16,17 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.ruin; package jsprit.core.algorithm.ruin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeSet;
import jsprit.core.algorithm.ruin.distance.JobDistance; import jsprit.core.algorithm.ruin.distance.JobDistance;
import jsprit.core.algorithm.ruin.listener.RuinListener; import jsprit.core.algorithm.ruin.listener.RuinListener;
import jsprit.core.algorithm.ruin.listener.RuinListeners; import jsprit.core.algorithm.ruin.listener.RuinListeners;
@ -35,9 +24,10 @@ import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.util.RandomNumberGeneration; import jsprit.core.util.RandomNumberGeneration;
import jsprit.core.util.StopWatch; import jsprit.core.util.StopWatch;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.*;
/** /**
@ -59,7 +49,7 @@ final class RuinRadial implements RuinStrategy {
static class NeighborhoodIterator implements Iterator<Job>{ static class NeighborhoodIterator implements Iterator<Job>{
private static Logger log = Logger.getLogger(NeighborhoodIterator.class); private static Logger log = LogManager.getLogger(NeighborhoodIterator.class);
private Iterator<ReferencedJob> jobIter; private Iterator<ReferencedJob> jobIter;
@ -99,7 +89,7 @@ final class RuinRadial implements RuinStrategy {
static class JobNeighborhoodsImpl implements JobNeighborhoods { static class JobNeighborhoodsImpl implements JobNeighborhoods {
private static Logger logger = Logger.getLogger(JobNeighborhoodsImpl.class); private static Logger logger = LogManager.getLogger(JobNeighborhoodsImpl.class);
private VehicleRoutingProblem vrp; private VehicleRoutingProblem vrp;
@ -161,7 +151,7 @@ final class RuinRadial implements RuinStrategy {
static class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods { static class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods {
private static Logger logger = Logger.getLogger(JobNeighborhoodsImpl.class); private static Logger logger = LogManager.getLogger(JobNeighborhoodsImpl.class);
private VehicleRoutingProblem vrp; private VehicleRoutingProblem vrp;
@ -259,7 +249,7 @@ final class RuinRadial implements RuinStrategy {
} }
} }
private Logger logger = Logger.getLogger(RuinRadial.class); private Logger logger = LogManager.getLogger(RuinRadial.class);
private VehicleRoutingProblem vrp; private VehicleRoutingProblem vrp;

View file

@ -16,21 +16,16 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.ruin; package jsprit.core.algorithm.ruin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import jsprit.core.algorithm.ruin.listener.RuinListener; import jsprit.core.algorithm.ruin.listener.RuinListener;
import jsprit.core.algorithm.ruin.listener.RuinListeners; import jsprit.core.algorithm.ruin.listener.RuinListeners;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
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 jsprit.core.util.RandomNumberGeneration; import jsprit.core.util.RandomNumberGeneration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.*;
/** /**
@ -43,7 +38,7 @@ import org.apache.log4j.Logger;
final class RuinRandom implements RuinStrategy { final class RuinRandom implements RuinStrategy {
private Logger logger = Logger.getLogger(RuinRandom.class); private Logger logger = LogManager.getLogger(RuinRandom.class);
private VehicleRoutingProblem vrp; private VehicleRoutingProblem vrp;

View file

@ -181,7 +181,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
this.routingCosts = vehicleRoutingProblem.getTransportCosts(); this.routingCosts = vehicleRoutingProblem.getTransportCosts();
this.vrp = vehicleRoutingProblem; this.vrp = vehicleRoutingProblem;
nuActivities = Math.max(10, vrp.getNuActivities() + 1); nuActivities = Math.max(10, vrp.getNuActivities() + 1);
nuVehicleTypeKeys = Math.max(3,getNuVehicleTypes(vrp) + 1); nuVehicleTypeKeys = Math.max(3, getNuVehicleTypes(vrp) + 2);
activity_states = new Object[nuActivities][initialNuStates]; activity_states = new Object[nuActivities][initialNuStates];
route_states = new Object[nuActivities][initialNuStates]; route_states = new Object[nuActivities][initialNuStates];
vehicle_dependent_activity_states = new Object[nuActivities][nuVehicleTypeKeys][initialNuStates]; vehicle_dependent_activity_states = new Object[nuActivities][nuVehicleTypeKeys][initialNuStates];
@ -285,6 +285,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
*/ */
@Override @Override
public <T> T getActivityState(TourActivity act, StateId stateId, Class<T> type) { public <T> T getActivityState(TourActivity act, StateId stateId, Class<T> type) {
if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be.");
if(act.getIndex()<0) return null; if(act.getIndex()<0) return null;
T state; T state;
try{ try{
@ -305,6 +306,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
* @return true if a state value is associated otherwise false * @return true if a state value is associated otherwise false
*/ */
public boolean hasActivityState(TourActivity act, Vehicle vehicle, StateId stateId){ public boolean hasActivityState(TourActivity act, Vehicle vehicle, StateId stateId){
if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be.");
return vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null; return vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null;
} }
@ -322,6 +324,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
* @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value
*/ */
public <T> T getActivityState(TourActivity act, Vehicle vehicle, StateId stateId, Class<T> type) { public <T> T getActivityState(TourActivity act, Vehicle vehicle, StateId stateId, Class<T> type) {
if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be.");
if(act.getIndex()<0) return null; if(act.getIndex()<0) return null;
T state; T state;
try { try {
@ -367,11 +370,13 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
public <T> T getRouteState(VehicleRoute route, StateId stateId, Class<T> type) { public <T> T getRouteState(VehicleRoute route, StateId stateId, Class<T> type) {
if(route.isEmpty()) return null; if(route.isEmpty()) return null;
T state; T state;
int index_of_first_act = route.getActivities().get(0).getIndex();
if(index_of_first_act == 0) throw new IllegalStateException("first activity in route has no index. this should not be.");
try{ try{
state = type.cast(route_states[route.getActivities().get(0).getIndex()][stateId.getIndex()]); state = type.cast(route_states[index_of_first_act][stateId.getIndex()]);
} }
catch (ClassCastException e){ catch (ClassCastException e){
throw getClassCastException(e,stateId,type.toString(),route_states[route.getActivities().get(0).getIndex()][stateId.getIndex()].getClass().toString()); throw getClassCastException(e,stateId,type.toString(),route_states[index_of_first_act][stateId.getIndex()].getClass().toString());
} }
return state; return state;
} }
@ -401,12 +406,14 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
*/ */
public <T> T getRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, Class<T> type) { public <T> T getRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, Class<T> type) {
if(route.isEmpty()) return null; if(route.isEmpty()) return null;
int index_of_first_act = route.getActivities().get(0).getIndex();
if(index_of_first_act == 0) throw new IllegalStateException("first activity in route has no index. this should not be.");
T state; T state;
try{ try{
state = type.cast(vehicle_dependent_route_states[route.getActivities().get(0).getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); state = type.cast(vehicle_dependent_route_states[index_of_first_act][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]);
} }
catch( ClassCastException e){ catch( ClassCastException e){
throw getClassCastException(e, stateId, type.toString(), vehicle_dependent_route_states[route.getActivities().get(0).getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()].getClass().toString()); throw getClassCastException(e, stateId, type.toString(), vehicle_dependent_route_states[index_of_first_act][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()].getClass().toString());
} }
return state; return state;
} }
@ -445,6 +452,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
*/ */
@Deprecated @Deprecated
public <T> void putActivityState(TourActivity act, StateId stateId, Class<T> type, T state){ public <T> void putActivityState(TourActivity act, StateId stateId, Class<T> type, T state){
if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be.");
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" + if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" + "internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
" does not assign indeces thus do not use it anymore, but use\n " + " does not assign indeces thus do not use it anymore, but use\n " +
@ -464,6 +472,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
* @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally. * @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally.
*/ */
public <T> void putActivityState(TourActivity act, StateId stateId, T state){ public <T> void putActivityState(TourActivity act, StateId stateId, T state){
if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be.");
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" + if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" + "internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
" does not assign indeces thus do not use it anymore, but use\n " + " does not assign indeces thus do not use it anymore, but use\n " +
@ -484,6 +493,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
* @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally. * @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally.
*/ */
public <T> void putActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state){ public <T> void putActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state){
if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be.");
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" + if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" + "internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
" does not assign indeces thus do not use it anymore, but use\n " + " does not assign indeces thus do not use it anymore, but use\n " +
@ -539,6 +549,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
* @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally. * @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally.
*/ */
public <T> void putRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, T state){ public <T> void putRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, T state){
if(vehicle.getIndex() == 0) throw new IllegalStateException("vehicle index is 0. this should not be.");
if(stateId.getIndex()<10) StateFactory.throwReservedIdException(stateId.toString()); if(stateId.getIndex()<10) StateFactory.throwReservedIdException(stateId.toString());
putTypedInternalRouteState(route, vehicle, stateId, state); putTypedInternalRouteState(route, vehicle, stateId, state);
} }

View file

@ -17,13 +17,13 @@
package jsprit.core.algorithm.termination; package jsprit.core.algorithm.termination;
import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution; import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.Logger;
public class IterationWithoutImprovementTermination implements PrematureAlgorithmTermination{ public class IterationWithoutImprovementTermination implements PrematureAlgorithmTermination{
private static Logger log = Logger.getLogger(IterationWithoutImprovementTermination.class); private static Logger log = LogManager.getLogger(IterationWithoutImprovementTermination.class);
private int nuOfIterationWithoutImprovement; private int nuOfIterationWithoutImprovement;

View file

@ -16,15 +16,15 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.termination; package jsprit.core.algorithm.termination;
import java.util.Collection;
import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution; import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.listener.AlgorithmStartsListener; import jsprit.core.algorithm.listener.AlgorithmStartsListener;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.Collection;
/** /**
@ -38,7 +38,7 @@ import org.apache.log4j.Logger;
*/ */
public class TimeTermination implements PrematureAlgorithmTermination, AlgorithmStartsListener{ public class TimeTermination implements PrematureAlgorithmTermination, AlgorithmStartsListener{
private static Logger logger = Logger.getLogger(TimeTermination.class); private static Logger logger = LogManager.getLogger(TimeTermination.class);
private double timeThreshold; private double timeThreshold;

View file

@ -16,8 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.termination; package jsprit.core.algorithm.termination;
import java.util.Collection;
import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution; import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.listener.AlgorithmStartsListener; import jsprit.core.algorithm.listener.AlgorithmStartsListener;
@ -26,10 +24,12 @@ import jsprit.core.algorithm.listener.IterationStartsListener;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.apache.commons.math.stat.StatUtils; import org.apache.commons.math.stat.StatUtils;
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collection;
/** /**
@ -44,7 +44,7 @@ import org.apache.log4j.Logger;
*/ */
public class VariationCoefficientTermination implements PrematureAlgorithmTermination, IterationStartsListener, AlgorithmStartsListener, IterationEndsListener{ public class VariationCoefficientTermination implements PrematureAlgorithmTermination, IterationStartsListener, AlgorithmStartsListener, IterationEndsListener{
private static Logger logger = Logger.getLogger(VariationCoefficientTermination.class); private static Logger logger = LogManager.getLogger(VariationCoefficientTermination.class);
private int nuOfIterations; private int nuOfIterations;

View file

@ -30,7 +30,8 @@ import jsprit.core.problem.vehicle.*;
import jsprit.core.util.Coordinate; import jsprit.core.util.Coordinate;
import jsprit.core.util.CrowFlyCosts; import jsprit.core.util.CrowFlyCosts;
import jsprit.core.util.Locations; import jsprit.core.util.Locations;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*; import java.util.*;
@ -127,13 +128,13 @@ public class VehicleRoutingProblem {
private Double penaltyFixedCosts = null; private Double penaltyFixedCosts = null;
private int jobIndexCounter = 0; private int jobIndexCounter = 1;
private int vehicleIndexCounter = 0; private int vehicleIndexCounter = 1;
private int activityIndexCounter = 0; private int activityIndexCounter = 1;
private int vehicleTypeIdIndexCounter = 0; private int vehicleTypeIdIndexCounter = 1;
private Map<VehicleTypeKey,Integer> typeKeyIndices = new HashMap<VehicleTypeKey, Integer>(); private Map<VehicleTypeKey,Integer> typeKeyIndices = new HashMap<VehicleTypeKey, Integer>();
@ -162,12 +163,6 @@ public class VehicleRoutingProblem {
return id; return id;
} }
@SuppressWarnings("UnusedDeclaration")
public Builder setJobActivityFactory(JobActivityFactory factory){
this.jobActivityFactory = factory;
return this;
}
private void incJobIndexCounter(){ private void incJobIndexCounter(){
jobIndexCounter++; jobIndexCounter++;
} }
@ -586,7 +581,7 @@ public class VehicleRoutingProblem {
/** /**
* logger logging for this class * logger logging for this class
*/ */
private final static Logger logger = Logger.getLogger(VehicleRoutingProblem.class); private final static Logger logger = LogManager.getLogger(VehicleRoutingProblem.class);
/** /**
* contains transportation costs, i.e. the costs traveling from location A to B * contains transportation costs, i.e. the costs traveling from location A to B
@ -632,6 +627,15 @@ public class VehicleRoutingProblem {
private int nuActivities; private int nuActivities;
private final JobActivityFactory jobActivityFactory = new JobActivityFactory() {
@Override
public List<AbstractActivity> createActivities(Job job) {
return copyAndGetActivities(job);
}
};
private VehicleRoutingProblem(Builder builder) { private VehicleRoutingProblem(Builder builder) {
this.jobs = builder.jobs; this.jobs = builder.jobs;
this.fleetSize = builder.fleetSize; this.fleetSize = builder.fleetSize;
@ -737,6 +741,10 @@ public class VehicleRoutingProblem {
public int getNuActivities(){ return nuActivities; } public int getNuActivities(){ return nuActivities; }
public JobActivityFactory getJobActivityFactory(){
return jobActivityFactory;
};
public List<AbstractActivity> copyAndGetActivities(Job job){ public List<AbstractActivity> copyAndGetActivities(Job job){
List<AbstractActivity> acts = new ArrayList<AbstractActivity>(); List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
if(activityMap.containsKey(job)) { if(activityMap.containsKey(job)) {

View file

@ -22,7 +22,8 @@ import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.misc.JobInsertionContext; import jsprit.core.problem.misc.JobInsertionContext;
import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -41,7 +42,7 @@ public class ConstraintManager implements HardActivityStateLevelConstraint, Hard
CRITICAL, HIGH, LOW CRITICAL, HIGH, LOW
} }
private static Logger log = Logger.getLogger(ConstraintManager.class); private static Logger log = LogManager.getLogger(ConstraintManager.class);
private HardActivityLevelConstraintManager actLevelConstraintManager = new HardActivityLevelConstraintManager(); private HardActivityLevelConstraintManager actLevelConstraintManager = new HardActivityLevelConstraintManager();

View file

@ -16,16 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.problem.io; package jsprit.core.problem.io;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jsprit.core.problem.VehicleRoutingProblem; 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;
@ -38,23 +28,23 @@ 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;
import jsprit.core.problem.solution.route.activity.TourActivityFactory; import jsprit.core.problem.solution.route.activity.TourActivityFactory;
import jsprit.core.problem.vehicle.PenaltyVehicleType; import jsprit.core.problem.vehicle.*;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.problem.vehicle.VehicleImpl.Builder; import jsprit.core.problem.vehicle.VehicleImpl.Builder;
import jsprit.core.problem.vehicle.VehicleType;
import jsprit.core.problem.vehicle.VehicleTypeImpl;
import jsprit.core.util.Coordinate; import jsprit.core.util.Coordinate;
import jsprit.core.util.Resource; import jsprit.core.util.Resource;
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration; import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class VrpXMLReader{ public class VrpXMLReader{
public interface ServiceBuilderFactory { public interface ServiceBuilderFactory {
@ -120,7 +110,7 @@ public class VrpXMLReader{
} }
private static Logger logger = Logger.getLogger(VrpXMLReader.class); private static Logger logger = LogManager.getLogger(VrpXMLReader.class);
private VehicleRoutingProblem.Builder vrpBuilder; private VehicleRoutingProblem.Builder vrpBuilder;

View file

@ -16,13 +16,6 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.problem.io; package jsprit.core.problem.io;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Service;
@ -34,15 +27,22 @@ import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
import jsprit.core.problem.vehicle.PenaltyVehicleType; import jsprit.core.problem.vehicle.PenaltyVehicleType;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleType; import jsprit.core.problem.vehicle.VehicleType;
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration; import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer; import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class VrpXMLWriter { public class VrpXMLWriter {
@ -60,7 +60,7 @@ public class VrpXMLWriter {
} }
} }
private Logger log = Logger.getLogger(VrpXMLWriter.class); private Logger log = LogManager.getLogger(VrpXMLWriter.class);
private VehicleRoutingProblem vrp; private VehicleRoutingProblem vrp;
@ -76,7 +76,7 @@ public class VrpXMLWriter {
this.solutions = null; this.solutions = null;
} }
private static Logger logger = Logger.getLogger(VrpXMLWriter.class); private static Logger logger = LogManager.getLogger(VrpXMLWriter.class);
public void write(String filename){ public void write(String filename){
if(!filename.endsWith(".xml")) filename+=".xml"; if(!filename.endsWith(".xml")) filename+=".xml";

View file

@ -16,18 +16,17 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.problem.vehicle; package jsprit.core.problem.vehicle;
import java.util.ArrayList; import org.apache.logging.log4j.LogManager;
import java.util.Collection; import org.apache.logging.log4j.Logger;
import java.util.HashMap;
import java.util.List; import java.util.*;
import java.util.Map;
import org.apache.log4j.Logger;
class InfiniteVehicles implements VehicleFleetManager{ class InfiniteVehicles implements VehicleFleetManager{
private static Logger logger = Logger.getLogger(InfiniteVehicles.class); private static Logger logger = LogManager.getLogger(InfiniteVehicles.class);
private Map<VehicleTypeKey,Vehicle> types = new HashMap<VehicleTypeKey, Vehicle>(); private Map<VehicleTypeKey,Vehicle> types = new HashMap<VehicleTypeKey, Vehicle>();

View file

@ -16,18 +16,12 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.problem.vehicle; package jsprit.core.problem.vehicle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
import org.apache.log4j.Logger;
class VehicleFleetManagerImpl implements VehicleFleetManager { class VehicleFleetManagerImpl implements VehicleFleetManager {
@ -79,7 +73,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
} }
private static Logger logger = Logger.getLogger(VehicleFleetManagerImpl.class); private static Logger logger = LogManager.getLogger(VehicleFleetManagerImpl.class);
private Collection<Vehicle> vehicles; private Collection<Vehicle> vehicles;

View file

@ -18,7 +18,9 @@ package jsprit.core.problem.vehicle;
import jsprit.core.problem.AbstractVehicle; import jsprit.core.problem.AbstractVehicle;
import jsprit.core.util.Coordinate; import jsprit.core.util.Coordinate;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/** /**
@ -56,7 +58,7 @@ public class VehicleImpl extends AbstractVehicle{
* *
*/ */
public static class Builder { public static class Builder {
static Logger log = Logger.getLogger(Builder.class); static Logger log = LogManager.getLogger(Builder.class.getName());
private String id; private String id;
private String locationId; private String locationId;

View file

@ -16,23 +16,17 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.util; package jsprit.core.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Service;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.*;
public class NeighborhoodImpl implements Neighborhood{ public class NeighborhoodImpl implements Neighborhood{
private static Logger log = Logger.getLogger(NeighborhoodImpl.class); private static Logger log = LogManager.getLogger(NeighborhoodImpl.class);
private Set<String> neighborsToAll; private Set<String> neighborsToAll;

View file

@ -16,6 +16,9 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.util; package jsprit.core.util;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -23,7 +26,6 @@ import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import org.apache.log4j.Logger;
/** /**
* *
@ -32,7 +34,7 @@ import org.apache.log4j.Logger;
*/ */
public class Resource { public class Resource {
private static Logger log = Logger.getLogger(Resource.class); private static Logger log = LogManager.getLogger(Resource.class);
public final static URL getAsURL(final String filename) { public final static URL getAsURL(final String filename) {
URL url = Resource.class.getClassLoader().getResource(filename); URL url = Resource.class.getClassLoader().getResource(filename);

View file

@ -16,20 +16,20 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.util; package jsprit.core.util;
import java.util.HashMap;
import java.util.Map;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts; import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
import jsprit.core.problem.driver.Driver; import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams; import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.log4j.Logger; import java.util.HashMap;
import java.util.Map;
/** /**
* CostMatrix that allows pre-compiled time and distance-matrices to be considered as {@link VehicleRoutingRoutingCosts} * CostMatrix that allows pre-compiled time and distance-matrices to be considered as {@link VehicleRoutingTransportCosts}
* in the {@link VehicleRoutingProblem}. * in the {@link VehicleRoutingProblem}.
* <p>Note that you can also use it with distance matrix only (or time matrix). But ones * <p>Note that you can also use it with distance matrix only (or time matrix). But ones
* you set a particular distance, this expects distance-entries for all relations. This counts also * you set a particular distance, this expects distance-entries for all relations. This counts also
@ -101,7 +101,7 @@ public class VehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRo
* *
*/ */
public static class Builder { public static class Builder {
private static Logger log = Logger.getLogger(Builder.class); private static Logger log = LogManager.getLogger(Builder.class);
private boolean isSymmetric; private boolean isSymmetric;

View file

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %5p %C{1}:%L %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="trace" />
<param name="LevelMax" value="info" />
</filter>
</appender>
<root>
<priority value="debug"></priority>
<appender-ref ref="stdout"/>
</root>
</log4j:configuration>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View file

@ -37,7 +37,8 @@ import jsprit.core.problem.solution.route.state.StateFactory;
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory; import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
import jsprit.core.problem.vehicle.VehicleFleetManager; import jsprit.core.problem.vehicle.VehicleFleetManager;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -50,7 +51,7 @@ public class BuildPDVRPAlgoFromScratch_IT {
VehicleRoutingAlgorithm vra; VehicleRoutingAlgorithm vra;
static Logger log = Logger.getLogger(BuildPDVRPAlgoFromScratch_IT.class); static Logger log = LogManager.getLogger(BuildPDVRPAlgoFromScratch_IT.class);
@Before @Before
public void setup(){ public void setup(){

View file

@ -0,0 +1,49 @@
package jsprit.core.algorithm;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.reporting.SolutionPrinter;
import jsprit.core.util.Coordinate;
import jsprit.core.util.Solutions;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
/**
* Created by schroeder on 24.07.14.
*/
public class ExternalInitialSolutionIsInValidTest {
@Test
public void itShouldSolveProblemWithIniSolutionExternallyCreated(){
Service s1 = Service.Builder.newInstance("s1").setCoord(Coordinate.newInstance(10,0)).build();
Service s2 = Service.Builder.newInstance("s2").setCoord(Coordinate.newInstance(0,10)).build();
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v1").setStartLocationCoordinate(Coordinate.newInstance(0,0)).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(vehicle).build();
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithm_without_construction.xml");
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v1").setStartLocationCoordinate(Coordinate.newInstance(0,0)).build();
/*
create ini sol
*/
VehicleRoute route1 = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(s1).build();
vra.addInitialSolution(new VehicleRoutingProblemSolution(Arrays.asList(route1),20.));
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
SolutionPrinter.print(vrp, Solutions.bestOf(solutions), SolutionPrinter.Print.VERBOSE);
}
}

View file

@ -36,8 +36,6 @@ import jsprit.core.problem.job.Pickup;
import jsprit.core.problem.job.Shipment; import jsprit.core.problem.job.Shipment;
import jsprit.core.problem.misc.JobInsertionContext; import jsprit.core.problem.misc.JobInsertionContext;
import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.DeliverService;
import jsprit.core.problem.solution.route.activity.PickupService;
import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
@ -48,13 +46,11 @@ import jsprit.core.util.CostFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ServiceInsertionAndLoadConstraintsTest { public class ServiceInsertionAndLoadConstraintsTest {
@ -117,41 +113,28 @@ public class ServiceInsertionAndLoadConstraintsTest {
Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 15).setLocationId("0,10").build(); Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 15).setLocationId("0,10").build();
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 50).setCostPerDistance(1).build(); VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 50).setCostPerDistance(1).build();
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(delivery).addJob(pickup).addVehicle(vehicle).build();
VehicleRoute route = VehicleRoute.emptyRoute(); VehicleRoute route = VehicleRoute.emptyRoute();
route.setVehicleAndDepartureTime(vehicle, 0.0); route.setVehicleAndDepartureTime(vehicle, 0.0);
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem); Inserter inserter = new Inserter(new InsertionListeners(), vrp);
{
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
acts.add(new DeliverService(delivery));
when(vehicleRoutingProblem.copyAndGetActivities(delivery)).thenReturn(acts);
}
{
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
acts.add(new PickupService(pickup));
when(vehicleRoutingProblem.copyAndGetActivities(pickup)).thenReturn(acts);
}
inserter.insertJob(delivery, new InsertionData(0,0,0,vehicle,null), route); inserter.insertJob(delivery, new InsertionData(0,0,0,vehicle,null), route);
JobActivityFactory activityFactory = new JobActivityFactory() { JobActivityFactory activityFactory = new JobActivityFactory() {
@Override @Override
public List<AbstractActivity> createActivities(Job job) { public List<AbstractActivity> createActivities(Job job) {
return vehicleRoutingProblem.copyAndGetActivities(job); return vrp.copyAndGetActivities(job);
} }
}; };
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
StateManager stateManager = new StateManager(vrp); StateManager stateManager = new StateManager(vrp);
stateManager.updateLoadStates(); stateManager.updateLoadStates();
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
constraintManager.addLoadConstraint(); constraintManager.addLoadConstraint();
// constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL);
// constraintManager.addConstraint(new ShipmentPickupsFirstConstraint(),Priority.CRITICAL);
stateManager.informInsertionStarts(Arrays.asList(route), null); stateManager.informInsertionStarts(Arrays.asList(route), null);
JobCalculatorSwitcher switcher = new JobCalculatorSwitcher(); JobCalculatorSwitcher switcher = new JobCalculatorSwitcher();
@ -164,9 +147,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
switcher.put(Delivery.class, serviceInsertionCalc); switcher.put(Delivery.class, serviceInsertionCalc);
switcher.put(Shipment.class, insertionCalculator); switcher.put(Shipment.class, insertionCalculator);
// Pickup service = (Pickup)Pickup.Builder.newInstance("pick", 1).setLocationId("5,5").build();
InsertionData iData = switcher.getInsertionData(route, pickup, vehicle, 0, DriverImpl.noDriver(), Double.MAX_VALUE); InsertionData iData = switcher.getInsertionData(route, pickup, vehicle, 0, DriverImpl.noDriver(), Double.MAX_VALUE);
// routeActVisitor.visit(route);
assertEquals(1, iData.getDeliveryInsertionIndex()); assertEquals(1, iData.getDeliveryInsertionIndex());
} }

View file

@ -249,7 +249,6 @@ public class ShipmentInsertionCalculatorTest {
route.setVehicleAndDepartureTime(vehicle, 0.0); route.setVehicleAndDepartureTime(vehicle, 0.0);
Inserter inserter = new Inserter(new InsertionListeners(), vrp); Inserter inserter = new Inserter(new InsertionListeners(), vrp);
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route); inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
@ -263,13 +262,7 @@ public class ShipmentInsertionCalculatorTest {
ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator,
constraintManager); constraintManager);
insertionCalculator.setJobActivityFactory(vrp.getJobActivityFactory());
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
activities.add(new PickupShipment(shipment3));
activities.add(new DeliverShipment(shipment3));
when(activityFactory.createActivities(shipment3)).thenReturn(activities);
insertionCalculator.setJobActivityFactory(activityFactory);
InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, DriverImpl.noDriver(), Double.MAX_VALUE); InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, DriverImpl.noDriver(), Double.MAX_VALUE);
assertTrue(iData instanceof InsertionData.NoInsertionFound); assertTrue(iData instanceof InsertionData.NoInsertionFound);

View file

@ -40,8 +40,6 @@ import jsprit.core.util.Coordinate;
import jsprit.core.util.EuclideanDistanceCalculator; import jsprit.core.util.EuclideanDistanceCalculator;
import jsprit.core.util.Locations; import jsprit.core.util.Locations;
import jsprit.core.util.ManhattanDistanceCalculator; import jsprit.core.util.ManhattanDistanceCalculator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -73,11 +71,10 @@ public class TestCalculatesServiceInsertion {
private NoDriver driver; private NoDriver driver;
// private UpdateStates stateUpdater; private VehicleRoutingProblem vrp;
@Before @Before
public void setup(){ public void setup(){
Logger.getRootLogger().setLevel(Level.DEBUG);
VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build(); VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build();
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t1).build(); vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t1).build();
@ -121,7 +118,7 @@ public class TestCalculatesServiceInsertion {
jobs.add(third); jobs.add(third);
jobs.add(second); jobs.add(second);
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).setRoutingCost(costs).build(); vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).setRoutingCost(costs).build();
states = new StateManager(vrp); states = new StateManager(vrp);
states.updateLoadStates(); states.updateLoadStates();
@ -154,7 +151,7 @@ public class TestCalculatesServiceInsertion {
@Test @Test
public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){ public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
@ -164,7 +161,7 @@ public class TestCalculatesServiceInsertion {
@Test @Test
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){ public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);
InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
@ -174,7 +171,7 @@ public class TestCalculatesServiceInsertion {
@Test @Test
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){ public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);
InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE); InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
@ -184,7 +181,7 @@ public class TestCalculatesServiceInsertion {
@Test @Test
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){ public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
@ -195,7 +192,7 @@ public class TestCalculatesServiceInsertion {
@Test @Test
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){ public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);

View file

@ -29,15 +29,11 @@ import jsprit.core.problem.driver.DriverImpl.NoDriver;
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.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.ServiceActivity;
import jsprit.core.problem.solution.route.activity.TimeWindow; import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.solution.route.activity.TourActivities;
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.VehicleType; import jsprit.core.problem.vehicle.VehicleType;
import jsprit.core.util.CostFactory; import jsprit.core.util.CostFactory;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -73,9 +69,11 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
private NoDriver driver; private NoDriver driver;
private VehicleRoutingProblem vrp;
@Before @Before
public void setup(){ public void setup(){
Logger.getRootLogger().setLevel(Level.DEBUG);
costs = mock(VehicleRoutingTransportCosts.class); costs = mock(VehicleRoutingTransportCosts.class);
vehicle = mock(AbstractVehicle.class); vehicle = mock(AbstractVehicle.class);
@ -113,7 +111,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
jobs.add(second); jobs.add(second);
jobs.add(third); jobs.add(third);
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).addVehicle(newVehicle).setRoutingCost(costs).build(); vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).addVehicle(newVehicle).setRoutingCost(costs).build();
states = new StateManager(vrp); states = new StateManager(vrp);
states.updateLoadStates(); states.updateLoadStates();
@ -152,11 +150,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
@Test @Test
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){ public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
tour.addActivity(ServiceActivity.newInstance(first));
tour.addActivity(ServiceActivity.newInstance(second));
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
@ -166,11 +160,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
@Test @Test
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){ public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){
TourActivities tour = new TourActivities(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
tour.addActivity(ServiceActivity.newInstance(first));
tour.addActivity(ServiceActivity.newInstance(second));
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);
InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
@ -180,11 +170,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
@Test @Test
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){ public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){
TourActivities tour = new TourActivities(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
tour.addActivity(ServiceActivity.newInstance(first));
tour.addActivity(ServiceActivity.newInstance(third));
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);
InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
@ -194,11 +180,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
@Test @Test
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){ public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
TourActivities tour = new TourActivities(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
tour.addActivity(ServiceActivity.newInstance(first));
tour.addActivity(ServiceActivity.newInstance(third));
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
states.informInsertionStarts(Arrays.asList(route), null); states.informInsertionStarts(Arrays.asList(route), null);
InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);

View file

@ -30,13 +30,13 @@ import jsprit.core.problem.solution.route.activity.PickupService;
import jsprit.core.problem.solution.route.activity.PickupShipment; import jsprit.core.problem.solution.route.activity.PickupShipment;
import jsprit.core.problem.solution.route.state.StateFactory; import jsprit.core.problem.solution.route.state.StateFactory;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
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 org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class HardPickupAndDeliveryShipmentActivityConstraintTest { public class HardPickupAndDeliveryShipmentActivityConstraintTest {
@ -47,22 +47,30 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
Shipment shipment; Shipment shipment;
Service s1;
Service s2;
PickupAndDeliverShipmentLoadActivityLevelConstraint constraint; PickupAndDeliverShipmentLoadActivityLevelConstraint constraint;
JobInsertionContext iFacts; JobInsertionContext iFacts;
VehicleRoutingProblem vrp;
@Before @Before
public void doBefore(){ public void doBefore(){
vehicle = mock(Vehicle.class); s1 = Service.Builder.newInstance("s1").setLocationId("loc").build();
s2 = Service.Builder.newInstance("s2").setLocationId("loc").build();
shipment = Shipment.Builder.newInstance("shipment").setPickupLocation("pickLoc").setDeliveryLocation("delLoc").addSizeDimension(0,1).build();
// when(vehicle.getCapacity()).thenReturn(2); // when(vehicle.getCapacity()).thenReturn(2);
VehicleType type = mock(VehicleType.class); VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,2).build();
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocationId("start").build();
when(vehicle.getType()).thenReturn(type);
// when(vehicle.getType().getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addJob(shipment).addVehicle(vehicle).build();
stateManager = new StateManager(mock(VehicleRoutingProblem.class));
shipment = mock(Shipment.class); stateManager = new StateManager(vrp);
when(shipment.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
// when(shipment.getCapacityDemand()).thenReturn(1);
iFacts = new JobInsertionContext(null, null, vehicle, null, 0.0); iFacts = new JobInsertionContext(null, null, vehicle, null, 0.0);
constraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); constraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager);
@ -70,43 +78,34 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
@Test @Test
public void whenPickupActivityIsInsertedAndLoadIsSufficient_returnFullFilled(){ public void whenPickupActivityIsInsertedAndLoadIsSufficient_returnFullFilled(){
PickupService pickupService = new PickupService(mock(Service.class)); PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0);
PickupService anotherService = new PickupService(mock(Service.class)); PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0);
PickupShipment pickupShipment = new PickupShipment(shipment); PickupShipment pickupShipment = (PickupShipment) vrp.getActivities(shipment).get(0);
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0)); assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
} }
@Test @Test
public void whenPickupActivityIsInsertedAndLoadIsNotSufficient_returnNOT_FullFilled(){ public void whenPickupActivityIsInsertedAndLoadIsNotSufficient_returnNOT_FullFilled(){
PickupService pickupService = new PickupService(mock(Service.class)); PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0);
PickupService anotherService = new PickupService(mock(Service.class)); PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0);
PickupShipment pickupShipment = new PickupShipment(shipment); PickupShipment pickupShipment = (PickupShipment) vrp.getActivities(shipment).get(0);
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build()); stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
// when(stateManager.getActivityState(pickupService, StateFactory.LOAD)).thenReturn(StateFactory.createState(2.0)); // when(stateManager.getActivityState(pickupService, StateFactory.LOAD)).thenReturn(StateFactory.createState(2.0));
assertEquals(ConstraintsStatus.NOT_FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0)); assertEquals(ConstraintsStatus.NOT_FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
} }
@Test
public void whenDeliveryActivityIsInsertedAndLoadIsNotSufficient_returnNOT_FullFilled_BREAK(){
PickupService pickupService = new PickupService(mock(Service.class));
PickupService anotherService = new PickupService(mock(Service.class));
DeliverShipment pickupShipment = new DeliverShipment(shipment);
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
}
@Test @Test
public void whenDeliveryActivityIsInsertedAndLoadIsSufficient_returnFullFilled(){ public void whenDeliveryActivityIsInsertedAndLoadIsSufficient_returnFullFilled(){
PickupService pickupService = new PickupService(mock(Service.class)); PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0);
PickupService anotherService = new PickupService(mock(Service.class)); PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0);
DeliverShipment pickupShipment = new DeliverShipment(shipment);
DeliverShipment deliverShipment = (DeliverShipment) vrp.getActivities(shipment).get(1);
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 1).build()); stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 1).build());
// stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1)); // stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1));
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0)); assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, deliverShipment, anotherService, 0.0));
} }

View file

@ -549,8 +549,8 @@ public class VehicleRoutingProblemTest {
vrpBuilder.addJob(shipment); vrpBuilder.addJob(shipment);
vrpBuilder.build(); vrpBuilder.build();
assertEquals(0,service.getIndex()); assertEquals(1,service.getIndex());
assertEquals(1,shipment.getIndex()); assertEquals(2,shipment.getIndex());
} }
@ -564,8 +564,8 @@ public class VehicleRoutingProblemTest {
vrpBuilder.addVehicle(veh2); vrpBuilder.addVehicle(veh2);
vrpBuilder.build(); vrpBuilder.build();
assertEquals(0,veh1.getIndex()); assertEquals(1,veh1.getIndex());
assertEquals(1,veh2.getIndex()); assertEquals(2,veh2.getIndex());
} }
@ -579,8 +579,8 @@ public class VehicleRoutingProblemTest {
vrpBuilder.addVehicle(veh2); vrpBuilder.addVehicle(veh2);
vrpBuilder.build(); vrpBuilder.build();
assertEquals(0, veh1.getVehicleTypeIdentifier().getIndex()); assertEquals(1, veh1.getVehicleTypeIdentifier().getIndex());
assertEquals(0, veh2.getVehicleTypeIdentifier().getIndex()); assertEquals(1, veh2.getVehicleTypeIdentifier().getIndex());
} }
@ -594,8 +594,8 @@ public class VehicleRoutingProblemTest {
vrpBuilder.addVehicle(veh2); vrpBuilder.addVehicle(veh2);
vrpBuilder.build(); vrpBuilder.build();
assertEquals(0,veh1.getVehicleTypeIdentifier().getIndex()); assertEquals(1,veh1.getVehicleTypeIdentifier().getIndex());
assertEquals(1,veh2.getVehicleTypeIdentifier().getIndex()); assertEquals(2,veh2.getVehicleTypeIdentifier().getIndex());
} }
} }

View file

@ -32,7 +32,9 @@ 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.solution.route.state.StateFactory; import jsprit.core.problem.solution.route.state.StateFactory;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
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 org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -333,26 +335,18 @@ public class ServiceLoadRouteLevelConstraintTest {
@Test @Test
public void whenNewVehicleCapacityIsNotSufficiant1_returnFalse(){ public void whenNewVehicleCapacityIsNotSufficiant1_returnFalse(){
Pickup service = mock(Pickup.class); final Service pickup = createPickup("pick",2);
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); final Service pickup2 = createPickup("pick2",3);
Service delivery = createDelivery("del1",3); VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0,3).build();
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocationId("loc").build();
routeBuilder.addService(delivery);
VehicleRoute route = routeBuilder.build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(pickup).addJob(pickup2).build();
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(pickup2).build();
stateManager.informInsertionStarts(Arrays.asList(route), null); stateManager.informInsertionStarts(Arrays.asList(route), null);
JobInsertionContext iContext = new JobInsertionContext(route,pickup,vehicle,null,0.);
VehicleType type = mock(VehicleType.class);
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
Vehicle vehicle = mock(Vehicle.class);
when(vehicle.getType()).thenReturn(type);
JobInsertionContext iContext = mock(JobInsertionContext.class);
when(iContext.getJob()).thenReturn(service);
when(iContext.getRoute()).thenReturn(route);
when(iContext.getNewVehicle()).thenReturn(vehicle);
assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext)); assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext));
} }

View file

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2013 Stefan Schroeder
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contributors:
Stefan Schroeder - initial API and implementation
-->
<algorithm xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd">
<iterations>2000</iterations>
<strategy>
<memory>1</memory>
<searchStrategies>
<searchStrategy name="randomRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="randomRuin">
<share>0.5</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.5</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<selector name="selectBest"/>
<acceptor name="acceptNewRemoveWorst"/>
<modules>
<module name="ruin_and_recreate">
<ruin name="radialRuin">
<share>0.3</share>
</ruin>
<insertion name="bestInsertion"/>
</module>
</modules>
<probability>0.5</probability>
</searchStrategy>
</searchStrategies>
</strategy>
</algorithm>

59
pom.xml
View file

@ -67,7 +67,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.10</junit.version> <junit.version>4.10</junit.version>
<mockito.version>1.9.5</mockito.version> <mockito.version>1.9.5</mockito.version>
<logger.version>1.2.15</logger.version> <logger.version>2.0</logger.version>
</properties> </properties>
<build> <build>
@ -249,7 +249,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version> <version>2.9.1</version>
</plugin> </plugin>
</plugins> </plugins>
</reporting> </reporting>
@ -270,30 +270,43 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j-api</artifactId>
<version>${logger.version}</version> <version>${logger.version}</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${logger.version}</version>
</dependency>
<!--<dependency>-->
<!--<groupId>log4j</groupId>-->
<!--<artifactId>log4j</artifactId>-->
<!--<version>${logger.version}</version>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>javax.mail</groupId>-->
<!--<artifactId>mail</artifactId>-->
<!--</exclusion>-->
<!--<exclusion>-->
<!--<groupId>javax.jms</groupId>-->
<!--<artifactId>jms</artifactId>-->
<!--</exclusion>-->
<!--<exclusion>-->
<!--<groupId>com.sun.jdmk</groupId>-->
<!--<artifactId>jmxtools</artifactId>-->
<!--</exclusion>-->
<!--<exclusion>-->
<!--<groupId>com.sun.jmx</groupId>-->
<!--<artifactId>jmxri</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency> -->
</dependencies> </dependencies>