MATSIM
QLanesNetworkFactory.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * QLanesNetworkFactory
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2010 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.mobsim.qsim.qnetsimengine;
22 
23 
24 import java.util.List;
25 
26 import jakarta.inject.Inject;
27 
28 import org.matsim.api.core.v01.Scenario;
39 import org.matsim.lanes.Lanes;
41 import org.matsim.lanes.LanesUtils;
42 import org.matsim.lanes.ModelLane;
44 
45 
46 public final class QLanesNetworkFactory implements QNetworkFactory {
47  private final Lanes laneDefinitions;
51  private final QSimConfigGroup qsimConfig;
52  private final EventsManager events;
53  private final Network network;
54  private final Scenario scenario;
56  @Inject QLanesNetworkFactory( EventsManager events, Scenario scenario, DefaultQNetworkFactory delegate ) {
57  this.qsimConfig = scenario.getConfig().qsim();
58  this.events = events ;
59  this.network = scenario.getNetwork() ;
60  this.scenario = scenario ;
61  this.laneDefinitions = scenario.getLanes();
62 // this.delegate = new DefaultQNetworkFactory( events, scenario ) ;
63  this.delegate = delegate;
64  }
65 
66  @Override
67  public void initializeFactory( AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1 ) {
68  this.netsimEngine = netsimEngine1 ;
69  double effectiveCellSize = network.getEffectiveCellSize() ;
70  SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator();
71  linkWidthCalculator.setLinkWidthForVis( qsimConfig.getLinkWidthForVis() );
72  if (! Double.isNaN(network.getEffectiveLaneWidth())){
73  linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() );
74  }
75  AbstractAgentSnapshotInfoBuilder agentSnapshotInfoBuilder = QNetsimEngineWithThreadpool.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator );
76  context = new NetsimEngineContext( events, effectiveCellSize, agentCounter, agentSnapshotInfoBuilder, qsimConfig, mobsimTimer, linkWidthCalculator );
77  delegate.initializeFactory(agentCounter, mobsimTimer, netsimEngine1);
78  }
79 
80  @Override
81  public QLinkI createNetsimLink(Link link, QNodeI queueNode) {
82  QLinkI ql = null;
83  LanesToLinkAssignment l2l = this.laneDefinitions.getLanesToLinkAssignments().get(link.getId());
84  if (l2l != null){
85  List<ModelLane> lanes = LanesUtils.createLanes(link, l2l);
86 
87  QLinkLanesImpl.Builder builder = new QLinkLanesImpl.Builder(context, netsimEngine) ;
88 
89  LinkSpeedCalculator linkSpeedCalculator = new DefaultLinkSpeedCalculator() ;
90  builder.setLinkSpeedCalculator( linkSpeedCalculator );
91 
92 
93  if (flowEfficiencyCalculator != null)
94  builder.setFlowEfficiencyCalculator(flowEfficiencyCalculator);
95 
96  ql = builder.build( link, queueNode, lanes ) ;
97  }
98  else {
99  ql = this.delegate.createNetsimLink(link, queueNode);
100  }
101  return ql;
102  }
103 
104  @Override
105  public QNodeI createNetsimNode(Node node) {
106  return this.delegate.createNetsimNode(node);
107  }
108 
112 // public void setDelegate(QNetworkFactory delegate) {
113 // this.delegate = delegate;
114 // }
115 
119  public void setFlowEfficiencyCalculator(FlowEfficiencyCalculator flowEfficiencyCalculator) {
120  this.flowEfficiencyCalculator = flowEfficiencyCalculator;
121  }
122 }
static List< ModelLane > createLanes(Link link, LanesToLinkAssignment lanesToLinkAssignment)
void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1)
SortedMap< Id< Link >, LanesToLinkAssignment > getLanesToLinkAssignments()
void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1)
QSimConfigGroup qsim()
Definition: Config.java:447
void setFlowEfficiencyCalculator(FlowEfficiencyCalculator flowEfficiencyCalculator)
QLinkI createNetsimLink(final Link link, final QNodeI toQueueNode)