@Test public void when_shipmentroute_pastMaxLoatAtAct4ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList()); Capacity atAct = stateManager.getActivityState( shipment_route.getActivities().get(3), InternalStates.PAST_MAXLOAD, Capacity.class); assertEquals(15, atAct.get(0)); }
@Test public void pastMaxLoatAtAct2ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList()); Capacity atAct2 = stateManager.getActivityState( serviceRoute.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class); assertEquals(15, atAct2.get(0)); }
@Test public void when_shipmentroute_loadAtAct3ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList()); Capacity atAct = stateManager.getActivityState( shipment_route.getActivities().get(2), InternalStates.LOAD, Capacity.class); assertEquals(10, atAct.get(0)); }
@Test public void futureMaxLoatAtAct1ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList()); Capacity atAct1 = stateManager.getActivityState( serviceRoute.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class); assertEquals(15, atAct1.get(0)); }
@Test public void when_pdroute_loadAtAct2ShouldBe10() { stateManager.informInsertionStarts( Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList()); Capacity atAct2 = stateManager.getActivityState( pickup_delivery_route.getActivities().get(1), InternalStates.LOAD, Capacity.class); assertEquals(10, atAct2.get(0)); }
private boolean hasActivityIn(VehicleRoute route, String jobId) { boolean isInRoute = false; for (TourActivity act : route.getActivities()) { if (act instanceof TourActivity.JobActivity) { if (((TourActivity.JobActivity) act).getJob().getId().equals(jobId)) isInRoute = true; } } return isInRoute; }
@Test public void when_pdroute_pastMaxLoatAtAct1ShouldBe15() { stateManager.informInsertionStarts( Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList()); Capacity atAct1 = stateManager.getActivityState( pickup_delivery_route.getActivities().get(0), InternalStates.PAST_MAXLOAD, Capacity.class); assertEquals(15, atAct1.get(0)); }
@Override public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) { if (job instanceof Shipment) { List<AbstractActivity> acts = vehicleRoutingProblem.copyAndGetActivities(job); TourActivity pickupShipment = acts.get(0); TourActivity deliverShipment = acts.get(1); route.setVehicleAndDepartureTime( iData.getSelectedVehicle(), iData.getVehicleDepartureTime()); if (!iData.getSelectedVehicle().isReturnToDepot()) { if (iData.getDeliveryInsertionIndex() >= route.getActivities().size()) { setEndLocation(route, (Shipment) job); } } route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), deliverShipment); route.getTourActivities().addActivity(iData.getPickupInsertionIndex(), pickupShipment); } else delegator.handleJobInsertion(job, iData, route); }
@Test public void whenSolvingProblem2_nuActsShouldBe6() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder) .read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); VehicleRoutingProblem vrp = vrpBuilder.build(); VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); int nuActs = 0; for (VehicleRoute r : solution.getRoutes()) { nuActs += r.getActivities().size(); } assertEquals(6, nuActs); }
private static void printVerbose( PrintWriter out, VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution) { String leftAlgin = "| %-7s | %-20s | %-21s | %-15s | %-15s | %-15s | %-15s |%n"; out.format( "+--------------------------------------------------------------------------------------------------------------------------------+%n"); out.printf( "| detailed solution |%n"); out.format( "+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n"); out.printf( "| route | vehicle | activity | job | arrTime | endTime | costs |%n"); int routeNu = 1; for (VehicleRoute route : solution.getRoutes()) { out.format( "+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n"); double costs = 0; out.format( leftAlgin, routeNu, getVehicleString(route), route.getStart().getName(), "-", "undef", Math.round(route.getStart().getEndTime()), Math.round(costs)); TourActivity prevAct = route.getStart(); for (TourActivity act : route.getActivities()) { String jobId; if (act instanceof JobActivity) { jobId = ((JobActivity) act).getJob().getId(); } else { jobId = "-"; } double c = problem .getTransportCosts() .getTransportCost( prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle()); c += problem .getActivityCosts() .getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle()); costs += c; out.format( leftAlgin, routeNu, getVehicleString(route), act.getName(), jobId, Math.round(act.getArrTime()), Math.round(act.getEndTime()), Math.round(costs)); prevAct = act; } double c = problem .getTransportCosts() .getTransportCost( prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle()); c += problem .getActivityCosts() .getActivityCost( route.getEnd(), route.getEnd().getArrTime(), route.getDriver(), route.getVehicle()); costs += c; out.format( leftAlgin, routeNu, getVehicleString(route), route.getEnd().getName(), "-", Math.round(route.getEnd().getArrTime()), "undef", Math.round(costs)); routeNu++; } out.format( "+--------------------------------------------------------------------------------------------------------------------------------+%n"); if (!solution.getUnassignedJobs().isEmpty()) { out.format("+----------------+%n"); out.format("| unassignedJobs |%n"); out.format("+----------------+%n"); String unassignedJobAlgin = "| %-14s |%n"; for (Job j : solution.getUnassignedJobs()) { out.format(unassignedJobAlgin, j.getId()); } out.format("+----------------+%n"); } }