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

Merge pull request #38 from bringg/MaxTimeInVehicleConstarint-added-to-Unassigned-jobs-tracker

MaxTimeInVehicleConstarint added to Unassigned jobs tracker
This commit is contained in:
kobyb 2018-03-14 08:32:50 +02:00 committed by GitHub
commit fd5664bf70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View file

@ -79,7 +79,7 @@ public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListene
logger.info("took {} seconds", ((System.currentTimeMillis() - now) / 1000.0));
logger.debug("initial threshold: {}", initialThreshold);
logger.info("---------------------------------------------------------------------");
logger.debug("---------------------------------------------------------------------");
}
}

View file

@ -62,6 +62,7 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
codesToHumanReadableReason.put(2, "cannot be visited within time window");
codesToHumanReadableReason.put(3, "does not fit into any vehicle due to capacity");
codesToHumanReadableReason.put(4, "cannot be assigned due to max distance constraint of vehicle");
codesToHumanReadableReason.put(5, "cannot be assigned due to max time on vehicle constraint of vehicle");
failedConstraintNamesToCode.put("HardSkillConstraint", 1);
failedConstraintNamesToCode.put("VehicleDependentTimeWindowConstraints", 2);
@ -69,6 +70,7 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
failedConstraintNamesToCode.put("PickupAndDeliverShipmentLoadActivityLevelConstraint", 3);
failedConstraintNamesToCode.put("ServiceLoadActivityLevelConstraint", 3);
failedConstraintNamesToCode.put("MaxDistanceConstraint", 4);
failedConstraintNamesToCode.put("MaxTimeInVehicleConstraint", 5);
}
public void ignore(String simpleNameOfConstraint) {

View file

@ -22,10 +22,13 @@ 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.algorithm.state.UpdateMaxTimeInVehicle;
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.constraint.MaxTimeInVehicleConstraint;
import com.graphhopper.jsprit.core.problem.job.Delivery;
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;
@ -134,6 +137,31 @@ public class UnassignedJobReasonTrackerTest {
Assert.assertEquals(4, reasonTracker.getMostLikelyReasonCode(solution.getUnassignedJobs().iterator().next().getId()));
}
@Test
public void shouldReturnCorrectMaxTimeInVehicle() {
Service service = Delivery.Builder.newInstance("1").setLocation(Location.newInstance(51, 50)).setMaxTimeInVehicle(1).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 id = stateManager.createStateId("max-time");
StateId openJobsId = stateManager.createStateId("open-jobs-id");
stateManager.addStateUpdater(new UpdateMaxTimeInVehicle(stateManager, id, vrp.getVehicles(), vrp.getTransportCosts(), vrp.getActivityCosts(), openJobsId));
constraintManager.addConstraint(new MaxTimeInVehicleConstraint(vrp.getTransportCosts(), vrp.getActivityCosts(), id, stateManager, vrp, openJobsId), 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(5, reasonTracker.getMostLikelyReasonCode(solution.getUnassignedJobs().iterator().next().getId()));
}
@Test
public void getMostLikelyTest() {
Frequency frequency = new Frequency();