MATSIM
Static Public Member Functions | List of all members
org.matsim.lanes.LanesUtils Class Reference

Static Public Member Functions

static Lanes createLanesContainer ()
 
static void createAndAddLane (LanesToLinkAssignment l2l, LanesFactory factory, Id< Lane > laneId, double capacity, double startsAtMeterFromLinkEnd, int alignment, int numberOfRepresentedLanes, List< Id< Link >> toLinkIds, List< Id< Lane >> toLaneIds)
 
static void createOriginalLanesAndSetLaneCapacities (Network network, Lanes lanes)
 
static List< ModelLanecreateLanes (Link link, LanesToLinkAssignment lanesToLinkAssignment)
 
static void calculateAndSetCapacity (Lane lane, boolean isLaneAtLinkEnd, Link link, Network network)
 
static void calculateMissingCapacitiesForLanes20 (String networkInputFilename, String lanes20InputFilename, String lanes20OutputFilename)
 
static void overwriteLaneCapacitiesByNetworkCapacities (Network net, Lanes lanes)
 

Detailed Description

Author
dgrether
tthunig

Definition at line 37 of file LanesUtils.java.

Member Function Documentation

◆ createLanesContainer()

static Lanes org.matsim.lanes.LanesUtils.createLanesContainer ( )
static

Definition at line 39 of file LanesUtils.java.

39  {
40  return new LanesImpl();
41  }

◆ createAndAddLane()

static void org.matsim.lanes.LanesUtils.createAndAddLane ( LanesToLinkAssignment  l2l,
LanesFactory  factory,
Id< Lane laneId,
double  capacity,
double  startsAtMeterFromLinkEnd,
int  alignment,
int  numberOfRepresentedLanes,
List< Id< Link >>  toLinkIds,
List< Id< Lane >>  toLaneIds 
)
static

Convenience method to create a lane with the given Id, the given length, the given capacity, the given number of represented lanes, the given alignment and the given Ids of the downstream links or lanes, respectively, the lane leads to. The lane is added to the LanesToLinkAssignment given as parameter.

Parameters
l2lthe LanesToLinkAssignment to that the created lane is added
factorya LaneDefinitionsFactory to create the lane
laneId
capacity
startsAtMeterFromLinkEnd
alignment
numberOfRepresentedLanes
toLinkIds
toLaneIds

Definition at line 62 of file LanesUtils.java.

References org.matsim.lanes.LanesToLinkAssignment.addLane(), org.matsim.lanes.Lane.addToLaneId(), org.matsim.lanes.Lane.addToLinkId(), org.matsim.lanes.LanesFactory.createLane(), org.matsim.lanes.Lane.setAlignment(), org.matsim.lanes.Lane.setCapacityVehiclesPerHour(), org.matsim.lanes.Lane.setNumberOfRepresentedLanes(), and org.matsim.lanes.Lane.setStartsAtMeterFromLinkEnd().

65  {
66 
67  Lane lane = factory.createLane(laneId);
68  if (toLinkIds != null){
69  for (Id<Link> toLinkId : toLinkIds) {
70  lane.addToLinkId(toLinkId);
71  }
72  }
73  if (toLaneIds != null){
74  for (Id<Lane> toLaneId : toLaneIds) {
75  lane.addToLaneId(toLaneId);
76  }
77  }
78  lane.setCapacityVehiclesPerHour(capacity);
79  lane.setStartsAtMeterFromLinkEnd(startsAtMeterFromLinkEnd);
80  lane.setNumberOfRepresentedLanes(numberOfRepresentedLanes);
81  lane.setAlignment(alignment);
82  l2l.addLane(lane);
83  }
Here is the call graph for this function:

◆ createOriginalLanesAndSetLaneCapacities()

static void org.matsim.lanes.LanesUtils.createOriginalLanesAndSetLaneCapacities ( Network  network,
Lanes  lanes 
)
static

Replaces the method that converted a lane from format 11 to format 20. Use this when you have not defined an original lane of the link and when you have not set lane capacities yet.

Definition at line 89 of file LanesUtils.java.

References org.matsim.lanes.Lane.addToLaneId(), org.matsim.lanes.LanesUtils.calculateAndSetCapacity(), org.matsim.api.core.v01.Id< T >.create(), org.matsim.lanes.LanesFactory.createLane(), org.matsim.lanes.Lanes.getFactory(), org.matsim.lanes.Lanes.getLanesToLinkAssignments(), org.matsim.api.core.v01.network.Link.getLength(), org.matsim.api.core.v01.network.Network.getLinks(), org.matsim.api.core.v01.network.Link.getNumberOfLanes(), org.matsim.lanes.Lane.setNumberOfRepresentedLanes(), and org.matsim.lanes.Lane.setStartsAtMeterFromLinkEnd().

89  {
90  LanesFactory factory = lanes.getFactory();
91  for (LanesToLinkAssignment l2l : lanes.getLanesToLinkAssignments().values()){
92  Link link = network.getLinks().get(l2l.getLinkId());
93 
94  Lane olLane = factory.createLane(Id.create(l2l.getLinkId().toString() + ".ol", Lane.class));
95  l2l.addLane(olLane);
96  for (Lane lane : l2l.getLanes().values()) {
97  olLane.addToLaneId(lane.getId());
98 
99  //set capacity of the lane depending on link capacity and number of representative lanes
100  LanesUtils.calculateAndSetCapacity(lane, true, link, network);
101  }
102  olLane.setNumberOfRepresentedLanes(link.getNumberOfLanes());
103  olLane.setStartsAtMeterFromLinkEnd(link.getLength());
104  }
105  }
Here is the call graph for this function:

◆ createLanes()

static List<ModelLane> org.matsim.lanes.LanesUtils.createLanes ( Link  link,
LanesToLinkAssignment  lanesToLinkAssignment 
)
static

Creates a sorted list of lanes for a link.

Parameters
link
lanesToLinkAssignment
Returns
sorted list with the most upstream lane at the first position.

Definition at line 113 of file LanesUtils.java.

References org.matsim.api.core.v01.Identifiable< T >.getId(), org.matsim.lanes.ModelLane.getLaneData(), org.matsim.lanes.LanesToLinkAssignment.getLanes(), org.matsim.api.core.v01.network.Link.getLength(), org.matsim.lanes.Lane.getStartsAtMeterFromLinkEnd(), org.matsim.lanes.Lane.getToLaneIds(), org.matsim.lanes.ModelLane.getToLanes(), and org.matsim.lanes.Lane.getToLinkIds().

Referenced by org.matsim.core.mobsim.qsim.qnetsimengine.QLanesNetworkFactory.createNetsimLink().

113  {
114  List<ModelLane> queueLanes = new ArrayList<>();
115  List<Lane> sortedLanes = new ArrayList<>(lanesToLinkAssignment.getLanes().values());
116 
117  // orders lanes by start on link an whether they are outgoing or not o the start is the same
118  sortedLanes.sort(Comparator.comparingDouble(Lane::getStartsAtMeterFromLinkEnd).thenComparing(
119  (l1, l2) -> {
120  boolean l1Outgoing = l1.getToLinkIds() != null && !l1.getToLinkIds().isEmpty();
121  boolean l2Outgoing = l2.getToLinkIds() != null && !l2.getToLinkIds().isEmpty();
122  if (l1Outgoing && !l2Outgoing)
123  return -1;
124  else if(l2Outgoing && !l1Outgoing)
125  return 1;
126  else
127  return 0;
128  }
129  ));
130  Collections.reverse(sortedLanes);
131 
132  List<ModelLane> laneList = new LinkedList<>();
133  Lane firstLane = sortedLanes.remove(0);
134  if (firstLane.getStartsAtMeterFromLinkEnd() != link.getLength()) {
135  throw new IllegalStateException("First Lane Id " + firstLane.getId() + " on Link Id " + link.getId() +
136  "isn't starting at the beginning of the link!");
137  }
138  ModelLane firstQLane = new ModelLane(firstLane);
139  laneList.add(firstQLane);
140  Stack<ModelLane> laneStack = new Stack<>();
141 
142  while (!laneList.isEmpty()){
143  ModelLane lastQLane = laneList.remove(0);
144  laneStack.push(lastQLane);
145  queueLanes.add(lastQLane);
146 
147  //if existing create the subsequent lanes
148  List<Id<Lane>> toLaneIds = lastQLane.getLaneData().getToLaneIds();
149  double nextMetersFromLinkEnd = 0.0;
150  double laneLength = 0.0;
151  if (toLaneIds != null && (!toLaneIds.isEmpty())) {
152  for (Id<Lane> toLaneId : toLaneIds){
153  Lane currentLane = lanesToLinkAssignment.getLanes().get(toLaneId);
154  nextMetersFromLinkEnd = currentLane.getStartsAtMeterFromLinkEnd();
155  ModelLane currentQLane = new ModelLane(currentLane);
156  laneList.add(currentQLane);
157  lastQLane.addAToLane(currentQLane);
158  }
159  laneLength = lastQLane.getLaneData().getStartsAtMeterFromLinkEnd() - nextMetersFromLinkEnd;
160  lastQLane.setEndsAtMetersFromLinkEnd(nextMetersFromLinkEnd);
161  }
162  //there are no subsequent lanes
163  else {
164  laneLength = lastQLane.getLaneData().getStartsAtMeterFromLinkEnd();
165  lastQLane.setEndsAtMetersFromLinkEnd(0.0);
166  }
167  lastQLane.setLength(laneLength);
168  }
169 
170  //fill toLinks
171  while (! laneStack.isEmpty()){
172  ModelLane qLane = laneStack.pop();
173  if (qLane.getToLanes() == null || (qLane.getToLanes().isEmpty())) {
174  for (Id<Link> toLinkId : qLane.getLaneData().getToLinkIds()){
175  qLane.addDestinationLink(toLinkId);
176  }
177  }
178  else {
179  for (ModelLane subsequentLane : qLane.getToLanes()){
180  for (Id<Link> toLinkId : subsequentLane.getDestinationLinkIds()){
181  qLane.addDestinationLink(toLinkId);
182  }
183  }
184  }
185  }
186 
187  Collections.sort(queueLanes, new Comparator<ModelLane>() {
188  @Override
189  public int compare(ModelLane o1, ModelLane o2) {
190  if (o1.getEndsAtMeterFromLinkEnd() < o2.getEndsAtMeterFromLinkEnd()) {
191  return -1;
192  } else if (o1.getEndsAtMeterFromLinkEnd() > o2.getEndsAtMeterFromLinkEnd()) {
193  return 1;
194  } else {
195  return 0;
196  }
197  }
198  });
199  return queueLanes;
200  }
double getStartsAtMeterFromLinkEnd()
Here is the call graph for this function:

◆ calculateAndSetCapacity()

static void org.matsim.lanes.LanesUtils.calculateAndSetCapacity ( Lane  lane,
boolean  isLaneAtLinkEnd,
Link  link,
Network  network 
)
static

Calculate capacity by formular from Neumann2008DA:

Flow of a Lane is given by the flow of the link divided by the number of lanes represented by the link.

A Lane may represent one or more lanes in reality. This is given by the attribute numberOfRepresentedLanes of the Lane definition. The flow of a lane is scaled by this number.

Definition at line 210 of file LanesUtils.java.

References org.matsim.api.core.v01.network.Link.getCapacity(), org.matsim.api.core.v01.network.Network.getCapacityPeriod(), org.matsim.api.core.v01.network.Link.getNumberOfLanes(), org.matsim.lanes.Lane.getNumberOfRepresentedLanes(), and org.matsim.lanes.Lane.setCapacityVehiclesPerHour().

Referenced by org.matsim.lanes.LanesUtils.calculateMissingCapacitiesForLanes20(), and org.matsim.lanes.LanesUtils.createOriginalLanesAndSetLaneCapacities().

210  {
211  if (isLaneAtLinkEnd){
212  double noLanesLink = link.getNumberOfLanes();
213  double linkFlowCapPerSecondPerLane = link.getCapacity() / network.getCapacityPeriod()
214  / noLanesLink;
215  double laneFlowCapPerHour = lane.getNumberOfRepresentedLanes()
216  * linkFlowCapPerSecondPerLane * 3600.0;
217  lane.setCapacityVehiclesPerHour(laneFlowCapPerHour);
218  }
219  else {
220  double capacity = link.getCapacity() / network.getCapacityPeriod() * 3600.0;
221  lane.setCapacityVehiclesPerHour(capacity);
222  }
223  }
Here is the call graph for this function:

◆ calculateMissingCapacitiesForLanes20()

static void org.matsim.lanes.LanesUtils.calculateMissingCapacitiesForLanes20 ( String  networkInputFilename,
String  lanes20InputFilename,
String  lanes20OutputFilename 
)
static

Definition at line 225 of file LanesUtils.java.

References org.matsim.lanes.LanesUtils.calculateAndSetCapacity(), org.matsim.core.config.ConfigUtils.createConfig(), org.matsim.api.core.v01.Scenario.getLanes(), org.matsim.lanes.Lanes.getLanesToLinkAssignments(), org.matsim.api.core.v01.network.Network.getLinks(), org.matsim.api.core.v01.Scenario.getNetwork(), org.matsim.core.scenario.ScenarioUtils.loadScenario(), org.matsim.core.config.Config.network(), org.matsim.core.config.Config.qsim(), org.matsim.core.config.groups.NetworkConfigGroup.setInputFile(), org.matsim.core.config.groups.NetworkConfigGroup.setLaneDefinitionsFile(), org.matsim.core.config.groups.QSimConfigGroup.setUseLanes(), and org.matsim.lanes.LanesWriter.write().

225  {
226  Config config = ConfigUtils.createConfig();
227  config.network().setInputFile(networkInputFilename);
228  config.qsim().setUseLanes(true);
229  config.network().setLaneDefinitionsFile(lanes20InputFilename);
230  Scenario scenario = ScenarioUtils.loadScenario(config);
231  Network network = scenario.getNetwork();
232  Lanes lanes = scenario.getLanes();
233  for (LanesToLinkAssignment l2l : lanes.getLanesToLinkAssignments().values()){
234  Link link = network.getLinks().get(l2l.getLinkId());
235  for (Lane lane : l2l.getLanes().values()){
236  if (lane.getToLaneIds() == null || lane.getToLaneIds().isEmpty()){
237  calculateAndSetCapacity(lane, true, link, network);
238  }
239  else {
240  calculateAndSetCapacity(lane, false, link, network);
241  }
242  }
243  }
244  LanesWriter writerDelegate = new LanesWriter(lanes);
245  writerDelegate.write(lanes20OutputFilename);
246  }
static void calculateAndSetCapacity(Lane lane, boolean isLaneAtLinkEnd, Link link, Network network)
Here is the call graph for this function:

◆ overwriteLaneCapacitiesByNetworkCapacities()

static void org.matsim.lanes.LanesUtils.overwriteLaneCapacitiesByNetworkCapacities ( Network  net,
Lanes  lanes 
)
static

Definition at line 248 of file LanesUtils.java.

References org.matsim.lanes.Lanes.getLanesToLinkAssignments(), and org.matsim.api.core.v01.network.Network.getLinks().

248  {
249  for (LanesToLinkAssignment linkLanes : lanes.getLanesToLinkAssignments().values()) {
250  double linkCap = net.getLinks().get(linkLanes.getLinkId()).getCapacity();
251  for (Lane lane : linkLanes.getLanes().values()) {
252  lane.setCapacityVehiclesPerHour(linkCap);
253  }
254  }
255  }
Here is the call graph for this function:

The documentation for this class was generated from the following file: