Java Code Examples for org.matsim.core.controler.AbstractModule

The following examples show how to use org.matsim.core.controler.AbstractModule. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: amodeus   Source File:    License: GNU General Public License v2.0 6 votes vote down vote up
static public Controler createController(Scenario scenario, EventHandler handler, int vehicleCapacity) {
    Controler controller = new Controler(scenario);

    controller.addOverridingModule(new DvrpModule());
    controller.addOverridingModule(new DvrpTravelTimeModule());
    controller.addOverridingModule(new AmodeusModule());

    controller.addOverridingModule(new AbstractModule() {
        public void install() {
            AmodeusUtils.registerGeneratorFactory(binder(), "Single", SingleVehicleGeneratorFactory.class);

        public SingleVehicleGeneratorFactory provideFactory() {
            return new SingleVehicleGeneratorFactory(vehicleCapacity, Id.createLinkId("link1"));

    controller.addOverridingQSimModule(new AmodeusQSimModule());


    return controller;
Example 2
Source Project: matsim-maas   Source File:    License: GNU General Public License v2.0 5 votes vote down vote up
public static void run(Config config, boolean otfvis) {
	Controler controler = DrtControlerCreator.createControler(config, otfvis);
	controler.addOverridingModule(new DrtFareModule());
	final SimpleVKTCounter vktCounter = new SimpleVKTCounter();
	controler.addOverridingModule(new AbstractModule() {
		public void install() {
	Logger.getLogger(RunDRTClass.class).info("VKT traveled in last iteration: " + Math.round(vktCounter.getVkt_counted()) + " km");
Example 3
Source Project: amod   Source File:    License: GNU General Public License v2.0 4 votes vote down vote up
/** runs a simulation run using input data from, av.xml and MATSim config.xml
 * @throws MalformedURLException
 * @throws Exception */

public void simulate(StringSocket stringSocket, int numReqTot, //
        File workingDirectory) throws MalformedURLException, Exception {
    /** working directory and options */
    scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());

    /** set to true in order to make server wait for at least 1 client, for
     * instance viewer client, for fals the ScenarioServer starts the simulation
     * immediately */
    boolean waitForClients = scenarioOptions.getBoolean("waitForClients");
    configFile = new File(scenarioOptions.getSimulationConfigName());
    /** geographic information */
    LocationSpec locationSpec = scenarioOptions.getLocationSpec();
    referenceFrame = locationSpec.referenceFrame();

    /** open server port for clients to connect to */

    /** load MATSim configs - including av.xml configurations, load routing packages */
    DvrpConfigGroup dvrpConfigGroup = new DvrpConfigGroup();
    Config config = ConfigUtils.loadConfig(configFile.toString(), new AmodeusConfigGroup(), dvrpConfigGroup);
    config.planCalcScore().addActivityParams(new ActivityParams("activity"));
    // TODO @Sebastian fix this to meaningful values, remove, or add comment
    // this was added because there are sometimes problems, is there a more elegant option?
    for (ActivityParams activityParams : config.planCalcScore().getActivityParams()) {

    /** load MATSim scenario for simulation */
    Scenario scenario = ScenarioUtils.loadScenario(config);;
    network = scenario.getNetwork();
    Population population = scenario.getPopulation();

    MatsimAmodeusDatabase db = MatsimAmodeusDatabase.initialize(network, referenceFrame);
    Controler controller = new Controler(scenario);
    AmodeusConfigurator.configureController(controller, db, scenarioOptions);

    /** try to load link speed data and use for speed adaption in network */
    try {
        File linkSpeedDataFile = new File(scenarioOptions.getLinkSpeedDataName());
        LinkSpeedDataContainer lsData = LinkSpeedUtils.loadLinkSpeedData(linkSpeedDataFile);
        controller.addOverridingQSimModule(new TrafficDataModule(lsData));
    } catch (Exception exception) {
        System.err.println("Unable to load linkspeed data, freeflow speeds will be used in the simulation.");

    controller.addOverridingModule(new SocketModule(stringSocket, numReqTot));

    /** Custom router that ensures same network speeds as taxis in original data set. */
    controller.addOverridingModule(new AbstractModule() {
        public void install() {
            AmodeusUtils.bindRouterFactory(binder(), TaxiTravelTimeRouter.class.getSimpleName()).to(TaxiTravelTimeRouter.Factory.class);

    /** adding the dispatcher to receive and process string fleet commands */
    controller.addOverridingModule(new AbstractModule() {
        public void install() {
            AmodeusUtils.registerDispatcherFactory(binder(), "SocketDispatcherHost", SocketDispatcherHost.Factory.class);

    /** adding an initial vehicle placer */
    controller.addOverridingModule(new AbstractModule() {
        public void install() {
            AmodeusUtils.bindGeneratorFactory(binder(), RandomDensityGenerator.class.getSimpleName()).//

    /** run simulation */;

    /** close port for visualizaiton */

    /** perform analysis of simulation */
    /** output directory for saving results */
    outputDirectory = new File(config.controler().getOutputDirectory());