@Override public void finish() { sum_transport_time += route.getEnd().getArrTime() - prevActDeparture; sum_too_late += Math.max( 0, route.getEnd().getArrTime() - route.getEnd().getTheoreticalLatestOperationStartTime()); stateManager.putRouteState(route, transport_time_id, sum_transport_time); stateManager.putRouteState(route, waiting_time_id, sum_waiting_time); stateManager.putRouteState(route, service_time_id, sum_service_time); stateManager.putRouteState(route, too_late_id, sum_too_late); }
@Override public void finish() { double distance = distanceCalculator.getDistance(prevAct.getLocation(), route.getEnd().getLocation()); sum_distance += distance; stateManager.putRouteState(route, distance_id, sum_distance); }
@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 Job getWorst(Collection<VehicleRoute> copied) { Job worst = null; double bestSavings = Double.MIN_VALUE; for (VehicleRoute route : copied) { if (route.isEmpty()) continue; Map<Job, Double> savingsMap = new HashMap<Job, Double>(); TourActivity actBefore = route.getStart(); TourActivity actToEval = null; for (TourActivity act : route.getActivities()) { if (actToEval == null) { actToEval = act; continue; } double savings = savings(route, actBefore, actToEval, act); Job job = ((TourActivity.JobActivity) actToEval).getJob(); if (!savingsMap.containsKey(job)) { savingsMap.put(job, savings); } else { double s = savingsMap.get(job); savingsMap.put(job, s + savings); } actBefore = actToEval; actToEval = act; } double savings = savings(route, actBefore, actToEval, route.getEnd()); Job job = ((TourActivity.JobActivity) actToEval).getJob(); if (!savingsMap.containsKey(job)) { savingsMap.put(job, savings); } else { double s = savingsMap.get(job); savingsMap.put(job, s + savings); } // getCounts best for (Job j : savingsMap.keySet()) { if (savingsMap.get(j) > bestSavings) { bestSavings = savingsMap.get(j); worst = j; } } } return worst; }
/* 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)); }
/** * @param route to get the total operation time from * @return operation time of this route, i.e. endTime - startTime of specified route */ public Double getOperationTime(VehicleRoute route) { if (route == null) throw new IllegalArgumentException("route is missing."); return route.getEnd().getArrTime() - route.getStart().getEndTime(); }
@Override public void finish() { stateManager.putRouteState(route, last_transport_distance_id, distance(route.getEnd())); stateManager.putRouteState(route, last_transport_time_id, transportTime(route.getEnd())); stateManager.putRouteState(route, last_transport_cost_id, transportCost(route.getEnd())); }