mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add and test .getAddedVehicleTypes()
This commit is contained in:
parent
c4bd72bae8
commit
8272554e8e
2 changed files with 51 additions and 0 deletions
|
|
@ -339,6 +339,15 @@ public class VehicleRoutingProblem {
|
||||||
return Collections.unmodifiableCollection(vehicles);
|
return Collections.unmodifiableCollection(vehicles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an unmodifiable collection of already added vehicle-types.
|
||||||
|
*
|
||||||
|
* @returns collection of vehicle-types
|
||||||
|
*/
|
||||||
|
public Collection<VehicleType> getAddedVehicleTypes(){
|
||||||
|
return Collections.unmodifiableCollection(vehicleTypes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds constraint to problem.
|
* Adds constraint to problem.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import jsprit.core.problem.job.Shipment;
|
||||||
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.problem.vehicle.VehicleImpl;
|
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||||
|
import jsprit.core.problem.vehicle.VehicleType;
|
||||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -278,5 +279,46 @@ public class VehicleRoutingProblemTest {
|
||||||
VehicleRoutingProblem problem = builder.build();
|
VehicleRoutingProblem problem = builder.build();
|
||||||
assertEquals(4.0,problem.getTransportCosts().getTransportCost("", "", 0.0, null, null),0.01);
|
assertEquals(4.0,problem.getTransportCosts().getTransportCost("", "", 0.0, null, null),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenAddingAVehicle_getAddedVehicleTypesShouldReturnItsType(){
|
||||||
|
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||||
|
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||||
|
builder.addVehicle(vehicle);
|
||||||
|
|
||||||
|
assertEquals(1,builder.getAddedVehicleTypes().size());
|
||||||
|
assertEquals(type,builder.getAddedVehicleTypes().iterator().next());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenAddingTwoVehicleWithSameType_getAddedVehicleTypesShouldReturnOnlyOneType(){
|
||||||
|
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||||
|
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||||
|
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||||
|
|
||||||
|
builder.addVehicle(vehicle);
|
||||||
|
builder.addVehicle(vehicle2);
|
||||||
|
|
||||||
|
assertEquals(1,builder.getAddedVehicleTypes().size());
|
||||||
|
assertEquals(type,builder.getAddedVehicleTypes().iterator().next());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenAddingTwoVehicleWithDiffType_getAddedVehicleTypesShouldReturnTheseType(){
|
||||||
|
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||||
|
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2", 0).build();
|
||||||
|
|
||||||
|
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||||
|
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type2).build();
|
||||||
|
|
||||||
|
builder.addVehicle(vehicle);
|
||||||
|
builder.addVehicle(vehicle2);
|
||||||
|
|
||||||
|
assertEquals(2,builder.getAddedVehicleTypes().size());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue