matsim-org/matsim-code-examples

Registering new modes in EES (BDI MATSIM) extension

HossseinMoradi opened this issue · 18 comments

I have defined a scenario, which perfectly works when the leg mode for all agents in the plan is car. When add a new mode to the plan file it drops this error:

Could not find requested vehicle 9056 in simulation for agent BasicPlanAgentImpl{plan=[score=undefined][nof_acts_legs=5][type=null][personId=9056], vehicle=null, state=LEG, currentPlanElementIndex=1, currentLinkId=1326} with id 9056 on link 1326 at time 43235.0.

and while the test get passed, all agents get stuck and aborted.

The log file is ttached. Furthermore, the config and vehicles file are as follows:

<module name="global">
	<param name="randomSeed" value="148256" />
	<param name="coordinateSystem" value="EPSG:25831" />
	<param name="numberOfThreads" value="1" />
</module>

<module name="network">
	<param name="inputNetworkFile" value="Mallorca_network_epsg25831.xml.gz" />
	<param name= "timeVariantNetwork" value= "false" />
</module>

<module name="plans">
	<param name="inputPlansFile" value="Mallorca_Population_epsg25831.xml" />
</module>

<module name="controler">
	<param name="outputDirectory" value="output" />
	<param name="firstIteration" value="0" />
	<param name="lastIteration" value="0" />
	<param name="mobsim" value="qsim" />
	<param name="snapshotFormat" value="googleearth"/>

</module>

<module name="qsim">
	<param name="vehiclesSource" value="modeVehicleTypesFromVehiclesData" />
	<param name="mainMode" value="car,other" />
	<param name="linkDynamics" value="PassingQ" />
	<param name="trafficDynamics" value="kinematicWaves" />

</module>

<module name="planCalcScore">

	<parameterset type="scoringParameters">
	<param name="lateArrival" value="-18" />
	<param name="performing" value="+6" />

		<parameterset type="modeParams">
			<param name="mode" value="car"/>
			<param name="marginalUtilityOfTraveling_util_hr" value="-6.0" />
		</parameterset>

		<parameterset type="modeParams">
			<param name="mode" value="pt"/>
		</parameterset>

	<parameterset type="activityParams">
		<param name="activityType"    value="home" /> <!-- home -->
		<param name="priority"        value="1" />
		<param name="typicalDuration" value="12:00:00" />
		<param name="minimalDuration" value="08:00:00" />
	</parameterset>

	<parameterset type="activityParams">
		<param name="activityType"    value="shop" />
		<param name="priority"        value="1" />
		<param name="typicalDuration" value="01:00:00" />
		<param name="minimalDuration" value="00:30:00" />
	</parameterset>

	<parameterset type="modeParams" >
		<param name="mode" value="other" />
	</parameterset>
	</parameterset>
</module>

<module name="planscalcroute" >
	<param name="networkModes" value="car,other" />
</module>

<module name="vehicles" >
	<param name="vehiclesFile" value="mode-vehicles.xml" />
</module>

<module name="strategy">
	<param name="maxAgentPlanMemorySize" value="5" /> <!-- 0 means unlimited -->

	<parameterset type="strategysettings">
		<param name="strategyName" value="BestScore"/>
		<param name="weight" value="0.9"/>
	</parameterset>

	<parameterset type="strategysettings">
		<param name="strategyName" value="ReRoute"/>
		<param name="weight" value="0.1"/>
	</parameterset>
</module>

<module name="travelTimeCalculator" >
	<param name="analyzedModes" value="car,other" />
	<param name="separateModes" value="true" />
</module>
<vehicleType id="other">
	<length meter="7.5"/>
	<width meter="1.0"/>
	<maximumVelocity meterPerSecond="0.5"/>
	<accessTime secondsPerPerson="1.0"/>
	<egressTime secondsPerPerson="1.0"/>
	<doorOperation mode="serial"/>
	<passengerCarEquivalents pce="0.25"/>
</vehicleType>

logfile.log

Could you try to add a car VehicleType to your vehicles.xml file?

Could you try to add a car VehicleType to your vehicles.xml file?

I had added it.

<vehicleType id="other">
	<length meter="7.5"/>
	<width meter="1.0"/>
	<maximumVelocity meterPerSecond="0.5"/>
	<accessTime secondsPerPerson="1.0"/>
	<egressTime secondsPerPerson="1.0"/>
	<doorOperation mode="serial"/>
	<passengerCarEquivalents pce="0.25"/>
</vehicleType>
The problem is when I use any mode/name instead of car, it does not work

You have set car and other as Qsim mainModes in your config. You have to make sure that both modes have a corresponding vehicle type in your vehicles.xml. From your message, I wasn't sure, whether this is the case. Your vehicles.xml should contain at least the following:

<vehicleType id="other">
	<length meter="7.5"/>
	<width meter="1.0"/>
	<maximumVelocity meterPerSecond="0.5"/>
	<accessTime secondsPerPerson="1.0"/>
	<egressTime secondsPerPerson="1.0"/>
	<doorOperation mode="serial"/>
	<passengerCarEquivalents pce="0.25"/>
</vehicleType>
<vehicleType id="car">
	<length meter="7.5"/>
	<width meter="1.0"/>
	<maximumVelocity meterPerSecond="0.5"/>
	<accessTime secondsPerPerson="1.0"/>
	<egressTime secondsPerPerson="1.0"/>
	<doorOperation mode="serial"/>
	<passengerCarEquivalents pce="0.25"/>
</vehicleType>

You could also try setting the following parameter within the qsim module in your config:

<param name="usePersonIdForMissingVehicleId" value="false" />

This way, MATSim generates vehicles for each mode and person before the simulation starts.

Apart from your crash, your log file contains a lot of these messages:

2023-10-18T23:30:38,788  WARN EditTrips:103 InternalInterface is null. Replanning of pt/transit legs will not work properly and will likely fail.
2023-10-18T23:30:38,788  WARN EditTrips:121 no TransitStopAgentTracker found in qsim. Replanning of pt/transit legs will not work properly and will likely fail.

This indicates that something is not right with your run. However, I can't really tell from the log file what it is. Once, you have resolved the crashing issue, you should also look into that.

You have set car and other as Qsim mainModes in your config. You have to make sure that both modes have a corresponding vehicle type in your vehicles.xml. From your message, I wasn't sure, whether this is the case. Your vehicles.xml should contain at least the following:

<vehicleType id="other">
	<length meter="7.5"/>
	<width meter="1.0"/>
	<maximumVelocity meterPerSecond="0.5"/>
	<accessTime secondsPerPerson="1.0"/>
	<egressTime secondsPerPerson="1.0"/>
	<doorOperation mode="serial"/>
	<passengerCarEquivalents pce="0.25"/>
</vehicleType>
<vehicleType id="car">
	<length meter="7.5"/>
	<width meter="1.0"/>
	<maximumVelocity meterPerSecond="0.5"/>
	<accessTime secondsPerPerson="1.0"/>
	<egressTime secondsPerPerson="1.0"/>
	<doorOperation mode="serial"/>
	<passengerCarEquivalents pce="0.25"/>
</vehicleType>

You could also try setting the following parameter within the qsim module in your config:

<param name="usePersonIdForMissingVehicleId" value="false" />

This way, MATSim generates vehicles for each mode and person before the simulation starts.

Apart from your crash, your log file contains a lot of these messages:

2023-10-18T23:30:38,788  WARN EditTrips:103 InternalInterface is null. Replanning of pt/transit legs will not work properly and will likely fail.
2023-10-18T23:30:38,788  WARN EditTrips:121 no TransitStopAgentTracker found in qsim. Replanning of pt/transit legs will not work properly and will likely fail.

This indicates that something is not right with your run. However, I can't really tell from the log file what it is. Once, you have resolved the crashing issue, you should also look into that.

I have used similar vehicles.xml containing all modes. I have also added <param name="usePersonIdForMissingVehicleId" value="false" /> To Qsim. The test succeeded, but all my agents became stuck and aborted. Note that switching to only 'car' mode resolves the issue. I believe I might need to define modes in a java class, in addition to the vehicles.xml file, but I do not know where. Could you guide me on where to do that?

This should not be that difficult. Would it be possible to upload a runnable example (including network.xml, plans.xml, config.xml) on a git repository and make this accessible for us? If you can share at least the network, it would be sufficient to have only 1 or 2 plans which demonstrate the problem.

This should not be that difficult. Would it be possible to upload a runnable example (including network.xml, plans.xml, config.xml) on a git repository and make this accessible for us? If you can share at least the network, it would be sufficient to have only 1 or 2 plans which demonstrate the problem.

Thanks. I have sent two invitations for ¨test 1¨ that results in error and ¨test 2¨ that uses ¨car¨ mode and passes without error.

Hello, I modified test1 so that I can run matsim from there. I also added the test2 material into the same repo. Please run from RunMatsim in that repo so that we are on the same page. There is also a RunTest class that runs both cases in sequence.

For me, both cases run. However, in both cases the agents do not move, i.e. the 1st and the 2nd activity are at the same location, and there are no other activities. So your error does not show up.

What now?

Hello, I modified test1 so that I can run matsim from there. I also added the test2 material into the same repo. Please run from RunMatsim in that repo so that we are on the same page. There is also a RunTest class that runs both cases in sequence.

For me, both cases run. However, in both cases the agents do not move, i.e. the 1st and the 2nd activity are at the same location, and there are no other activities. So your error does not show up.

What now?

Hello Kai, thanks. The problem is in the ees extension. Yes, there is no activities until agents move towards centers after lets say earthquake. For such an evacuation, one mode (only car) is defined. I do not know how to add/define other modes (lets say netwalk, bikee, etc) for the evac part. Attach is the run test which can be used and see the error.

`package io.github.agentsoz.ees.it;

import io.github.agentsoz.ees.Run;
import org.junit.Rule;
import org.junit.Test;
import org.matsim.testcases.MatsimTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Mallorca {

// have tests in separate classes so that they run, at least under maven, in separate JVMs.  kai, nov'17

private static final Logger log = LoggerFactory.getLogger(Mallorca.class) ;

@Rule
public MatsimTestUtils utils = new MatsimTestUtils() ;

@Test
public void test() {

    utils.getOutputDirectory(); // creates a clean one so need to call this first
    String[] args = {
            "--config", "scenarios/Mallorca/ees.xml",
    };
    Run.main(args);

}

}
`

Would it be possible to set up a git repo that contains runnable code from which I could reconstruct the problem? Otherwise, it is quite difficult to say anything specific. I don't have a runnable ees setup any more, sorry. In the (not updated for a long time) version that I have, at some point it says (in ActionHandlerForDriveto) // routingMode: String routingMode = null ; // could have some default switch (((MATSimModel.RoutingMode) args[3])) { case carFreespeed: routingMode = MATSimModel.RoutingMode.carFreespeed.name() ; break; case carGlobalInformation: routingMode = MATSimModel.RoutingMode.carGlobalInformation.name() ; break; default: throw new RuntimeException("not implemented" ) ; } This means that at that point only those two modes are implemented. I can't say from this how those two routing modes interact with mode vehicles. I am, in fact, a bit surprised that it works with "car". Would need an example.

What I have done is to first build the system as instructed in ees and then run the scenario provided in ¨test 2¨ (which is only using car mode) through the run class I have provided above. This setup works. On the other hand, if we use scenario provided in ¨test1¨, it does not. I tried to build a git repo that contains runnable code here, but I could not (I am not really experienced in using Git). Thanks a lot for your help.

@HossseinMoradi would you be able to add me to your repo with the tests so I can have a look? The BDI-MATSim machinery that EES uses was only ever tested with evacuating "cars", so will require some updating as you have hinted.

@dhixsingh Hi Dhirendra. I have added you.

@HossseinMoradi I can't run your EES example in full because you are using a custom BDI class that I don't have access to.

However, the problem in this case seems to be that you have restricted all network links to allow only car mode:

<link id= ... modes="car" >

If I change the allowed modes on all links to modes="car,other" and run your example with a single agent that has the following example plan for instance, then it works fine, as in, the agent moves on the network.

<plan selected="yes">
  <activity type="home" x="524500" y="4384600" end_time="00:01:00"/>
  <leg mode="other"/>
  <activity type="home" x="523500" y="4384600"/>
</plan>

@dhixsingh No, it is not a problem. I have created a simple test, that is test4. Please find the log attached.
logfile.log
logfileWarningsErrors.log

@HossseinMoradi the new repo you shared looks empty. Note though that it would be better to commit changes in the existing test repo to make is easier to see what changed between tries.

@dhixsingh As you can find in the test1Multimodal, I have added the simple population/plan to be on the same page. The network was already `modes="car,other", resulting in the following log files:
logfile.log
logfileWarningsErrors.log

@HossseinMoradi I have checked in a branch with a version that works with the latest EES. Let me know if that works for you.