Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a custom linkDynamics for QSim? #1195

Closed
A-Mashiro opened this issue Jan 1, 2025 · 1 comment
Closed

How to add a custom linkDynamics for QSim? #1195

A-Mashiro opened this issue Jan 1, 2025 · 1 comment

Comments

@A-Mashiro
Copy link

Hi all,

I am currently working on my bachelor's thesis which involves simulating the behaviour of emergency vehicles in MATSim. I understand this is not supported out of the box since QSim uses a FIFO queuing discipline that cannot simulate the priority an emergency vehicle would have had in real life. So, my idea of achieving it was to add another linkDynamics similar to how passingQ can be used instead of the default FIFO queue for QSim.

However, I can't seem to find any examples of how this can be achieved. For example, I am unable to find an extension point for adding a custom linkDynamics for QSim. Second, I don't see how can the QueueWithBuffer be modified so that the new custom linkDynamics can be used in QSim for simulation.

Therefore, I wish to know that is adding a custom linkDynamics for QSim possible? If so, what should be the correct procedure for it? Any help is much appreciated, thank you.

@kainagel
Copy link
Member

kainagel commented Jan 2, 2025

Hello, I don't know how good your programming is but you could try

import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.Controler;
import org.matsim.core.mobsim.qsim.AbstractQSimModule;
import org.matsim.core.mobsim.qsim.qnetsimengine.linkspeedcalculator.LinkSpeedCalculator;
import org.matsim.core.scenario.ScenarioUtils;

/**
 * @author nagel
 *
 */
public class RunConfigurableQNetworkFactoryExample {

	public static void main(String[] args) {

		Config config = ConfigUtils.createConfig(args[0]) ;
		
		run(config);
		
	}

	static void run(Config config) {
		final Scenario scenario = ScenarioUtils.createScenario( config ) ;
		
		Controler controler = new Controler( scenario ) ;
		
		final EventsManager events = controler.getEvents() ;
		
		controler.addOverridingQSimModule( new AbstractQSimModule(){
			@Override public void configureQSim() {
				final ConfigurableQNetworkFactory factory = new ConfigurableQNetworkFactory(events, scenario);
				factory.setVehicleQFactory( ... );
				bind(QNetworkFactory.class).toInstance(factory);
				// NOTE: Other than when using a provider, this uses the same factory instance over all iterations, re-configuring
				// it in every iteration via the initializeFactory(...) method. kai, mar'16
			}
		});
		
		controler.run();
	}

}

And set the replaced VehicleQ factory where the ... are. If this does not help please let me know and I will try to extend the example a bit.

Best wishes

Kai

PS: The reason why there is no example for this in code-examples is that we would prefer to bind the VehicleQFactory directly since that would be easier to use. But for that I would need a bit more time which I do not have right now :-(. @sebhoerl : Maybe you or someone in your group would have time to do this? I would add it into AbstractQSimModule in the same was as addLinkSpeedCalculator() is added there. This is modeled in parallel to AbstractModule, which has such methods to simplify access to standard MATSim bindings. Should IMO be relatively straightforward but should also have a test etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants