SUMO - Simulation of Urban MObility
MSJunction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The base class for an intersection
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include "MSVehicle.h"
27 #include "MSEdge.h"
28 #include "MSJunction.h"
29 
30 
31 
32 
33 
34 
35 // ===========================================================================
36 // debug constants
37 // ===========================================================================
38 //#define DEBUG_LINKLEADER
39 //#define DEBUG_COND (ego->isSelected())
40 //#define DEBUG_COND (true)
41 
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class MSLink;
48 
49 // ===========================================================================
50 // static member definitions
51 // ===========================================================================
52 
53 // ===========================================================================
54 // member method definition
55 // ===========================================================================
56 MSJunction::MSJunction(const std::string& id, SumoXMLNodeType type, const Position& position,
57  const PositionVector& shape) :
58  Named(id),
59  myType(type),
60  myPosition(position),
61  myShape(shape) {
62 }
63 
64 
66 
67 
68 const Position&
70  return myPosition;
71 }
72 
73 
74 void
76 
77 
78 int
80  int nr = 0;
81  for (const MSEdge* e : myIncoming) {
82  nr += (int)e->getLanes().size();
83  }
84  return nr;
85 }
86 
87 
88 void
90  myLinkLeaders.erase(vehicle);
91 #ifdef DEBUG_LINKLEADER
92  if DEBUG_COND {
93  std::cout << SIMTIME << " MSJunction::passedJunction " << getID() << " veh=" << vehicle->getID() << "\n";
94  }
95 #endif
96 }
97 
98 
99 bool
100 MSJunction::isLeader(const MSVehicle* ego, const MSVehicle* foe, bool updateLeader) {
101 #ifdef DEBUG_LINKLEADER
102  if DEBUG_COND {
103  std::cout << SIMTIME << " MSJunction::isLeader " << getID()
104  << " ego=" << ego->getID()
105  << " foe=" << foe->getID()
106  << std::endl;
107  }
108 #endif
109  if (foe->getLane()->getEdge().getToJunction() != this) {
110  // foe is already past the junction so is definitely a leader
111 #ifdef DEBUG_LINKLEADER
112  if DEBUG_COND {
113  std::cout << " foe (" << foe->getID() << ") is past the junction (leader)" << std::endl;
114  }
115 #endif
116  return true;
117  }
118  if (myLinkLeaders.find(ego) == myLinkLeaders.end() || myLinkLeaders[ego].count(foe) == 0) {
119  // we are not yet the leader for foe, thus foe will be our leader
120  if (updateLeader) {
121  myLinkLeaders[foe].insert(ego);
122  }
123 #ifdef DEBUG_LINKLEADER
124  if DEBUG_COND {
125  std::cout << " foe (" << foe->getID() << ") is the leader!" << std::endl;
126  }
127 #endif
128  return true;
129  } else {
130 #ifdef DEBUG_LINKLEADER
131  if DEBUG_COND {
132  std::cout << " ego (" << ego->getID() << ") is the leader!" << std::endl;
133  }
134 #endif
135  return false;
136  }
137 }
138 /****************************************************************************/
139 
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:617
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
LeaderMap myLinkLeaders
Definition: MSJunction.h:161
const std::string & getID() const
Returns the id.
Definition: Named.h:69
const MSJunction * getToJunction() const
Definition: MSEdge.h:346
virtual ~MSJunction()
Destructor.
Definition: MSJunction.cpp:65
#define SIMTIME
Definition: SUMOTime.h:65
A road/street connecting two junctions.
Definition: MSEdge.h:75
ConstMSEdgeVector myIncoming
incoming edges
Definition: MSJunction.h:152
Position myPosition
The position of the junction.
Definition: MSJunction.h:142
MSJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape)
Constructor.
Definition: MSJunction.cpp:56
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders
Definition: MSJunction.cpp:89
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
const Position & getPosition() const
Definition: MSJunction.cpp:69
Base class for objects which have an id.
Definition: Named.h:49
bool isLeader(const MSVehicle *ego, const MSVehicle *foe, bool updateLeader)
Definition: MSJunction.cpp:100
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
int getNrOfIncomingLanes() const
Definition: MSJunction.cpp:79
virtual void postloadInit()
Definition: MSJunction.cpp:75
#define DEBUG_COND
Definition: MESegment.cpp:54
const std::string & getID() const
Returns the name of the vehicle.