1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

add unassignedReason tests

This commit is contained in:
oblonski 2017-05-11 16:43:28 +02:00
parent 69537d109c
commit 8ca85f13ba
No known key found for this signature in database
GPG key ID: 179DE487285680D1

View file

@ -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"));
}
}