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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // The base class for an intersection
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include "MSVehicle.h"
33 #include "MSEdge.h"
34 #include "MSJunction.h"
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class MSLink;
41 
42 // ===========================================================================
43 // static member definitions
44 // ===========================================================================
45 
46 // ===========================================================================
47 // member method definition
48 // ===========================================================================
49 MSJunction::MSJunction(const std::string& id, SumoXMLNodeType type, const Position& position,
50  const PositionVector& shape) :
51  Named(id),
52  myType(type),
53  myPosition(position),
54  myShape(shape) {
55 }
56 
57 
59 
60 
61 const Position&
63  return myPosition;
64 }
65 
66 
67 void
69 
70 
71 void
73  myLinkLeaders.erase(vehicle);
74 }
75 
76 
77 bool
78 MSJunction::isLeader(const MSVehicle* ego, const MSVehicle* foe) {
79  if (foe->getLane()->getEdge().getToJunction() != this) {
80  // foe is already past the junction so is definitely a leader
81  return true;
82  }
83  if (myLinkLeaders.find(ego) == myLinkLeaders.end() || myLinkLeaders[ego].count(foe) == 0) {
84  // we are not yet the leader for foe, thus foe will be our leader
85  myLinkLeaders[foe].insert(ego);
86  return true;
87  } else {
88  return false;
89  }
90 }
91 /****************************************************************************/
92 
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:607
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:564
LeaderMap myLinkLeaders
Definition: MSJunction.h:163
const MSJunction * getToJunction() const
Definition: MSEdge.h:352
virtual ~MSJunction()
Destructor.
Definition: MSJunction.cpp:58
Position myPosition
The position of the junction.
Definition: MSJunction.h:144
MSJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape)
Constructor.
Definition: MSJunction.cpp:49
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders
Definition: MSJunction.cpp:72
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
const Position & getPosition() const
Definition: MSJunction.cpp:62
Base class for objects which have an id.
Definition: Named.h:54
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
virtual void postloadInit()
Definition: MSJunction.cpp:68
bool isLeader(const MSVehicle *ego, const MSVehicle *foe)
Definition: MSJunction.cpp:78