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

add bad job list

This commit is contained in:
oblonski 2014-08-11 22:14:33 +02:00
parent 6b82b90a7f
commit 590f2c1877

View file

@ -0,0 +1,58 @@
package jsprit.core.algorithm.state;
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.box.GreedySchrimpfFactory;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.util.Coordinate;
import jsprit.core.util.Solutions;
import org.junit.Test;
import java.util.Collection;
import static org.junit.Assert.assertTrue;
public class BadJobListTest {
@Test
public void job2ShouldBeInBadJobList_dueToTimeWindow(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.addVehicle(VehicleImpl.Builder.newInstance("v1").setEarliestStart(0).setLatestArrival(12).setStartLocationCoordinate(Coordinate.newInstance(1, 1)).build());
Service job1 = Service.Builder.newInstance("job1").setCoord(Coordinate.newInstance(0, 0)).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build();
builder.addJob(job1);
Service job2 = Service.Builder.newInstance("job2").setCoord(Coordinate.newInstance(2, 2)).setTimeWindow(TimeWindow.newInstance(12, 24)).setServiceTime(1).build();
builder.addJob(job2);
VehicleRoutingProblem vrp = builder.build();
VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
algorithm.setMaxIterations(10);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
assertTrue(!solution.getBadJobs().contains(job1));
assertTrue(solution.getBadJobs().contains(job2));
}
@Test
public void job2ShouldBeInBadJobList_dueToSize(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
builder.addVehicle(VehicleImpl.Builder.newInstance("v1").setEarliestStart(0).setLatestArrival(12).setStartLocationCoordinate(Coordinate.newInstance(1, 1)).build());
Service job1 = Service.Builder.newInstance("job1").setCoord(Coordinate.newInstance(0, 0)).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build();
builder.addJob(job1);
Service job2 = Service.Builder.newInstance("job2").setCoord(Coordinate.newInstance(2, 2)).addSizeDimension(0,10).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build();
builder.addJob(job2);
VehicleRoutingProblem vrp = builder.build();
VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
algorithm.setMaxIterations(10);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
assertTrue(!solution.getBadJobs().contains(job1));
assertTrue(solution.getBadJobs().contains(job2));
}
}