MATSIM
RunFlexibleQNetworkFactoryExample.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.* *
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2008 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 package org.matsim.core.mobsim.qsim.qnetsimengine;
20 
21 import jakarta.inject.Inject;
22 
23 import org.matsim.api.core.v01.Scenario;
28 import org.matsim.core.config.Config;
38 
44 
45  static final class MyQNetworkFactory implements QNetworkFactory {
46  @Inject private EventsManager events ;
47  @Inject private Scenario scenario ; // yyyyyy I would like to get rid of this. kai, mar'16
48  @Inject private Network network ;
49  @Inject private QSimConfigGroup qsimConfig ;
50 
51  private NetsimEngineContext context;
52  private NetsimInternalInterface netsimEngine;
53 
54  @Override
55  public final void initializeFactory( AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1 ) {
56  double effectiveCellSize = ((Network)network).getEffectiveCellSize() ;
57 
58  SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator();
59  linkWidthCalculator.setLinkWidthForVis( qsimConfig.getLinkWidthForVis() );
60  if (! Double.isNaN(network.getEffectiveLaneWidth())){
61  linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() );
62  }
63  AbstractAgentSnapshotInfoBuilder snapshotBuilder = QNetsimEngineWithThreadpool.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator );
64 
65  this.context = new NetsimEngineContext(events, effectiveCellSize, agentCounter, snapshotBuilder, qsimConfig, mobsimTimer, linkWidthCalculator ) ;
66 
67  this.netsimEngine = netsimEngine1 ;
68  }
69  @Override
70  public final QNodeI createNetsimNode( Node node ) {
71  QNodeImpl.Builder builder = new QNodeImpl.Builder( netsimEngine, context, qsimConfig ) ;
72  return builder.build( node ) ;
73 
74  }
75  @Override
76  public final QLinkI createNetsimLink( Link link, QNodeI queueNode ) {
77 
78  QLinkImpl.Builder linkBuilder = new QLinkImpl.Builder(context, netsimEngine) ;
79  {
80  QueueWithBuffer.Builder laneBuilder = new QueueWithBuffer.Builder( context );
81  linkBuilder.setLaneFactory( laneBuilder );
82  }
83  return linkBuilder.build(link, queueNode) ;
84  }
85  }
86 
90  public static void main(String[] args) {
91  Config config = ConfigUtils.createConfig() ;
92 
93  Scenario scenario = ScenarioUtils.createScenario( config ) ;
94 
95  Controler controler = new Controler( scenario ) ;
96 
97  controler.addOverridingModule( new AbstractModule(){
98  @Override public void install() {
99  bind( QNetworkFactory.class ).to( MyQNetworkFactory.class ) ;
100  }
101  });
102 
103  controler.run();
104 
105  }
106 
107 }
final Controler addOverridingModule(AbstractModule abstractModule)
Definition: Controler.java:473
static Scenario createScenario(final Config config)
static Config createConfig(final String context)