matsim-org / matsim-libs

Multi-Agent Transport Simulation
www.matsim.org
479 stars 446 forks source link

How to change link allowed modes dynamically? Using NetworkChangeEvent? #2088

Closed FrankHuang777 closed 2 years ago

FrankHuang777 commented 2 years ago

Hello, all!

I know NetworkChangeEvent can help change the flowCapacity, freespeed and lanes of specified links during simulation by using networkChangeEvents.xml or writing some code, like the following shows:

<?xml version="1.0" encoding="UTF-8"?>
<networkChangeEvents xmlns="http://www.matsim.org/files/dtd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.matsim.org/files/dtd http://www.matsim.org/files/dtd/networkChangeEvents.xsd">
    <networkChangeEvent startTime="03:00:00">
        <link refId="1"/>
        <link refId="2"/>
        <link refId="3"/>
        <freespeed type="absolute" value="1.0"/>
    </networkChangeEvent>
</networkChangeEvents>
NetworkChangeEvent networkChangeEvent = new NetworkChangeEvent(3*3600);
Link link1 = scenario.getNetwork().getLinks().get(Id.createLinkId("1"));
networkChangeEvent.setFreespeedChange(new NetworkChangeEvent.ChangeValue(NetworkChangeEvent.ChangeType.ABSOLUTE_IN_SI_UNITS, 1));
networkChangeEvent.addLink(link1);
NetworkUtils.addNetworkChangeEvent(scenario.getNetwork(), networkChangeEvent);

In my project, I need to change the link allowed modes dynamically. For example, link 1 allowed car and pt <link id="1112" from="11" to="12" length="1200.00" capacity="2000" freespeed="12" modes="car, pt" permlanes="1" /> I want to make link 1 pt only, i.e. modes="pt" from 7am to 9am, what should I do?

Thanks!

JWJoubert commented 2 years ago

Hi @FrankHuang777, an undergraduate student of mine, @rgraebe did something similar for the high-occupancy vehicle (HOV) lane on the N2 freeway in the City of Cape Town (I hope the street view link works - bus/HOV lane is right-most lane).

Anyway, the approach we followed is the following:

Did I get that right, @rgraebe? The only unintended consequence is that I cannot remember what happens to agents when they find themselves still on AB_hov when its number of lanes become zero again. Maybe @rgraebe can chip in.

FrankHuang777 commented 2 years ago

Thanks @JWJoubert , I think it is a very clever way to achieve the effect I want. I will check what will happen to vehicles when the number of lanes goes to zero, perhaps they will be stuck.

I'm also trying to extend NetworkChangeEvent to support more dynamic changes to link attributes, but that's a bit difficult for me. 😂

Thanks again for your help!

rgraebe commented 2 years ago

Hi @FrankHuang777. Actually, we had quite some difficulties when using NetworkchangeEvents for the functionality you seek. If I am not mistaken, exactly that: the issue of the stuck vehicles. Instead, we (@JWJoubert and I) got away without using a NetworkChangeEvent.

  1. We duplicated every AB link that was relevant to the case.
  2. Link AB's permlanes attribute was reduced by one and the duplicated link AB_hov had permlanes=1. This is how we kept the same "capacity".
  3. But, to enforce adherence to our intervention: "Only HOV on the single lane during 7-9am" we had to implement the VehicleBanChecker.
  4. The vehicleBan determines if it is a banned vehicle, on a banned link, on a banned time and penalises the agent.

We used this to "incentivise" non-HGVs to stay out of the HOV lane (link) during peak travel times. This did the trick with no NetworkChangeEvent - hope it helps!

FrankHuang777 commented 2 years ago

Thank you @rgraebe , I think I have achieved the effect I wanted without using NetworkChangeEvent.

In fact, I study the scenario of traffic restrictions based on the last digit of license plate numbers. This means I need to ban certain vehicles at certain times and on certain roads depending on their license plate number. I achieve this indirectly by increasing the time required for the restricted vehicle to pass on the restricted road. The only thing I do is modifying TravelTimeCalculator.

Thanks for your advice!