SUMO - Simulation of Urban MObility
MSJunction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The base class for an intersection
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "MSVehicle.h"
34 #include "MSEdge.h"
35 #include "MSJunction.h"
36 
37 #ifdef CHECK_MEMORY_LEAKS
38 #include <foreign/nvwa/debug_new.h>
39 #endif // CHECK_MEMORY_LEAKS
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class MSLink;
46 
47 // ===========================================================================
48 // static member definitions
49 // ===========================================================================
50 
51 // ===========================================================================
52 // member method definition
53 // ===========================================================================
54 MSJunction::MSJunction(const std::string& id, SumoXMLNodeType type, const Position& position,
55  const PositionVector& shape) :
56  Named(id),
57  myType(type),
58  myPosition(position),
59  myShape(shape)
60 {}
61 
62 
64 
65 
66 const Position&
68  return myPosition;
69 }
70 
71 
72 void
74 
75 
76 void
78  myLinkLeaders.erase(vehicle);
79 }
80 
81 
82 bool
83 MSJunction::isLeader(const MSVehicle* ego, const MSVehicle* foe) {
84  if (foe->getLane()->getEdge().getToJunction() != this) {
85  // foe is already past the junction so is definitely a leader
86  return true;
87  }
88  if (myLinkLeaders.find(ego) == myLinkLeaders.end() || myLinkLeaders[ego].count(foe) == 0) {
89  // we are not yet the leader for foe, thus foe will be our leader
90  myLinkLeaders[foe].insert(ego);
91  return true;
92  } else {
93  return false;
94  }
95 }
96 /****************************************************************************/
97 
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:461
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
LeaderMap myLinkLeaders
Definition: MSJunction.h:154
virtual ~MSJunction()
Destructor.
Definition: MSJunction.cpp:63
Position myPosition
The position of the junction.
Definition: MSJunction.h:135
MSJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape)
Constructor.
Definition: MSJunction.cpp:54
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders
Definition: MSJunction.cpp:77
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
Base class for objects which have an id.
Definition: Named.h:45
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
virtual void postloadInit()
Definition: MSJunction.cpp:73
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:331
bool isLeader(const MSVehicle *ego, const MSVehicle *foe)
Definition: MSJunction.cpp:83
const MSJunction * getToJunction() const
Definition: MSEdge.h:349
const Position & getPosition() const
Definition: MSJunction.cpp:67