Case 2: Your own mental module

The short story

A mental module

  • extracts information from the events stream
  • modifies plans when they are given to it

You can write your own mental module and plug it into MATSim.

The slightly longer story

Essentially:

public class MyModule implements PlanStrategyModule {
        MyModule() {
        }

	public void prepareReplanning() {
	}

	public void handlePlan(Plan plan) {
            // when given a plan, decide here what to do with it
	}

	public void finishReplanning() {
	}
}

public class MyStrategy extends PlanStrategy {
    public MyStrategy(Scenario s) {	
        this.addStrategyModule(new MyModule());
    }
}

Additional options can be found from the examples (see below).

You can then specify the class name of your module in the config-file as a replanning strategy, e.g.

<module name="strategy">
  <param name="ModuleProbability_1" value="0.1" />
  <param name="Module_1" value="your.package.MyStrategy" />
  ...add other modules here...
</module>

If you run a simulation with the default MATSim-Controler, it will then load your mental module and use it to modify the plans. This API is not yet complete, in the sense that it only offers limited functionality. We are working on a more powerful way to add your mental modules, but this may take quite some time.

Notes:

  •  Please forgive the confusion between "modules" and "strategy".  In the code, a "strategy" is composed of a plan selector, and several (strategy) modules.  In the config file, what is called a "strategy" in the code is called a "module".

Examples

One example is under tutorial.programming.example10PluggablePlanStrategy in the source repository (under "matsim").


Warning: Table 'watchdog' is read only query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;sessions&amp;#039; is read only\nquery: UPDATE sessions SET uid = 0, cache = 0, hostname = &amp;#039;38.107.179.234&amp;#039;, session = &amp;#039;&amp;#039;, timestamp = 1328355140 WHERE sid = &amp;#039;e972b2ab7dd755a2094beea8ac708f02&amp;#039;</em> in <em>/home01/vsp_access/matsimwww/includes/database.mysql.inc</em> on line <em>174</em>.', 2, '', 'http://matsim.org/node/469', '', '38.107.179.234', 1328355140) in /home01/vsp_access/matsimwww/includes/database.mysql.inc on line 174