diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java index 33238111..87379f89 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java @@ -290,17 +290,13 @@ public class JobInsertionCostsCalculatorBuilder { ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager); serviceInsertion.setJobActivityFactory(activityFactory); - JobCalculatorSwitcher switcher = new JobCalculatorSwitcher(); + JobCalculatorSwitcher switcher = new JobCalculatorSwitcher(); switcher.put(Shipment.class, shipmentInsertion); switcher.put(Service.class, serviceInsertion); switcher.put(Pickup.class, serviceInsertion); switcher.put(Delivery.class, serviceInsertion); - - PenalyzeInsertionCostsWithPenaltyVehicle penalyzeInsertionCosts = new PenalyzeInsertionCostsWithPenaltyVehicle(switcher); - - CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(penalyzeInsertionCosts); - - return calcPlusListeners; + + return new CalculatorPlusListeners(switcher); } private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCostsCalculator baseCalculator, RouteAndActivityStateGetter activityStates2, double weightOfFixedCosts){ @@ -344,11 +340,7 @@ public class JobInsertionCostsCalculatorBuilder { return vrp.copyAndGetActivities(job); } }); - - PenalyzeInsertionCostsWithPenaltyVehicle penalyzeInsertionCosts = new PenalyzeInsertionCostsWithPenaltyVehicle(jobInsertionCalculator); - - CalculatorPlusListeners calcPlusListener = new CalculatorPlusListeners(penalyzeInsertionCosts); - return calcPlusListener; + return new CalculatorPlusListeners(jobInsertionCalculator); } private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, RouteAndActivityStateGetter activityStates2){ diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java index eaa43f38..29095b3a 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java @@ -26,7 +26,10 @@ import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.DefaultShipmentActivityFactory; import jsprit.core.problem.solution.route.activity.DefaultTourActivityFactory; import jsprit.core.problem.solution.route.activity.TourActivity; -import jsprit.core.problem.vehicle.*; +import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleType; +import jsprit.core.problem.vehicle.VehicleTypeImpl; +import jsprit.core.problem.vehicle.VehicleTypeKey; import jsprit.core.util.Coordinate; import jsprit.core.util.CrowFlyCosts; import jsprit.core.util.Locations; @@ -119,12 +122,6 @@ public class VehicleRoutingProblem { }; - private boolean addPenaltyVehicles = false; - - private double penaltyFactor = 1.0; - - private Double penaltyFixedCosts = null; - private int jobIndexCounter = 1; private int vehicleIndexCounter = 1; @@ -141,25 +138,6 @@ public class VehicleRoutingProblem { private final DefaultTourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory(); - /** - * Create a location (i.e. coordinate) and returns the key of the location which is Coordinate.toString(). - * - * @param x x-coordinate of location - * @param y y-coordinate of location - * @return locationId - * @see Coordinate - */ - @SuppressWarnings("UnusedDeclaration") - @Deprecated - public String createLocation(double x, double y){ - Coordinate coordinate = new Coordinate(x, y); - String id = coordinate.toString(); - if(!tentative_coordinates.containsKey(id)){ - tentative_coordinates.put(id, coordinate); - } - return id; - } - private void incJobIndexCounter(){ jobIndexCounter++; } @@ -426,56 +404,14 @@ public class VehicleRoutingProblem { logger.warn("set routing costs crowFlyDistance."); transportCosts = new CrowFlyCosts(getLocations()); } - if(addPenaltyVehicles){ - if(fleetSize.equals(FleetSize.INFINITE)){ - logger.warn("penaltyType and FleetSize.INFINITE does not make sense. thus no penalty-types are added."); - } - else{ - addPenaltyVehicles(); - } - } - for(Job job : tentativeJobs.values()) + for(Job job : tentativeJobs.values()) if (!jobsInInitialRoutes.contains(job.getId())) { addJobToFinalJobMapAndCreateActivities(job); } return new VehicleRoutingProblem(this); } - - private void addPenaltyVehicles() { - Set vehicleTypeKeys = new HashSet(); - List uniqueVehicles = new ArrayList(); - for(Vehicle v : this.uniqueVehicles){ - VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(),v.getStartLocationId(),v.getEndLocationId(),v.getEarliestDeparture(),v.getLatestArrival(), v.getSkills()); - if(!vehicleTypeKeys.contains(key)){ - uniqueVehicles.add(v); - vehicleTypeKeys.add(key); - } - } - for(Vehicle v : uniqueVehicles){ - double fixed = v.getType().getVehicleCostParams().fix * penaltyFactor; - if(penaltyFixedCosts!=null){ - fixed = penaltyFixedCosts; - } - VehicleTypeImpl t = VehicleTypeImpl.Builder.newInstance(v.getType().getTypeId()) - .setCostPerDistance(penaltyFactor*v.getType().getVehicleCostParams().perDistanceUnit) - .setCostPerTime(penaltyFactor*v.getType().getVehicleCostParams().perTimeUnit) - .setFixedCost(fixed) - .setCapacityDimensions(v.getType().getCapacityDimensions()) - .build(); - PenaltyVehicleType penType = new PenaltyVehicleType(t,penaltyFactor); - String vehicleId = v.getId(); - VehicleImpl penVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(v.getEarliestDeparture()) - .setLatestArrival(v.getLatestArrival()).setStartLocationCoordinate(v.getStartLocationCoordinate()).setStartLocationId(v.getStartLocationId()) - .setEndLocationId(v.getEndLocationId()).setEndLocationCoordinate(v.getEndLocationCoordinate()) - .addSkills(v.getSkills()) - .setReturnToDepot(v.isReturnToDepot()).setType(penType).build(); - addVehicle(penVehicle); - } - } - - - @SuppressWarnings("UnusedDeclaration") + @SuppressWarnings("UnusedDeclaration") public Builder addLocation(String locationId, Coordinate coordinate) { tentative_coordinates.put(locationId, coordinate); return this; @@ -526,47 +462,8 @@ public class VehicleRoutingProblem { public Collection getAddedVehicleTypes(){ return Collections.unmodifiableCollection(vehicleTypes); } - - /** - * 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). - * - *

This only makes sense for FleetSize.FINITE. Thus, penaltyVehicles are only added if is FleetSize.FINITE. - *

The id of penaltyVehicles is constructed as follows vehicleId = "penaltyVehicle" + "_" + {locationId} + "_" + {typeId}. - *

By default: no penalty-vehicles are added - * - * @param penaltyFactor penaltyFactor of penaltyVehicle - * @return this builder - * @deprecated since 1.3.2-SNAPSHOT bad job list replaces penalty vehicles - */ - @Deprecated - public Builder addPenaltyVehicles(double penaltyFactor){ - this.addPenaltyVehicles = true; - this.penaltyFactor = penaltyFactor; - 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. - *

This method takes penaltyFixedCosts as absolute value in contrary to the method without penaltyFixedCosts where fixedCosts is the product of penaltyFactor and typeFixedCosts. - *

This only makes sense for FleetSize.FINITE. Thus, penaltyVehicles are only added if is FleetSize.FINITE. - *

The id of penaltyVehicles is constructed as follows vehicleId = "penaltyVehicle" + "_" + {locationId} + "_" + {typeId}. - *

By default: no penalty-vehicles are added - * - * @param penaltyFactor the penaltyFactor of penaltyVehicle - * @param penaltyFixedCosts which is an absolute penaltyValue (in contrary to penaltyFactor) - * @return this builder - * @deprecated since 1.3.2-SNAPSHOT bad job list replaces penalty vehicles - */ - @Deprecated - public Builder addPenaltyVehicles(double penaltyFactor, double penaltyFixedCosts){ - this.addPenaltyVehicles = true; - this.penaltyFactor = penaltyFactor; - this.penaltyFixedCosts = penaltyFixedCosts; - return this; - } - - /** + + /** * Returns an unmodifiable collection of already added jobs. * * @return collection of jobs diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/SolomonSkills_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/SolomonSkills_IT.java index d67b0094..3714687c 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/SolomonSkills_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/SolomonSkills_IT.java @@ -1,3 +1,20 @@ +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ + package jsprit.core.algorithm.state; import jsprit.core.algorithm.VehicleRoutingAlgorithm; @@ -57,7 +74,6 @@ public class SolomonSkills_IT { else skillServiceBuilder.addRequiredSkill("skill1"); skillProblemBuilder.addJob(skillServiceBuilder.build()); } - skillProblemBuilder.addPenaltyVehicles(3.); skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); VehicleRoutingProblem skillProblem = skillProblemBuilder.build(); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java index 5ef0072b..e48f6569 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java @@ -27,7 +27,10 @@ import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Shipment; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.TourActivity; -import jsprit.core.problem.vehicle.*; +import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleImpl; +import jsprit.core.problem.vehicle.VehicleType; +import jsprit.core.problem.vehicle.VehicleTypeImpl; import jsprit.core.util.Coordinate; import org.junit.Test; @@ -317,154 +320,7 @@ public class VehicleRoutingProblemTest { } - @Test - public void whenSettingAddPenaltyVehicleOptions_itShouldAddPenaltyVehicle(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build(); - - builder.addVehicle(vehicle); - builder.setFleetSize(FleetSize.FINITE); - builder.addPenaltyVehicles(3.0); - - VehicleRoutingProblem vrp = builder.build(); - - assertEquals(2,vrp.getVehicles().size()); - - boolean penaltyVehicleInCollection = false; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType() instanceof PenaltyVehicleType) penaltyVehicleInCollection = true; - } - assertTrue(penaltyVehicleInCollection); - - } - - @Test - public void whenSettingAddPenaltyVehicleOptionsAndFleetSizeIsInfinite_noPenaltyVehicleIsAdded(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build(); - - builder.addVehicle(vehicle); - builder.addPenaltyVehicles(3.0); - - VehicleRoutingProblem vrp = builder.build(); - - assertEquals(1,vrp.getVehicles().size()); - - boolean penaltyVehicleInCollection = false; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType() instanceof PenaltyVehicleType) penaltyVehicleInCollection = true; - } - assertFalse(penaltyVehicleInCollection); - - } - - - @Test - public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithSameLocationAndType_onlyOnePenaltyVehicleIsAdded(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build(); - VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type).build(); - - builder.addVehicle(vehicle); - builder.addVehicle(vehicle2); - builder.setFleetSize(FleetSize.FINITE); - builder.addPenaltyVehicles(3.0); - - VehicleRoutingProblem vrp = builder.build(); - - assertEquals(3,vrp.getVehicles().size()); - - boolean penaltyVehicleInCollection = false; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType() instanceof PenaltyVehicleType) penaltyVehicleInCollection = true; - } - assertTrue(penaltyVehicleInCollection); - - } - - @Test - public void whenSettingAddPenaltyVehicleOptionsWithAbsoluteFixedCostsAndTwoVehiclesWithSameLocationAndType_onePenaltyVehicleIsAddedWithTheCorrectPenaltyFixedCosts(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build(); - VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type).build(); - - builder.addVehicle(vehicle); - builder.addVehicle(vehicle2); - builder.setFleetSize(FleetSize.FINITE); - builder.addPenaltyVehicles(3.0,10000); - - VehicleRoutingProblem vrp = builder.build(); - - assertEquals(3,vrp.getVehicles().size()); - - double fix = 0.0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType() instanceof PenaltyVehicleType) { - fix = v.getType().getVehicleCostParams().fix; - } - } - assertEquals(10000,fix,0.01); - - } - - @Test - public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithDiffLocationAndType_twoPenaltyVehicleIsAdded(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build(); - VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc2").setType(type).build(); - - builder.addVehicle(vehicle); - builder.addVehicle(vehicle2); - builder.setFleetSize(FleetSize.FINITE); - builder.addPenaltyVehicles(3.0); - - VehicleRoutingProblem vrp = builder.build(); - - assertEquals(4,vrp.getVehicles().size()); - - int countPenaltyVehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType() instanceof PenaltyVehicleType) { - countPenaltyVehicles++; - } - - } - assertEquals(2,countPenaltyVehicles); - - } - - @Test - public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithSameLocationButDiffType_twoPenaltyVehicleIsAdded(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build(); - VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build(); - - builder.addVehicle(vehicle); - builder.addVehicle(vehicle2); - builder.setFleetSize(FleetSize.FINITE); - builder.addPenaltyVehicles(3.0); - - VehicleRoutingProblem vrp = builder.build(); - - assertEquals(4,vrp.getVehicles().size()); - - int countPenaltyVehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType() instanceof PenaltyVehicleType) { - countPenaltyVehicles++; - } - } - assertEquals(2,countPenaltyVehicles); - } - @Test public void whenAddingVehicleWithDiffStartAndEnd_startLocationMustBeRegisteredInLocationMap(){ VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build(); diff --git a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample2.java similarity index 98% rename from jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java rename to jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample2.java index b36f7f81..8486e788 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java +++ b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample2.java @@ -38,7 +38,7 @@ import java.util.Arrays; import java.util.Collection; -public class MultipleDepotExampleWithPenaltyVehicles { +public class MultipleDepotExample2 { public static void main(String[] args) { diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java index 09cecffa..c3b1e8ba 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java @@ -1,10 +1,21 @@ -package jsprit.instance.reader; +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; +package jsprit.instance.reader; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.Builder; @@ -16,6 +27,8 @@ import jsprit.core.problem.vehicle.VehicleImpl; import jsprit.core.problem.vehicle.VehicleTypeImpl; import jsprit.core.util.Coordinate; +import java.io.*; + /** * Reads modified files from Taillard's website * http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html. You can find the modified version here: @@ -108,7 +121,6 @@ public class VrphGoldenReader { typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); nuOfVehicles = Integer.parseInt(tokens[5]); vrpBuilder.setFleetSize(FleetSize.FINITE); - vrpBuilder.addPenaltyVehicles(5.0, 5000); } else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); } @@ -118,7 +130,6 @@ public class VrphGoldenReader { typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); nuOfVehicles = Integer.parseInt(tokens[5]); vrpBuilder.setFleetSize(FleetSize.FINITE); - vrpBuilder.addPenaltyVehicles(5.0, 5000); } else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); }