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-2017 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 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class MSLink;
42 
43 // ===========================================================================
44 // static member definitions
45 // ===========================================================================
46 
47 // ===========================================================================
48 // member method definition
49 // ===========================================================================
50 MSJunction::MSJunction(const std::string& id, SumoXMLNodeType type, const Position& position,
51  const PositionVector& shape) :
52  Named(id),
53  myType(type),
54  myPosition(position),
55  myShape(shape) {
56 }
57 
58 
60 
61 
62 const Position&
64  return myPosition;
65 }
66 
67 
68 void
70 
71 
72 void
74  myLinkLeaders.erase(vehicle);
75 }
76 
77 
78 bool
79 MSJunction::isLeader(const MSVehicle* ego, const MSVehicle* foe) {
80  if (foe->getLane()->getEdge().getToJunction() != this) {
81  // foe is already past the junction so is definitely a leader
82  return true;
83  }
84  if (myLinkLeaders.find(ego) == myLinkLeaders.end() || myLinkLeaders[ego].count(foe) == 0) {
85  // we are not yet the leader for foe, thus foe will be our leader
86  myLinkLeaders[foe].insert(ego);
87  return true;
88  } else {
89  return false;
90  }
91 }
92 /****************************************************************************/
93 
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:582
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:488
LeaderMap myLinkLeaders
Definition: MSJunction.h:163
const MSJunction * getToJunction() const
Definition: MSEdge.h:372
virtual ~MSJunction()
Destructor.
Definition: MSJunction.cpp:59
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:50
void passedJunction(const MSVehicle *vehicle)
erase vehicle from myLinkLeaders
Definition: MSJunction.cpp:73
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
const Position & getPosition() const
Definition: MSJunction.cpp:63
Base class for objects which have an id.
Definition: Named.h:46
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
virtual void postloadInit()
Definition: MSJunction.cpp:69
bool isLeader(const MSVehicle *ego, const MSVehicle *foe)
Definition: MSJunction.cpp:79