org.matsim.core.controler.AbstractModule Java Examples
The following examples show how to use
org.matsim.core.controler.AbstractModule.
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 File: TestScenario.java From amodeus with GNU General Public License v2.0 | 6 votes |
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() { @Override public void install() { AmodeusUtils.registerGeneratorFactory(binder(), "Single", SingleVehicleGeneratorFactory.class); addEventHandlerBinding().toInstance(handler); } @Provides public SingleVehicleGeneratorFactory provideFactory() { return new SingleVehicleGeneratorFactory(vehicleCapacity, Id.createLinkId("link1")); } }); controller.addOverridingQSimModule(new AmodeusQSimModule()); controller.configureQSimComponents(AmodeusQSimModule.activateModes(scenario.getConfig())); return controller; }
Example #2
Source File: RunDRTClass.java From matsim-maas with GNU General Public License v2.0 | 5 votes |
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() { this.addEventHandlerBinding().toInstance(vktCounter); } }); controler.run(); Logger.getLogger(RunDRTClass.class).info("VKT traveled in last iteration: " + Math.round(vktCounter.getVkt_counted()) + " km"); }
Example #3
Source File: SocketServer.java From amod with GNU General Public License v2.0 | 4 votes |
/** runs a simulation run using input data from Amodeus.properties, av.xml and MATSim config.xml * * @throws MalformedURLException * @throws Exception */ public void simulate(StringSocket stringSocket, int numReqTot, // File workingDirectory) throws MalformedURLException, Exception { Static.setup(); /** 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 */ SimulationServer.INSTANCE.startAcceptingNonBlocking(); SimulationServer.INSTANCE.setWaitForClients(waitForClients); /** load MATSim configs - including av.xml configurations, load routing packages */ GlobalAssert.that(configFile.exists()); DvrpConfigGroup dvrpConfigGroup = new DvrpConfigGroup(); dvrpConfigGroup.setTravelTimeEstimationAlpha(0.05); 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()) { activityParams.setTypicalDuration(3600.0); } /** load MATSim scenario for simulation */ Scenario scenario = ScenarioUtils.loadScenario(config); AddCoordinatesToActivities.run(scenario); network = scenario.getNetwork(); Population population = scenario.getPopulation(); GlobalAssert.that(Objects.nonNull(network)); GlobalAssert.that(Objects.nonNull(population)); Objects.requireNonNull(network); 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()); System.out.println(linkSpeedDataFile.toString()); 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."); exception.printStackTrace(); } controller.addOverridingModule(new SocketModule(stringSocket, numReqTot)); /** Custom router that ensures same network speeds as taxis in original data set. */ controller.addOverridingModule(new AbstractModule() { @Override public void install() { bind(TaxiTravelTimeRouter.Factory.class); AmodeusUtils.bindRouterFactory(binder(), TaxiTravelTimeRouter.class.getSimpleName()).to(TaxiTravelTimeRouter.Factory.class); } }); /** adding the dispatcher to receive and process string fleet commands */ controller.addOverridingModule(new AbstractModule() { @Override public void install() { AmodeusUtils.registerDispatcherFactory(binder(), "SocketDispatcherHost", SocketDispatcherHost.Factory.class); } }); /** adding an initial vehicle placer */ controller.addOverridingModule(new AbstractModule() { @Override public void install() { AmodeusUtils.bindGeneratorFactory(binder(), RandomDensityGenerator.class.getSimpleName()).// to(RandomDensityGenerator.Factory.class); } }); /** run simulation */ controller.run(); /** close port for visualizaiton */ SimulationServer.INSTANCE.stopAccepting(); /** perform analysis of simulation */ /** output directory for saving results */ outputDirectory = new File(config.controler().getOutputDirectory()); }