52 #include <mesosim/MELoop.h>
53 #include <mesosim/MESegment.h>
54 #include <mesosim/MEVehicle.h>
57 #ifdef CHECK_MEMORY_LEAKS
59 #endif // CHECK_MEMORY_LEAKS
74 const std::string& streetName,
75 const std::string& edgeType,
77 Named(id), myNumericalID(numericalID), myLanes(0),
78 myLaneChanger(0), myFunction(function), myVaporizationRequests(0),
79 myLastFailedInsertionTime(-1),
80 myFromJunction(0), myToJunction(0),
81 myStreetName(streetName),
85 myEmptyTraveltime(-1.),
87 myAmRoundabout(false) {}
96 for (AllowedLanesCont::iterator i1 = (*i2).second.begin(); i1 != (*i2).second.end(); i1++) {
109 if (!lanes->empty()) {
129 myAllowed[0] =
new std::vector<MSLane*>();
130 for (std::vector<MSLane*>::const_iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
133 for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
134 MSLane* toL = (*j)->getLane();
146 myAllowed[&to] =
new std::vector<MSLane*>();
150 #ifdef HAVE_INTERNAL_LANES
151 toL = (*j)->getViaLane();
171 for (AllowedLanesCont::iterator i1 = (*i2).second.begin(); i1 != (*i2).second.end(); i1++) {
179 for (std::vector<MSLane*>::const_iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
202 if (index == (
int)
myLanes->size()) {
205 const int resultIndex = index + offset;
206 if (resultIndex >= (
int)
myLanes->size() || resultIndex < 0) {
209 return (*
myLanes)[resultIndex];
214 const std::vector<MSLane*>*
220 const std::vector<MSLane*>*
226 const std::vector<MSLane*>*
228 AllowedLanesCont::const_iterator it = c.find(dest);
236 const std::vector<MSLane*>*
251 for (AllowedLanesCont::const_iterator i1 =
myAllowed.begin(); i1 !=
myAllowed.end(); ++i1) {
252 const MSEdge* edge = i1->first;
253 const std::vector<MSLane*>* lanes = i1->second;
256 for (std::vector<MSLane*>::const_iterator i2 = lanes->begin(); i2 != lanes->end(); ++i2) {
258 if ((*i2)->allowsVehicleClass(vclass)) {
297 for (std::vector<MSLane*>::const_iterator i = allowed->begin(); i != allowed->end(); ++i) {
298 const SUMOReal occupancy = (*i)->getBruttoOccupancy();
299 if (occupancy < leastOccupancy) {
301 leastOccupancy = occupancy;
329 const std::vector<MSVehicle::LaneQ>& bl = veh.
getBestLanes();
331 for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
332 if ((*i).length > bestLength) {
333 bestLength = (*i).length;
336 std::vector<MSLane*>* bestLanes =
new std::vector<MSLane*>();
337 for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
338 if ((*i).length == bestLength) {
339 bestLanes->push_back((*i).lane);
348 for (std::vector<MSLane*>::const_iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
374 WRITE_WARNING(
"Choosing new speed factor for vehicle '" + pars.
id +
"' to match departure speed.");
378 "' is too high for the departure edge '" +
getID() +
"'.");
393 v.
getID() +
"'. Inserting at lane end instead.");
405 MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*
this, pos);
406 MEVehicle* veh =
static_cast<MEVehicle*
>(&v);
408 while (segment != 0 && !result) {
410 result = segment->hasSpaceFor(veh, time,
true);
412 result = segment->initialise(veh, time);
414 segment = segment->getNextSegment();
418 result = segment->hasSpaceFor(veh, time,
true);
420 result = segment->initialise(veh, time);
435 for (std::vector<MSLane*>::const_iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
444 return insertionLane != 0 && insertionLane->
insertVehicle(static_cast<MSVehicle&>(v));
455 for (std::vector<MSLane*>::const_iterator it =
myLanes->begin(); it !=
myLanes->end(); ++it) {
469 #ifdef HAVE_INTERNAL_LANES
471 MSEdge::getInternalFollowingEdge(
MSEdge* followerAfterInternal)
const {
473 for (std::vector<MSLane*>::const_iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
476 for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
479 if (link->getViaLane() != 0) {
480 return &link->getViaLane()->getEdge();
494 assert(minSpeed > 0);
501 MESegment* first = MSGlobals::gMesoNet->getSegmentForEdge(*
this);
502 unsigned segments = 0;
504 v += first->getMeanSpeed();
505 first = first->getNextSegment();
507 }
while (first != 0);
511 for (std::vector<MSLane*>::const_iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
512 v += (*i)->getMeanSpeed();
524 DictType::iterator it =
myDict.find(
id);
540 DictType::iterator it =
myDict.find(
id);
570 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
579 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
580 into.push_back((*i).first);
587 const std::string& rid) {
589 std::istringstream in(desc, std::ios::binary);
602 const std::string& rid) {
603 for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
607 throw ProcessError(
"The edge '" + *i +
"' within the route " + rid +
" is not known."
608 +
"\n The route can not be build.");
610 into.push_back(edge);
628 return getLanes()[0]->getSpeedLimit();
635 return getLanes()[0]->getVehicleMaxSpeed(veh);
639 std::vector<MSPerson*>
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
bool myAmDelayed
whether this edge had a vehicle with less than max speed on it
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.
static void insertIDs(std::vector< std::string > &into)
Inserts IDs of all known edges into the given vector.
SUMOReal myLength
the length of the edge (cached value for speedup)
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Sorts edges by their ids.
bool insertVehicle(SUMOVehicle &v, SUMOTime time, const bool checkOnly=false) const
Tries to insert the given vehicle into the network.
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.
void initialize(const std::vector< MSLane * > *lanes)
Initialize the edge.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
std::vector< MSEdge * > mySuccessors
The succeeding edges.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
void recalcCache()
Recalculates the cached values.
SUMOReal departSpeed
(optional) The initial speed of the vehicle
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.
const MSRoute & getRoute() const
Returns the current route.
SUMOReal computeChosenSpeedDeviation(MTRand *rng, const SUMOReal minDevFactor=0.2) const
Computes and returns the speed deviation.
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)
std::vector< MSEdge * > myPredecessors
The preceeding edges.
#define WRITE_WARNING(msg)
std::map< std::string, MSEdge * > DictType
definition of the static dictionary type
The car-following model and parameter.
static OptionsCont & getOptions()
Retrieves the options.
static std::vector< MSEdge * > myEdges
Static list of edges.
Performs lane changing of vehicles.
const std::string & getID() const
Returns the id.
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
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
SUMOReal getSpeedDeviation() const
Returns this type's speed deviation.
The edge is a district edge.
virtual void setChosenSpeedFactor(const SUMOReal factor)=0
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.
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
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.
MSEdge(const std::string &id, int numericalID, const EdgeBasicFunction function, const std::string &streetName, const std::string &edgeType, int priority)
Constructor.
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
int operator()(const MSPerson *const p1, const MSPerson *const p2) const
comparing operator
const std::vector< MSLane * > * myLanes
Container for the edge's lane; should be sorted: (right-hand-traffic) the more left the lane...
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.
MSLane * getDepartLane(MSVehicle &veh) const
Finds a depart lane for the given vehicle parameters.
Base class for objects which have an id.
The rightmost lane the vehicle may use.
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()
SVCPermissions myCombinedPermissions
The union of lane permissions for this edge.
SUMOReal getSpeedFactor() const
Returns this type's speed factor.
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)
SUMOReal myEmptyTraveltime
the traveltime on the empty edge (cached value for speedup)
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.
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
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
const MSJunction * getFromJunction() const
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.
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
SUMOReal getBruttoOccupancy() const
Returns the brutto (including minGaps) occupancy of this lane during the last step.
std::vector< MSPerson * > getSortedPersons(SUMOTime timestep) const
Returns this edge's persons sorted by pos.
Representation of a lane in the micro simulation.
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
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.
std::string id
The vehicle's id.
const MSJunction * getToJunction() const
const Position & getPosition() const
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.