SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSEdge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
13 // A road/street connecting two junctions
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
16 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <algorithm>
38 #include <iostream>
39 #include <cassert>
42 #include "MSEdge.h"
43 #include "MSJunction.h"
44 #include "MSLane.h"
45 #include "MSLaneChanger.h"
46 #include "MSGlobals.h"
47 #include "MSVehicle.h"
49 #include "MSContainer.h"
50 #include "MSEdgeWeightsStorage.h"
51 
52 #ifdef HAVE_INTERNAL
53 #include <mesosim/MELoop.h>
54 #include <mesosim/MESegment.h>
55 #include <mesosim/MEVehicle.h>
56 #endif
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif // CHECK_MEMORY_LEAKS
61 
62 
63 // ===========================================================================
64 // static member definitions
65 // ===========================================================================
68 
69 
70 // ===========================================================================
71 // member method definitions
72 // ===========================================================================
73 MSEdge::MSEdge(const std::string& id, int numericalID,
74  const EdgeBasicFunction function,
75  const std::string& streetName,
76  const std::string& edgeType,
77  int priority) :
78  Named(id), myNumericalID(numericalID), myLanes(0),
79  myLaneChanger(0), myFunction(function), myVaporizationRequests(0),
80  myLastFailedInsertionTime(-1),
81  myFromJunction(0), myToJunction(0),
82  myStreetName(streetName),
83  myEdgeType(edgeType),
84  myPriority(priority),
85  myLength(-1.),
86  myEmptyTraveltime(-1.),
87  myAmDelayed(false),
88  myAmRoundabout(false) {}
89 
90 
92  delete myLaneChanger;
93  for (AllowedLanesCont::iterator i1 = myAllowed.begin(); i1 != myAllowed.end(); i1++) {
94  delete(*i1).second;
95  }
96  for (ClassedAllowedLanesCont::iterator i2 = myClassedAllowed.begin(); i2 != myClassedAllowed.end(); i2++) {
97  for (AllowedLanesCont::iterator i1 = (*i2).second.begin(); i1 != (*i2).second.end(); i1++) {
98  delete(*i1).second;
99  }
100  }
101  delete myLanes;
102  // Note: Lanes are delete using MSLane::clear();
103 }
104 
105 
106 void
107 MSEdge::initialize(const std::vector<MSLane*>* lanes) {
108  assert(lanes != 0);
109  myLanes = lanes;
110  if (!lanes->empty()) {
111  recalcCache();
112  if (myLanes->size() > 1) {
113  myLaneChanger = new MSLaneChanger(myLanes, OptionsCont::getOptions().getBool("lanechange.allow-swap"));
114  }
115  }
118  }
119 }
120 
121 
123  myLength = myLanes->front()->getLength();
125 }
126 
127 
128 void
130  myAllowed[0] = new std::vector<MSLane*>();
131  for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
132  myAllowed[0]->push_back(*i);
133  const MSLinkCont& lc = (*i)->getLinkCont();
134  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
135  MSLane* toL = (*j)->getLane();
136  if (toL != 0) {
137  MSEdge& to = toL->getEdge();
138  //
139  if (std::find(mySuccessors.begin(), mySuccessors.end(), &to) == mySuccessors.end()) {
140  mySuccessors.push_back(&to);
141  }
142  if (std::find(to.myPredecessors.begin(), to.myPredecessors.end(), this) == to.myPredecessors.end()) {
143  to.myPredecessors.push_back(this);
144  }
145  //
146  if (myAllowed.find(&to) == myAllowed.end()) {
147  myAllowed[&to] = new std::vector<MSLane*>();
148  }
149  myAllowed[&to]->push_back(*i);
150  }
151 #ifdef HAVE_INTERNAL_LANES
152  toL = (*j)->getViaLane();
153  if (toL != 0) {
154  MSEdge& to = toL->getEdge();
155  if (std::find(to.myPredecessors.begin(), to.myPredecessors.end(), this) == to.myPredecessors.end()) {
156  to.myPredecessors.push_back(this);
157  }
158  }
159 #endif
160  }
161  }
162  std::sort(mySuccessors.begin(), mySuccessors.end(), by_id_sorter());
164 }
165 
166 
167 void
169  // clear myClassedAllowed.
170  // it will be rebuilt on demand
171  for (ClassedAllowedLanesCont::iterator i2 = myClassedAllowed.begin(); i2 != myClassedAllowed.end(); i2++) {
172  for (AllowedLanesCont::iterator i1 = (*i2).second.begin(); i1 != (*i2).second.end(); i1++) {
173  delete(*i1).second;
174  }
175  }
176  myClassedAllowed.clear();
177  myClassesSuccessorMap.clear();
178  // rebuild myMinimumPermissions and myCombinedPermissions
181  for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
182  myMinimumPermissions &= (*i)->getPermissions();
183  myCombinedPermissions |= (*i)->getPermissions();
184  }
185 }
186 
187 
188 // ------------ Access to the edge's lanes
189 MSLane*
190 MSEdge::leftLane(const MSLane* const lane) const {
191  return parallelLane(lane, 1);
192 }
193 
194 
195 MSLane*
196 MSEdge::rightLane(const MSLane* const lane) const {
197  return parallelLane(lane, -1);
198 }
199 
200 
201 MSLane*
202 MSEdge::parallelLane(const MSLane* const lane, int offset) const {
203  const int index = (int)(find(myLanes->begin(), myLanes->end(), lane) - myLanes->begin());
204  if (index == (int)myLanes->size()) {
205  return 0;
206  }
207  const int resultIndex = index + offset;
208  if (resultIndex >= (int)myLanes->size() || resultIndex < 0) {
209  return 0;
210  } else {
211  return (*myLanes)[resultIndex];
212  }
213 }
214 
215 
216 const std::vector<MSLane*>*
217 MSEdge::allowedLanes(const MSEdge& destination, SUMOVehicleClass vclass) const {
218  return allowedLanes(&destination, vclass);
219 }
220 
221 
222 const std::vector<MSLane*>*
224  return allowedLanes(0, vclass);
225 }
226 
227 
228 const std::vector<MSLane*>*
230  AllowedLanesCont::const_iterator it = c.find(dest);
231  if (it == c.end()) {
232  return 0;
233  }
234  return it->second;
235 }
236 
237 
238 const std::vector<MSLane*>*
239 MSEdge::allowedLanes(const MSEdge* destination, SUMOVehicleClass vclass) const {
240  if ((myMinimumPermissions & vclass) == vclass) {
241  // all lanes allow vclass
242  return getAllowedLanesWithDefault(myAllowed, destination);
243  }
244  // look up cached result in myClassedAllowed
245  ClassedAllowedLanesCont::const_iterator i = myClassedAllowed.find(vclass);
246  if (i != myClassedAllowed.end()) {
247  // can use cached value
248  const AllowedLanesCont& c = (*i).second;
249  return getAllowedLanesWithDefault(c, destination);
250  } else {
251  // this vclass is requested for the first time. rebuild all destinations
252  // go through connected edges
253  for (AllowedLanesCont::const_iterator i1 = myAllowed.begin(); i1 != myAllowed.end(); ++i1) {
254  const MSEdge* edge = i1->first;
255  const std::vector<MSLane*>* lanes = i1->second;
256  myClassedAllowed[vclass][edge] = new std::vector<MSLane*>();
257  // go through lanes approaching current edge
258  for (std::vector<MSLane*>::const_iterator i2 = lanes->begin(); i2 != lanes->end(); ++i2) {
259  // allows the current vehicle class?
260  if ((*i2)->allowsVehicleClass(vclass)) {
261  // -> may be used
262  myClassedAllowed[vclass][edge]->push_back(*i2);
263  }
264  }
265  // assert that 0 is returned if no connection is allowed for a class
266  if (myClassedAllowed[vclass][edge]->size() == 0) {
267  delete myClassedAllowed[vclass][edge];
268  myClassedAllowed[vclass][edge] = 0;
269  }
270  }
271  return myClassedAllowed[vclass][destination];
272  }
273 }
274 
275 
276 // ------------
277 SUMOTime
280  return 0;
281 }
282 
283 
284 SUMOTime
287  return 0;
288 }
289 
290 
291 MSLane*
292 MSEdge::getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const {
293  if (allowed == 0) {
294  allowed = allowedLanes(vclass);
295  }
296  MSLane* res = 0;
297  if (allowed != 0) {
298  SUMOReal leastOccupancy = std::numeric_limits<SUMOReal>::max();;
299  for (std::vector<MSLane*>::const_iterator i = allowed->begin(); i != allowed->end(); ++i) {
300  const SUMOReal occupancy = (*i)->getBruttoOccupancy();
301  if (occupancy < leastOccupancy) {
302  res = (*i);
303  leastOccupancy = occupancy;
304  }
305  }
306  }
307  return res;
308 }
309 
310 
311 MSLane*
313  switch (veh.getParameter().departLaneProcedure) {
314  case DEPART_LANE_GIVEN:
315  if ((int) myLanes->size() <= veh.getParameter().departLane || !(*myLanes)[veh.getParameter().departLane]->allowsVehicleClass(veh.getVehicleType().getVehicleClass())) {
316  return 0;
317  }
318  return (*myLanes)[veh.getParameter().departLane];
319  case DEPART_LANE_RANDOM:
321  case DEPART_LANE_FREE:
322  return getFreeLane(0, veh.getVehicleType().getVehicleClass());
324  if (veh.getRoute().size() == 1) {
325  return getFreeLane(0, veh.getVehicleType().getVehicleClass());
326  } else {
327  return getFreeLane(allowedLanes(**(veh.getRoute().begin() + 1)), veh.getVehicleType().getVehicleClass());
328  }
329  case DEPART_LANE_BEST_FREE: {
330  veh.updateBestLanes(false, myLanes->front());
331  const std::vector<MSVehicle::LaneQ>& bl = veh.getBestLanes();
332  SUMOReal bestLength = -1;
333  for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
334  if ((*i).length > bestLength) {
335  bestLength = (*i).length;
336  }
337  }
338  std::vector<MSLane*>* bestLanes = new std::vector<MSLane*>();
339  for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
340  if ((*i).length == bestLength) {
341  bestLanes->push_back((*i).lane);
342  }
343  }
344  MSLane* ret = getFreeLane(bestLanes, veh.getVehicleType().getVehicleClass());
345  delete bestLanes;
346  return ret;
347  }
348  case DEPART_LANE_DEFAULT:
350  for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
351  if ((*i)->allowsVehicleClass(veh.getVehicleType().getVehicleClass())) {
352  return *i;
353  }
354  }
355  return 0;
356  default:
357  break;
358  }
359  if (!(*myLanes)[0]->allowsVehicleClass(veh.getVehicleType().getVehicleClass())) {
360  return 0;
361  }
362  return (*myLanes)[0];
363 }
364 
365 
366 bool
367 MSEdge::insertVehicle(SUMOVehicle& v, SUMOTime time, const bool checkOnly) const {
368  // when vaporizing, no vehicles are inserted, but checking needs to be successful to trigger removal
369  if (isVaporizing()) {
370  return checkOnly;
371  }
372  const SUMOVehicleParameter& pars = v.getParameter();
373  const MSVehicleType& type = v.getVehicleType();
375  if (type.getSpeedDeviation() > 0 && pars.departSpeed <= type.getSpeedFactor() * getSpeedLimit() * (2 * type.getSpeedDeviation() + 1.)) {
376  WRITE_WARNING("Choosing new speed factor for vehicle '" + pars.id + "' to match departure speed.");
378  } else {
379  throw ProcessError("Departure speed for vehicle '" + pars.id +
380  "' is too high for the departure edge '" + getID() + "'.");
381  }
382  }
383 #ifdef HAVE_INTERNAL
385  SUMOReal pos = 0.0;
386  switch (pars.departPosProcedure) {
387  case DEPART_POS_GIVEN:
388  if (pars.departPos >= 0.) {
389  pos = pars.departPos;
390  } else {
391  pos = pars.departPos + getLength();
392  }
393  if (pos < 0 || pos > getLength()) {
394  WRITE_WARNING("Invalid departPos " + toString(pos) + " given for vehicle '" +
395  v.getID() + "'. Inserting at lane end instead.");
396  pos = getLength();
397  }
398  break;
399  case DEPART_POS_RANDOM:
401  pos = RandHelper::rand(getLength());
402  break;
403  default:
404  break;
405  }
406  bool result = false;
407  MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this, pos);
408  MEVehicle* veh = static_cast<MEVehicle*>(&v);
409  if (pars.departPosProcedure == DEPART_POS_FREE) {
410  while (segment != 0 && !result) {
411  if (checkOnly) {
412  result = segment->hasSpaceFor(veh, time, true);
413  } else {
414  result = segment->initialise(veh, time);
415  }
416  segment = segment->getNextSegment();
417  }
418  } else {
419  if (checkOnly) {
420  result = segment->hasSpaceFor(veh, time, true);
421  } else {
422  result = segment->initialise(veh, time);
423  }
424  }
425  return result;
426  }
427 #else
428  UNUSED_PARAMETER(time);
429 #endif
430  if (checkOnly) {
432  return true;
433  }
434  switch (v.getParameter().departLaneProcedure) {
435  case DEPART_LANE_GIVEN:
436  case DEPART_LANE_DEFAULT:
438  const SUMOReal occupancy = getDepartLane(static_cast<MSVehicle&>(v))->getBruttoOccupancy();
439  return occupancy == (SUMOReal)0 || occupancy * myLength + v.getVehicleType().getLengthWithGap() <= myLength;
440  }
441  default:
442  for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
443  const SUMOReal occupancy = (*i)->getBruttoOccupancy();
444  if (occupancy == (SUMOReal)0 || occupancy * myLength + v.getVehicleType().getLengthWithGap() <= myLength) {
445  return true;
446  }
447  }
448  }
449  return false;
450  }
451  MSLane* insertionLane = getDepartLane(static_cast<MSVehicle&>(v));
452  return insertionLane != 0 && insertionLane->insertVehicle(static_cast<MSVehicle&>(v));
453 }
454 
455 
456 void
458  if (myLaneChanger == 0) {
459  return;
460  }
462  // allow changing only if all links leading to this internal lane have priority
463  for (std::vector<MSLane*>::const_iterator it = myLanes->begin(); it != myLanes->end(); ++it) {
464  MSLane* pred = (*it)->getLogicalPredecessorLane();
465  MSLink* link = MSLinkContHelper::getConnectingLink(*pred, **it);
466  assert(link != 0);
467  if (!link->havePriority()) {
468  return;
469  }
470  }
471  }
473 }
474 
475 
476 
477 #ifdef HAVE_INTERNAL_LANES
478 const MSEdge*
479 MSEdge::getInternalFollowingEdge(MSEdge* followerAfterInternal) const {
480  //@todo to be optimized
481  for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
482  MSLane* l = *i;
483  const MSLinkCont& lc = l->getLinkCont();
484  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
485  MSLink* link = *j;
486  if (&link->getLane()->getEdge() == followerAfterInternal) {
487  if (link->getViaLane() != 0) {
488  return &link->getViaLane()->getEdge();
489  } else {
490  return 0; // network without internal links
491  }
492  }
493  }
494  }
495  return 0;
496 }
497 #endif
498 
499 
500 SUMOReal
502  assert(minSpeed > 0);
503  if (!myAmDelayed) {
504  return myEmptyTraveltime;
505  }
506  SUMOReal v = 0;
507 #ifdef HAVE_INTERNAL
509  MESegment* first = MSGlobals::gMesoNet->getSegmentForEdge(*this);
510  unsigned segments = 0;
511  do {
512  v += first->getMeanSpeed();
513  first = first->getNextSegment();
514  segments++;
515  } while (first != 0);
516  v /= (SUMOReal) segments;
517  } else {
518 #endif
519  for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
520  v += (*i)->getMeanSpeed();
521  }
522  v /= (SUMOReal) myLanes->size();
523 #ifdef HAVE_INTERNAL
524  }
525 #endif
526  return getLength() / MAX2(minSpeed, v);
527 }
528 
529 
530 bool
531 MSEdge::dictionary(const std::string& id, MSEdge* ptr) {
532  DictType::iterator it = myDict.find(id);
533  if (it == myDict.end()) {
534  // id not in myDict.
535  myDict[id] = ptr;
536  while ((int)myEdges.size() < ptr->getNumericalID() + 1) {
537  myEdges.push_back(0);
538  }
539  myEdges[ptr->getNumericalID()] = ptr;
540  return true;
541  }
542  return false;
543 }
544 
545 
546 MSEdge*
547 MSEdge::dictionary(const std::string& id) {
548  DictType::iterator it = myDict.find(id);
549  if (it == myDict.end()) {
550  // id not in myDict.
551  return 0;
552  }
553  return it->second;
554 }
555 
556 
557 MSEdge*
558 MSEdge::dictionary(size_t id) {
559  assert(myEdges.size() > id);
560  return myEdges[id];
561 }
562 
563 
564 size_t
566  return myDict.size();
567 }
568 
569 
570 size_t
572  return myEdges.size();
573 }
574 
575 
576 void
578  for (DictType::iterator i = myDict.begin(); i != myDict.end(); ++i) {
579  delete(*i).second;
580  }
581  myDict.clear();
582 }
583 
584 
585 void
586 MSEdge::insertIDs(std::vector<std::string>& into) {
587  for (DictType::iterator i = myDict.begin(); i != myDict.end(); ++i) {
588  into.push_back((*i).first);
589  }
590 }
591 
592 
593 void
594 MSEdge::parseEdgesList(const std::string& desc, ConstMSEdgeVector& into,
595  const std::string& rid) {
596  if (desc[0] == BinaryFormatter::BF_ROUTE) {
597  std::istringstream in(desc, std::ios::binary);
598  char c;
599  in >> c;
600  FileHelpers::readEdgeVector(in, into, rid);
601  } else {
602  StringTokenizer st(desc);
603  parseEdgesList(st.getVector(), into, rid);
604  }
605 }
606 
607 
608 void
609 MSEdge::parseEdgesList(const std::vector<std::string>& desc, ConstMSEdgeVector& into,
610  const std::string& rid) {
611  for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
612  const MSEdge* edge = MSEdge::dictionary(*i);
613  // check whether the edge exists
614  if (edge == 0) {
615  throw ProcessError("The edge '" + *i + "' within the route " + rid + " is not known."
616  + "\n The route can not be build.");
617  }
618  into.push_back(edge);
619  }
620 }
621 
622 
623 SUMOReal
624 MSEdge::getDistanceTo(const MSEdge* other) const {
625  if (getLanes().size() > 0 && other->getLanes().size() > 0) {
627  } else {
628  return 0; // optimism is just right for astar
629  }
630 }
631 
632 
633 SUMOReal
635  // @note lanes might have different maximum speeds in theory
636  return getLanes()[0]->getSpeedLimit();
637 }
638 
639 
640 SUMOReal
641 MSEdge::getVehicleMaxSpeed(const SUMOVehicle* const veh) const {
642  // @note lanes might have different maximum speeds in theory
643  return getLanes()[0]->getVehicleMaxSpeed(veh);
644 }
645 
646 
647 std::vector<MSPerson*>
649  std::vector<MSPerson*> result(myPersons.begin(), myPersons.end());
650  sort(result.begin(), result.end(), person_by_offset_sorter(timestep));
651  return result;
652 }
653 
654 
655 std::vector<MSContainer*>
657  std::vector<MSContainer*> result(myContainers.begin(), myContainers.end());
658  sort(result.begin(), result.end(), container_by_position_sorter(timestep));
659  return result;
660 }
661 
662 
663 int
664 MSEdge::person_by_offset_sorter::operator()(const MSPerson* const p1, const MSPerson* const p2) const {
665  const SUMOReal pos1 = p1->getCurrentStage()->getEdgePos(myTime);
666  const SUMOReal pos2 = p2->getCurrentStage()->getEdgePos(myTime);
667  if (pos1 != pos2) {
668  return pos1 < pos2;
669  }
670  return p1->getID() < p2->getID();
671 }
672 
673 int
675  const SUMOReal pos1 = c1->getCurrentStage()->getEdgePos(myTime);
676  const SUMOReal pos2 = c2->getCurrentStage()->getEdgePos(myTime);
677  if (pos1 != pos2) {
678  return pos1 < pos2;
679  }
680  return c1->getID() < c2->getID();
681 }
682 
683 const MSEdgeVector&
685  if (vClass == SVC_IGNORING) {
686  return mySuccessors;
687  }
688  ClassesSuccesorMap::const_iterator i = myClassesSuccessorMap.find(vClass);
689  if (i != myClassesSuccessorMap.end()) {
690  // can use cached value
691  return i->second;
692  } else {
693  // this vClass is requested for the first time. rebuild all succesors
694  for (MSEdgeVector::const_iterator it = mySuccessors.begin(); it != mySuccessors.end(); ++it) {
695  const std::vector<MSLane*>* allowed = allowedLanes(*it, vClass);
696  if (allowed == 0 || allowed->size() > 0) {
697  myClassesSuccessorMap[vClass].push_back(*it);
698  }
699  }
700  return myClassesSuccessorMap[vClass];
701  }
702 }
703 
704 
705 /****************************************************************************/
706 
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
bool myAmDelayed
whether this edge had a vehicle with less than max speed on it
Definition: MSEdge.h:770
const std::string & getID() const
returns the person id
Definition: MSPerson.cpp:552
std::set< MSPerson * > myPersons
Persons on the edge (only for drawing)
Definition: MSEdge.h:733
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:455
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
static void insertIDs(std::vector< std::string > &into)
Inserts IDs of all known edges into the given vector.
Definition: MSEdge.cpp:586
SUMOReal myLength
the length of the edge (cached value for speedup)
Definition: MSEdge.h:764
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Sorts edges by their ids.
Definition: MSEdge.h:647
bool insertVehicle(SUMOVehicle &v, SUMOTime time, const bool checkOnly=false) const
Tries to insert the given vehicle into the network.
Definition: MSEdge.cpp:367
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
SUMOReal getDistanceTo(const MSEdge *other) const
optimistic air distance heuristic for use in routing
Definition: MSEdge.cpp:624
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
Definition: MSEdge.cpp:571
void initialize(const std::vector< MSLane * > *lanes)
Initialize the edge.
Definition: MSEdge.cpp:107
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:186
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
virtual SUMOReal getEdgePos(SUMOTime now) const =0
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
void recalcCache()
Recalculates the cached values.
Definition: MSEdge.cpp:122
SUMOReal departSpeed
(optional) The initial speed of the vehicle
static MSEdgeVector myEdges
Static list of edges.
Definition: MSEdge.h:789
const EdgeBasicFunction myFunction
the purpose of the edge
Definition: MSEdge.h:714
The position is given.
ClassesSuccesorMap myClassesSuccessorMap
Definition: MSEdge.h:795
ClassedAllowedLanesCont myClassedAllowed
From vehicle class to lanes allowed to be used by it.
Definition: MSEdge.h:746
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
int operator()(const MSContainer *const c1, const MSContainer *const c2) const
comparing operator
Definition: MSEdge.cpp:674
The least occupied lane is used.
void closeBuilding()
Definition: MSEdge.cpp:129
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
virtual ~MSEdge()
Destructor.
Definition: MSEdge.cpp:91
T MAX2(T a, T b)
Definition: StdDefs.h:74
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:82
SUMOReal computeChosenSpeedDeviation(MTRand *rng, const SUMOReal minDevFactor=0.2) const
Computes and returns the speed deviation.
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary...
Definition: MSEdge.cpp:531
SUMOTime incVaporization(SUMOTime t)
Enables vaporization.
Definition: MSEdge.cpp:278
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:292
The lane is chosen randomly.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:79
std::vector< MSContainer * > getSortedContainers(SUMOTime timestep) const
Returns this edge's containers sorted by pos.
Definition: MSEdge.cpp:656
static T getRandomFrom(const std::vector< T > &v)
Returns a random element from the given vector.
Definition: RandHelper.h:109
const SVCPermissions SVCAll
int myVaporizationRequests
Vaporizer counter.
Definition: MSEdge.h:717
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:90
The least occupied lane from best lanes.
The position is chosen randomly.
SUMOTime decVaporization(SUMOTime t)
Disables vaporization.
Definition: MSEdge.cpp:285
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
MSContainerStage * getCurrentStage() const
Return the current stage.
Definition: MSContainer.h:641
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The speed is given.
std::map< std::string, MSEdge * > DictType
definition of the static dictionary type
Definition: MSEdge.h:779
The car-following model and parameter.
Definition: MSVehicleType.h:74
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
The lane is given.
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:55
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:81
bool insertVehicle(MSVehicle &v)
Tries to insert the given vehicle.
Definition: MSLane.cpp:358
void rebuildAllowedLanes()
Definition: MSEdge.cpp:168
Sorts persons by their positions.
Definition: MSEdge.h:662
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:535
MSLane * getLogicalPredecessorLane() const
Definition: MSLane.cpp:1357
#define max(a, b)
Definition: polyfonts.c:65
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
SUMOReal getSpeedDeviation() const
Returns this type's speed deviation.
The edge is a district edge.
Definition: MSEdge.h:100
virtual void setChosenSpeedFactor(const SUMOReal factor)=0
Representation of a vehicle.
Definition: SUMOVehicle.h:65
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
The least occupied lane from lanes which allow the continuation.
AllowedLanesCont myAllowed
Associative container from destination-edge to allowed-lanes.
Definition: MSEdge.h:742
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
Definition: MSVehicle.cpp:1902
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:577
SVCPermissions myMinimumPermissions
The intersection of lane permissions for this edge.
Definition: MSEdge.h:749
MSPersonStage * getCurrentStage() const
Definition: MSPerson.h:576
MSEdgeVector mySuccessors
The succeeding edges.
Definition: MSEdge.h:723
MSLane * leftLane(const MSLane *const lane) const
Returns the lane left to the one given, 0 if the given lane is leftmost.
Definition: MSEdge.cpp:190
MSLaneChanger * myLaneChanger
This member will do the lane-change.
Definition: MSEdge.h:711
MSEdge(const std::string &id, int numericalID, const EdgeBasicFunction function, const std::string &streetName, const std::string &edgeType, int priority)
Constructor.
Definition: MSEdge.cpp:73
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
Definition: MSEdge.h:368
int operator()(const MSPerson *const p1, const MSPerson *const p2) const
comparing operator
Definition: MSEdge.cpp:664
const std::vector< MSLane * > * myLanes
Container for the edge's lane; should be sorted: (right-hand-traffic) the more left the lane...
Definition: MSEdge.h:708
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
SUMOReal getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
Definition: MSEdge.cpp:634
If a fixed number of random choices fails, a free position is chosen.
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
Definition: MSVehicle.cpp:1896
MSLane * getDepartLane(MSVehicle &veh) const
Finds a depart lane for the given vehicle parameters.
Definition: MSEdge.cpp:312
Base class for objects which have an id.
Definition: Named.h:45
The rightmost lane the vehicle may use.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
virtual SUMOReal getEdgePos(SUMOTime now) const =0
std::vector< std::string > getVector()
SVCPermissions myCombinedPermissions
The union of lane permissions for this edge.
Definition: MSEdge.h:751
SUMOReal getSpeedFactor() const
Returns this type's speed factor.
No information given; use default.
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:235
Sorts containers by their positions.
Definition: MSEdge.h:676
Structure representing possible vehicle parameter.
std::set< MSContainer * > myContainers
Containers on the edge.
Definition: MSEdge.h:736
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:257
MSLane * parallelLane(const MSLane *const lane, int offset) const
Returns the lane with the given offset parallel to the given lane one or 0 if it does not exist...
Definition: MSEdge.cpp:202
virtual void changeLanes(SUMOTime t)
Performs lane changing on this edge.
Definition: MSEdge.cpp:457
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
SUMOReal myEmptyTraveltime
the traveltime on the empty edge (cached value for speedup)
Definition: MSEdge.h:767
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
Definition: MSEdge.cpp:217
static size_t dictSize()
Returns the number of edges.
Definition: MSEdge.cpp:565
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:90
const std::string & getID() const
returns the container id
int SUMOTime
Definition: SUMOTime.h:43
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
SUMOReal departPos
(optional) The position the vehicle shall depart from
std::map< const MSEdge *, std::vector< MSLane * > * > AllowedLanesCont
Suceeding edges (keys) and allowed lanes to reach these edges (values).
Definition: MSEdge.h:109
unsigned size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:87
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:240
static DictType myDict
Static dictionary to associate string-ids with objects.
Definition: MSEdge.h:784
static void readEdgeVector(std::istream &in, std::vector< const E * > &edges, const std::string &rid)
Reads an edge vector binary.
Definition: FileHelpers.h:283
#define SUMOReal
Definition: config.h:218
static const bool gUseMesoSim
Definition: MSGlobals.h:102
const MSJunction * getFromJunction() const
Definition: MSEdge.h:345
const MSEdgeVector & getSuccessors() const
Returns the following edges.
Definition: MSEdge.h:315
#define NUMERICAL_EPS
Definition: config.h:162
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:641
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1026
A free position is chosen.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
MSLane * rightLane(const MSLane *const lane) const
Returns the lane right to the one given, 0 if the given lane is rightmost.
Definition: MSEdge.cpp:196
The edge is an internal edge.
Definition: MSEdge.h:98
const std::vector< MSLane * > * getAllowedLanesWithDefault(const AllowedLanesCont &c, const MSEdge *dest) const
lookup in map and return 0 if not found
Definition: MSEdge.cpp:229
SUMOReal getBruttoOccupancy() const
Returns the brutto (including minGaps) occupancy of this lane during the last step.
Definition: MSLane.cpp:1432
std::vector< MSPerson * > getSortedPersons(SUMOTime timestep) const
Returns this edge's persons sorted by pos.
Definition: MSEdge.cpp:648
MSEdgeVector myPredecessors
The preceeding edges.
Definition: MSEdge.h:726
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:501
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:594
virtual const std::string & getID() const =0
Get the vehicle's ID.
vehicles ignoring classes
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:75
std::string id
The vehicle's id.
const MSJunction * getToJunction() const
Definition: MSEdge.h:349
const Position & getPosition() const
Definition: MSJunction.cpp:61
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.