MATSIM
DefaultQNetworkFactory.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 
20 package org.matsim.core.mobsim.qsim.qnetsimengine;
21 
22 
23 import jakarta.inject.Inject;
24 
25 import org.matsim.api.core.v01.Scenario;
30 import org.matsim.core.gbl.Gbl;
38 
39 import java.util.Collections;
40 import java.util.Set;
41 
42 
68 public final class DefaultQNetworkFactory implements QNetworkFactory {
69  private final EventsManager events ;
70  private final Scenario scenario ;
72  private QNodeImpl.Builder nodeBuilder;
73  @Inject private Set<LinkSpeedCalculator> calculators = Collections.emptySet();
76  @Inject DefaultQNetworkFactory( EventsManager events, Scenario scenario ) {
77  this.events = events;
78  this.scenario = scenario;
79  }
80  @Override public void initializeFactory( AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1 ) {
81  double effectiveCellSize = scenario.getNetwork().getEffectiveCellSize() ;
82 
83  SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator();
84  linkWidthCalculator.setLinkWidthForVis( scenario.getConfig().qsim().getLinkWidthForVis() );
85  linkWidthCalculator.setLaneWidth( scenario.getNetwork().getEffectiveLaneWidth() );
86 
87  AbstractAgentSnapshotInfoBuilder agentSnapshotInfoBuilder = QNetsimEngineWithThreadpool.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator );
88 
89  // (vis needs network and may need population attributes and config; in consequence, makes sense to have scenario here. kai, apr'16)
90  context = new NetsimEngineContext( events, effectiveCellSize, agentCounter, agentSnapshotInfoBuilder, scenario.getConfig().qsim(),
91  mobsimTimer, linkWidthCalculator );
92 
93  Gbl.assertNotNull(context);
94 
95  this.netsimEngine1 = netsimEngine1;
96 
97 
98  }
99  @Override public QLinkI createNetsimLink( final Link link, final QNodeI toQueueNode ) {
100  this.linkBuilder = new QLinkImpl.Builder( context, netsimEngine1 ) ;
101  // it is not possible to construct the builder in the initializeFactory method. I do not know why. kai, jun'23
102 
104  for( LinkSpeedCalculator calculator : calculators ){
105  theCalculator.addLinkSpeedCalculator( calculator );
106  }
107  this.linkBuilder.setLinkSpeedCalculator( theCalculator );
108  return linkBuilder.build(link, toQueueNode) ;
109  }
110  @Override public QNodeI createNetsimNode( final Node node ) {
111  this.nodeBuilder = new QNodeImpl.Builder( netsimEngine1, context, scenario.getConfig().qsim() ) ;
112  return nodeBuilder.build( node ) ;
113  }
114 }
void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1)
QSimConfigGroup qsim()
Definition: Config.java:447
static void assertNotNull(Object obj)
Definition: Gbl.java:212
QLinkI createNetsimLink(final Link link, final QNodeI toQueueNode)