mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'master' into max-time-feature
# Conflicts: # jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java # jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java # jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java # jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java # jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java
This commit is contained in:
commit
b5998e1d93
100 changed files with 4103 additions and 2386 deletions
|
|
@ -31,7 +31,6 @@ import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolutio
|
|||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
|
||||
import com.graphhopper.jsprit.core.util.Solutions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
|
@ -43,10 +42,10 @@ public class MaxTimeInVehicle_IT {
|
|||
public void test(){
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(0,0)).setDeliveryLocation(Location.newInstance(100,0)).setDeliveryServiceTime(10)
|
||||
.setMaxTimeInVehicle(90d)
|
||||
.setMaxTimeInVehicle(100d)
|
||||
.build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance(0,0)).setDeliveryLocation(Location.newInstance(100,0)).setDeliveryServiceTime(10)
|
||||
.setMaxTimeInVehicle(90d)
|
||||
.setMaxTimeInVehicle(100d)
|
||||
.build();
|
||||
|
||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
|
||||
|
|
@ -58,12 +57,12 @@ public class MaxTimeInVehicle_IT {
|
|||
stateManager.addStateUpdater(new UpdateMaxTimeInVehicle(stateManager,id,vrp.getTransportCosts(),vrp.getActivityCosts()));
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addConstraint(new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts(),id,stateManager), ConstraintManager.Priority.CRITICAL);
|
||||
constraintManager.addConstraint(new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts(),id,stateManager, vrp), ConstraintManager.Priority.CRITICAL);
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setStateAndConstraintManager(stateManager,constraintManager).buildAlgorithm();
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||
|
||||
Assert.assertEquals(400, solution.getCost(), 0.001);
|
||||
// SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE);
|
||||
// Assert.assertEquals(400, solution.getCost(), 0.001);
|
||||
SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,14 +26,17 @@ import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolutio
|
|||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.util.Solutions;
|
||||
import com.graphhopper.jsprit.core.util.UnassignedJobReasonTracker;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class UnassignedJobListTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void job2ShouldBeInBadJobList_dueToTimeWindow() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -46,11 +49,17 @@ public class UnassignedJobListTest {
|
|||
VehicleRoutingProblem vrp = builder.build();
|
||||
VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
|
||||
algorithm.setMaxIterations(10);
|
||||
|
||||
UnassignedJobReasonTracker reasonTracker = new UnassignedJobReasonTracker();
|
||||
algorithm.addListener(reasonTracker);
|
||||
|
||||
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
|
||||
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||
|
||||
assertTrue(!solution.getUnassignedJobs().contains(job1));
|
||||
assertTrue(solution.getUnassignedJobs().contains(job2));
|
||||
assertEquals(2, reasonTracker.getMostLikelyReasonCode("job2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -63,13 +72,19 @@ public class UnassignedJobListTest {
|
|||
builder.addJob(job2);
|
||||
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
|
||||
VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
|
||||
algorithm.setMaxIterations(10);
|
||||
|
||||
UnassignedJobReasonTracker reasonTracker = new UnassignedJobReasonTracker();
|
||||
algorithm.addListener(reasonTracker);
|
||||
|
||||
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
|
||||
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||
assertTrue(!solution.getUnassignedJobs().contains(job1));
|
||||
assertTrue(solution.getUnassignedJobs().contains(job2));
|
||||
assertEquals(3, reasonTracker.getMostLikelyReasonCode("job2"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* Licensed to GraphHopper GmbH under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* GraphHopper GmbH licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.graphhopper.jsprit.core.algorithm.recreate;
|
||||
|
||||
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
||||
import com.graphhopper.jsprit.core.problem.AbstractJob;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 15/08/16.
|
||||
*/
|
||||
public class ConfigureFixCostCalculatorTest {
|
||||
|
||||
VehicleRoutingProblem vrp;
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
for(int i=0;i<100;i++){
|
||||
Service service = Service.Builder.newInstance("" + i).setLocation(Location.newInstance(0)).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
vrp = vrpBuilder.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCalculateCorrectly(){
|
||||
List<Job> unassigned = new ArrayList<>();
|
||||
int count = 1;
|
||||
for(String key : vrp.getJobs().keySet()) {
|
||||
if(count <= 25) {
|
||||
unassigned.add(vrp.getJobs().get(key));
|
||||
}
|
||||
count++;
|
||||
}
|
||||
JobInsertionConsideringFixCostsCalculator jicc = new JobInsertionConsideringFixCostsCalculator(mock(JobInsertionCostsCalculator.class),mock(StateManager.class));
|
||||
ConfigureFixCostCalculator c = new ConfigureFixCostCalculator(vrp,jicc);
|
||||
c.informInsertionStarts(new ArrayList<VehicleRoute>(), unassigned);
|
||||
Assert.assertEquals(0.75, jicc.getSolutionCompletenessRatio(), 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeMinRatio(){
|
||||
List<Job> unassigned = new ArrayList<>();
|
||||
int count = 1;
|
||||
for(String key : vrp.getJobs().keySet()) {
|
||||
if(count <= 75) {
|
||||
unassigned.add(vrp.getJobs().get(key));
|
||||
}
|
||||
count++;
|
||||
}
|
||||
JobInsertionConsideringFixCostsCalculator jicc = new JobInsertionConsideringFixCostsCalculator(mock(JobInsertionCostsCalculator.class),mock(StateManager.class));
|
||||
ConfigureFixCostCalculator c = new ConfigureFixCostCalculator(vrp,jicc);
|
||||
c.informInsertionStarts(new ArrayList<VehicleRoute>(), unassigned);
|
||||
Assert.assertEquals(0.5, jicc.getSolutionCompletenessRatio(), 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeOne(){
|
||||
List<Job> unassigned = new ArrayList<>();
|
||||
JobInsertionConsideringFixCostsCalculator jicc = new JobInsertionConsideringFixCostsCalculator(mock(JobInsertionCostsCalculator.class),mock(StateManager.class));
|
||||
ConfigureFixCostCalculator c = new ConfigureFixCostCalculator(vrp,jicc);
|
||||
c.informInsertionStarts(new ArrayList<VehicleRoute>(), unassigned);
|
||||
Assert.assertEquals(1.0, jicc.getSolutionCompletenessRatio(), 0.001);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ package com.graphhopper.jsprit.core.algorithm.recreate;
|
|||
import com.graphhopper.jsprit.core.algorithm.state.InternalStates;
|
||||
import com.graphhopper.jsprit.core.problem.Capacity;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -34,11 +35,15 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||
|
||||
private JobInsertionConsideringFixCostsCalculator calc;
|
||||
private IncreasingAbsoluteFixedCosts absFixedCosts;
|
||||
|
||||
private Vehicle oVehicle;
|
||||
private DecreasingRelativeFixedCosts relFixedCosts;
|
||||
|
||||
private Vehicle nVehicle;
|
||||
private Vehicle small;
|
||||
|
||||
private Vehicle medium;
|
||||
|
||||
private Vehicle large;
|
||||
|
||||
private Job job;
|
||||
|
||||
|
|
@ -52,194 +57,333 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
|||
job = mock(Job.class);
|
||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).build());
|
||||
|
||||
oVehicle = mock(Vehicle.class);
|
||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).setFixedCost(50.0).build();
|
||||
when(oVehicle.getType()).thenReturn(oType);
|
||||
small = mock(Vehicle.class);
|
||||
VehicleType smallType = VehicleTypeImpl.Builder.newInstance("smallType").addCapacityDimension(0, 50).setFixedCost(50.0).build();
|
||||
when(small.getType()).thenReturn(smallType);
|
||||
|
||||
nVehicle = mock(Vehicle.class);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).setFixedCost(100.0).build();
|
||||
when(nVehicle.getType()).thenReturn(type);
|
||||
medium = mock(Vehicle.class);
|
||||
VehicleType mediumType = VehicleTypeImpl.Builder.newInstance("mediumType").addCapacityDimension(0, 100).setFixedCost(100.0).build();
|
||||
when(medium.getType()).thenReturn(mediumType);
|
||||
|
||||
InsertionData iData = new InsertionData(0.0, 1, 1, nVehicle, null);
|
||||
large = mock(Vehicle.class);
|
||||
VehicleType largeType = VehicleTypeImpl.Builder.newInstance("largeType").addCapacityDimension(0, 400).setFixedCost(200.0).build();
|
||||
when(large.getType()).thenReturn(largeType);
|
||||
|
||||
InsertionData iData = new InsertionData(0.0, 1, 1, medium, null);
|
||||
route = mock(VehicleRoute.class);
|
||||
|
||||
when(jobInsertionCosts.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE)).thenReturn(iData);
|
||||
when(jobInsertionCosts.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE)).thenReturn(iData);
|
||||
when(jobInsertionCosts.getInsertionData(route, job, large, 0.0, null, Double.MAX_VALUE)).thenReturn(new InsertionData(0.0, 1, 1, large, null));
|
||||
|
||||
stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
calc = new JobInsertionConsideringFixCostsCalculator(jobInsertionCosts, stateGetter);
|
||||
absFixedCosts = new IncreasingAbsoluteFixedCosts(10);
|
||||
relFixedCosts = new DecreasingRelativeFixedCosts(stateGetter, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionComplete_itShouldReturnFixedCostsOfNewVehicle() {
|
||||
calc.setSolutionCompletenessRatio(1.0);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
absFixedCosts.setSolutionCompletenessRatio(1.0);
|
||||
absFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1.0);
|
||||
relFixedCosts.setWeightOfFixCost(1.0);
|
||||
//(1.*absFix + 0.*relFix) * completeness * weight = (1.*100. + 0.*50.) * 1. * 1. = 100.
|
||||
assertEquals(100., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
assertEquals(100., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts() {
|
||||
calc.setSolutionCompletenessRatio(0.0);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.0);
|
||||
absFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.0);
|
||||
relFixedCosts.setWeightOfFixCost(1.0);
|
||||
//(0.*absFix + 1.*relFix) * completeness * weight = 0.
|
||||
assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
|
||||
assertEquals(0., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs50PercentComplete_itShouldReturnAvgOfRelFixedAndAbsFixedCostOfNewVehicle() {
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
absFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
relFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*100+0.5*50)*0.5*1. = 37.5
|
||||
assertEquals(37.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(37.5, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs75PercentComplete_itShouldReturnAvgOfRelFixedAndAbsFixedCostOfNewVehicle() {
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
absFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
relFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*100.+0.25*50.)*0.75*1. = 65.625
|
||||
assertEquals(65.625, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(65.625, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionCompleteAndWeightIs05_itShouldReturnHalfOfFixedCostsOfNewVehicle() {
|
||||
calc.setSolutionCompletenessRatio(1.0);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
absFixedCosts.setSolutionCompletenessRatio(1.0);
|
||||
absFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1.0);
|
||||
relFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*100. + 0.*50.) * 1. * 0.5 = 5.
|
||||
assertEquals(50., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(50., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnHalfOfNoFixedCosts() {
|
||||
calc.setSolutionCompletenessRatio(0.0);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.0);
|
||||
absFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.0);
|
||||
relFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.*absFix + 1.*relFix) * 0. * .5 = 0.
|
||||
assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(0., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnHalfOfAvgOfRelFixedAndAbsFixedCostOfNewVehicle() {
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
absFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
relFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*100+0.5*50)*0.5*0.5 = 18.75
|
||||
assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(18.75, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnHalfOfAvgOfRelFixedAndAbsFixedCostOfNewVehicle() {
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(0.5);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
absFixedCosts.setWeightOfFixCost(0.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
relFixedCosts.setWeightOfFixCost(0.5);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*100.+0.25*50.)*0.75*0.5 = 32.8125
|
||||
assertEquals(32.8125, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(32.8125, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionComplete_itShouldReturnHalfOfFixedCostsOfNewVehicle() {
|
||||
calc.setSolutionCompletenessRatio(1.0);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(1.0);
|
||||
absFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1.0);
|
||||
relFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
|
||||
//(1.*absFix + 0.*relFix) * completeness * weight = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 1. = 50.
|
||||
assertEquals(50., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(50., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts() {
|
||||
calc.setSolutionCompletenessRatio(0.0);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.0);
|
||||
absFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.0);
|
||||
relFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.*absFix + 1.*relFix) * completeness * weight = 0.
|
||||
assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(0., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs50PercentComplete_itShouldCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
absFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
relFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*(100-50)+0.5*(50-0))*0.5*1. = 25.
|
||||
assertEquals(25., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(25., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs75PercentComplete_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
absFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
relFixedCosts.setWeightOfFixCost(1.0);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*(100.-50.)+0.25*(50.-0.))*0.75*1. = 37.5
|
||||
assertEquals(37.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(37.5, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(1.0);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(1.0);
|
||||
absFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1.0);
|
||||
relFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 0.5 = 25.
|
||||
assertEquals(25., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(25., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(0.0);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.0);
|
||||
absFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.0);
|
||||
relFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.*absFix + 1.*relFix) * 0. * .5 = 0.
|
||||
assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(0., absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
absFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
relFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(50-0))*0.5*0.5 = 12.5
|
||||
assertEquals(12.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(12.5, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(0.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
absFixedCosts.setWeightOfFixCost(0.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
relFixedCosts.setWeightOfFixCost(0.5);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(50.-0.))*0.75*0.5 = 18.75
|
||||
assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(18.75, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
absFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.5);
|
||||
relFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).build());
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||
assertEquals(12.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(12.5, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(0.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
absFixedCosts.setWeightOfFixCost(0.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
relFixedCosts.setWeightOfFixCost(0.5);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(75.-25.))*0.75*0.5 = 18.75
|
||||
assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(18.75, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05WithMultipleCapDims_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
absFixedCosts.setSolutionCompletenessRatio(.5);
|
||||
absFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(.5);
|
||||
relFixedCosts.setWeightOfFixCost(.5);
|
||||
|
||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||
|
||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||
when(oVehicle.getType()).thenReturn(oType);
|
||||
when(small.getType()).thenReturn(oType);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||
when(nVehicle.getType()).thenReturn(type);
|
||||
when(medium.getType()).thenReturn(type);
|
||||
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||
/*
|
||||
* (0.5*(100-50)+0.5*(
|
||||
* relFixNew - relFixOld = (75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.) =
|
||||
* )*0.5*0.5
|
||||
* = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5
|
||||
* = (0.5*(100-50)+0.5*12.5)*0.5*0.5 = 7.8125
|
||||
*/
|
||||
assertEquals(7.8125, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsMoreExpensive() {
|
||||
absFixedCosts.setSolutionCompletenessRatio(1);
|
||||
absFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1);
|
||||
relFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||
|
||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||
when(medium.getType()).thenReturn(oType);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||
when(small.getType()).thenReturn(type);
|
||||
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||
/*
|
||||
|
|
@ -249,26 +393,125 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
|||
* = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5
|
||||
* = (0.5*(100-50)+0.5*12.5)*0.5*0.5 = 7.8125
|
||||
*/
|
||||
assertEquals(7.8125, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
|
||||
double insertionCost = absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context);
|
||||
assertEquals(-50d, insertionCost, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallVSMediumAbsCosts() {
|
||||
absFixedCosts.setSolutionCompletenessRatio(1);
|
||||
absFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1);
|
||||
relFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
double insertionCost = absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context);
|
||||
assertEquals(50d, insertionCost, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallVSLargeAbsCosts() {
|
||||
absFixedCosts.setSolutionCompletenessRatio(1);
|
||||
absFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1);
|
||||
relFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, large, null, 0d);
|
||||
double insertionCost = absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context);
|
||||
assertEquals(150d, insertionCost, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void largeVSMediumAbsCosts() {
|
||||
absFixedCosts.setSolutionCompletenessRatio(1);
|
||||
absFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1);
|
||||
relFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
when(route.getVehicle()).thenReturn(large);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
double insertionCost = absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context);
|
||||
assertEquals(-100d, insertionCost, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mediumVSLargeAbsCosts() {
|
||||
absFixedCosts.setSolutionCompletenessRatio(1);
|
||||
absFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(1);
|
||||
relFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
when(route.getVehicle()).thenReturn(medium);
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, large, null, 0d);
|
||||
|
||||
double insertionCost = absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context);
|
||||
assertEquals(100d, insertionCost, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsMoreExpensive2() {
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.1);
|
||||
absFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.1);
|
||||
relFixedCosts.setWeightOfFixCost(1);
|
||||
|
||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||
|
||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||
when(medium.getType()).thenReturn(oType);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||
when(small.getType()).thenReturn(type);
|
||||
|
||||
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
/*
|
||||
job = 50
|
||||
abs = (50 - 100) * 0.1 * 0.1 * 1.0 = -0.5
|
||||
rel = ( (75/50+100/100)/2 * 50 - (25/100 + 100/400)/2 * 100) * 0.9 * 0.1 = 3.375
|
||||
c = -0.5 + 3.375 = 2.875
|
||||
|
||||
*/
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
|
||||
double insertionCost = absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context);
|
||||
assertEquals(2.875, insertionCost, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05WithMultipleCapDims_itShouldReturnCorrectVal() {
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(0.5);
|
||||
absFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
absFixedCosts.setWeightOfFixCost(0.5);
|
||||
|
||||
relFixedCosts.setSolutionCompletenessRatio(0.75);
|
||||
relFixedCosts.setWeightOfFixCost(0.5);
|
||||
|
||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||
|
||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||
when(oVehicle.getType()).thenReturn(oType);
|
||||
when(small.getType()).thenReturn(oType);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||
when(nVehicle.getType()).thenReturn(type);
|
||||
when(medium.getType()).thenReturn(type);
|
||||
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
when(route.getVehicle()).thenReturn(small);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, job, medium, null, 0d);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*12.5)*0.75*0.5 = 15.234375
|
||||
|
||||
assertEquals(15.234375, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
assertEquals(15.234375, absFixedCosts.getCosts(context) + relFixedCosts.getCosts(context), 0.01);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
insertionCalculator.setJobActivityFactory(activityFactory);
|
||||
|
||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||
assertEquals(InsertionData.createEmptyInsertionData(), iData);
|
||||
assertTrue(iData instanceof InsertionData.NoInsertionFound);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|||
import com.graphhopper.jsprit.core.problem.cost.WaitingTimeCosts;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
import com.graphhopper.jsprit.core.problem.job.Shipment;
|
||||
import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.End;
|
||||
|
|
@ -91,6 +92,74 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
return Location.Builder.newInstance().setId(i).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingServiceBetweenDiffStartAndEnd_costMustBeCorrect() {
|
||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v")
|
||||
.setStartLocation(Location.newInstance(0, 0))
|
||||
.setEndLocation(Location.newInstance(20, 0))
|
||||
.build();
|
||||
Service s = Service.Builder.newInstance("s")
|
||||
.setLocation(Location.newInstance(10, 0))
|
||||
.build();
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||
.addVehicle(v)
|
||||
.addJob(s)
|
||||
.build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
JobInsertionContext jobInsertionContext =
|
||||
new JobInsertionContext(route, s, v, null, 0);
|
||||
LocalActivityInsertionCostsCalculator localActivityInsertionCostsCalculator =
|
||||
new LocalActivityInsertionCostsCalculator(
|
||||
vrp.getTransportCosts(),
|
||||
vrp.getActivityCosts(),
|
||||
new StateManager(vrp));
|
||||
double cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
new Start(v.getStartLocation(),0,Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(0),
|
||||
0);
|
||||
assertEquals(20., cost, Math.ulp(20.));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingShipmentBetweenDiffStartAndEnd_costMustBeCorrect() {
|
||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v")
|
||||
.setStartLocation(Location.newInstance(0, 0))
|
||||
.setEndLocation(Location.newInstance(20, 0))
|
||||
.build();
|
||||
Shipment s = Shipment.Builder.newInstance("p")
|
||||
.setPickupLocation(Location.newInstance(10, 0))
|
||||
.setDeliveryLocation(Location.newInstance(10, 7.5))
|
||||
.build();
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||
.addVehicle(v)
|
||||
.addJob(s)
|
||||
.build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
JobInsertionContext jobInsertionContext =
|
||||
new JobInsertionContext(route, s, v, null, 0);
|
||||
LocalActivityInsertionCostsCalculator localActivityInsertionCostsCalculator =
|
||||
new LocalActivityInsertionCostsCalculator(
|
||||
vrp.getTransportCosts(),
|
||||
vrp.getActivityCosts(),
|
||||
new StateManager(vrp));
|
||||
double cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
new Start(v.getStartLocation(),0,Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(0),
|
||||
0);
|
||||
assertEquals(20., cost, Math.ulp(20.));
|
||||
cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
vrp.getActivities(s).get(0),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(1),
|
||||
0);
|
||||
assertEquals(10, cost, Math.ulp(10.));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts() {
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Licensed to GraphHopper GmbH under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* GraphHopper GmbH licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.graphhopper.jsprit.core.algorithm.ruin;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 13/01/17.
|
||||
*/
|
||||
public class StringUtilTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
int stringLength = 4;
|
||||
int seedIndex = 4;
|
||||
int noActivities = 10;
|
||||
List<Integer> bounds = StringUtil.getLowerBoundsOfAllStrings(stringLength, seedIndex, noActivities);
|
||||
Assert.assertEquals(4, bounds.size());
|
||||
Assert.assertEquals(1, (int) bounds.get(0));
|
||||
Assert.assertEquals(2, (int) bounds.get(1));
|
||||
Assert.assertEquals(3, (int) bounds.get(2));
|
||||
Assert.assertEquals(4, (int) bounds.get(3));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
int stringLength = 4;
|
||||
int seedIndex = 2;
|
||||
int noActivities = 10;
|
||||
List<Integer> bounds = StringUtil.getLowerBoundsOfAllStrings(stringLength, seedIndex, noActivities);
|
||||
Assert.assertEquals(3, bounds.size());
|
||||
Assert.assertEquals(0, (int) bounds.get(0));
|
||||
Assert.assertEquals(1, (int) bounds.get(1));
|
||||
Assert.assertEquals(2, (int) bounds.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
int stringLength = 4;
|
||||
int seedIndex = 0;
|
||||
int noActivities = 10;
|
||||
List<Integer> bounds = StringUtil.getLowerBoundsOfAllStrings(stringLength, seedIndex, noActivities);
|
||||
Assert.assertEquals(1, bounds.size());
|
||||
Assert.assertEquals(0, (int) bounds.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4() {
|
||||
int stringLength = 4;
|
||||
int seedIndex = 9;
|
||||
int noActivities = 10;
|
||||
List<Integer> bounds = StringUtil.getLowerBoundsOfAllStrings(stringLength, seedIndex, noActivities);
|
||||
Assert.assertEquals(1, bounds.size());
|
||||
Assert.assertEquals(6, (int) bounds.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5() {
|
||||
int stringLength = 4;
|
||||
int seedIndex = 8;
|
||||
int noActivities = 10;
|
||||
List<Integer> bounds = StringUtil.getLowerBoundsOfAllStrings(stringLength, seedIndex, noActivities);
|
||||
Assert.assertEquals(2, bounds.size());
|
||||
Assert.assertEquals(5, (int) bounds.get(0));
|
||||
Assert.assertEquals(6, (int) bounds.get(1));
|
||||
}
|
||||
}
|
||||
|
|
@ -18,10 +18,18 @@
|
|||
|
||||
package com.graphhopper.jsprit.core.problem;
|
||||
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 16.12.14.
|
||||
*/
|
||||
|
|
@ -34,6 +42,12 @@ public class LocationTest {
|
|||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNameSet_buildLocation() {
|
||||
Location l = Location.Builder.newInstance().setName("mystreet 6a").setIndex(1).build();
|
||||
Assert.assertEquals("mystreet 6a",l.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIndexSetWitFactory_returnCorrectLocation() {
|
||||
Location l = Location.newInstance(1);
|
||||
|
|
@ -68,19 +82,31 @@ public class LocationTest {
|
|||
@Test
|
||||
public void whenCoordinateSet_build() {
|
||||
Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20)).build();
|
||||
Assert.assertEquals(10., l.getCoordinate().getX());
|
||||
Assert.assertEquals(20., l.getCoordinate().getY());
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(),0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(),0.001);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCoordinateSetWithFactory_returnCorrectLocation() {
|
||||
// Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
||||
// Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
||||
Location l = Location.newInstance(10, 20);
|
||||
Assert.assertEquals(10., l.getCoordinate().getX());
|
||||
Assert.assertEquals(20., l.getCoordinate().getY());
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(),0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(),0.001);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheLocation() {
|
||||
Location one = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Location two = Location.Builder.newInstance().setIndex(1).setUserData(42).build();
|
||||
Location three = Location.Builder.newInstance().setIndex(2).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import com.graphhopper.jsprit.core.problem.job.Shipment;
|
|||
import com.graphhopper.jsprit.core.problem.misc.ActivityContext;
|
||||
import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
|
||||
|
|
@ -47,7 +48,9 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
|
||||
Delivery d1;
|
||||
|
||||
Shipment shipment;
|
||||
Shipment s1;
|
||||
|
||||
Shipment s2;
|
||||
|
||||
Delivery d2;
|
||||
|
||||
|
|
@ -68,8 +71,13 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
|
||||
private void ini(double maxTime){
|
||||
d1 = Delivery.Builder.newInstance("d1").setLocation(Location.newInstance(10,0)).build();
|
||||
shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.newInstance(20,0))
|
||||
|
||||
s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(20,0))
|
||||
.setDeliveryLocation(Location.newInstance(40,0)).setMaxTimeInVehicle(maxTime).build();
|
||||
|
||||
s2 = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance(20,0))
|
||||
.setDeliveryLocation(Location.newInstance(40,0)).setMaxTimeInVehicle(maxTime).build();
|
||||
|
||||
d2 = Delivery.Builder.newInstance("d2").setLocation(Location.newInstance(30,0)).setServiceTime(10).build();
|
||||
|
||||
p1 = Pickup.Builder.newInstance("p1").setLocation(Location.newInstance(10, 0)).build();
|
||||
|
|
@ -77,11 +85,59 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
|
||||
v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
|
||||
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance().addJob(d1).addJob(shipment).addJob(d2).addJob(p1).addJob(p2)
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance().addJob(d1).addJob(s1).addJob(d2).addJob(p1).addJob(p2)
|
||||
.addVehicle(v).build();
|
||||
|
||||
route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory())
|
||||
.addDelivery(d1).addPickup(shipment).addDelivery(shipment).build();
|
||||
.addDelivery(d1).addPickup(s1).addDelivery(s1).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shiftOfExistingShipmentsShouldWork(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(20,0))
|
||||
.setDeliveryLocation(Location.newInstance(40,0)).setMaxTimeInVehicle(20).build();
|
||||
|
||||
Shipment s2 = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance(20,0))
|
||||
.setPickupServiceTime(10)
|
||||
.setDeliveryLocation(Location.newInstance(40,0)).setMaxTimeInVehicle(20).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(v).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory())
|
||||
.addPickup(s1).addDelivery(s1).build();
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
StateId latestStartId = stateManager.createStateId("latest-start-id");
|
||||
|
||||
UpdateMaxTimeInVehicle updater = new UpdateMaxTimeInVehicle(stateManager,latestStartId,vrp.getTransportCosts(), vrp.getActivityCosts());
|
||||
stateManager.addStateUpdater(updater);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route),new ArrayList<Job>());
|
||||
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager, vrp);
|
||||
JobInsertionContext c = new JobInsertionContext(route,s2,v,route.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(s2);
|
||||
|
||||
c.getAssociatedActivities().add(acts.get(0));
|
||||
c.getAssociatedActivities().add(acts.get(1));
|
||||
|
||||
Assert.assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, constraint.fulfilled(c, route.getStart(), acts.get(0), route.getActivities().get(0), 0));
|
||||
Assert.assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, constraint.fulfilled(c, act(route,0), acts.get(0), act(route,1), 20));
|
||||
Assert.assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, constraint.fulfilled(c, act(route,1), acts.get(0), route.getEnd(), 40));
|
||||
|
||||
//insert pickup at 0
|
||||
c.setRelatedActivityContext(new ActivityContext());
|
||||
c.getRelatedActivityContext().setArrivalTime(20);
|
||||
c.getRelatedActivityContext().setEndTime(30);
|
||||
c.getRelatedActivityContext().setInsertionIndex(0);
|
||||
|
||||
Assert.assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, constraint.fulfilled(c, acts.get(0), acts.get(1), act(route,0), 30));
|
||||
Assert.assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, constraint.fulfilled(c, act(route,0), acts.get(1), act(route,1), 30));
|
||||
}
|
||||
|
||||
private TourActivity act(VehicleRoute route, int index){
|
||||
return route.getActivities().get(index);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -94,7 +150,7 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
stateManager.addStateUpdater(updater);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route),new ArrayList<Job>());
|
||||
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager);
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager, vrp);
|
||||
JobInsertionContext c = new JobInsertionContext(route,d2,v,route.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(d2);
|
||||
c.getAssociatedActivities().add(acts.get(0));
|
||||
|
|
@ -116,7 +172,7 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
stateManager.addStateUpdater(updater);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route),new ArrayList<Job>());
|
||||
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager);
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager, vrp);
|
||||
JobInsertionContext c = new JobInsertionContext(route,d2,v,route.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(d2);
|
||||
c.getAssociatedActivities().add(acts.get(0));
|
||||
|
|
@ -142,9 +198,9 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
stateManager.addStateUpdater(updater);
|
||||
stateManager.informInsertionStarts(Arrays.asList(r),new ArrayList<Job>());
|
||||
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager);
|
||||
JobInsertionContext c = new JobInsertionContext(r,shipment,v,r.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(shipment);
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager, vrp);
|
||||
JobInsertionContext c = new JobInsertionContext(r, s1,v,r.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(s1);
|
||||
c.getAssociatedActivities().add(acts.get(0));
|
||||
c.getAssociatedActivities().add(acts.get(1));
|
||||
|
||||
|
|
@ -169,8 +225,8 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
// stateManager.informInsertionStarts(Arrays.asList(r),new ArrayList<Job>());
|
||||
//
|
||||
// MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(), vrp.getActivityCosts(), latestStartId, stateManager);
|
||||
// JobInsertionContext c = new JobInsertionContext(r,shipment,v,r.getDriver(),0.);
|
||||
// List<AbstractActivity> acts = vrp.getActivities(shipment);
|
||||
// JobInsertionContext c = new JobInsertionContext(r,s1,v,r.getDriver(),0.);
|
||||
// List<AbstractActivity> acts = vrp.getActivities(s1);
|
||||
// c.getAssociatedActivities().add(acts.get(0));
|
||||
// c.getAssociatedActivities().add(acts.get(1));
|
||||
//
|
||||
|
|
@ -192,14 +248,14 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
StateId latestStartId = stateManager.createStateId("latest-start-id");
|
||||
|
||||
Map<String,Double> maxTimes = new HashMap<>();
|
||||
maxTimes.put("shipment",25d);
|
||||
maxTimes.put("s1",25d);
|
||||
UpdateMaxTimeInVehicle updater = new UpdateMaxTimeInVehicle(stateManager,latestStartId,vrp.getTransportCosts(), vrp.getActivityCosts());
|
||||
stateManager.addStateUpdater(updater);
|
||||
stateManager.informInsertionStarts(Arrays.asList(r),new ArrayList<Job>());
|
||||
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager);
|
||||
JobInsertionContext c = new JobInsertionContext(r,shipment,v,r.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(shipment);
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager, vrp);
|
||||
JobInsertionContext c = new JobInsertionContext(r, s1,v,r.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(s1);
|
||||
c.getAssociatedActivities().add(acts.get(0));
|
||||
c.getAssociatedActivities().add(acts.get(1));
|
||||
|
||||
|
|
@ -223,14 +279,14 @@ public class MaxTimeInVehicleConstraintTest {
|
|||
StateId latestStartId = stateManager.createStateId("latest-start-id");
|
||||
|
||||
Map<String,Double> maxTimes = new HashMap<>();
|
||||
maxTimes.put("shipment",25d);
|
||||
maxTimes.put("s1",25d);
|
||||
UpdateMaxTimeInVehicle updater = new UpdateMaxTimeInVehicle(stateManager,latestStartId,vrp.getTransportCosts(), vrp.getActivityCosts());
|
||||
stateManager.addStateUpdater(updater);
|
||||
stateManager.informInsertionStarts(Arrays.asList(r),new ArrayList<Job>());
|
||||
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager);
|
||||
JobInsertionContext c = new JobInsertionContext(r,shipment,v,r.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(shipment);
|
||||
MaxTimeInVehicleConstraint constraint = new MaxTimeInVehicleConstraint(vrp.getTransportCosts(),vrp.getActivityCosts() , latestStartId, stateManager, vrp);
|
||||
JobInsertionContext c = new JobInsertionContext(r, s1,v,r.getDriver(),0.);
|
||||
List<AbstractActivity> acts = vrp.getActivities(s1);
|
||||
c.getAssociatedActivities().add(acts.get(0));
|
||||
c.getAssociatedActivities().add(acts.get(1));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,357 @@
|
|||
/*
|
||||
* Licensed to GraphHopper GmbH under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* GraphHopper GmbH licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.graphhopper.jsprit.core.problem.constraint;
|
||||
|
||||
|
||||
import com.graphhopper.jsprit.core.algorithm.state.StateId;
|
||||
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.job.Delivery;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import com.graphhopper.jsprit.core.problem.job.Pickup;
|
||||
import com.graphhopper.jsprit.core.problem.job.Shipment;
|
||||
import com.graphhopper.jsprit.core.problem.misc.ActivityContext;
|
||||
import com.graphhopper.jsprit.core.problem.misc.JobInsertionContext;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.End;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.Start;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.util.ManhattanCosts;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 18/05/16.
|
||||
*/
|
||||
public class VehicleDependentTraveledDistanceTest {
|
||||
|
||||
StateManager stateManager;
|
||||
|
||||
VehicleRoute route;
|
||||
|
||||
StateId traveledDistanceId;
|
||||
|
||||
Vehicle vehicle;
|
||||
|
||||
Vehicle vehicle2;
|
||||
|
||||
VehicleRoutingProblem vrp;
|
||||
|
||||
Delivery d1,d2,newDelivery;
|
||||
|
||||
Pickup pickup;
|
||||
|
||||
Shipment s1;
|
||||
|
||||
Map<Vehicle,Double> maxDistanceMap;
|
||||
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
|
||||
vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(10,10)).build();
|
||||
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,200d);
|
||||
maxDistanceMap.put(vehicle2,200d);
|
||||
|
||||
d1 = Delivery.Builder.newInstance("d1").setLocation(Location.newInstance(10,10)).build();
|
||||
d2 = Delivery.Builder.newInstance("d2").setLocation(Location.newInstance(20,15)).build();
|
||||
pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(50,50)).build();
|
||||
s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(35,30))
|
||||
.setDeliveryLocation(Location.newInstance(20,25)).build();
|
||||
|
||||
newDelivery = Delivery.Builder.newInstance("new").setLocation(Location.newInstance(-10,10)).build();
|
||||
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||
.setRoutingCost(new ManhattanCosts()).addVehicle(vehicle).addVehicle(vehicle2)
|
||||
.addJob(d1).addJob(d2).addJob(s1).addJob(pickup).addJob(newDelivery).build();
|
||||
|
||||
route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory())
|
||||
.addDelivery(d1).addDelivery(d2).addPickup(s1).addPickup(pickup).addDelivery(s1).build();
|
||||
|
||||
stateManager = new StateManager(vrp);
|
||||
|
||||
traveledDistanceId = stateManager.createStateId("traveledDistance");
|
||||
|
||||
com.graphhopper.jsprit.core.algorithm.state.VehicleDependentTraveledDistance traveledDistance =
|
||||
new com.graphhopper.jsprit.core.algorithm.state.VehicleDependentTraveledDistance(new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return new ManhattanCosts().getDistance(from,to,departureTime,vehicle);
|
||||
}
|
||||
},stateManager,traveledDistanceId,Arrays.asList(vehicle,vehicle2));
|
||||
|
||||
stateManager.addStateUpdater(traveledDistance);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationIsSet_constraintShouldWork(){
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0))
|
||||
.setEndLocation(Location.newInstance(10,0)).build();
|
||||
Pickup pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(10,0)).build();
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(pickup).build();
|
||||
route = VehicleRoute.emptyRoute();
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,5d);
|
||||
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(new StateManager(vrp), traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,pickup,vehicle,null,0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(),0,Double.MAX_VALUE),vrp.getActivities(pickup).get(0),
|
||||
new End(vehicle.getEndLocation(),0,Double.MAX_VALUE),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
}
|
||||
|
||||
/*
|
||||
vehicle: 200.0
|
||||
vehicle (max distance): 200.0
|
||||
vehicle2: 160.0
|
||||
vehicle2 (max distance): 180.0
|
||||
*/
|
||||
@Test
|
||||
public void insertNewInVehicleShouldFail(){
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,newDelivery,vehicle,null,0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,route.getStart(),newAct(),act(0),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(0),newAct(),act(1),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(1),newAct(),act(2),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(2),newAct(),act(3),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(3),newAct(),act(4),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(4),newAct(),route.getEnd(),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void insertNewInVehicle2ShouldBeCorrect(){
|
||||
//current distance vehicle2: 160 allowed: 200
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,newDelivery,vehicle2,null,0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,route.getStart(),newAct(),act(0),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
//additional distance: 20+35-15=40
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(0),newAct(),act(1),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
//additional distance: 35+65-30=70
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(1),newAct(),act(2),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 65+100-35
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(2),newAct(),act(3),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 100+45-55
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(3),newAct(),act(4),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 45+20-25
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(4),newAct(),route.getEnd(),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
}
|
||||
|
||||
private TourActivity act(int i) {
|
||||
return route.getActivities().get(i);
|
||||
}
|
||||
|
||||
private TourActivity newAct(){
|
||||
return vrp.getActivities(newDelivery).get(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traveledDistanceShouldBeCorrect(){
|
||||
Assert.assertEquals(20d,stateManager.getActivityState(route.getActivities().get(0),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(35d,stateManager.getActivityState(route.getActivities().get(1),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(65d,stateManager.getActivityState(route.getActivities().get(2),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(100d,stateManager.getActivityState(route.getActivities().get(3),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(155d,stateManager.getActivityState(route.getActivities().get(4),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traveledDistanceWithVehicle2ShouldBeCorrect(){
|
||||
Assert.assertEquals(0d,stateManager.getActivityState(route.getActivities().get(0),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(15d,stateManager.getActivityState(route.getActivities().get(1),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(45d,stateManager.getActivityState(route.getActivities().get(2),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(80d,stateManager.getActivityState(route.getActivities().get(3),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(135d,stateManager.getActivityState(route.getActivities().get(4),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfShipmentInRoute(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle,traveledDistanceId, Double.class);
|
||||
double traveledDistanceBeforeDelivery = stateManager.getActivityState(route.getActivities().get(4), vehicle, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(90d,traveledDistanceBeforeDelivery-traveledDistanceBeforePickup,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfShipmentInRouteVehicle2(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle2,traveledDistanceId, Double.class);
|
||||
double traveledDistanceBeforeDelivery = stateManager.getActivityState(route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(90d,traveledDistanceBeforeDelivery-traveledDistanceBeforePickup,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfPickupInRoute(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(3), vehicle, traveledDistanceId, Double.class);
|
||||
double total = stateManager.getRouteState(route, vehicle,traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(100d,total-traveledDistanceBeforePickup,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfPickupInRouteVehicle2(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class);
|
||||
double total = stateManager.getRouteState(route, vehicle2,traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(80d,total-traveledDistanceBeforePickup,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceToTravelShouldBeCorrect(){
|
||||
double total = stateManager.getRouteState(route, vehicle, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(180d,total - stateManager.getActivityState(route.getActivities().get(0),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(165d, total - stateManager.getActivityState(route.getActivities().get(1), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(135d,total - stateManager.getActivityState(route.getActivities().get(2),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(100d, total - stateManager.getActivityState(route.getActivities().get(3), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(45d, total - stateManager.getActivityState(route.getActivities().get(4), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceToTravelShouldBeCorrectVehicle2(){
|
||||
double total = stateManager.getRouteState(route, vehicle2, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(160d,total - stateManager.getActivityState(route.getActivities().get(0),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(145d, total - stateManager.getActivityState(route.getActivities().get(1), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(115d,total - stateManager.getActivityState(route.getActivities().get(2),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(80d, total - stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(25d, total - stateManager.getActivityState(route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingDeliverShipment_constraintShouldWork() {
|
||||
Shipment shipment = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation(Location.newInstance(0, 3))
|
||||
.setDeliveryLocation(Location.newInstance(4, 0))
|
||||
.build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v")
|
||||
.setStartLocation(Location.newInstance(0, 0))
|
||||
.build();
|
||||
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||
.addJob(shipment)
|
||||
.addVehicle(vehicle)
|
||||
.build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
JobInsertionContext context = new JobInsertionContext(route, shipment, vehicle, null, 0);
|
||||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(0));
|
||||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(1));
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,12d);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(shipment).get(0),
|
||||
new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
|
||||
ActivityContext pickupContext = new ActivityContext();
|
||||
pickupContext.setArrivalTime(3);
|
||||
pickupContext.setEndTime(3);
|
||||
pickupContext.setInsertionIndex(0);
|
||||
context.setRelatedActivityContext(pickupContext);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
vrp.getActivities(shipment).get(0),
|
||||
vrp.getActivities(shipment).get(1),
|
||||
new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
3).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingDeliverShipmentWithVehDiffStartEndLocs_constraintShouldWork() {
|
||||
Shipment shipment = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation(Location.newInstance(0, 1))
|
||||
.setDeliveryLocation(Location.newInstance(4, 1))
|
||||
.build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v")
|
||||
.setStartLocation(Location.newInstance(0, 0))
|
||||
.setEndLocation(Location.newInstance(0, 4))
|
||||
.build();
|
||||
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||
.addJob(shipment)
|
||||
.addVehicle(vehicle)
|
||||
.build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
JobInsertionContext context = new JobInsertionContext(route, shipment, vehicle, null, 0);
|
||||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(0));
|
||||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(1));
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,10d);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(shipment).get(0),
|
||||
new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
|
||||
ActivityContext pickupContext = new ActivityContext();
|
||||
pickupContext.setArrivalTime(1);
|
||||
pickupContext.setEndTime(1);
|
||||
pickupContext.setInsertionIndex(0);
|
||||
context.setRelatedActivityContext(pickupContext);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
vrp.getActivities(shipment).get(0),
|
||||
vrp.getActivities(shipment).get(1),
|
||||
new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
1).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
}
|
||||
}
|
||||
|
|
@ -17,11 +17,18 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
|
||||
public class DeliveryTest {
|
||||
|
||||
|
|
@ -33,9 +40,9 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
assertEquals(2, one.getSize().get(0));
|
||||
assertEquals(4, one.getSize().get(1));
|
||||
|
|
@ -45,7 +52,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -53,7 +60,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -61,7 +68,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
|
@ -69,7 +76,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -77,7 +84,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -85,21 +92,21 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe(){
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
|
|
@ -119,4 +126,16 @@ public class DeliveryTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Delivery two = Delivery.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42)
|
||||
.build();
|
||||
Delivery three = Delivery.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,18 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
|
||||
public class PickupTest {
|
||||
|
||||
|
|
@ -33,9 +40,9 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
assertEquals(2, one.getSize().get(0));
|
||||
assertEquals(4, one.getSize().get(1));
|
||||
|
|
@ -45,7 +52,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -53,7 +60,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -61,7 +68,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -70,7 +77,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -78,7 +85,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -86,7 +93,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
|
|
@ -94,17 +101,29 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Pickup two = Pickup.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||
Pickup three = Pickup.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void whenAddingMaxTimeInVehicle_itShouldThrowEx(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
|
|
|
|||
|
|
@ -17,17 +17,25 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.*;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
|
||||
public class ServiceTest {
|
||||
|
||||
|
|
@ -53,7 +61,7 @@ public class ServiceTest {
|
|||
Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build();
|
||||
Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build();
|
||||
serviceSet.add(one);
|
||||
// assertTrue(serviceSet.contains(two));
|
||||
// assertTrue(serviceSet.contains(two));
|
||||
serviceSet.remove(two);
|
||||
assertTrue(serviceSet.isEmpty());
|
||||
}
|
||||
|
|
@ -67,16 +75,16 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -84,7 +92,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Service one = Service.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -116,71 +124,71 @@ public class ServiceTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build();
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
@Test
|
||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build();
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").build();
|
||||
}
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenServiceTimeSmallerZero_throwIllegalStateException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build();
|
||||
}
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenServiceTimeSmallerZero_throwIllegalStateException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingServiceTime_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build();
|
||||
assertEquals(1.0,s.getServiceDuration(),0.01);
|
||||
}
|
||||
@Test
|
||||
public void whenSettingServiceTime_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build();
|
||||
assertEquals(1.0,s.getServiceDuration(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenTimeWindowIsNull_throwException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build();
|
||||
}
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenTimeWindowIsNull_throwException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||
}
|
||||
@Test
|
||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSeveralTimeWindows_itShouldBeSetCorrectly(){
|
||||
TimeWindow tw1 = TimeWindow.newInstance(1.0, 2.0);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(3.0, 5.0);
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(tw1)
|
||||
.addTimeWindow(tw2)
|
||||
.build();
|
||||
.addTimeWindow(tw1)
|
||||
.addTimeWindow(tw2)
|
||||
.build();
|
||||
assertEquals(2, s.getTimeWindows().size());
|
||||
assertThat(s.getTimeWindows(),hasItem(is(tw1)));
|
||||
assertThat(s.getTimeWindows(),hasItem(is(tw2)));
|
||||
|
|
@ -189,7 +197,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingTimeWindow_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -200,7 +208,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -208,66 +216,73 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldKnowMultipleTimeWindows(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.setName("name").build();
|
||||
assertEquals(2,s.getTimeWindows().size());
|
||||
}
|
||||
@Test
|
||||
public void shouldKnowMultipleTimeWindows(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.setName("name").build();
|
||||
assertEquals(2,s.getTimeWindows().size());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap_throwEx(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0.,10.))
|
||||
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
||||
.setName("name").build();
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap_throwEx(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0.,10.))
|
||||
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
||||
.setName("name").build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap2_throwEx(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
||||
.setName("name").build();
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap2_throwEx(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
||||
.setName("name").build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
.setPriority(1).build();
|
||||
Assert.assertEquals(1, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(10).build();
|
||||
Assert.assertEquals(10, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
.setPriority(30).build();
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
.setPriority(0).build();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -285,4 +300,17 @@ public class ServiceTest {
|
|||
Assert.assertEquals(Double.MAX_VALUE, s.getMaxTimeInVehicle(),0.001);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Service two = Service.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42)
|
||||
.build();
|
||||
Service three = Service.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,25 +17,34 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import com.graphhopper.jsprit.core.util.TestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ShipmentTest {
|
||||
|
||||
@Test
|
||||
public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
|
||||
assertTrue(one != two);
|
||||
}
|
||||
|
|
@ -43,9 +52,9 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
|
||||
assertTrue(one.equals(two));
|
||||
}
|
||||
|
|
@ -53,7 +62,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
assertEquals(10, one.getSize().get(0));
|
||||
}
|
||||
|
||||
|
|
@ -61,24 +70,24 @@ public class ShipmentTest {
|
|||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenIdIsNull_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance(null).addSizeDimension(0, 10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -115,7 +124,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupCoordIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build();
|
||||
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getPickupLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
||||
|
|
@ -126,7 +135,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
||||
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
||||
}
|
||||
|
|
@ -135,8 +144,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryCoordIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(1, 2)))
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build())
|
||||
.build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build())
|
||||
.build();
|
||||
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
||||
|
|
@ -146,22 +155,22 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupServiceTimeIsNotSet_itShouldBeZero() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(0.0, s.getPickupServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryServiceTimeIsNotSet_itShouldBeZero() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(0.0, s.getDeliveryServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setPickupServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setPickupServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(2.0, s.getPickupServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
|
|
@ -169,13 +178,13 @@ public class ShipmentTest {
|
|||
public void whenPickupServiceIsSmallerThanZero_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupServiceTime(-2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(2.0, s.getDeliveryServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +210,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -222,7 +231,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -230,7 +239,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddDeliveryTimeWindow_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -238,7 +247,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddDeliveryTimeWindow2_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -248,7 +257,7 @@ public class ShipmentTest {
|
|||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(tw1).addDeliveryTimeWindow(tw2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(s.getDeliveryTimeWindows().size(),2);
|
||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw1)));
|
||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2)));
|
||||
|
|
@ -257,7 +266,7 @@ public class ShipmentTest {
|
|||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -267,7 +276,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddPickupTimeWindow_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -275,7 +284,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddPickupTimeWindow2_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -285,7 +294,7 @@ public class ShipmentTest {
|
|||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(tw1).addPickupTimeWindow(tw2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(s.getPickupTimeWindows().size(),2);
|
||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw1)));
|
||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw2)));
|
||||
|
|
@ -294,7 +303,7 @@ public class ShipmentTest {
|
|||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -305,26 +314,26 @@ public class ShipmentTest {
|
|||
public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, -2)
|
||||
.build();
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, -2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Shipment one = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -332,8 +341,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 1)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -341,8 +350,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -351,9 +360,9 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -361,8 +370,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -370,15 +379,15 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.setName("name").build();
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingLocation_itShouldWork() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
||||
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
||||
assertEquals("loc", s.getPickupLocation().getId());
|
||||
assertEquals("loc", s.getPickupLocation().getId());
|
||||
assertEquals("del", s.getDeliveryLocation().getId());
|
||||
|
|
@ -388,43 +397,64 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
Assert.assertEquals(1, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(10).build();
|
||||
Assert.assertEquals(10, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(new HashMap<String, Object>()).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||
Shipment three = Shipment.Builder.newInstance("s3").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
@Test
|
||||
public void whenAddingMaxTimeInVehicle_itShouldBeSet(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")).setDeliveryLocation(Location.newInstance("loc"))
|
||||
|
|
|
|||
|
|
@ -18,12 +18,20 @@
|
|||
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class VehicleImplTest {
|
||||
|
|
@ -39,10 +47,10 @@ public class VehicleImplTest {
|
|||
@Test
|
||||
public void whenAddingDriverBreak_itShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Break aBreak = (Break) Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build();
|
||||
Break aBreak = Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start"))
|
||||
.setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.setBreak(aBreak).build();
|
||||
.setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.setBreak(aBreak).build();
|
||||
assertNotNull(v.getBreak());
|
||||
assertEquals(100., v.getBreak().getTimeWindow().getStart(), 0.1);
|
||||
assertEquals(200., v.getBreak().getTimeWindow().getEnd(), 0.1);
|
||||
|
|
@ -54,7 +62,7 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("screwdriver"));
|
||||
|
|
@ -64,7 +72,7 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("dRill"));
|
||||
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -233,9 +241,23 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").build();
|
||||
.addSkill("drill").build();
|
||||
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheVehicle() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle one = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(new HashMap<String, Object>()).build();
|
||||
Vehicle two = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(42).build();
|
||||
Vehicle three = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,15 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class VehicleTypeImplTest {
|
||||
|
||||
|
|
@ -32,18 +38,18 @@ public class VehicleTypeImplTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, type.getCapacityDimensions().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_dimValuesMustBeCorrect() {
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, type.getCapacityDimensions().get(0));
|
||||
assertEquals(4, type.getCapacityDimensions().get(1));
|
||||
}
|
||||
|
|
@ -152,4 +158,15 @@ public class VehicleTypeImplTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheVehicleType() {
|
||||
VehicleType one = VehicleTypeImpl.Builder.newInstance("type").setUserData(new HashMap<String, Object>())
|
||||
.build();
|
||||
VehicleType two = VehicleTypeImpl.Builder.newInstance("type").setUserData(42).build();
|
||||
VehicleType three = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ public class FastVehicleRoutingTransportCostsMatrixTest {
|
|||
assertEquals(2., matrix.getDistance(2, 1), 0.1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenAddingDistanceToAsymmetricMatrix_itShouldReturnCorrectValues() {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, false);
|
||||
|
|
@ -62,6 +63,18 @@ public class FastVehicleRoutingTransportCostsMatrixTest {
|
|||
assertEquals(2., matrix.getTransportTime(loc(2), loc(1), 0.0, null, null), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTimeAndDistanceToSymmetricMatrix_itShouldReturnCorrectValues2() {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, true);
|
||||
matrixBuilder.addTransportTimeAndDistance(1, 2, 2.,100.);
|
||||
FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2., matrix.getTransportTime(loc(1), loc(2), 0.0, null, null), 0.1);
|
||||
assertEquals(2., matrix.getTransportTime(loc(2), loc(1), 0.0, null, null), 0.1);
|
||||
|
||||
assertEquals(100., matrix.getDistance(loc(1), loc(2), 0.0, null), 0.1);
|
||||
assertEquals(100., matrix.getDistance(loc(2), loc(1), 0.0, null), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTimeToAsymmetricMatrix_itShouldReturnCorrectValues() {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, false);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* Licensed to GraphHopper GmbH under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* GraphHopper GmbH licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.graphhopper.jsprit.core.util;
|
||||
|
||||
import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
|
||||
import com.graphhopper.jsprit.core.algorithm.state.StateId;
|
||||
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.MaxDistanceConstraint;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import org.apache.commons.math3.stat.Frequency;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 06/02/17.
|
||||
*/
|
||||
public class UnassignedJobReasonTrackerTest {
|
||||
|
||||
Vehicle vehicle;
|
||||
|
||||
@Before
|
||||
public void doBefore() {
|
||||
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 1);
|
||||
VehicleType vehicleType = vehicleTypeBuilder.build();
|
||||
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
|
||||
vehicleBuilder.setStartLocation(Location.newInstance(10, 10));
|
||||
vehicleBuilder.setType(vehicleType);
|
||||
vehicleBuilder.setEarliestStart(0).setLatestArrival(100);
|
||||
vehicle = vehicleBuilder.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCorrectCapacityReasonCode() {
|
||||
Service service = Service.Builder.newInstance("1").addSizeDimension(0, 5).setLocation(Location.newInstance(5, 7)).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addVehicle(vehicle).addJob(service)
|
||||
.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||
UnassignedJobReasonTracker reasonTracker = new UnassignedJobReasonTracker();
|
||||
vra.addListener(reasonTracker);
|
||||
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||
Assert.assertEquals(1, solution.getUnassignedJobs().size());
|
||||
Assert.assertEquals(3, reasonTracker.getMostLikelyReasonCode(solution.getUnassignedJobs().iterator().next().getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCorrectSkillReasonCode() {
|
||||
Service service = Service.Builder.newInstance("1").addSizeDimension(0, 1).addRequiredSkill("ice").setLocation(Location.newInstance(5, 7)).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addVehicle(vehicle).addJob(service)
|
||||
.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||
UnassignedJobReasonTracker reasonTracker = new UnassignedJobReasonTracker();
|
||||
vra.addListener(reasonTracker);
|
||||
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||
Assert.assertEquals(1, solution.getUnassignedJobs().size());
|
||||
Assert.assertEquals(1, reasonTracker.getMostLikelyReasonCode(solution.getUnassignedJobs().iterator().next().getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCorrectTWReasonCode() {
|
||||
Service service = Service.Builder.newInstance("1").addSizeDimension(0, 1).setTimeWindow(TimeWindow.newInstance(110, 200)).setLocation(Location.newInstance(5, 7)).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addVehicle(vehicle).addJob(service)
|
||||
.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||
UnassignedJobReasonTracker reasonTracker = new UnassignedJobReasonTracker();
|
||||
vra.addListener(reasonTracker);
|
||||
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||
Assert.assertEquals(1, solution.getUnassignedJobs().size());
|
||||
Assert.assertEquals(2, reasonTracker.getMostLikelyReasonCode(solution.getUnassignedJobs().iterator().next().getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCorrectMaxDistanceReasonCode() {
|
||||
Service service = Service.Builder.newInstance("1").setLocation(Location.newInstance(51, 0)).build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||
|
||||
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addVehicle(vehicle).addJob(service).build();
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
|
||||
StateId maxDistance = stateManager.createStateId("max-distance");
|
||||
Map<Vehicle, Double> distMap = new HashMap<>();
|
||||
distMap.put(vehicle, 100d);
|
||||
MaxDistanceConstraint distanceConstraint = new MaxDistanceConstraint(stateManager, maxDistance, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportCost(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
}, distMap);
|
||||
constraintManager.addConstraint(distanceConstraint, ConstraintManager.Priority.CRITICAL);
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setStateAndConstraintManager(stateManager, constraintManager)
|
||||
.buildAlgorithm();
|
||||
UnassignedJobReasonTracker reasonTracker = new UnassignedJobReasonTracker();
|
||||
vra.addListener(reasonTracker);
|
||||
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||
Assert.assertEquals(1, solution.getUnassignedJobs().size());
|
||||
Assert.assertEquals(4, reasonTracker.getMostLikelyReasonCode(solution.getUnassignedJobs().iterator().next().getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFreq() {
|
||||
Frequency frequency = new Frequency();
|
||||
frequency.addValue("VehicleDependentTimeWindowHardActivityConstraint");
|
||||
frequency.addValue("b");
|
||||
frequency.addValue("VehicleDependentTimeWindowHardActivityConstraint");
|
||||
|
||||
Iterator<Map.Entry<Comparable<?>, Long>> entryIterator = frequency.entrySetIterator();
|
||||
while (entryIterator.hasNext()) {
|
||||
Map.Entry<Comparable<?>, Long> e = entryIterator.next();
|
||||
System.out.println(e.getKey().toString() + " " + e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue