mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
rem penalty vehicle stuff
This commit is contained in:
parent
69b23e9da4
commit
9938a6a123
6 changed files with 53 additions and 281 deletions
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue