diff --git a/src/main/java/org/matsim/prepare/commercial/LTLFreightAgentGeneratorRuhr.java b/src/main/java/org/matsim/prepare/commercial/LTLFreightAgentGeneratorRuhr.java index 8479711..04d587f 100644 --- a/src/main/java/org/matsim/prepare/commercial/LTLFreightAgentGeneratorRuhr.java +++ b/src/main/java/org/matsim/prepare/commercial/LTLFreightAgentGeneratorRuhr.java @@ -143,14 +143,14 @@ else if (Math.abs(parcelDeliveryRoundingError.get()) >= 1.) { } } // is the number of sampled tours for this carrier reached, we ignore the rest. If the carrier is not for waste collections or parcel delivery, we use all tours - else if (sampledToursForThisCarrier.get() == integratedToursForThisCarrier.get()) + if (sampledToursForThisCarrier.get() == integratedToursForThisCarrier.get()) return; integratedToursForThisCarrier.getAndIncrement(); - if ((int) carrier.getAttributes().getAttribute("goodsType") == 140) { + if (goodsType == 140) { integratedToursForWasteCollections.getAndIncrement(); } - if ((int) carrier.getAttributes().getAttribute("goodsType") == 150) { + if (goodsType == 150) { integratedToursForParcelDelivery.getAndIncrement(); } Plan plan = PopulationUtils.createPlan(); @@ -208,7 +208,7 @@ else if (sampledToursForThisCarrier.get() == integratedToursForThisCarrier.get() newPerson.addPlan(plan); PopulationUtils.putSubpopulation(newPerson, subpopulation); - newPerson.getAttributes().putAttribute("goodsType", carrier.getAttributes().getAttribute("goodsType")); + newPerson.getAttributes().putAttribute("goodsType", goodsType); Id vehicleId = scheduledTour.getVehicle().getId(); @@ -220,9 +220,10 @@ else if (sampledToursForThisCarrier.get() == integratedToursForThisCarrier.get() }); }); - if (sampledToursForWasteCollections != integratedToursForWasteCollections.get()) + // because of rounding errors of each carrier, the number of integrated tours for waste collections and parcel delivery should differ at maximum by 1 + if (Math.abs(sampledToursForWasteCollections - integratedToursForWasteCollections.get()) > 1) throw new RuntimeException("The number of integrated tours for waste collections does not match the sampled tours"); - if (sampledToursForParcelDelivery != integratedToursForParcelDelivery.get()) + if (Math.abs(sampledToursForParcelDelivery - integratedToursForParcelDelivery.get()) > 1) throw new RuntimeException("The number of integrated tours for parcel delivery does not match the sampled tours"); }