From bfa2f1ada2edd3741cf42e309f8c4802370e4212 Mon Sep 17 00:00:00 2001 From: vsp-gleich Date: Tue, 13 Jul 2021 14:29:00 +0200 Subject: [PATCH 01/13] Add github actions testing --- .github/workflows/maven.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 000000000..a3f52621d --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,25 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ 5.5.x ] + pull_request: + branches: [ 5.5.x ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + - name: Build with Maven + run: mvn -B package --file pom.xml From 5fa19d93c6e0f32011a2e3cd822b7f46b41db97b Mon Sep 17 00:00:00 2001 From: vsp-gleich Date: Tue, 13 Jul 2021 14:42:09 +0200 Subject: [PATCH 02/13] update opt-drt to first version after matsim repo move --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 45a7157ce..63112a5b9 100644 --- a/pom.xml +++ b/pom.xml @@ -157,7 +157,7 @@ com.github.matsim-vsp opt-drt - e955606ea4 + d61d2c8294 From 2809838e3031e56fa40b65005cd36c9b1037be4f Mon Sep 17 00:00:00 2001 From: vsp-gleich Date: Tue, 13 Jul 2021 15:26:37 +0200 Subject: [PATCH 03/13] update matsim-analysis to first commit after matsim repo move --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 63112a5b9..69db8e6ec 100644 --- a/pom.xml +++ b/pom.xml @@ -163,8 +163,7 @@ com.github.matsim-vsp matsim-analysis - v3.2 - + 933a6dd From 1114e365692cfcc8c41b826ede9600f9fff5a00c Mon Sep 17 00:00:00 2001 From: leich Date: Tue, 13 Jul 2021 16:24:54 +0200 Subject: [PATCH 04/13] fixme: set test to ignore which needs password to be set on the server --- .../org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java b/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java index eb208b1d2..a3be58ec1 100644 --- a/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java +++ b/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java @@ -19,6 +19,7 @@ package org.matsim.analysis; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.matsim.testcases.MatsimTestUtils; @@ -28,6 +29,7 @@ public class RunOfflineAirPollutionAnalysisTest{ @Rule public MatsimTestUtils utils = new MatsimTestUtils() ; // to run this test an environment variable needs to be set in your IDE and on the server... + @Ignore @Test public final void test1() { try { From fab724c9d0f9025103defc5b0e38c37e4ffb5f1b Mon Sep 17 00:00:00 2001 From: leich Date: Tue, 13 Jul 2021 16:25:37 +0200 Subject: [PATCH 05/13] add comment fixme --- .../org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java b/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java index a3be58ec1..bf16fdb09 100644 --- a/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java +++ b/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java @@ -29,6 +29,7 @@ public class RunOfflineAirPollutionAnalysisTest{ @Rule public MatsimTestUtils utils = new MatsimTestUtils() ; // to run this test an environment variable needs to be set in your IDE and on the server... + // FIXME @Ignore @Test public final void test1() { From 402c21c2fc8ffcd82e3e06fee73f4fbd699deba5 Mon Sep 17 00:00:00 2001 From: vsp-gleich Date: Wed, 14 Jul 2021 11:30:25 +0200 Subject: [PATCH 06/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 077af25b1..835bdab83 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The **MATSim input files, output files, analysis data and visualizations** are l ### Note -Handling of large files within git is not without problems (git lfs files are not included in the zip download; we have to pay; ...). In consequence, large files, both on the input and on the output side, reside at https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin . +Handling of large files within git is not without problems (git lfs files are not included in the zip download; we have to pay; ...). In consequence, large files, both on the input and on the output side, reside at https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin . Please check out the latest release / the latest numbered branch since those are stable. The master branch is an potentially unstable development head. ---- ### Simple things (without installing/running MATSim) From c083805e61a6a42fd5d156a896b29ebc930c0800 Mon Sep 17 00:00:00 2001 From: tschlenther Date: Thu, 15 Jul 2021 10:28:57 +0200 Subject: [PATCH 07/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 077af25b1..ef67ce7ff 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ java -jar [FILENAME].jar com.github.matsim-scenarios matsim-berlin - 5.5 + 5.5.3 ``` From 0dd3f9dfcfdb8926f69e043ea6d20b5305f04c79 Mon Sep 17 00:00:00 2001 From: rakow Date: Fri, 16 Jul 2021 12:26:59 +0200 Subject: [PATCH 08/13] Update maven.yml Configure new environment --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a3f52621d..4d1cd6a43 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -2,7 +2,6 @@ # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven name: Java CI with Maven - on: push: branches: [ 5.5.x ] @@ -13,6 +12,7 @@ jobs: build: runs-on: ubuntu-latest + environment: Build steps: - uses: actions/checkout@v2 From 43d77cbcb3d71cd03693e3520386c64af3d81142 Mon Sep 17 00:00:00 2001 From: rakow Date: Fri, 16 Jul 2021 12:28:23 +0200 Subject: [PATCH 09/13] Update RunOfflineAirPollutionAnalysisTest.java unignore test --- .../org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java b/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java index bf16fdb09..e1e25841f 100644 --- a/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java +++ b/src/test/java/org/matsim/analysis/RunOfflineAirPollutionAnalysisTest.java @@ -29,8 +29,6 @@ public class RunOfflineAirPollutionAnalysisTest{ @Rule public MatsimTestUtils utils = new MatsimTestUtils() ; // to run this test an environment variable needs to be set in your IDE and on the server... - // FIXME - @Ignore @Test public final void test1() { try { From 5ba197ac09b58650edddcd896f014d54bf7581b2 Mon Sep 17 00:00:00 2001 From: rakow Date: Fri, 16 Jul 2021 13:39:03 +0200 Subject: [PATCH 10/13] Update maven.yml Set the encryption password from the environment --- .github/workflows/maven.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4d1cd6a43..e996ec5b4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-latest environment: Build + env: + MATSIM_DECRYPTION_PASSWORD: ${{ secrets.MATSIM_DECRYPTION_PASSWORD }} steps: - uses: actions/checkout@v2 From f445fafbd26d1fb22af097ffe96c5b53b03293a7 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 4 Nov 2021 13:56:30 +0100 Subject: [PATCH 11/13] update code wasteCollection and add input files --- .../carriers_diesel_vehicle.xml | 43 ++ .../wasteCollection/carriers_medium_EV.xml | 43 ++ .../wasteCollection/carriers_small_EV.xml | 43 ++ .../districtsWithGarbageInformations.cpg | 0 .../districtsWithGarbageInformations.dbf | Bin .../districtsWithGarbageInformations.prj | 0 .../districtsWithGarbageInformations.qpj | 0 .../districtsWithGarbageInformations.shp | Bin .../districtsWithGarbageInformations.shx | Bin .../input/wasteCollection/vehicleTypes.xml | 72 +++ .../AbfallChessboardUtils.java | 19 +- .../run/wasteCollection/AbfallUtils.java | 594 +++++++++++------- .../run/wasteCollection/Run_Abfall.java | 178 +++--- .../run/wasteCollection/AbfallUtilsTest.java | 95 ++- 14 files changed, 743 insertions(+), 344 deletions(-) create mode 100644 scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_diesel_vehicle.xml create mode 100644 scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_medium_EV.xml create mode 100644 scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_small_EV.xml rename scenarios/berlin-v5.5-10pct/input/wasteCollection/{ => garbageInput}/districtsWithGarbageInformations.cpg (100%) rename scenarios/berlin-v5.5-10pct/input/wasteCollection/{ => garbageInput}/districtsWithGarbageInformations.dbf (100%) rename scenarios/berlin-v5.5-10pct/input/wasteCollection/{ => garbageInput}/districtsWithGarbageInformations.prj (100%) rename scenarios/berlin-v5.5-10pct/input/wasteCollection/{ => garbageInput}/districtsWithGarbageInformations.qpj (100%) rename scenarios/berlin-v5.5-10pct/input/wasteCollection/{ => garbageInput}/districtsWithGarbageInformations.shp (100%) rename scenarios/berlin-v5.5-10pct/input/wasteCollection/{ => garbageInput}/districtsWithGarbageInformations.shx (100%) create mode 100644 scenarios/berlin-v5.5-10pct/input/wasteCollection/vehicleTypes.xml diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_diesel_vehicle.xml b/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_diesel_vehicle.xml new file mode 100644 index 000000000..90c8de932 --- /dev/null +++ b/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_diesel_vehicle.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_medium_EV.xml b/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_medium_EV.xml new file mode 100644 index 000000000..2446f9160 --- /dev/null +++ b/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_medium_EV.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_small_EV.xml b/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_small_EV.xml new file mode 100644 index 000000000..b1e196e4d --- /dev/null +++ b/scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_small_EV.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.cpg b/scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.cpg similarity index 100% rename from scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.cpg rename to scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.cpg diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.dbf b/scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.dbf similarity index 100% rename from scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.dbf rename to scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.dbf diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.prj b/scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.prj similarity index 100% rename from scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.prj rename to scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.prj diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.qpj b/scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.qpj similarity index 100% rename from scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.qpj rename to scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.qpj diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.shp b/scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.shp similarity index 100% rename from scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.shp rename to scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.shp diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.shx b/scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.shx similarity index 100% rename from scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.shx rename to scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.shx diff --git a/scenarios/berlin-v5.5-10pct/input/wasteCollection/vehicleTypes.xml b/scenarios/berlin-v5.5-10pct/input/wasteCollection/vehicleTypes.xml new file mode 100644 index 000000000..7b5316520 --- /dev/null +++ b/scenarios/berlin-v5.5-10pct/input/wasteCollection/vehicleTypes.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + 0.5 + 60.0 + diesel + + + + + + + + + + + + + + + + + + 80.0 + 1.4 + 1.0 + electricity + + + + + + + + + + + + + + + + + + + + + 310.0 + 1.4 + 1.0 + electricity + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/matsim/run/wasteCollection/AbfallChessboardUtils.java b/src/main/java/org/matsim/run/wasteCollection/AbfallChessboardUtils.java index 454682d9f..6ada1c7e4 100644 --- a/src/main/java/org/matsim/run/wasteCollection/AbfallChessboardUtils.java +++ b/src/main/java/org/matsim/run/wasteCollection/AbfallChessboardUtils.java @@ -10,7 +10,9 @@ import org.matsim.contrib.freight.carrier.CarrierCapabilities; import org.matsim.contrib.freight.carrier.CarrierVehicle; import org.matsim.contrib.freight.carrier.CarrierVehicleTypeLoader; +import org.matsim.contrib.freight.carrier.CarrierVehicleTypes; import org.matsim.contrib.freight.carrier.Carriers; +import org.matsim.vehicles.Vehicle; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.contrib.freight.carrier.CarrierImpl; @@ -81,16 +83,21 @@ static void createShipmentsForChessboardII(HashMap carrierMap, * * @param */ - static void createCarriersForChessboard(Carriers carriers, FleetSize fleetSize) { + static void createCarriersForChessboard(Carriers carriers, FleetSize fleetSize, CarrierVehicleTypes carrierVehicleTypes) { String vehicleName = "TruckChessboard"; double earliestStartingTime = 6 * 3600; double latestFinishingTime = 14 * 3600; - AbfallUtils.createGarbageTruck(vehicleName, linkChessboardDepot, earliestStartingTime, latestFinishingTime); + CarrierVehicle newCarrierVehicle = CarrierVehicle.Builder + .newInstance(Id.create(vehicleName, Vehicle.class), Id.createLinkId(linkChessboardDepot)) + .setEarliestStart(earliestStartingTime).setLatestEnd(latestFinishingTime) + .setTypeId(carrierVehicleTypes.getVehicleTypes().values().iterator().next().getId()).build(); + +// AbfallUtils.createGarbageTruck(vehicleName, linkChessboardDepot, earliestStartingTime, latestFinishingTime); // define Carriers - defineCarriersChessboard(carriers, AbfallUtils.vehicleAtDepot, fleetSize); + defineCarriersChessboard(carriers, newCarrierVehicle, fleetSize, carrierVehicleTypes); } /** @@ -100,13 +107,13 @@ static void createCarriersForChessboard(Carriers carriers, FleetSize fleetSize) * @param * */ - private static void defineCarriersChessboard(Carriers carriers, CarrierVehicle vehicleDepot, FleetSize fleetSize) { + private static void defineCarriersChessboard(Carriers carriers, CarrierVehicle vehicleDepot, FleetSize fleetSize, CarrierVehicleTypes carrierVehicleTypes) { CarrierCapabilities carrierCapabilities = CarrierCapabilities.Builder.newInstance() - .addType(AbfallUtils.carrierVehType).addVehicle(vehicleDepot).setFleetSize(fleetSize).build(); + .addType(carrierVehicleTypes.getVehicleTypes().values().iterator().next()).addVehicle(vehicleDepot).setFleetSize(fleetSize).build(); carrierChessboard.setCarrierCapabilities(carrierCapabilities); // Fahrzeugtypen den Anbietern zuordenen - new CarrierVehicleTypeLoader(carriers).loadVehicleTypes(AbfallUtils.vehicleTypes); + new CarrierVehicleTypeLoader(carriers).loadVehicleTypes(carrierVehicleTypes); } } diff --git a/src/main/java/org/matsim/run/wasteCollection/AbfallUtils.java b/src/main/java/org/matsim/run/wasteCollection/AbfallUtils.java index 83dc9efb3..8fcaeea48 100644 --- a/src/main/java/org/matsim/run/wasteCollection/AbfallUtils.java +++ b/src/main/java/org/matsim/run/wasteCollection/AbfallUtils.java @@ -1,10 +1,13 @@ package org.matsim.run.wasteCollection; +import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -17,39 +20,40 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; +import org.matsim.api.core.v01.population.Person; +import org.matsim.contrib.freight.Freight; +import org.matsim.contrib.freight.FreightConfigGroup; import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierCapabilities; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; -import org.matsim.contrib.freight.carrier.CarrierImpl; import org.matsim.contrib.freight.carrier.CarrierPlan; import org.matsim.contrib.freight.carrier.CarrierPlanXmlWriterV2; import org.matsim.contrib.freight.carrier.CarrierShipment; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleTypeLoader; +import org.matsim.contrib.freight.carrier.CarrierUtils; import org.matsim.contrib.freight.carrier.CarrierVehicleTypes; import org.matsim.contrib.freight.carrier.Carriers; import org.matsim.contrib.freight.carrier.ScheduledTour; import org.matsim.contrib.freight.carrier.TimeWindow; +import org.matsim.contrib.freight.carrier.Tour; import org.matsim.contrib.freight.carrier.Tour.Delivery; import org.matsim.contrib.freight.carrier.Tour.Leg; import org.matsim.contrib.freight.carrier.Tour.Pickup; import org.matsim.contrib.freight.carrier.Tour.TourElement; +import org.matsim.contrib.freight.controler.CarrierModule; import org.matsim.contrib.freight.jsprit.MatsimJspritFactory; import org.matsim.contrib.freight.jsprit.NetworkBasedTransportCosts; import org.matsim.contrib.freight.jsprit.NetworkBasedTransportCosts.Builder; import org.matsim.contrib.freight.jsprit.NetworkRouter; import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.ControlerConfigGroup; +import org.matsim.core.controler.AbstractModule; +import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.population.routes.RouteUtils; import org.matsim.core.utils.geometry.geotools.MGC; import org.matsim.core.utils.geometry.transformations.TransformationFactory; -import org.matsim.vehicles.EngineInformation.FuelType; -import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; -import org.matsim.vehicles.VehicleUtils; import org.opengis.feature.simple.SimpleFeature; import com.google.common.collect.ArrayListMultimap; @@ -89,16 +93,8 @@ class AbfallUtils { static List districtsWithShipments = new ArrayList(); static List districtsWithNoShipments = new ArrayList(); static HashMap dataEnt = new HashMap(); - static CarrierVehicleTypes vehicleTypes = null; - static VehicleType carrierVehType = null; - static int capacityTruck = 0; - static double powerConsumptionPerWeight = 0; - static double powerConsumptionPerDistance = 0; - static CarrierVehicle vehicleAtDepot = null; static Multimap linksInDistricts; static boolean streetAlreadyInGarbageLinks = false; - static boolean oneCarrierForEachDistrict = false; - static String vehicleTypeId; /** * Creates a map for getting the name of the attribute, where you can find the @@ -117,17 +113,13 @@ private static void createMapEnt() { * * @return */ - static HashMap createCarrier() { + static HashMap createCarrier(Carriers carriers) { HashMap carrierMap = new HashMap(); - Carrier bsrForckenbeck = CarrierImpl.newInstance(Id.create("BSR_Forckenbeck", Carrier.class)); - Carrier bsrMalmoeer = CarrierImpl.newInstance(Id.create("BSR_MalmoeerStr", Carrier.class)); - Carrier bsrNordring = CarrierImpl.newInstance(Id.create("BSR_Nordring", Carrier.class)); - Carrier bsrGradestrasse = CarrierImpl.newInstance(Id.create("BSR_Gradestrasse", Carrier.class)); - carrierMap.put("Nordring", bsrNordring); - carrierMap.put("MalmoeerStr", bsrMalmoeer); - carrierMap.put("Forckenbeck", bsrForckenbeck); - carrierMap.put("Gradestrasse", bsrGradestrasse); + carrierMap.put("Nordring", carriers.getCarriers().get(Id.create("BSR_Nordring", Carrier.class))); + carrierMap.put("MalmoeerStr", carriers.getCarriers().get(Id.create("BSR_MalmoeerStr", Carrier.class))); + carrierMap.put("Forckenbeck", carriers.getCarriers().get(Id.create("BSR_Forckenbeck", Carrier.class))); + carrierMap.put("Gradestrasse", carriers.getCarriers().get(Id.create("BSR_Gradestrasse", Carrier.class))); return carrierMap; } @@ -188,7 +180,7 @@ static HashMap> createDumpMap() { * * @param config */ - static Config prepareConfig(Config config, int lastIteration) { + static Config prepareConfig(Config config, int lastIteration, String inputVehicleTypes, String inputCarriers) { config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); new OutputDirectoryHierarchy(config.controler().getOutputDirectory(), config.controler().getRunId(), config.controler().getOverwriteFileSetting(), ControlerConfigGroup.CompressionType.gzip); @@ -199,6 +191,11 @@ static Config prepareConfig(Config config, int lastIteration) { config.global().setRandomSeed(4177); config.controler().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); config.global().setCoordinateSystem(TransformationFactory.GK4); + FreightConfigGroup freightConfigGroup = ConfigUtils.addOrGetModule(config, FreightConfigGroup.class); + freightConfigGroup.setCarriersFile(inputCarriers); + freightConfigGroup.setCarriersVehicleTypesFile(inputVehicleTypes); + freightConfigGroup.setTravelTimeSliceWidth(1800); + freightConfigGroup.setTimeWindowHandling(FreightConfigGroup.TimeWindowHandling.enforceBeginnings); return config; } @@ -402,21 +399,26 @@ static void createShipmentsGarbagePerVolume(Collection districtsW static void createShipmentsForSelectedDay(Collection districtsWithGarbage, String day, HashMap> garbageDumps, Scenario scenario, Carriers carriers, HashMap carrierMap, Map, ? extends Link> allLinks, double volumeBigTrashcan, - double serviceTimePerBigDustbin) { + double serviceTimePerBigDustbin, boolean oneCarrierForEachDistrict) { Id dumpId = null; double distanceWithShipments = 0; int garbageToCollect = 0; - // String depot = null; + String usedCarrier = null; + String district = null; Map, Link> garbageLinks = new HashMap, Link>(); createMapEnt(); - carrierMap.clear(); +// carrierMap.clear(); for (SimpleFeature districtInformation : districtsWithGarbage) { if ((double) districtInformation.getAttribute(day) > 0) { garbageToCollect = (int) ((double) districtInformation.getAttribute(day) * 1000); dumpId = garbageDumps.get(districtInformation.getAttribute(dataEnt.get(day))); - // depot = districtInformation.getAttribute("Depot").toString(); - carrierMap.put(districtInformation.getAttribute("Ortsteil").toString(), CarrierImpl.newInstance(Id - .create("Carrier " + districtInformation.getAttribute("Ortsteil").toString(), Carrier.class))); + usedCarrier = districtInformation.getAttribute("Depot").toString(); + if (oneCarrierForEachDistrict == true) { + district = districtInformation.getAttribute("Ortsteil").toString(); + Carrier newCarrier = createSingleCarrier(usedCarrier, carrierMap, district); + carrierMap.put(district, newCarrier); + usedCarrier = district; + } for (Link link : allLinks.values()) { for (String linkInDistrict : linksInDistricts .get(districtInformation.getAttribute("Ortsteil").toString())) { @@ -448,14 +450,37 @@ static void createShipmentsForSelectedDay(Collection districtsWit createShipmentsForCarrierII(garbageToCollect, volumeBigTrashcan, serviceTimePerBigDustbin, distanceWithShipments, garbageLinks, scenario, - carrierMap.get(districtInformation.getAttribute("Ortsteil").toString()), dumpId, carriers); + carrierMap.get(usedCarrier), dumpId, carriers); } distanceWithShipments = 0; garbageLinks.clear(); } - oneCarrierForEachDistrict = true; - for (Carrier carrier : carrierMap.values()) + if (oneCarrierForEachDistrict == true) { + carrierMap.remove("Nordring"); + carrierMap.remove("MalmoeerStr"); + carrierMap.remove("Forckenbeck"); + carrierMap.remove("Gradestrasse"); + } + carriers.getCarriers().clear(); + for (Carrier carrier : carrierMap.values()) { carriers.addCarrier(carrier); + } + } + + private static Carrier createSingleCarrier(String depot, HashMap carrierMap, String district) { + Carrier newCarrier = CarrierUtils.createCarrier(Id.create("Carrier " + district, Carrier.class)); + for (Carrier originalCarrier : carrierMap.values()) { + if (originalCarrier.getId().toString().contains(depot)) { + newCarrier.getCarrierCapabilities() + .setFleetSize(originalCarrier.getCarrierCapabilities().getFleetSize()); + newCarrier.getCarrierCapabilities().getCarrierVehicles() + .putAll(originalCarrier.getCarrierCapabilities().getCarrierVehicles()); + newCarrier.getCarrierCapabilities().getVehicleTypes() + .addAll(originalCarrier.getCarrierCapabilities().getVehicleTypes()); + } + } + + return newCarrier; } /** @@ -472,9 +497,11 @@ static void createShipmentsForCarrierI(double garbagePerMeterToCollect, double v for (Link link : garbageLinks.values()) { double maxWeightBigDustbin = volumeBigDustbin * 0.1; // Umrechnung von Volumen [l] in Masse[kg] int volumeGarbage = (int) Math.ceil(link.getLength() * garbagePerMeterToCollect); - amountOfCollectedDustbins = amountOfCollectedDustbins + (int) Math.ceil(((double) volumeGarbage) / maxWeightBigDustbin); + amountOfCollectedDustbins = amountOfCollectedDustbins + + (int) Math.ceil(((double) volumeGarbage) / maxWeightBigDustbin); double serviceTime = Math.ceil(((double) volumeGarbage) / maxWeightBigDustbin) * serviceTimePerBigTrashcan; - double deliveryTime = ((double) volumeGarbage / capacityTruck) * 45 * 60; + // double deliveryTime = ((double) volumeGarbage / capacityTruck) * 45 * 60; + double deliveryTime = ((double) volumeGarbage / 11000) * 45 * 60; CarrierShipment shipment = CarrierShipment.Builder .newInstance(Id.create("Shipment_" + link.getId(), CarrierShipment.class), link.getId(), (dumpId), volumeGarbage) @@ -517,9 +544,11 @@ static void createShipmentsForCarrierII(int garbageToCollect, double volumeBigDu } count++; } - amountOfCollectedDustbins = amountOfCollectedDustbins + (int) Math.ceil(((double) volumeGarbage) / maxWeightBigDustbin); + amountOfCollectedDustbins = amountOfCollectedDustbins + + (int) Math.ceil(((double) volumeGarbage) / maxWeightBigDustbin); double serviceTime = Math.ceil(((double) volumeGarbage) / maxWeightBigDustbin) * serviceTimePerBigTrashcan; - double deliveryTime = ((double) volumeGarbage / capacityTruck) * 45 * 60; +// double deliveryTime = ((double) volumeGarbage / capacityTruck) * 45 * 60; + double deliveryTime = ((double) volumeGarbage / 11000) * 45 * 60; CarrierShipment shipment = CarrierShipment.Builder .newInstance(Id.create("Shipment_" + link.getId(), CarrierShipment.class), link.getId(), garbageDumpId, volumeGarbage) @@ -554,172 +583,17 @@ private static void countingGarbage(Id garbageDumpId, int volumeGarbage) { garbageGradestr = garbageGradestr + volumeGarbage; } - /** - * Creates a new vehicleType and ads this type to the CarrierVehicleTypes - */ - static void createAndAddVehicles(boolean electricCar) { - vehicleTypeId = "MB_Econic_Diesel"; - capacityTruck = 11500; // in kg - double maxVelocity = 80 / 3.6; - double costPerDistanceUnit = 0.000846; // Berechnung aus Excel - double costPerTimeUnit = 0.0; // Lohnkosten bei Fixkosten integriert - double fixCosts = 999.93; // Berechnung aus Excel - FuelType engineInformation = FuelType.diesel; - double literPerMeter = 0.00067; // Berechnung aus Ecxel - - if (electricCar == true) { - vehicleTypeId = "E-Force KSF"; - capacityTruck = 10500; // in kg - powerConsumptionPerDistance = 0.886; // in kwh/km - powerConsumptionPerWeight = 1.4; // in kwh/1000kg collected garbage - maxVelocity = 80 / 3.6; - costPerDistanceUnit = 0.0001356; // Berechnung aus Excel - costPerTimeUnit = 0.0; // Lohnkosten bei Fixkosten integriert - fixCosts = 1222.32 + 4.4982; // Berechnung aus Excel - engineInformation = FuelType.electricity; - literPerMeter = 0.0; // Berechnung aus Ecxel - } - createGarbageTruckType(vehicleTypeId, maxVelocity, costPerDistanceUnit, costPerTimeUnit, fixCosts, - engineInformation, literPerMeter); - adVehicleType(); - } - - /** - * Method creates a new garbage truck type - * - * @param maxVelocity in m/s - * @return - */ - private static void createGarbageTruckType(String vehicleTypeId, double maxVelocity, double costPerDistanceUnit, - double costPerTimeUnit, double fixCosts, FuelType engineInformation, double literPerMeter) { - carrierVehType = VehicleUtils.createVehicleType(Id.create(vehicleTypeId, VehicleType.class)); - carrierVehType.getCapacity().setOther(capacityTruck); - carrierVehType.setMaximumVelocity(maxVelocity); - carrierVehType.getCostInformation().setCostsPerMeter(costPerDistanceUnit).setCostsPerSecond(costPerTimeUnit).setFixedCost(fixCosts); - carrierVehType.getEngineInformation().setFuelType(engineInformation).setFuelConsumption(literPerMeter); - - } - - /** - * Method adds a new vehicle Type to the list of vehicleTyps - * - * @param - * @return - */ - private static void adVehicleType() { - vehicleTypes = new CarrierVehicleTypes(); - vehicleTypes.getVehicleTypes().put(carrierVehType.getId(), carrierVehType); - - } - - /** - * Method for creating a new Garbage truck - * - * @param - * - * @return - */ - static CarrierVehicle createGarbageTruck(String vehicleName, String linkDepot, double earliestStartingTime, - double latestFinishingTime) { - - return vehicleAtDepot = CarrierVehicle.Builder - .newInstance(Id.create(vehicleName, Vehicle.class), Id.createLinkId(linkDepot)) - .setEarliestStart(earliestStartingTime).setLatestEnd(latestFinishingTime) - .setTypeId(carrierVehType.getId()).build(); - } - - /** - * Creates the vehicles at the depots, ads this vehicles to the carriers and - * sets the capabilities. This method is for the Berlin network and creates the - * vehicles for the 4 different depots. - * - * @param - */ - static void createCarriersBerlin(Collection districtsWithGarbage, Carriers carriers, - HashMap carrierMap, FleetSize fleetSize) { - String depotForckenbeck = "27766"; - String depotMalmoeerStr = "116212"; - String depotNordring = "42882"; - String depotGradestrasse = "71781"; - - String vehicleIdForckenbeck = "TruckForckenbeck"; - String vehicleIdMalmoeer = "TruckMalmoeer"; - String vehicleIdNordring = "TruckNordring"; - String vehicleIdGradestrasse = "TruckGradestrasse"; - double earliestStartingTime = 6 * 3600; - double latestFinishingTime = 14 * 3600; - - HashMap depotMap = new HashMap(); - - CarrierVehicle vehicleForckenbeck = createGarbageTruck(vehicleIdForckenbeck, depotForckenbeck, - earliestStartingTime, latestFinishingTime); - CarrierVehicle vehicleMalmoeerStr = createGarbageTruck(vehicleIdMalmoeer, depotMalmoeerStr, - earliestStartingTime, latestFinishingTime); - CarrierVehicle vehicleNordring = createGarbageTruck(vehicleIdNordring, depotNordring, earliestStartingTime, - latestFinishingTime); - CarrierVehicle vehicleGradestrasse = createGarbageTruck(vehicleIdGradestrasse, depotGradestrasse, - earliestStartingTime, latestFinishingTime); - depotMap.put("Forckenbeck", vehicleForckenbeck); - depotMap.put("MalmoeerStr", vehicleMalmoeerStr); - depotMap.put("Nordring", vehicleNordring); - depotMap.put("Gradestrasse", vehicleGradestrasse); - - // define Carriers - - defineCarriersBerlin(depotMap, districtsWithGarbage, carriers, carrierMap, vehicleForckenbeck, - vehicleMalmoeerStr, vehicleNordring, vehicleGradestrasse, fleetSize); - } - - /** - * Defines and sets the Capabilities of the Carrier, including the vehicleTypes - * for the carriers for the Berlin network - * - * @param - * - */ - private static void defineCarriersBerlin(HashMap depotMap, - Collection districtsWithGarbage, Carriers carriers, HashMap carrierMap, - CarrierVehicle vehicleForckenbeck, CarrierVehicle vehicleMalmoeerStr, CarrierVehicle vehicleNordring, - CarrierVehicle vehicleGradestrasse, FleetSize fleetSize) { - - if (oneCarrierForEachDistrict == false) { - CarrierCapabilities carrierCapabilities = CarrierCapabilities.Builder.newInstance().addType(carrierVehType) - .addVehicle(vehicleForckenbeck).setFleetSize(fleetSize).build(); - carrierMap.get("Forckenbeck").setCarrierCapabilities(carrierCapabilities); - carrierCapabilities = CarrierCapabilities.Builder.newInstance().addType(carrierVehType) - .addVehicle(vehicleMalmoeerStr).setFleetSize(fleetSize).build(); - carrierMap.get("MalmoeerStr").setCarrierCapabilities(carrierCapabilities); - carrierCapabilities = CarrierCapabilities.Builder.newInstance().addType(carrierVehType) - .addVehicle(vehicleNordring).setFleetSize(fleetSize).build(); - carrierMap.get("Nordring").setCarrierCapabilities(carrierCapabilities); - carrierCapabilities = CarrierCapabilities.Builder.newInstance().addType(carrierVehType) - .addVehicle(vehicleGradestrasse).setFleetSize(fleetSize).build(); - carrierMap.get("Gradestrasse").setCarrierCapabilities(carrierCapabilities); - } else { - for (Carrier carrier : carrierMap.values()) { - for (SimpleFeature simpleFeature : districtsWithGarbage) { - if (carrier.getId().toString().equals("Carrier " + simpleFeature.getAttribute("Ortsteil"))) { - carrier.setCarrierCapabilities(CarrierCapabilities.Builder.newInstance().addType(carrierVehType) - .addVehicle(depotMap.get(simpleFeature.getAttribute("Depot"))).setFleetSize(fleetSize) - .build()); - } - } - } - } - // Fahrzeugtypen den Anbietern zuordenen - new CarrierVehicleTypeLoader(carriers).loadVehicleTypes(vehicleTypes); - } - /** * Solves with jsprit and gives a xml output of the plans and a plot of the * solution * * @param */ - static void solveWithJsprit(Scenario scenario, Carriers carriers, HashMap carrierMap, int jspritIteration) { + static void solveWithJsprit(Scenario scenario, Carriers carriers, HashMap carrierMap, + int jspritIteration) { int carrierCount = 1; - // Netzwerk integrieren und Kosten für jsprit + CarrierVehicleTypes vehicleTypes = (CarrierVehicleTypes) scenario.getScenarioElement("carrierVehicleTypes"); Network network = scenario.getNetwork(); Builder netBuilder = NetworkBasedTransportCosts.Builder.newInstance(network, vehicleTypes.getVehicleTypes().values()); @@ -727,6 +601,7 @@ static void solveWithJsprit(Scenario scenario, Carriers carriers, HashMap need solution to // convert Services to Shipments VehicleRoutingProblem.Builder vrpBuilder = MatsimJspritFactory.createRoutingProblemBuilder(singleCarrier, @@ -758,12 +633,89 @@ static void solveWithJsprit(Scenario scenario, Carriers carriers, HashMap createStrategyManager() { +// return null; +// } +// }; +// } + /** * Gives an output of a .txt file with some important information * + * @param allGarbage + * + * @param */ static void outputSummary(Collection districtsWithGarbage, Scenario scenario, - HashMap carrierMap, String day, boolean electricCar, double volumeDustbin, double secondsServiceTimePerDustbin) { + HashMap carrierMap, String day, double volumeDustbin, + double secondsServiceTimePerDustbin) { int vehiclesForckenbeck = 0; int vehiclesMalmoeer = 0; int vehiclesNordring = 0; @@ -831,6 +783,24 @@ static void outputSummary(Collection districtsWithGarbage, Scenar double powerConsumptionGradestrasse = 0; double tourDistanceChessboard = 0; double powerConsumptionChessboard = 0; + boolean electricCar = false; + double capacityTruck = 0; + String vehicleTypeId = null; + double energyConsumptionPerDistance = 0; + double energyConsumptionPerWeight = 0; + + Carriers allCarriers = (Carriers) scenario.getScenarioElement("carriers"); + Carrier testCarrier = allCarriers.getCarriers().values().iterator().next(); + for (VehicleType usedType : testCarrier.getCarrierCapabilities().getVehicleTypes()) { + if (usedType.getEngineInformation().getAttributes().getAttribute("fuelType").equals("electric")) { + electricCar = true; + energyConsumptionPerDistance = (double) usedType.getEngineInformation().getAttributes() + .getAttribute("engeryConsumptionPerKm"); + energyConsumptionPerWeight = 1.4; + } + capacityTruck = usedType.getCapacity().getOther(); + vehicleTypeId = usedType.getId().toString(); + } for (Carrier thisCarrier : carrierMap.values()) { @@ -838,8 +808,8 @@ static void outputSummary(Collection districtsWithGarbage, Scenar Map, CarrierShipment> shipments = thisCarrier.getShipments(); HashMap shipmentSizes = new HashMap(); matsimCosts = matsimCosts + thisCarrier.getSelectedPlan().getScore(); - - for (Entry, CarrierShipment> entry : shipments.entrySet()) { + + for (Entry, CarrierShipment> entry : shipments.entrySet()) { String shipmentId = entry.getKey().toString(); int shipmentSize = entry.getValue().getSize(); shipmentSizes.put(shipmentId, shipmentSize); @@ -853,23 +823,23 @@ static void outputSummary(Collection districtsWithGarbage, Scenar if (element instanceof Pickup) { Pickup pickupElement = (Pickup) element; String pickupShipmentId = pickupElement.getShipment().getId().toString(); - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckForckenbeck")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckForckenbeck")) { sizeForckenbeck = sizeForckenbeck + (shipmentSizes.get(pickupShipmentId)); sizeTour = sizeTour + (shipmentSizes.get(pickupShipmentId)); } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckMalmoeer")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckMalmoeer")) { sizeMalmooer = sizeMalmooer + (shipmentSizes.get(pickupShipmentId)); sizeTour = sizeTour + (shipmentSizes.get(pickupShipmentId)); } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckNordring")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckNordring")) { sizeNordring = sizeNordring + (shipmentSizes.get(pickupShipmentId)); sizeTour = sizeTour + (shipmentSizes.get(pickupShipmentId)); } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckGradestrasse")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckGradestrasse")) { sizeGradestrasse = sizeGradestrasse + (shipmentSizes.get(pickupShipmentId)); sizeTour = sizeTour + (shipmentSizes.get(pickupShipmentId)); } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckChessboard")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckChessboard")) { sizeChessboard = sizeChessboard + (shipmentSizes.get(pickupShipmentId)); sizeTour = sizeTour + (shipmentSizes.get(pickupShipmentId)); } @@ -893,7 +863,7 @@ static void outputSummary(Collection districtsWithGarbage, Scenar if (deliveryElement.getLocation() == Id.createLinkId(linkGruenauerStr)) { sizeGruenauerStr = sizeGruenauerStr + (shipmentSizes.get(deliveryShipmentId)); } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckChessboard")) { + if (scheduledTour.getVehicle().getId() == Id.createVehicleId("TruckChessboard")) { sizeChessboardDelivery = sizeChessboardDelivery + (shipmentSizes.get(deliveryShipmentId)); } } @@ -906,31 +876,31 @@ static void outputSummary(Collection districtsWithGarbage, Scenar } } allCollectedGarbage = sizeForckenbeck + sizeMalmooer + sizeNordring + sizeGradestrasse + sizeChessboard; - powerConsumptionTour = (double) (distanceTour / 1000) * powerConsumptionPerDistance - + (double) (sizeTour / 1000) * powerConsumptionPerWeight; + powerConsumptionTour = (double) (distanceTour / 1000) * energyConsumptionPerDistance + + (double) (sizeTour / 1000) * energyConsumptionPerWeight; - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckForckenbeck")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckForckenbeck")) { tourDistancesForckenbeck.add(vehiclesForckenbeck, (double) Math.round(distanceTour / 1000)); powerConsumptionTourForckenbeck.add(vehiclesForckenbeck, (double) Math.round(powerConsumptionTour)); vehiclesForckenbeck++; } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckMalmoeer")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckMalmoeer")) { tourDistancesMalmoeerStr.add(vehiclesMalmoeer, (double) Math.round(distanceTour / 1000)); powerConsumptionTourMalmoeerStr.add(vehiclesMalmoeer, (double) Math.round(powerConsumptionTour)); vehiclesMalmoeer++; } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckNordring")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckNordring")) { tourDistancesNordring.add(vehiclesNordring, (double) Math.round(distanceTour / 1000)); powerConsumptionTourNordring.add(vehiclesNordring, (double) Math.round(powerConsumptionTour)); vehiclesNordring++; } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckGradestrasse")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckGradestrasse")) { tourDistancesGradestrasse.add(vehiclesGradestrasse, (double) Math.round(distanceTour / 1000)); powerConsumptionTourGradestrasse.add(vehiclesGradestrasse, (double) Math.round(powerConsumptionTour)); vehiclesGradestrasse++; } - if (scheduledTour.getVehicle().getVehicleId() == Id.createVehicleId("TruckChessboard")) { + if (scheduledTour.getVehicle().getId().toString().contains("TruckChessboard")) { tourDistancesChessboard.add(vehiclesChessboard, (double) Math.round(distanceTour / 1000)); tourDistanceChessboard = tourDistanceChessboard + tourDistancesChessboard.get(vehiclesChessboard); powerConsumptionTourChessboard.add(vehiclesChessboard, (double) Math.round(powerConsumptionTour)); @@ -1053,17 +1023,19 @@ static void outputSummary(Collection districtsWithGarbage, Scenar + "\n"); } writer.write("\n" + "Fahrzeug: \t\t\t\t\t\t\t\t\t\t\t\t\t" + vehicleTypeId + "\n"); - writer.write("Kapazität je Fahrzeug: \t\t\t\t\t\t\t\t\t\t" + ((double) capacityTruck / 1000) + " Tonnen\n\n"); - writer.write("Volumen der Mülltonne: \t\t\t\t\t\t\t\t\t\t"+ volumeDustbin+" Liter\n"); - writer.write("ServiceTime pro Mülltonne:\t\t\t\t\t\t\t\t\t"+secondsServiceTimePerDustbin+" Sekunden\n\n"); - writer.write("Iterationen jsprit:\t\t\t\t\t\t\t\t\t\t\t"+ jspritIterations +"\n"); - writer.write("Iterationen MATSim:\t\t\t\t\t\t\t\t\t\t\t"+ matsimIterations+"\n"); + writer.write( + "Kapazität je Fahrzeug: \t\t\t\t\t\t\t\t\t\t" + ((double) capacityTruck / 1000) + " Tonnen\n\n"); + writer.write("Volumen der Mülltonne: \t\t\t\t\t\t\t\t\t\t" + volumeDustbin + " Liter\n"); + writer.write( + "ServiceTime pro Mülltonne:\t\t\t\t\t\t\t\t\t" + secondsServiceTimePerDustbin + " Sekunden\n\n"); + writer.write("Iterationen jsprit:\t\t\t\t\t\t\t\t\t\t\t" + jspritIterations + "\n"); + writer.write("Iterationen MATSim:\t\t\t\t\t\t\t\t\t\t\t" + matsimIterations + "\n"); writer.write("\n" + "Die Summe des abzuholenden Mülls beträgt: \t\t\t\t\t" + ((double) allGarbage) / 1000 + " t\n\n"); writer.write("Anzahl der Abholstellen: \t\t\t\t\t\t\t\t\t" + numberOfShipments + "\n"); writer.write("Anzahl der Abholstellen ohne Abholung: \t\t\t\t\t\t" + noPickup + "\n\n"); writer.write("Anzahl der Carrier mit Shipments:\t\t\t\t\t\t\t" + carrierWithShipments + "\n\n"); - writer.write("Anzahl der entleerten Mülltonnen:\t\t\t\t\t\t\t"+amountOfCollectedDustbins+"\n\n"); + writer.write("Anzahl der entleerten Mülltonnen:\t\t\t\t\t\t\t" + amountOfCollectedDustbins + "\n\n"); writer.write("Anzahl der Muellfahrzeuge im Einsatz: \t\t\t\t\t\t" + (numberVehicles) + "\t\tMenge gesamt:\t" + ((double) allCollectedGarbage) / 1000 + " t\n\n"); if (day != null) { @@ -1075,6 +1047,7 @@ static void outputSummary(Collection districtsWithGarbage, Scenar writer.write("\t\t\tFahrstrecke Min:\t\t\t\t" + minTourForckenbeck + " km\n"); writer.write("\t\t\tFahrstrecke Durchschnitt:\t\t" + Math.round(averageTourDistanceForckenbeck) + " km\n"); + if (electricCar == true) { writer.write("\t\t\tEnergieverbrauch Summe:\t\t\t" + powerConsumptionForckenbeck + " kwh\n"); writer.write("\t\t\tEnergieverbrauch Max:\t\t\t" + maxPowerConsumptionForckenbeck + " kwh\n"); @@ -1178,6 +1151,15 @@ static void outputSummary(Collection districtsWithGarbage, Scenar */ static void outputSummaryShipments(Scenario scenario, String day, HashMap carrierMap) { + double capacityTruck = 0; + String vehicleTypeId = null; + + Carriers allCarriers = (Carriers) scenario.getScenarioElement("carriers"); + Carrier testCarrier = allCarriers.getCarriers().values().iterator().next(); + for (VehicleType usedType : testCarrier.getCarrierCapabilities().getVehicleTypes()) { + capacityTruck = usedType.getCapacity().getOther(); + vehicleTypeId = usedType.getId().toString(); + } FileWriter writer; File file; file = new File(scenario.getConfig().controler().getOutputDirectory() + "/01_ZusammenfassungShipments.txt"); @@ -1213,4 +1195,178 @@ static void outputSummaryShipments(Scenario scenario, String day, HashMap, Double> personId2tourDistance = new HashMap<>(); + Map, Double> personId2tourConsumptionkWh = new HashMap<>(); + Map usedNumberPerVehicleType = new HashMap<>(); + ArrayList toursWithOverconsumption = new ArrayList<>(); + CarrierVehicleTypes vehicleTypes = new CarrierVehicleTypes(); + + Carriers allCarriers = (Carriers) scenario.getScenarioElement("carriers"); + Carrier testCarrier = allCarriers.getCarriers().values().iterator().next(); + for (VehicleType usedType : testCarrier.getCarrierCapabilities().getVehicleTypes()) { + vehicleTypes.getVehicleTypes().put(usedType.getId(), usedType); + usedNumberPerVehicleType.put(usedType.getId().toString(), 0); + } + + Network network = scenario.getNetwork(); + + BufferedWriter writer; + File file; + file = new File(scenario.getConfig().controler().getOutputDirectory() + "/02_SummaryOutput.txt"); + + writer = new BufferedWriter(new FileWriter(file, true)); + String now = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date()); + writer.write("Tourenstatisitik erstellt am: " + now + "\n\n"); + + for (Carrier singleCarrier : carriers.getCarriers().values()) { + + double totalDistance = 0; + int numberOfVehicles = 0; + double distanceTour; + int numCollections = 0; + int tourNumberCarrier = 1; + VehicleType vt = null; + + for (ScheduledTour scheduledTour : singleCarrier.getSelectedPlan().getScheduledTours()) { + distanceTour = 0.0; + for (VehicleType vt2 : singleCarrier.getCarrierCapabilities().getVehicleTypes()) { + if (vt2.getId().toString() + .contains(scheduledTour.getVehicle().getType().getId().toString())) { + + vt = vt2; + break; + } + } + + int vehicleTypeCount = usedNumberPerVehicleType + .get(scheduledTour.getVehicle().getType().getId().toString()); + usedNumberPerVehicleType.replace(scheduledTour.getVehicle().getType().getId().toString(), + vehicleTypeCount + 1); + + List elements = scheduledTour.getTour().getTourElements(); + for (Tour.TourElement element : elements) { + if (element instanceof Tour.Pickup) { + numCollections++; + + } + if (element instanceof Tour.Leg) { + Tour.Leg legElement = (Tour.Leg) element; + if (legElement.getRoute().getDistance() != 0) + distanceTour = distanceTour + + RouteUtils.calcDistance((NetworkRoute) legElement.getRoute(), 0, 0, network); + } + } + Id personId = Id.create( + scheduledTour.getVehicle().getType().getId() + "-Tour " + tourNumberCarrier, + Person.class); + personId2tourDistance.put(personId, distanceTour); + if (vt.getEngineInformation().getAttributes().getAttribute("fuelType").equals("electricity")) { + personId2tourConsumptionkWh.put(personId, (distanceTour / 1000) * (double) vt.getEngineInformation() + .getAttributes().getAttribute("engeryConsumptionPerKm")); + } + totalDistance = totalDistance + distanceTour; + tourNumberCarrier++; + } + numberOfVehicles = numberOfVehicles + (tourNumberCarrier - 1); + writer.write("\n\n" + "Version: " + singleCarrier.getId().toString() + "\n"); + writer.write("\tAnzahl der Abholstellen (Soll): \t\t\t\t\t" + singleCarrier.getShipments().size() + "\n"); + writer.write("\tAnzahl der Abholstellen ohne Abholung: \t\t\t\t" + + (singleCarrier.getShipments().size() - numCollections) + "\n"); + writer.write("\tAnzahl der Fahrzeuge:\t\t\t\t\t\t\t\t" + numberOfVehicles + "\n"); + for (VehicleType singleVehicleType : vehicleTypes.getVehicleTypes().values()) { + if (singleCarrier.getId().toString().equals(singleVehicleType.getDescription())) { + writer.write("\t\t\tAnzahl Typ " + singleVehicleType.getId().toString() + ":\t\t\t\t" + + usedNumberPerVehicleType.get(singleVehicleType.getId().toString()) + "\n"); + } + } + writer.write( + "\n" + "\tGefahrene Kilometer insgesamt:\t\t\t\t\t\t" + Math.round(totalDistance / 1000) + " km\n"); + writer.write("\tVerfügbare Fahrzeugtypen:\t\t\t\t\t\n\n"); + for (VehicleType singleVehicleType : vehicleTypes.getVehicleTypes().values()) { + + writer.write( + "\t\t\tID: " + singleVehicleType.getId() + "\t\tAntrieb: " + + singleVehicleType.getEngineInformation().getAttributes().getAttribute("fuelType") + .toString() + + "\t\tKapazität: " + singleVehicleType.getCapacity().getOther() + "\t\tFixkosten:" + + singleVehicleType.getCostInformation().getFixedCosts() + " €"); + if (singleVehicleType.getEngineInformation().getAttributes().getAttribute("fuelType") + .equals("electricity")) { + double electricityConsumptionPer100km = 0; + double electricityCapacityinkWh = 0; + electricityConsumptionPer100km = (double) singleVehicleType.getEngineInformation().getAttributes() + .getAttribute("engeryConsumptionPerKm"); + electricityCapacityinkWh = (double) singleVehicleType.getEngineInformation().getAttributes() + .getAttribute("engeryCapacity"); + + writer.write("\t\tLadekapazität: " + electricityCapacityinkWh + " kWh\t\tVerbrauch: " + + electricityConsumptionPer100km + " kWh/100km\t\tReichweite: " + + (int) Math.round(electricityCapacityinkWh / electricityConsumptionPer100km) + " km\n"); + } else + writer.write("\n"); + + } + writer.write("\n\n" + "\tTourID\t\t\t\t\t\tdistance (max Distance) (km)\tconsumption (capacity) (kWh)\n\n"); + + for (Id id : personId2tourDistance.keySet()) { + + int tourDistance = (int) Math.round(personId2tourDistance.get(id) / 1000); + int consumption = 0; + double distanceRange = 0; + double electricityCapacityinkWh = 0; + double electricityConsumptionPerkm = 0; + + for (VehicleType singleVehicleType : vehicleTypes.getVehicleTypes().values()) { + + if (id.toString().contains(singleVehicleType.getId().toString()) && singleVehicleType + .getEngineInformation().getAttributes().getAttribute("fuelType").equals("electricity")) { + + electricityConsumptionPerkm = (double) singleVehicleType.getEngineInformation().getAttributes() + .getAttribute("engeryConsumptionPerKm"); + electricityCapacityinkWh = (double) singleVehicleType.getEngineInformation().getAttributes() + .getAttribute("engeryCapacity"); + distanceRange = (int) Math.round(electricityCapacityinkWh / electricityConsumptionPerkm); + consumption = (int) Math.round(personId2tourConsumptionkWh.get(id)); + + if (consumption > electricityCapacityinkWh) + toursWithOverconsumption.add(id.toString()); + } + } + + writer.write("\t" + id + "\t\t" + tourDistance); + if (distanceRange > 0) { + writer.write(" (" + distanceRange + ")\t\t\t\t\t\t" + consumption + " (" + electricityCapacityinkWh + + ")"); + } else + writer.write("\t\t\t\t\t\t\t\t\t\t"); + writer.newLine(); + + } + personId2tourConsumptionkWh.clear(); + personId2tourDistance.clear(); + } + writer.flush(); + writer.close(); + log.info("Output geschrieben"); + log.info("### Done."); + if (toursWithOverconsumption.isEmpty() == false) + throw new Exception("The tour(s) " + toursWithOverconsumption.toString() + + " have a higher consumption then their capacity"); + + } + } diff --git a/src/main/java/org/matsim/run/wasteCollection/Run_Abfall.java b/src/main/java/org/matsim/run/wasteCollection/Run_Abfall.java index dc7d56002..d75d92dc8 100644 --- a/src/main/java/org/matsim/run/wasteCollection/Run_Abfall.java +++ b/src/main/java/org/matsim/run/wasteCollection/Run_Abfall.java @@ -11,10 +11,10 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.freight.Freight; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; import org.matsim.contrib.freight.carrier.CarrierPlanXmlWriterV2; +import org.matsim.contrib.freight.carrier.CarrierVehicleTypes; import org.matsim.contrib.freight.carrier.Carriers; import org.matsim.contrib.freight.utils.FreightUtils; import org.matsim.core.config.Config; @@ -34,13 +34,15 @@ public class Run_Abfall { static final Logger log = Logger.getLogger(Run_Abfall.class); private static final String original_Chessboard = "https://raw.githubusercontent.com/matsim-org/matsim/master/examples/scenarios/freight-chessboard-9x9/grid9x9.xml"; - private static final String modified_Chessboard = "scenarios/chessboard/modifiedChessboard9x9.xml"; - //TODO update to v5.5 private static final String berlin = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin/berlin-v5.2-1pct/output-berlin-v5.2-1pct/berlin-v5.2-1pct.output_network.xml.gz"; - private static final String berlinDistrictsWithGarbageInformations = "scenarios/berlin-v5.5-10pct/wasteCollection/districtsWithGarbageInformations.shp"; + private static final String berlinDistrictsWithGarbageInformations = "scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.shp"; + private static final String inputVehicleTypes = "scenarios/berlin-v5.5-10pct/input/wasteCollection/vehicleTypes.xml"; + private static final String inputCarriersWithDieselVehicle = "scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_diesel_vehicle.xml"; + private static final String inputCarriersWithMediumBatteryVehicle = "scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_medium_EV.xml"; + private static final String inputCarriersWithSmallBatteryVehicle = "scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_small_EV.xml"; private enum netzwerkAuswahl { - originalChessboard, modifiedChessboard, berlinNetwork + originalChessboard, berlinNetwork }; private enum scenarioAuswahl { @@ -50,19 +52,12 @@ private enum scenarioAuswahl { }; - public static void main(String[] args) { - -/* String shapeFileLocation = args[0]; - int jspritIterations = Integer.parseInt(args[1]); - double volumeDustbin = Double.parseDouble(args[2]); // in liter - double secondsServiceTimePerDustbin = Double.parseDouble(args[3]); - boolean electricCar = Boolean.parseBoolean(args[4]); - String outputLocation = args[5]; -*/ - FleetSize fleetSize = null; - String day = null; + private enum carrierChoice { + carriersWithDieselVehicle, carriersWithMediumBattereyVehicle, carriersWithSmallBatteryVehicle, + carriersFromInputFile + } - log.setLevel(Level.INFO); + public static void main(String[] args) throws Exception { /* * You have to decide the network. If you choose one of the chessboard networks, @@ -70,8 +65,51 @@ public static void main(String[] args) { * network, you have to select one of the Berlin cases. The beginning of the * name of the scenario shows you the needed network. */ + netzwerkAuswahl netzwerkWahl = netzwerkAuswahl.berlinNetwork; - scenarioAuswahl scenarioWahl = scenarioAuswahl.berlinCollectedGarbageForOneDay; + scenarioAuswahl scenarioWahl = null; + carrierChoice chosenCarrier = null; + int jspritIterations; + double volumeDustbinInLiters; + double secondsServiceTimePerDustbin; + String outputLocation; + String day; + String networkChangeEventsFileLocation; + String carriersFileLocation = null; + String vehicleTypesFileLocation = null; + String shapeFileLocation; + boolean oneCarrierForOneDistrict; + + for (String arg : args) { + log.info(arg); + } + if (args.length == 0) { + chosenCarrier = carrierChoice.carriersWithDieselVehicle; + scenarioWahl = scenarioAuswahl.berlinSelectedDistricts; + shapeFileLocation = berlinDistrictsWithGarbageInformations; + oneCarrierForOneDistrict = true; + jspritIterations = 100; + volumeDustbinInLiters = 1100; // in liter + secondsServiceTimePerDustbin = 41; + outputLocation = "output/wasteCollection/Scenario1"; + day = "MO"; + networkChangeEventsFileLocation = ""; + } else { + scenarioWahl = scenarioAuswahl.berlinCollectedGarbageForOneDay; + jspritIterations = Integer.parseInt(args[0]); + volumeDustbinInLiters = Double.parseDouble(args[1]); // in liter + secondsServiceTimePerDustbin = Double.parseDouble(args[2]); + day = args[3]; + outputLocation = args[4]; + vehicleTypesFileLocation = args[5]; + networkChangeEventsFileLocation = args[6]; + carriersFileLocation = args[7]; + shapeFileLocation = args[8]; + oneCarrierForOneDistrict = Boolean.parseBoolean(args[9]); + chosenCarrier = carrierChoice.carriersFromInputFile; + } + + log.setLevel(Level.INFO); // MATSim config Config config = ConfigUtils.createConfig(); @@ -81,70 +119,75 @@ public static void main(String[] args) { config.controler().setOutputDirectory("output/original_Chessboard/04_Distances"); config.network().setInputFile(original_Chessboard); break; - case modifiedChessboard: - // modified with some different freespeeds and lengths for some links - config.controler().setOutputDirectory("output/modified_Chessboard/03_Test_elektrisch"); - config.network().setInputFile(modified_Chessboard); - break; case berlinNetwork: // Berlin scenario network -// config.controler().setOutputDirectory(outputLocation); //for cluster - config.controler().setOutputDirectory("output/Berlin_Neu/Montag/Hellersdorf_elektr5"); + config.controler().setOutputDirectory(outputLocation); config.network().setInputFile(berlin); + if (networkChangeEventsFileLocation != "") { + log.info("Setting networkChangeEventsInput file: " + networkChangeEventsFileLocation); + config.network().setTimeVariantNetwork(true); + config.network().setChangeEventsInputFile(networkChangeEventsFileLocation); + } break; default: new RuntimeException("no network selected."); } - int lastMATSimIteration = 0; - int jspritIterations = 20; //Moved to args[] for cluster - config = AbfallUtils.prepareConfig(config, lastMATSimIteration); + switch (chosenCarrier) { + case carriersWithDieselVehicle: + vehicleTypesFileLocation = inputVehicleTypes; + carriersFileLocation = inputCarriersWithDieselVehicle; + break; + case carriersWithSmallBatteryVehicle: + vehicleTypesFileLocation = inputVehicleTypes; + carriersFileLocation = inputCarriersWithSmallBatteryVehicle; + break; + case carriersWithMediumBattereyVehicle: + vehicleTypesFileLocation = inputVehicleTypes; + carriersFileLocation = inputCarriersWithMediumBatteryVehicle; + break; + case carriersFromInputFile: + break; + default: + new RuntimeException("no carriers selected."); + } + config = AbfallUtils.prepareConfig(config, 0, vehicleTypesFileLocation, carriersFileLocation); Scenario scenario = ScenarioUtils.loadScenario(config); + FreightUtils.loadCarriersAccordingToFreightConfig(scenario); // creates carrier - Carriers carriers = FreightUtils.getOrCreateCarriers(scenario); - HashMap carrierMap = AbfallUtils.createCarrier(); - - // creates a garbage truck type and ads this type to the carrierVehicleTypes - boolean electricCar = false; //Moved to args[] for cluster - AbfallUtils.createAndAddVehicles(electricCar); + Carriers carriers = FreightUtils.addOrGetCarriers(scenario); + HashMap carrierMap = AbfallUtils.createCarrier(carriers); - // Map, ? extends Link> allLinks = scenario.getNetwork().getLinks(); HashMap> garbageDumps = AbfallUtils.createDumpMap(); -// Collection districtsWithGarbage = ShapeFileReader -// .getAllFeatures(shapeFileLocation); - Collection districtsWithGarbage = ShapeFileReader - .getAllFeatures(berlinDistrictsWithGarbageInformations); + Collection districtsWithGarbage = ShapeFileReader + .getAllFeatures(shapeFileLocation); AbfallUtils.createMapWithLinksInDistricts(districtsWithGarbage, allLinks); - double volumeDustbin = 1100; // in liter ////Moved to args[] for cluster - double secondsServiceTimePerDustbin = 41; //Moved to args[] for cluster - switch (scenarioWahl) { case chessboardTotalGarbageToCollect: int kgGarbageToCollect = 12 * 1000; + CarrierVehicleTypes carrierVehicleTypes = FreightUtils.getCarrierVehicleTypes(scenario); AbfallChessboardUtils.createShipmentsForChessboardI(carrierMap, kgGarbageToCollect, allLinks, - volumeDustbin, secondsServiceTimePerDustbin, scenario, carriers); - fleetSize = FleetSize.INFINITE; - AbfallChessboardUtils.createCarriersForChessboard(carriers, fleetSize); + volumeDustbinInLiters, secondsServiceTimePerDustbin, scenario, carriers); + FleetSize fleetSize = FleetSize.INFINITE; + AbfallChessboardUtils.createCarriersForChessboard(carriers, fleetSize, carrierVehicleTypes); break; case chessboardGarbagePerMeterToCollect: double kgGarbagePerMeterToCollect = 0.2; + CarrierVehicleTypes carrierVehicleTypes2 = FreightUtils.getCarrierVehicleTypes(scenario); AbfallChessboardUtils.createShipmentsForChessboardII(carrierMap, kgGarbagePerMeterToCollect, allLinks, - volumeDustbin, secondsServiceTimePerDustbin, scenario, carriers); - fleetSize = FleetSize.INFINITE; - AbfallChessboardUtils.createCarriersForChessboard(carriers, fleetSize); + volumeDustbinInLiters, secondsServiceTimePerDustbin, scenario, carriers); + FleetSize fleetSize2 = FleetSize.INFINITE; + AbfallChessboardUtils.createCarriersForChessboard(carriers, fleetSize2, carrierVehicleTypes2); break; case berlinSelectedDistricts: // day input: MO or DI or MI or DO or FR - List districtsForShipments = Arrays.asList("Lichtenberg"); - day = "MO"; + List districtsForShipments = Arrays.asList("Malchow"); + day = "MI"; AbfallUtils.createShipmentsForSelectedArea(districtsWithGarbage, districtsForShipments, day, garbageDumps, - scenario, carriers, carrierMap, allLinks, volumeDustbin, - secondsServiceTimePerDustbin); - fleetSize = FleetSize.INFINITE; - AbfallUtils.createCarriersBerlin(districtsWithGarbage, carriers, carrierMap, fleetSize); + scenario, carriers, carrierMap, allLinks, volumeDustbinInLiters, secondsServiceTimePerDustbin); break; case berlinDistrictsWithInputGarbagePerMeter: // day input: MO or DI or MI or DO or FR @@ -153,10 +196,8 @@ public static void main(String[] args) { areasForShipmentPerMeterMap.put("Malchow", 1.0); day = "MI"; AbfallUtils.createShipmentsWithGarbagePerMeter(districtsWithGarbage, areasForShipmentPerMeterMap, day, - garbageDumps, scenario, carriers, carrierMap, allLinks, volumeDustbin, + garbageDumps, scenario, carriers, carrierMap, allLinks, volumeDustbinInLiters, secondsServiceTimePerDustbin); - fleetSize = FleetSize.INFINITE; - AbfallUtils.createCarriersBerlin(districtsWithGarbage, carriers, carrierMap, fleetSize); break; case berlinDistrictsWithInputTotalGarbagePerDistrict: // day input: MO or DI or MI or DO or FR @@ -166,18 +207,13 @@ public static void main(String[] args) { // areasForShipmentPerVolumeMap.put("Hansaviertel", 20 * 1000); day = "MI"; AbfallUtils.createShipmentsGarbagePerVolume(districtsWithGarbage, areasForShipmentPerVolumeMap, day, - garbageDumps, scenario, carriers, carrierMap, allLinks, volumeDustbin, + garbageDumps, scenario, carriers, carrierMap, allLinks, volumeDustbinInLiters, secondsServiceTimePerDustbin); - fleetSize = FleetSize.INFINITE; - AbfallUtils.createCarriersBerlin(districtsWithGarbage, carriers, carrierMap, fleetSize); break; case berlinCollectedGarbageForOneDay: // MO or DI or MI or DO or FR - day = "MO"; AbfallUtils.createShipmentsForSelectedDay(districtsWithGarbage, day, garbageDumps, scenario, carriers, - carrierMap, allLinks, volumeDustbin, secondsServiceTimePerDustbin); - fleetSize = FleetSize.INFINITE; - AbfallUtils.createCarriersBerlin(districtsWithGarbage, carriers, carrierMap, fleetSize); + carrierMap, allLinks, volumeDustbinInLiters, secondsServiceTimePerDustbin, oneCarrierForOneDistrict); break; default: new RuntimeException("no scenario selected."); @@ -189,19 +225,21 @@ public static void main(String[] args) { */ AbfallUtils.outputSummaryShipments(scenario, day, carrierMap); // jsprit - + AbfallUtils.solveWithJsprit(scenario, carriers, carrierMap, jspritIterations); - final Controler controler = new Controler(scenario); + // final Controler controler = new Controler(scenario); + Controler controler = AbfallUtils.prepareControler(scenario); + +// AbfallUtils.scoringAndManagerFactory(scenario, controler); - Freight.configure(controler); controler.run(); new CarrierPlanXmlWriterV2(carriers) .write(scenario.getConfig().controler().getOutputDirectory() + "/output_CarrierPlans.xml"); - AbfallUtils.outputSummary(districtsWithGarbage, scenario, carrierMap, day, electricCar, volumeDustbin, secondsServiceTimePerDustbin); - + AbfallUtils.outputSummary(districtsWithGarbage, scenario, carrierMap, day, volumeDustbinInLiters, + secondsServiceTimePerDustbin); + AbfallUtils.createResultFile(scenario, carriers); } - } diff --git a/src/test/java/org/matsim/run/wasteCollection/AbfallUtilsTest.java b/src/test/java/org/matsim/run/wasteCollection/AbfallUtilsTest.java index a2d2bda41..475d33b3e 100644 --- a/src/test/java/org/matsim/run/wasteCollection/AbfallUtilsTest.java +++ b/src/test/java/org/matsim/run/wasteCollection/AbfallUtilsTest.java @@ -26,16 +26,16 @@ import org.junit.Rule; import org.junit.Test; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; -import org.matsim.contrib.freight.carrier.CarrierVehicle; -import org.matsim.contrib.freight.carrier.CarrierVehicleType; import org.matsim.contrib.freight.carrier.Carriers; -import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize; +import org.matsim.contrib.freight.utils.FreightUtils; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.utils.gis.ShapeFileReader; import org.matsim.testcases.MatsimTestUtils; -import org.matsim.vehicles.VehicleType; -import org.matsim.vehicles.EngineInformation.FuelType; import org.opengis.feature.simple.SimpleFeature; /** @@ -54,7 +54,18 @@ public final void setUp() { @Test public final void testCreateCarrierMap() { - HashMap carrierMap = AbfallUtils.createCarrier(); + String vehicleTypesFileLocation = "scenarios/berlin-v5.5-10pct/input/wasteCollection/vehicleTypes.xml"; + String inputCarriersWithDieselVehicle = "scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_diesel_vehicle.xml"; + String inputCarriersWithMediumBatteryVehicle = "scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_medium_EV.xml"; + String inputCarriersWithSmallBatteryVehicle = "scenarios/berlin-v5.5-10pct/input/wasteCollection/carriers_small_EV.xml"; + Config config = ConfigUtils.createConfig(); + config = AbfallUtils.prepareConfig(config, 0, vehicleTypesFileLocation, inputCarriersWithDieselVehicle); + Scenario scenario = ScenarioUtils.loadScenario(config); + FreightUtils.loadCarriersAccordingToFreightConfig(scenario); + + // creates carrier + Carriers carriers = FreightUtils.addOrGetCarriers(scenario); + HashMap carrierMap = AbfallUtils.createCarrier(carriers); Assert.assertEquals(4, carrierMap.size()); Assert.assertTrue(carrierMap.containsKey("Nordring")); Assert.assertTrue(carrierMap.containsKey("MalmoeerStr")); @@ -63,51 +74,37 @@ public final void testCreateCarrierMap() { for (Carrier singleCarrier : carrierMap.values()) { Assert.assertNotNull(singleCarrier); } - } - - @Test - public final void testCreateAndAddVehicles() { - AbfallUtils.createAndAddVehicles(true); - Assert.assertEquals(FuelType.electricity, AbfallUtils.carrierVehType.getEngineInformation().getFuelType()); - Assert.assertEquals(0., AbfallUtils.carrierVehType.getVehicleCostInformation().getCostsPerSecond(), 0); - Assert.assertTrue(AbfallUtils.vehicleTypes.getVehicleTypes().containsKey(AbfallUtils.carrierVehType.getId())); - AbfallUtils.createAndAddVehicles(false); - Assert.assertEquals(FuelType.diesel, AbfallUtils.carrierVehType.getEngineInformation().getFuelType()); - Assert.assertEquals(0., AbfallUtils.carrierVehType.getCostInformation().getCostsPerSecond(), 0); - Assert.assertTrue(AbfallUtils.vehicleTypes.getVehicleTypes().containsKey(AbfallUtils.carrierVehType.getId())); - } - - @Test - public final void testCreateGarbageTruck() { - AbfallUtils.carrierVehType = CarrierVehicleType.Builder.newInstance(Id.create("truckType", VehicleType.class)) - .build(); - CarrierVehicle truck = AbfallUtils.createGarbageTruck("testTruck", "12345", 3600., 7200.); - Assert.assertEquals("testTruck", truck.getVehicleId().toString()); - Assert.assertEquals("12345", truck.getLocation().toString()); - Assert.assertEquals(3600., truck.getEarliestStartTime(), MatsimTestUtils.EPSILON); - Assert.assertEquals(7200., truck.getLatestEndTime(), MatsimTestUtils.EPSILON); - - } - - @Test - public final void testCreateCarriersBerlin() { - final String berlinDistrictsWithGarbageInformations = "scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.shp"; - Carriers testCarriers = new Carriers(); - HashMap carrierMap = AbfallUtils.createCarrier(); - Collection districtsWithGarbage = ShapeFileReader - .getAllFeatures(berlinDistrictsWithGarbageInformations); - AbfallUtils.carrierVehType = CarrierVehicleType.Builder.newInstance(Id.create("truckType", VehicleType.class)) - .build(); - AbfallUtils.createCarriersBerlin(districtsWithGarbage, testCarriers, carrierMap, FleetSize.INFINITE); - + + config = AbfallUtils.prepareConfig(config, 0, vehicleTypesFileLocation, inputCarriersWithMediumBatteryVehicle); + scenario = ScenarioUtils.loadScenario(config); + FreightUtils.loadCarriersAccordingToFreightConfig(scenario); + + // creates carrier + carriers = FreightUtils.addOrGetCarriers(scenario); + carrierMap = AbfallUtils.createCarrier(carriers); + Assert.assertEquals(4, carrierMap.size()); + Assert.assertTrue(carrierMap.containsKey("Nordring")); + Assert.assertTrue(carrierMap.containsKey("MalmoeerStr")); + Assert.assertTrue(carrierMap.containsKey("Gradestrasse")); + Assert.assertTrue(carrierMap.containsKey("Forckenbeck")); for (Carrier singleCarrier : carrierMap.values()) { - Assert.assertEquals(FleetSize.INFINITE, singleCarrier.getCarrierCapabilities().getFleetSize()); - Assert.assertEquals(1, singleCarrier.getCarrierCapabilities().getVehicleTypes().size()); - Assert.assertTrue( - singleCarrier.getCarrierCapabilities().getVehicleTypes().contains(AbfallUtils.carrierVehType)); - Assert.assertEquals(1, singleCarrier.getCarrierCapabilities().getCarrierVehicles().size()); + Assert.assertNotNull(singleCarrier); } + config = AbfallUtils.prepareConfig(config, 0, vehicleTypesFileLocation, inputCarriersWithSmallBatteryVehicle); + scenario = ScenarioUtils.loadScenario(config); + FreightUtils.loadCarriersAccordingToFreightConfig(scenario); + // creates carrier + carriers = FreightUtils.addOrGetCarriers(scenario); + carrierMap = AbfallUtils.createCarrier(carriers); + Assert.assertEquals(4, carrierMap.size()); + Assert.assertTrue(carrierMap.containsKey("Nordring")); + Assert.assertTrue(carrierMap.containsKey("MalmoeerStr")); + Assert.assertTrue(carrierMap.containsKey("Gradestrasse")); + Assert.assertTrue(carrierMap.containsKey("Forckenbeck")); + for (Carrier singleCarrier : carrierMap.values()) { + Assert.assertNotNull(singleCarrier); + } } @Test @@ -132,7 +129,7 @@ public final void testCreateDumpMap() { @Test public final void testShapeFile() { - final String berlinDistrictsWithGarbageInformations = "scenarios/berlin-v5.5-10pct/input/wasteCollection/districtsWithGarbageInformations.shp"; + final String berlinDistrictsWithGarbageInformations = "scenarios/berlin-v5.5-10pct/input/wasteCollection/garbageInput/districtsWithGarbageInformations.shp"; Collection districtsWithGarbage = ShapeFileReader .getAllFeatures(berlinDistrictsWithGarbageInformations); for (SimpleFeature districtInformation : districtsWithGarbage) { From b302ece69fa1cc163723f044552b13adffe5cea8 Mon Sep 17 00:00:00 2001 From: dziemke Date: Thu, 3 Mar 2022 15:03:10 +0100 Subject: [PATCH 12/13] remove old WP that was referenced here. it's updated and the newer one is stated on top --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index c2cc9568e..ad53d1bc0 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,4 @@ controler.run --- ### More information -For more information about the scenario generation, see VSP working paper # 19-01 under https://www.vsp.tu-berlin.de/publications/vspwp . - For more information about MATSim, see here: https://www.matsim.org/. From cdf79663de795719c39866a45812ac40c2c418d3 Mon Sep 17 00:00:00 2001 From: kainagel Date: Mon, 23 May 2022 18:38:50 +0200 Subject: [PATCH 13/13] Update README.md --- README.md | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index c2cc9568e..a4a84494a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # The MATSim Open Berlin Scenario ![Berlin MATSim network and agents)](scenarios/berlin-v5.5-10pct/visualization-berlin.png "Berlin MATSim network and agents") -### About this project +## About this project This repository provides an open MATSim transport model for Berlin, provided by the [Transport Systems Planning and Transport Telematics group](https://www.vsp.tu-berlin.de) of [Technische Universität Berlin](http://www.tu-berlin.de). Please reference/cite the scenario based on this paper. @@ -11,15 +11,15 @@ This repository provides an open MATSim transport model for Berlin, provided by Currently, there are two versions of the MATSim Open Berlin model: -##### 10pct scenario (`scenarios/berlin-v5.x-10pct`) +### 10pct scenario (`scenarios/berlin-v5.x-10pct`) This scenario contains a 10pct sample of the Greater Berlin population; road capacities are accordingly reduced. The scenario is calibrated taking into consideration the traffic counts, modal split and mode-specific trip distance distributions. -##### 1pct scenario (`scenarios/berlin-v5.x-1pct`) +### 1pct scenario (`scenarios/berlin-v5.x-1pct`) This scenario contains a 1pct sample of the Greater Berlin population; road capacities are accordingly reduced. This scenario was not (!) calibrated and should only be used for testing purposes or pre-studies. -### Licenses +## Licenses The **MATSim program code** in this repository is distributed under the terms of the [GNU General Public License as published by the Free Software Foundation (version 2)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html). The MATSim program code are files that reside in the `src` directory hierarchy and typically end with `*.java`. @@ -30,21 +30,21 @@ The **MATSim input files, output files, analysis data and visualizations** are l **Other data files**, in particular in `original-input-data`, have their own individual licenses that need to be individually clarified with the copyright holders. -### Note +## Note Handling of large files within git is not without problems (git lfs files are not included in the zip download; we have to pay; ...). In consequence, large files, both on the input and on the output side, reside at https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin . Please check out the latest release / the latest numbered branch since those are stable. The master branch is an potentially unstable development head. ---- -### Simple things (without installing/running MATSim) +## Simple things (without installing/running MATSim) -##### Movies +### Movies 1. Go to https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin/ 1. Decide for a scenario that you find interesting (e.g. `berlin-v5.x-10pct`) and go into that directory. 1. Inside there, look for an `output-*` directory that you find interesting and go into that directory. 1. Inside there, look for `movie-*` files. You can't watch them directly, but there are various ways to download them. You can watch them then. Try that. -##### Run VIA on output files +### Run VIA on output files 1. Get VIA from https://www.simunto.com/via/. (There is a free license for a small number of agents; that will probably work but only display a small number of vehicles/agents.) 1. Go to https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin/ . @@ -55,15 +55,15 @@ Handling of large files within git is not without problems (git lfs files are no 1. Run VIA and enjoy. ---- -### Downloading the repository - Alternative 1: Download ZIP +## Downloading the repository - Alternative 1: Download ZIP 1. Click on `Clone or download` and then on `Download ZIP`. 1. Unzip the repository. 1. Go to "Run the MATSim Berlin scenario" below. -### Downloading the repository - Alternative 2: Clone the repository +## Downloading the repository - Alternative 2: Clone the repository -##### Initial stuff (needs to be done once) +### Initial stuff (needs to be done once) 1. Install git for the command line. 1. Type `git clone https://github.com/matsim-scenarios/matsim-berlin.git` in the command line. @@ -72,7 +72,7 @@ Handling of large files within git is not without problems (git lfs files are no This will result in a new `matsim-berlin` directory. Memorize where you have put it. You can move it, as a whole, to some other place. -##### Update your local clone of the repository. +### Update your local clone of the repository. 1. Go into the `matsim-berlin` directory. 1. Type `git pull` @@ -82,9 +82,11 @@ This will result in a new `matsim-berlin` directory. Memorize where you have pu This will update your repository to the newest version. ---- -### Run the MATSim Berlin scenario - -##### ... using a runnable jar file +## Run the MATSim Berlin scenario ... +
+ +

... using a runnable jar file

+
(Requires either cloning or downloading the repository.) 1. Depending on the version of matsim-berlin you have selected, you might have to create the jar file yourself. @@ -106,7 +108,11 @@ java -jar [FILENAME].jar 1. "Open" the output directory. You can drag files into VIA as was already done above. 1. "Edit..." (in the GUI) the config file. Re-run MATSim. -##### ... using an IDE, e.g. Eclipse, IntelliJ - Alternative 1: use cloned/downloaded matsim-berlin repository +
+
+ +

... using an IDE, e.g. Eclipse, IntelliJ - Alternative 1: use cloned/downloaded matsim-berlin repository

+
(Requires either cloning or downloading the repository.) 1. Set up the project in your IDE. @@ -114,8 +120,9 @@ java -jar [FILENAME].jar 1. Run the JAVA class `src/main/java/org/matsim/run/RunBerlinScenario.java` or `src/main/java/org/matsim/gui/RunBerlinScenarioGUI.java`. 1. "Open" the output directory. You can drag files into VIA as was already done above. 1. Edit the config file or adjust the run class. Re-run MATSim. - -##### ... using an IDE, e.g. Eclipse, IntelliJ - Alternative 2: use matsim-berlin as a maven dependency +
+
+

... using an IDE, e.g. Eclipse, IntelliJ - Alternative 2: use matsim-berlin as a maven dependency

1. Clone the matsim-example-project: https://github.com/matsim-org/matsim-example-project 2. Add a maven dependency to the open berlin project by writing the following to the pom file: @@ -150,9 +157,10 @@ Controler controler = RunBerlinScenario.prepareControler( scenario ) ; controler.run ``` +
--- -### More information +## More information For more information about the scenario generation, see VSP working paper # 19-01 under https://www.vsp.tu-berlin.de/publications/vspwp .