mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
removed addConstraint in core.problem.VehicleRoutingProblem
This commit is contained in:
parent
1f96eefc4d
commit
b991793aba
10 changed files with 128 additions and 147 deletions
|
|
@ -158,7 +158,7 @@ public class VehicleRoutingAlgorithmBuilder {
|
|||
*/
|
||||
public VehicleRoutingAlgorithm build() {
|
||||
if(stateManager == null) stateManager = new StateManager(vrp);
|
||||
if(constraintManager == null) constraintManager = new ConstraintManager(vrp,stateManager,vrp.getConstraints());
|
||||
if(constraintManager == null) constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
//add core updater
|
||||
stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
|
||||
// stateManager.addStateUpdater(new OpenRouteStateVerifier());
|
||||
|
|
|
|||
|
|
@ -471,7 +471,7 @@ public class VehicleRoutingAlgorithms {
|
|||
* define constraints
|
||||
*/
|
||||
//constraint manager
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager,vrp.getConstraints());
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addTimeWindowConstraint();
|
||||
constraintManager.addLoadConstraint();
|
||||
constraintManager.addSkillsConstraint();
|
||||
|
|
|
|||
|
|
@ -102,9 +102,6 @@ public class VehicleRoutingProblem {
|
|||
|
||||
private Set<Vehicle> uniqueVehicles = new HashSet<Vehicle>();
|
||||
|
||||
@Deprecated
|
||||
private Collection<jsprit.core.problem.constraint.Constraint> constraints = new ArrayList<jsprit.core.problem.constraint.Constraint>();
|
||||
|
||||
private JobActivityFactory jobActivityFactory = new JobActivityFactory() {
|
||||
|
||||
@Override
|
||||
|
|
@ -500,20 +497,6 @@ public class VehicleRoutingProblem {
|
|||
return Collections.unmodifiableCollection(vehicleTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds constraint to problem.
|
||||
*
|
||||
* @param constraint constraint to be added
|
||||
* @return this builder
|
||||
* @deprecated use ConstraintManager instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder addConstraint(jsprit.core.problem.constraint.Constraint constraint){
|
||||
//noinspection deprecation
|
||||
constraints.add(constraint);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds penaltyVehicles, i.e. for every unique vehicle-location and type combination a penalty-vehicle is constructed having penaltyFactor times higher fixed and variable costs
|
||||
* (see .addPenaltyVehicles(double penaltyFactor, double penaltyFixedCosts) if fixed costs = 0.0).
|
||||
|
|
@ -616,11 +599,6 @@ public class VehicleRoutingProblem {
|
|||
*/
|
||||
private final FleetSize fleetSize;
|
||||
|
||||
/**
|
||||
* contains all constraints
|
||||
*/
|
||||
private final Collection<jsprit.core.problem.constraint.Constraint> constraints;
|
||||
|
||||
private final Locations locations;
|
||||
|
||||
private Map<Job,List<AbstractActivity>> activityMap;
|
||||
|
|
@ -644,8 +622,6 @@ public class VehicleRoutingProblem {
|
|||
this.initialVehicleRoutes = builder.initialRoutes;
|
||||
this.transportCosts = builder.transportCosts;
|
||||
this.activityCosts = builder.activityCosts;
|
||||
//noinspection deprecation
|
||||
this.constraints = builder.constraints;
|
||||
this.locations = builder.getLocations();
|
||||
this.activityMap = builder.activityMap;
|
||||
this.nuActivities = builder.activityIndexCounter;
|
||||
|
|
@ -720,17 +696,6 @@ public class VehicleRoutingProblem {
|
|||
return activityCosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable collection of constraints.
|
||||
*
|
||||
* @return collection of constraints
|
||||
* @deprecated use ConstraintManager instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Collection<jsprit.core.problem.constraint.Constraint> getConstraints(){
|
||||
return Collections.unmodifiableCollection(constraints);
|
||||
}
|
||||
|
||||
public Locations getLocations(){
|
||||
return locations;
|
||||
}
|
||||
|
|
@ -743,14 +708,12 @@ public class VehicleRoutingProblem {
|
|||
|
||||
public JobActivityFactory getJobActivityFactory(){
|
||||
return jobActivityFactory;
|
||||
};
|
||||
}
|
||||
|
||||
public List<AbstractActivity> copyAndGetActivities(Job job){
|
||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
if(activityMap.containsKey(job)) {
|
||||
for (AbstractActivity act : activityMap.get(job)) {
|
||||
acts.add((AbstractActivity) act.duplicate());
|
||||
}
|
||||
for (AbstractActivity act : activityMap.get(job)) acts.add((AbstractActivity) act.duplicate());
|
||||
}
|
||||
return acts;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package jsprit.core.problem;
|
||||
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.constraint.Constraint;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
|
|
@ -98,10 +97,10 @@ public class VehicleRoutingProblemTest {
|
|||
VehicleTypeImpl type1 = mock(VehicleTypeImpl.class);
|
||||
VehicleTypeImpl type2 = mock(VehicleTypeImpl.class);
|
||||
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("yo").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("yo").setType(type1).build();
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("yo").setType(type2).build();
|
||||
Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("yo").setType(type2).build();
|
||||
VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("yo").setType(type1).build();
|
||||
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("yo").setType(type1).build();
|
||||
VehicleImpl v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("yo").setType(type2).build();
|
||||
VehicleImpl v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("yo").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4);
|
||||
|
||||
|
|
@ -234,16 +233,7 @@ public class VehicleRoutingProblemTest {
|
|||
assertEquals(s2,vrp.getJobs().get("s2"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenConstraintsAdded_vrpShouldContainThem(){
|
||||
Constraint c1 = mock(Constraint.class);
|
||||
Constraint c2 = mock(Constraint.class);
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
builder.addConstraint(c1).addConstraint(c2);
|
||||
VehicleRoutingProblem problem = builder.build();
|
||||
assertEquals(2,problem.getConstraints().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingActivityCosts_vrpShouldContainIt(){
|
||||
|
|
|
|||
|
|
@ -16,21 +16,20 @@
|
|||
******************************************************************************/
|
||||
package jsprit.examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||
import jsprit.analysis.toolbox.GraphStreamViewer.Label;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.constraint.HardRouteStateLevelConstraint;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.Builder;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
|
@ -39,6 +38,8 @@ import jsprit.core.util.Coordinate;
|
|||
import jsprit.core.util.Solutions;
|
||||
import jsprit.util.Examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class EnRoutePickupAndDeliveryWithMultipleDepotsAndVehicleAccessConstraintAndSpecifiedVehicleEndLocationsExample {
|
||||
|
||||
|
|
@ -66,12 +67,12 @@ public class EnRoutePickupAndDeliveryWithMultipleDepotsAndVehicleAccessConstrain
|
|||
Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("v1");
|
||||
vehicleBuilder1.setStartLocationCoordinate(Coordinate.newInstance(10, 10));
|
||||
vehicleBuilder1.setType(vehicleType);
|
||||
Vehicle vehicle1 = vehicleBuilder1.build();
|
||||
VehicleImpl vehicle1 = vehicleBuilder1.build();
|
||||
|
||||
Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("v2");
|
||||
vehicleBuilder2.setStartLocationCoordinate(Coordinate.newInstance(30, 30)).setEndLocationCoordinate(Coordinate.newInstance(30, 19));
|
||||
vehicleBuilder2.setType(vehicleType);
|
||||
Vehicle vehicle2 = vehicleBuilder2.build();
|
||||
VehicleImpl vehicle2 = vehicleBuilder2.build();
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -119,36 +120,36 @@ public class EnRoutePickupAndDeliveryWithMultipleDepotsAndVehicleAccessConstrain
|
|||
//you only have two vehicles
|
||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||
|
||||
|
||||
|
||||
//build the problem
|
||||
VehicleRoutingProblem problem = vrpBuilder.build();
|
||||
|
||||
/*
|
||||
* add a geographic constraint determining that vehicle1 cannot go to x>15 and vehicle2 cannot go to x<15
|
||||
*
|
||||
* switch off the geoConstraints to see the impact of this constraint on routes, or just exchange v1 and v2 to reverse the geo-constraint.
|
||||
*/
|
||||
HardRouteStateLevelConstraint geoClusterConstraint = new HardRouteStateLevelConstraint() {
|
||||
HardRouteStateLevelConstraint geoClusterConstraint = new HardRouteStateLevelConstraint() {
|
||||
|
||||
@Override
|
||||
public boolean fulfilled(JobInsertionContext insertionContext) {
|
||||
Shipment shipment2insert = ((Shipment)insertionContext.getJob());
|
||||
if(insertionContext.getNewVehicle().getId().equals("v1")){
|
||||
if(shipment2insert.getPickupCoord().getX() > 15. || shipment2insert.getDeliveryCoord().getX() > 15.){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(insertionContext.getNewVehicle().getId().equals("v2")){
|
||||
if(shipment2insert.getPickupCoord().getX() < 15. || shipment2insert.getDeliveryCoord().getX() < 15.){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
//add the constraint to the problem
|
||||
vrpBuilder.addConstraint(geoClusterConstraint);
|
||||
//build the problem
|
||||
VehicleRoutingProblem problem = vrpBuilder.build();
|
||||
@Override
|
||||
public boolean fulfilled(JobInsertionContext insertionContext) {
|
||||
Shipment shipment2insert = ((Shipment)insertionContext.getJob());
|
||||
if(insertionContext.getNewVehicle().getId().equals("v1")){
|
||||
if(shipment2insert.getPickupCoord().getX() > 15. || shipment2insert.getDeliveryCoord().getX() > 15.){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(insertionContext.getNewVehicle().getId().equals("v2")){
|
||||
if(shipment2insert.getPickupCoord().getX() < 15. || shipment2insert.getDeliveryCoord().getX() < 15.){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* get a sample algorithm.
|
||||
*
|
||||
* Note that you need to make sure to prohibit vehicle-switching by adding the insertion-tag <vehicleSwitchAllowed>false</vehicleSwitchAllowed>.
|
||||
|
|
@ -157,7 +158,17 @@ public class EnRoutePickupAndDeliveryWithMultipleDepotsAndVehicleAccessConstrain
|
|||
* bit more complicated and you cannot just add the above hard-constraint. Latter will be covered in another example.
|
||||
*
|
||||
*/
|
||||
VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig_noVehicleSwitch.xml");
|
||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem,"input/algorithmConfig_noVehicleSwitch.xml");
|
||||
vraBuilder.addCoreConstraints();
|
||||
vraBuilder.addDefaultCostCalculators();
|
||||
|
||||
StateManager stateManager = new StateManager(problem);
|
||||
ConstraintManager constraintManager = new ConstraintManager(problem,stateManager);
|
||||
constraintManager.addConstraint(geoClusterConstraint);
|
||||
|
||||
vraBuilder.setStateAndConstraintManager(stateManager,constraintManager);
|
||||
VehicleRoutingAlgorithm algorithm = vraBuilder.build();
|
||||
|
||||
algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100));
|
||||
// algorithm.setNuOfIterations(30000);
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -16,14 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.examples;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener;
|
||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||
import jsprit.analysis.toolbox.Plotter;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.analysis.toolbox.StopWatch;
|
||||
import jsprit.analysis.toolbox.*;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority;
|
||||
|
|
@ -31,19 +24,18 @@ import jsprit.core.problem.VehicleRoutingProblem;
|
|||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.io.VrpXMLReader;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.Solutions;
|
||||
import jsprit.util.Examples;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class MultipleDepotExample {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
/*
|
||||
* some preparation - create output folder
|
||||
|
|
@ -77,7 +69,7 @@ public class MultipleDepotExample {
|
|||
for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second,third,fourth)){
|
||||
for(int i=0;i<nuOfVehicles;i++){
|
||||
VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance(depotCounter + "_type").addCapacityDimension(0, capacity).setCostPerDistance(1.0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance(depotCounter + "_" + (i+1) + "_vehicle").setStartLocationCoordinate(depotCoord).setType(vehicleType).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance(depotCounter + "_" + (i+1) + "_vehicle").setStartLocationCoordinate(depotCoord).setType(vehicleType).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
depotCounter++;
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
******************************************************************************/
|
||||
package jsprit.examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.Plotter;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.box.SchrimpfFactory;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.constraint.ServiceDeliveriesFirstConstraint;
|
||||
import jsprit.core.problem.io.VrpXMLWriter;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
|
|
@ -37,6 +37,8 @@ import jsprit.core.util.Coordinate;
|
|||
import jsprit.core.util.Solutions;
|
||||
import jsprit.util.Examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample {
|
||||
|
||||
|
|
@ -92,14 +94,19 @@ public class SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample {
|
|||
vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4)
|
||||
.addJob(delivery1).addJob(delivery2).addJob(delivery3).addJob(delivery4).build();
|
||||
|
||||
vrpBuilder.addConstraint(new ServiceDeliveriesFirstConstraint());
|
||||
|
||||
VehicleRoutingProblem problem = vrpBuilder.build();
|
||||
|
||||
/*
|
||||
* get the algorithm out-of-the-box.
|
||||
* build the algorithm
|
||||
*/
|
||||
VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem);
|
||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem,"input/algorithmConfig.xml");
|
||||
vraBuilder.addCoreConstraints();
|
||||
vraBuilder.addDefaultCostCalculators();
|
||||
StateManager stateManager = new StateManager(problem);
|
||||
ConstraintManager constraintManager = new ConstraintManager(problem,stateManager);
|
||||
constraintManager.addConstraint(new ServiceDeliveriesFirstConstraint(), ConstraintManager.Priority.CRITICAL);
|
||||
vraBuilder.setStateAndConstraintManager(stateManager,constraintManager);
|
||||
VehicleRoutingAlgorithm algorithm = vraBuilder.build();
|
||||
|
||||
/*
|
||||
* and search a solution
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@
|
|||
******************************************************************************/
|
||||
package jsprit.examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.Plotter;
|
||||
import jsprit.analysis.toolbox.Plotter.Label;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.box.SchrimpfFactory;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.constraint.ServiceDeliveriesFirstConstraint;
|
||||
import jsprit.core.problem.io.VrpXMLWriter;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
|
|
@ -38,6 +38,8 @@ import jsprit.core.util.Coordinate;
|
|||
import jsprit.core.util.Solutions;
|
||||
import jsprit.util.Examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class SimpleVRPWithBackhaulsExample {
|
||||
|
||||
|
|
@ -76,15 +78,16 @@ public class SimpleVRPWithBackhaulsExample {
|
|||
|
||||
vrpBuilder.addJob(pickup1).addJob(pickup2).addJob(delivery1).addJob(delivery2);
|
||||
|
||||
//
|
||||
vrpBuilder.addConstraint(new ServiceDeliveriesFirstConstraint());
|
||||
|
||||
VehicleRoutingProblem problem = vrpBuilder.build();
|
||||
|
||||
/*
|
||||
* get the algorithm out-of-the-box.
|
||||
*/
|
||||
VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem);
|
||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem,"input/algorithmConfig.xml");
|
||||
vraBuilder.addCoreConstraints();
|
||||
vraBuilder.addDefaultCostCalculators();
|
||||
StateManager stateManager = new StateManager(problem);
|
||||
ConstraintManager constraintManager = new ConstraintManager(problem,stateManager);
|
||||
constraintManager.addConstraint(new ServiceDeliveriesFirstConstraint(), ConstraintManager.Priority.CRITICAL);
|
||||
vraBuilder.setStateAndConstraintManager(stateManager,constraintManager);
|
||||
VehicleRoutingAlgorithm algorithm = vraBuilder.build();
|
||||
|
||||
/*
|
||||
* and search a solution
|
||||
|
|
|
|||
|
|
@ -16,21 +16,23 @@
|
|||
******************************************************************************/
|
||||
package jsprit.examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener;
|
||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter.Print;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder;
|
||||
import jsprit.core.algorithm.selector.SelectBest;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.constraint.ServiceDeliveriesFirstConstraint;
|
||||
import jsprit.core.problem.io.VrpXMLReader;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.util.Examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class VRPWithBackhaulsExample {
|
||||
|
||||
|
|
@ -56,9 +58,7 @@ public class VRPWithBackhaulsExample {
|
|||
/*
|
||||
* Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances).
|
||||
*/
|
||||
// vrpBuilder.addProblemConstraint(Constraint.DELIVERIES_FIRST);
|
||||
vrpBuilder.addConstraint(new ServiceDeliveriesFirstConstraint());
|
||||
|
||||
//
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
// SolutionPlotter.plotVrpAsPNG(vrp, "output/vrpwbh_solomon_r101.png", "pd_r101");
|
||||
|
|
@ -68,9 +68,15 @@ public class VRPWithBackhaulsExample {
|
|||
*
|
||||
* The algorithm can be defined and configured in an xml-file.
|
||||
*/
|
||||
// VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml");
|
||||
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
|
||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"input/algorithmConfig_solomon.xml");
|
||||
vraBuilder.addCoreConstraints();
|
||||
vraBuilder.addDefaultCostCalculators();
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addConstraint(new ServiceDeliveriesFirstConstraint(), ConstraintManager.Priority.CRITICAL);
|
||||
vraBuilder.setStateAndConstraintManager(stateManager,constraintManager);
|
||||
VehicleRoutingAlgorithm vra = vraBuilder.build();
|
||||
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
|
||||
/*
|
||||
* Solve the problem.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,20 +16,22 @@
|
|||
******************************************************************************/
|
||||
package jsprit.examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.Plotter;
|
||||
import jsprit.analysis.toolbox.Plotter.Label;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder;
|
||||
import jsprit.core.algorithm.selector.SelectBest;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.constraint.ServiceDeliveriesFirstConstraint;
|
||||
import jsprit.core.problem.io.VrpXMLReader;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.util.Examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class VRPWithBackhaulsExample2 {
|
||||
|
||||
|
|
@ -52,10 +54,6 @@ public class VRPWithBackhaulsExample2 {
|
|||
*/
|
||||
new VrpXMLReader(vrpBuilder).read("input/pd_christophides_vrpnc1_vcap50.xml");
|
||||
|
||||
/*
|
||||
* add the backhaul constraint to the problem
|
||||
*/
|
||||
vrpBuilder.addConstraint(new ServiceDeliveriesFirstConstraint());
|
||||
|
||||
/*
|
||||
* Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances).
|
||||
|
|
@ -70,7 +68,18 @@ public class VRPWithBackhaulsExample2 {
|
|||
*
|
||||
* The algorithm can be defined and configured in an xml-file.
|
||||
*/
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml");
|
||||
// VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml");
|
||||
|
||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"input/algorithmConfig_solomon.xml");
|
||||
vraBuilder.addDefaultCostCalculators();
|
||||
vraBuilder.addCoreConstraints();
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addConstraint(new ServiceDeliveriesFirstConstraint(), ConstraintManager.Priority.CRITICAL);
|
||||
|
||||
vraBuilder.setStateAndConstraintManager(stateManager,constraintManager);
|
||||
VehicleRoutingAlgorithm vra = vraBuilder.build();
|
||||
|
||||
/*
|
||||
* Solve the problem.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue