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:
parent
69537d109c
commit
8ca85f13ba
1 changed files with 15 additions and 0 deletions
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue