MATSIM
ConfigurableQNetworkFactory.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 java.util.Optional;
24 
25 import org.matsim.api.core.v01.Scenario;
39 
40 
47 public final class ConfigurableQNetworkFactory implements QNetworkFactory {
50  private Network network;
51  private Scenario scenario;
55  private Optional<TurnAcceptanceLogic> turnAcceptanceLogic = Optional.empty();
56  private Optional<VehicleHandler> vehicleHandler = Optional.empty();
57  private Optional<FlowEfficiencyCalculator> flowEfficiencyCalculator = Optional.empty();
58  private Optional<VehicleQ.Factory<QVehicle>> vehicleQFactory = Optional.empty();
59 
61  this.events = events;
62  this.scenario = scenario;
63  this.network = scenario.getNetwork();
64  this.qsimConfig = scenario.getConfig().qsim();
65  }
66 
67  @Override
68  public void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1) {
69  this.netsimEngine = netsimEngine1;
70  double effectiveCellSize = network.getEffectiveCellSize();
71  SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator();
72  linkWidthCalculator.setLinkWidthForVis(qsimConfig.getLinkWidthForVis());
73  if (!Double.isNaN(network.getEffectiveLaneWidth())) {
74  linkWidthCalculator.setLaneWidth(network.getEffectiveLaneWidth());
75  }
76  AbstractAgentSnapshotInfoBuilder agentSnapshotInfoBuilder = QNetsimEngineWithThreadpool.createAgentSnapshotInfoBuilder(scenario, linkWidthCalculator);
77  context = new NetsimEngineContext(events, effectiveCellSize, agentCounter, agentSnapshotInfoBuilder, qsimConfig, mobsimTimer, linkWidthCalculator);
78  }
79  @Override
80  public QLinkI createNetsimLink( final Link link, final QNodeI toQueueNode ) {
81 
82  // the QLink.Builder and the QueueWithBuffer.Builder pick the correct implementations of
83  // vehicleQFactory, flowEfficiencyCalculator and so on based on the config.
84  // We should only override that choice if the configured properties are explicitly set. Janek 11.19
85  QLinkImpl.Builder linkBuilder = new QLinkImpl.Builder(context, netsimEngine);
86  {
87  QueueWithBuffer.Builder laneFactory = new QueueWithBuffer.Builder(context);
88  vehicleQFactory.ifPresent(factory -> laneFactory.setVehicleQueue(factory.createVehicleQ()));
89  flowEfficiencyCalculator.ifPresent(laneFactory::setFlowEfficiencyCalculator);
90  linkBuilder.setLaneFactory(laneFactory);
91  }
92 // linkSpeedCalculator.ifPresent(linkBuilder::setLinkSpeedCalculator);
93  linkBuilder.setLinkSpeedCalculator( this.linkSpeedCalculator );
94  vehicleHandler.ifPresent(linkBuilder::setVehicleHandler);
95 
96  return linkBuilder.build(link, toQueueNode);
97  }
98 
99  @Override
100  public QNodeI createNetsimNode( final Node node ) {
101  QNodeImpl.Builder builder = new QNodeImpl.Builder(netsimEngine, context, qsimConfig);
102 
103  turnAcceptanceLogic.ifPresent(builder::setTurnAcceptanceLogic);
104 
105  return builder.build(node);
106  }
107 
108  public final void setLinkSpeedCalculator(LinkSpeedCalculator linkSpeedCalculator) {
109  this.linkSpeedCalculator = linkSpeedCalculator;
110  }
111 
112  public final void setTurnAcceptanceLogic( TurnAcceptanceLogic turnAcceptanceLogic ) {
113  this.turnAcceptanceLogic = Optional.of(turnAcceptanceLogic);
114  }
115 
116  public final void setVehicleHandler(VehicleHandler vehicleHandler) {
117  this.vehicleHandler = Optional.of(vehicleHandler);
118  }
119 
120  public final void setVehicleQFactory( VehicleQ.Factory<QVehicle> factory ) {
121  this.vehicleQFactory = Optional.of(factory);
122  }
123 
124  public final void setFlowEfficiencyCalculator(FlowEfficiencyCalculator flowEfficiencyCalculator) {
125  this.flowEfficiencyCalculator = Optional.of(flowEfficiencyCalculator);
126  }
127 }
final void setFlowEfficiencyCalculator(FlowEfficiencyCalculator flowEfficiencyCalculator)
final void setLinkSpeedCalculator(LinkSpeedCalculator linkSpeedCalculator)
QSimConfigGroup qsim()
Definition: Config.java:447
final void setTurnAcceptanceLogic(TurnAcceptanceLogic turnAcceptanceLogic)
void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface netsimEngine1)