matsim-org / matsim-code-examples

A repository containing code examples around MATSim
GNU General Public License v3.0
81 stars 178 forks source link

set back the changes in the network after change event #388

Open SarahSie opened 4 years ago

SarahSie commented 4 years ago

I want to change the network for a limited time; let’s say one hour. When I put the freeSpeed and Capacity to zero, then after that, agents do not use that road. However, as a new event, when I set back the freeSpeed and Capacity to the original value, then still agents do not use that road any more for the whole day. (Please consider that I want to run MATSim one time, so one iteration. I got the output of 200 iterations and used as the input for this one iteration for road disruption analysis.). I have the following netwrokChangeEvent.xml file:

What should I do that after a particular moment again, the road comes back to its original situation, and agents use it again?

<?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="08:00:00">
        <link refId="36907"/>
        <freespeed type="absolute" value="0.0"/>
    </networkChangeEvent>

    <networkChangeEvent startTime="08:00:01">
        <link refId="36907"/>
        <flowCapacity type="absolute" value="0.0"/>
    </networkChangeEvent>

    <networkChangeEvent startTime="09:00:00">
        <link refId="36907"/>
        <freespeed type="absolute" value="13.88888888888889"/>
    </networkChangeEvent>

    <networkChangeEvent startTime="09:00:01">
        <link refId="36907"/>       
        <flowCapacity type="absolute" value="3000.0"/>
    </networkChangeEvent>

</networkChangeEvents>
kainagel commented 4 years ago

Looks ok. You might have the problem that freespeed=0 means linkLeaveTime=infinity, and so a car that entered while the link was blocked will never leave. Which has the consequence that any car entering later also cannot leave. Things to try:

Let us know how it goes.

SarahSie commented 4 years ago

@kainagel Thank you for your reply. As you mentioned, I used the passingQ in the mobsim:

<param name="linkDynamics" value="PassingQ" />

Then the networkChangeEvent as:

<?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="08:00:00">
        <link refId="36907"/>
        <flowCapacity type="absolute" value="0.0"/>
    </networkChangeEvent>

    <networkChangeEvent startTime="09:00:00">
        <link refId="36907"/>           
        <flowCapacity type="absolute" value="3000.0"/>
    </networkChangeEvent>

</networkChangeEvents>

which such changes, the road is not disrupted for the agents and agnates can pass the road easily during the disruption time (between 8 and 9 o'clock). What should I do then to make a disruption road for one hour?

kainagel commented 4 years ago

That shouldn't be the case. But maybe the following resolves the riddle:

MATSim uses the queue model for computational speed. It roughly works as follows:

Any change to these link properties only applies in the very mechanical sense. So:


So one guess is that what you are seeing is the effect of stuckTime. You could try to set stucktime to a very large value. However, in general that does not work so well. Hm. We never that the situation yet that a link got reopened. Maybe what you want is a traffic signal at that particular link?

SarahSie commented 4 years ago

I use passingQ, and I set flowcapacity and freespeed to zero between 8 and 9 o’clock. and my stuck time is: <param name="stuckTime" value="108000.0" />

I have seen that agents who in a normal day pass that special street, in the disruption situation (setting flowcapacity and freespeed to zero), they are not able to continue their travel. They never complete their plan, which is somehow weird. Because usually, they should wait until 9 and then the street is again available, and they can pass. However, it is not the case. I run this simulation thought one iteration. So it means that those agents enter the link, but they can never leave the link. what should I do to make agents be able to leave the link after 9 o’clock? (I have already set the freespeed and flowCapacity to their normal value when the time is 9)

Another issue is that When I run it through the serval iterations (200 iterations), still those agents cannot complete their traveling. It means that they could not learn that the street is not available between 8 and 9.

How can I solve the issue?

kainagel commented 4 years ago

If you set freespeed to zero between 8 and 9, than any vehicle entering the link during that time will have a earliest link exit time of inifinity, i.e. never leave the link.

I guess that you are confronted with the issue that MATSim is not as microscopically detailed as it seems; we do that to improve computational speed.

Things to play around with:


An alternative would be to use the "signals" contrib. Define a traffic light that is red from 8 to 9.

===

The replanning ...

... should react to vehicles that are delayed on the link ... should react to freespeed changes ... will not react to capacity changes except when the capacity reduction produces a traffic jam.

Again, for what you have in mind, you might be more happy with a traffic signal.

SarahSie commented 4 years ago

@kainagel thank you for your reply. then I have defined the signal_systems.xml input data such as:

    <signalSystem id="1">
        <signals>
            <signal linkIdRef="44848" id="1"/>
        <signal linkIdRef="44841" id="2"/>
        </signals>
    </signalSystem>

I have seen in the code by @tthunig (CreateAllDayGreenFromSignalControl)

// set them to green for the whole cycle (all day green)
                    signalGroupSetting.setOnset(0);
                    signalGroupSetting.setDropping(signalPlan.getCycleTime());

for all green, onSet is zero and dropping is cycleTime. I used the same logic vise versa for Red signal light (onSet equal CycleTime and dropping zero) in the input XML data. however, it is not working and still, agents can pass the links.

    <signalSystem refId="1">
        <signalSystemController>
            <controllerIdentifier>DefaultPlanbasedSignalSystemController</controllerIdentifier>
            <signalPlan id="1">
                <start daytime="08:00:00"/>
                <stop daytime="09:00:00"/>
                <cycleTime sec="120"/>
                <offset sec="0"/>
                <signalGroupSettings refId="1">
                    <onset sec="120"/>
                    <dropping sec="0"/>
                </signalGroupSettings>
            </signalPlan>
            <signalPlan id="2">
                <start daytime="00:00:00"/>
                <stop daytime="08:00:00"/>
                <cycleTime sec="60"/>
                <offset sec="0"/>
                <signalGroupSettings refId="1">
                    <onset sec="0"/>
                    <dropping sec="120"/>
                </signalGroupSettings>
            </signalPlan>
            <signalPlan id="3">
                <start daytime="09:00:00"/>
                <stop daytime="00:00:00"/>
                <cycleTime sec="120"/>
                <offset sec="0"/>
                <signalGroupSettings refId="1">
                    <onset sec="0"/>
                    <dropping sec="120"/>
                </signalGroupSettings>
            </signalPlan>
        </signalSystemController>

How can I set the signal_control.xml in order to have red lights between 8 and 9 o'clock and the rest of the day green?

SarahSie commented 4 years ago

@kainagel update about he netwrokChangeEvent.xml, as you told me:

Things to play around with:

* Set your reduced speed to a value such that those vehicles can eventually escape.

I have put the freeSpeed to 1.0 instead of 13.88888888888889, then I observed that agents pass the links with a very low speed, not only on those specific links that I have defined, but also the links before and after them as well.

* Leave speed at high value; change only the capacity (and use a relative high stucktime).

I have run the simulation with the mentioned condition, then agents still can pass the links although the capacity of the links is 0.