Skip to content

Commit

Permalink
added test for carfreeare
Browse files Browse the repository at this point in the history
  • Loading branch information
zlukich committed Feb 19, 2024
1 parent 3ec0d53 commit d3ce7fd
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions src/test/java/org/matsim/run/ParkingLeipzigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.matsim.analysis.ParkingLocation;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.ActivityStartEvent;
import org.matsim.api.core.v01.events.Event;
import org.matsim.api.core.v01.events.PersonMoneyEvent;
import org.matsim.api.core.v01.events.handler.ActivityStartEventHandler;
import org.matsim.api.core.v01.population.Person;
Expand All @@ -17,9 +18,15 @@
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.events.EventsManagerImpl;
import org.matsim.core.events.EventsUtils;
import org.matsim.core.events.handler.BasicEventHandler;
import org.matsim.core.population.PopulationUtils;
import org.matsim.run.prepare.NetworkOptions;
import org.matsim.simwrapper.SimWrapperConfigGroup;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -34,6 +41,7 @@ public class ParkingLeipzigTest {

private static final String URL = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/leipzig/leipzig-v1.2/input/";
private static final String exampleShp = "input/v1.2/drtServiceArea/Leipzig_stadt.shp";
private static final List<String> agents = new ArrayList<>(List.of("residentLeisureInOA", "outsiderLeisureInOA", "parkingAgentCarFreeLeisureCloseToResParkingZone"));

@Test
public final void runPoint1pctIntegrationTestWithParking() {
Expand All @@ -45,7 +53,7 @@ public final void runPoint1pctIntegrationTestWithParking() {
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controler().setOutputDirectory(output.toString());
ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;
config.plans().setInputFile("/Users/gregorr/Documents/work/respos/public-svn/matsim/scenarios/countries/de/leipzig/leipzig-v1.3/input/testParkingPopulation.xml");
config.plans().setInputFile("testParkingPopulation.xml");

MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct","--drt-area", exampleShp, "--post-processing", "disabled",
"--parking-cost-area", "input/v" + "1.3" + "/parkingCostArea/Bewohnerparken_2020.shp",
Expand All @@ -65,7 +73,7 @@ public final void runPoint1pctIntegrationTestWithParking() {
}

@Test
public final void runPoint1pctIntegrationTestWithParkingWithCarFreeArea() {
public final void runPoint1pctIntegrationTestWithParkingWithCarFreeArea() throws IOException {
Path output = Path.of("output-parking-test-withCarFreeArea/it-1pct");
Config config = ConfigUtils.loadConfig("input/v1.2/leipzig-v1.2-10pct.config.xml");
config.global().setNumberOfThreads(1);
Expand All @@ -77,29 +85,55 @@ public final void runPoint1pctIntegrationTestWithParkingWithCarFreeArea() {

//TODO maybe write the test population
// for the test case combination look at the ChessboardParkingTest
config.plans().setInputFile("/Users/gregorr/Documents/work/respos/public-svn/matsim/scenarios/countries/de/leipzig/leipzig-v1.3/input/testParkingPopulation.xml");
config.plans().setInputFile("testParkingPopulation.xml");

MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct","--drt-area", exampleShp, "--post-processing", "disabled",
"--parking-cost-area", "input/v" + "1.3" + "/parkingCostArea/Bewohnerparken_2020.shp",
"--intermodality", "drtAsAccessEgressForPt", "--parking", "--car-free-area", "/Users/gregorr/Documents/work/respos/shared-svn/projects/NaMAV/data/shapefiles/leipzig_carfree_area_small/Zonen99_update.shp");
"--intermodality", "drtAsAccessEgressForPt", "--parking", "--car-free-area", "input/v1.2/carfree/leipzig_carfree_area_small/Zonen99_update.shp");

EventsManager eventsManager = EventsUtils.createEventsManager();
eventsManager.addHandler(new ParkingActivityStartEventHandler());
EventsUtils.readEvents(eventsManager , output +"/" + "/leipzig-1pct.output_events.xml.gz");


for (ActivityStartEvent event: ParkingActivityStartEventHandler.parkingEvents) {
if (event.getPersonId().equals("parkingAgentCarFreeLeisureCloseToResParkingZone")) {
Assert.assertTrue(event.getLinkId().equals("11827009#2"));
if (event.getAttributes().get("person").equals("residentLeisureInOA")) {
var link = event.getAttributes().get("link");
var time = event.getAttributes().get("time");
if(time.equals("3888.0")){
Assert.assertTrue(link.equals("206552443"));
}

//Assert.assertTrue(event.getLinkId().equals("11827009#2"));
}
if (event.getAttributes().get("person").equals("outsiderLeisureInOA")) {
var link = event.getAttributes().get("link");
var time = event.getAttributes().get("time");
if(time.equals("4113.0")){
Assert.assertTrue(link.equals("-56064787#1"));
}
}
if (event.getAttributes().get("person").equals("parkingAgentCarFreeLeisureCloseToResParkingZone")) {
var link = event.getAttributes().get("link");
var time = event.getAttributes().get("time");
if(time.equals("3889.0")){
Assert.assertTrue(link.equals("11827009#2"));
}

}
}

// writer.close();

}

class ParkingActivityStartEventHandler implements ActivityStartEventHandler {
static List<ActivityStartEvent> parkingEvents = new ArrayList<>();
@Override
public void handleEvent(ActivityStartEvent activityStartEvent) {
if (activityStartEvent.getActType().equals("parking interaction")) {
parkingEvents.add(activityStartEvent);
public void handleEvent(ActivityStartEvent event) {
if(agents.contains(event.getPersonId().toString())){
if(event.getActType().equals("car interaction") || event.getActType().equals("parking interaction"))
parkingEvents.add(event);
}
}
}
Expand Down

0 comments on commit d3ce7fd

Please sign in to comment.