51 #include <mesosim/MELoop.h>
52 #include <mesosim/MESegment.h>
53 #include <mesosim/MEVehicle.h>
56 #ifdef CHECK_MEMORY_LEAKS
58 #endif // CHECK_MEMORY_LEAKS
73 const std::string& streetName,
74 const std::string& edgeType) :
75 Named(id), myNumericalID(numericalID), myLanes(0),
76 myLaneChanger(0), myFunction(function), myVaporizationRequests(0),
77 myLastFailedInsertionTime(-1),
78 myFromJunction(0), myToJunction(0),
79 myStreetName(streetName),
81 myAmRoundabout(false) {}
90 for (AllowedLanesCont::iterator i1 = (*i2).second.begin(); i1 != (*i2).second.end(); i1++) {
121 for (std::vector<MSLane*>::iterator it =
myLanes->begin(); it !=
myLanes->end(); ++it) {
135 myAllowed[0] =
new std::vector<MSLane*>();
136 for (std::vector<MSLane*>::iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
139 for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
140 MSLane* toL = (*j)->getLane();
152 myAllowed[&to] =
new std::vector<MSLane*>();
156 #ifdef HAVE_INTERNAL_LANES
157 toL = (*j)->getViaLane();
177 for (AllowedLanesCont::iterator i1 = (*i2).second.begin(); i1 != (*i2).second.end(); i1++) {
185 for (std::vector<MSLane*>::iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
208 if (index == (
int)
myLanes->size()) {
211 const int resultIndex = index + offset;
212 if (resultIndex >= (
int)
myLanes->size() || resultIndex < 0) {
215 return (*
myLanes)[resultIndex];
220 const std::vector<MSLane*>*
226 const std::vector<MSLane*>*
232 const std::vector<MSLane*>*
234 AllowedLanesCont::const_iterator it = c.find(dest);
242 const std::vector<MSLane*>*
257 for (AllowedLanesCont::const_iterator i1 =
myAllowed.begin(); i1 !=
myAllowed.end(); ++i1) {
258 const MSEdge* edge = i1->first;
259 const std::vector<MSLane*>* lanes = i1->second;
262 for (std::vector<MSLane*>::const_iterator i2 = lanes->begin(); i2 != lanes->end(); ++i2) {
264 if ((*i2)->allowsVehicleClass(vclass)) {
302 unsigned int noCars = INT_MAX;
303 for (std::vector<MSLane*>::const_iterator i = allowed->begin(); i != allowed->end(); ++i) {
304 if ((*i)->getVehicleNumber() < noCars) {
333 const std::vector<MSVehicle::LaneQ>& bl = veh.
getBestLanes();
335 for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
336 if ((*i).length > bestLength) {
337 bestLength = (*i).length;
340 std::vector<MSLane*>* bestLanes =
new std::vector<MSLane*>();
341 for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
342 if ((*i).length == bestLength) {
343 bestLanes->push_back((*i).lane);
380 v.
getID() +
"'. Inserting at lane end instead.");
392 MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*
this, pos);
393 MEVehicle* veh =
static_cast<MEVehicle*
>(&v);
395 while (segment != 0 && !result) {
396 result = segment->initialise(veh, time);
397 segment = segment->getNextSegment();
400 result = segment->initialise(veh, time);
408 return insertionLane != 0 && insertionLane->
insertVehicle(static_cast<MSVehicle&>(v));
421 #ifdef HAVE_INTERNAL_LANES
423 MSEdge::getInternalFollowingEdge(
MSEdge* followerAfterInternal)
const {
425 for (std::vector<MSLane*>::const_iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
428 for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
431 if (link->getViaLane() != 0) {
432 return &link->getViaLane()->getEdge();
446 assert(minSpeed > 0);
450 MESegment* first = MSGlobals::gMesoNet->getSegmentForEdge(*
this);
451 unsigned segments = 0;
453 v += first->getMeanSpeed();
454 first = first->getNextSegment();
456 }
while (first != 0);
460 for (std::vector<MSLane*>::iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
461 v += (*i)->getMeanSpeed();
467 v =
MAX2(minSpeed, v);
474 DictType::iterator it =
myDict.find(
id);
490 DictType::iterator it =
myDict.find(
id);
520 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
529 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
530 into.push_back((*i).first);
537 const std::string& rid) {
539 std::istringstream in(desc, std::ios::binary);
552 const std::string& rid) {
553 for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
557 throw ProcessError(
"The edge '" + *i +
"' within the route " + rid +
" is not known."
558 +
"\n The route can not be build.");
560 into.push_back(edge);
568 return getLanes()[0]->getShape()[-1].distanceTo2D(other->
getLanes()[0]->getShape()[0]);
584 return getLanes()[0]->getSpeedLimit();
591 return getLanes()[0]->getVehicleMaxSpeed(veh);
595 std::vector<MSPerson*>
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
const std::string & getID() const
returns the person id
std::set< MSPerson * > myPersons
Persons on the edge (only for drawing)
MSEdge & getEdge() const
Returns the lane's edge.
Representation of a vehicle in the micro simulation.
std::vector< MSLane * > * myLanes
Container for the edge's lane; should be sorted: (right-hand-traffic) the more left the lane...
static void insertIDs(std::vector< std::string > &into)
Inserts IDs of all known edges into the given vector.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Sorts edges by their ids.
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
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
std::vector< MSEdge * > mySuccessors
The succeeding edges.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
const EdgeBasicFunction myFunction
the purpose of the edge
ClassedAllowedLanesCont myClassedAllowed
From vehicle class to lanes allowed to be used by it.
The least occupied lane is used.
static SUMOReal rand()
Returns a random real number in [0, 1)
virtual ~MSEdge()
Destructor.
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=0.00001) const
Computes and returns the current travel time for this edge.
const MSRoute & getRoute() const
Returns the current route.
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...
SUMOTime incVaporization(SUMOTime t)
Enables vaporization.
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
The lane is chosen randomly.
static T getRandomFrom(const std::vector< T > &v)
Returns a random element from the given vector.
const SVCPermissions SVCAll
int myVaporizationRequests
Vaporizer counter.
EdgeBasicFunction
Defines possible edge types.
The least occupied lane from best lanes.
The position is chosen randomly.
SUMOTime decVaporization(SUMOTime t)
Disables vaporization.
#define UNUSED_PARAMETER(x)
#define WRITE_WARNING(msg)
std::map< std::string, MSEdge * > DictType
definition of the static dictionary type
static OptionsCont & getOptions()
Retrieves the options.
void initialize(std::vector< MSLane * > *lanes)
Initialize the edge.
static std::vector< MSEdge * > myEdges
Static list of edges.
Performs lane changing of vehicles.
A road/street connecting two junctions.
static void parseEdgesList(const std::string &desc, std::vector< const MSEdge * > &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
bool insertVehicle(MSVehicle &v)
Tries to insert the given vehicle.
void rebuildAllowedLanes()
Sorts edges by their ids.
SUMOReal getLength() const
return the length of the edge
MSLane * getLogicalPredecessorLane() const
The edge is a district edge.
Representation of a vehicle.
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.
MSLane * getLane() const
Returns the connected lane.
static void clear()
Clears the dictionary.
SVCPermissions myMinimumPermissions
The intersection of lane permissions for this edge.
MSPersonStage * getCurrentStage() const
MSLane * leftLane(const MSLane *const lane) const
Returns the lane left to the one given, 0 if the given lane is leftmost.
MSLaneChanger * myLaneChanger
This member will do the lane-change.
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
std::vector< MSEdge * > myPredeccesors
The preceeding edges.
int operator()(const MSPerson *const p1, const MSPerson *const p2) const
comparing operator
MSLane * getDepartLane(const MSVehicle &veh) const
Finds a depart lane for the given vehicle parameters.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
SUMOReal getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
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.
Base class for objects which have an id.
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()
unsigned int getVehicleNumber() const
Returns the number of vehicles on this lane.
SVCPermissions myCombinedPermissions
The union of lane permissions for this edge.
No information given; use default.
Structure representing possible vehicle parameter.
bool havePriority() const
Returns whether this link is a major link.
int getNumericalID() const
Returns the numerical id of the edge.
static MSLink * getConnectingLink(const MSLane &from, const MSLane &to)
Returns the link connecting both lanes Both lanes have to be non-internal; 0 may be returned if no co...
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...
virtual void changeLanes(SUMOTime t)
Performs lane changing on this edge.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
static size_t dictSize()
Returns the number of edges.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
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).
unsigned size() const
Returns the number of edges to pass.
static DictType myDict
Static dictionary to associate string-ids with objects.
static void readEdgeVector(std::istream &in, std::vector< const E * > &edges, const std::string &rid)
Reads an edge vector binary.
static const bool gUseMesoSim
bool laneChangeAllowed() const
whether lane changing may be performed on this edge
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
A free position is chosen.
MSLane * rightLane(const MSLane *const lane) const
Returns the lane right to the one given, 0 if the given lane is rightmost.
bool insertVehicle(SUMOVehicle &v, SUMOTime time) const
Tries to insert the given vehicle into the network.
MSEdge(const std::string &id, int numericalID, const EdgeBasicFunction function, const std::string &streetName="", const std::string &edgeType="")
Constructor.
The edge is an internal edge.
const std::vector< MSLane * > * getAllowedLanesWithDefault(const AllowedLanesCont &c, const MSEdge *dest) const
lookup in map and return 0 if not found
std::vector< MSPerson * > getSortedPersons(SUMOTime timestep) const
Returns this edge's persons sorted by pos.
Representation of a lane in the micro simulation.
virtual const std::string & getID() const =0
Get the vehicle's ID.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.