50 #include <mesosim/MELoop.h>
51 #include <mesosim/MESegment.h>
52 #include <mesosim/MEVehicle.h>
55 #ifdef CHECK_MEMORY_LEAKS
57 #endif // CHECK_MEMORY_LEAKS
72 const std::string& streetName) :
73 Named(id), myNumericalID(numericalID), myLanes(0),
74 myLaneChanger(0), myFunction(function), myVaporizationRequests(0),
75 myLastFailedInsertionTime(-1), myStreetName(streetName) {}
84 for (AllowedLanesCont::iterator i1 = (*i2).second.begin(); i1 != (*i2).second.end(); i1++) {
108 myAllowed[0] =
new std::vector<MSLane*>();
109 for (std::vector<MSLane*>::iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
112 for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
113 MSLane* toL = (*j)->getLane();
125 myAllowed[&to] =
new std::vector<MSLane*>();
129 #ifdef HAVE_INTERNAL_LANES
130 toL = (*j)->getViaLane();
148 for (AllowedLanesCont::iterator i1 = (*i2).second.begin(); i1 != (*i2).second.end(); i1++) {
156 for (std::vector<MSLane*>::iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
179 if (index == (
int)
myLanes->size()) {
182 const int resultIndex = index + offset;
183 if (resultIndex >= (
int)
myLanes->size() || resultIndex < 0) {
192 if (predParallel != 0 && nextParallel != 0) {
194 if (connecting != 0) {
201 return (*
myLanes)[resultIndex];
206 const std::vector<MSLane*>*
212 const std::vector<MSLane*>*
218 const std::vector<MSLane*>*
220 AllowedLanesCont::const_iterator it = c.find(dest);
228 const std::vector<MSLane*>*
243 for (AllowedLanesCont::const_iterator i1 =
myAllowed.begin(); i1 !=
myAllowed.end(); ++i1) {
244 const MSEdge* edge = i1->first;
245 const std::vector<MSLane*>* lanes = i1->second;
248 for (std::vector<MSLane*>::const_iterator i2 = lanes->begin(); i2 != lanes->end(); ++i2) {
250 if ((*i2)->allowsVehicleClass(vclass)) {
288 unsigned int noCars = INT_MAX;
289 for (std::vector<MSLane*>::const_iterator i = allowed->begin(); i != allowed->end(); ++i) {
290 if ((*i)->getVehicleNumber() < noCars) {
321 for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
322 if ((*i).length > bestLength) {
323 bestLength = (*i).length;
326 std::vector<MSLane*>* bestLanes =
new std::vector<MSLane*>();
327 for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
328 if ((*i).length == bestLength) {
329 bestLanes->push_back((*i).lane);
366 v.
getID() +
"'. Inserting at lane end instead.");
378 MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*
this, pos);
379 MEVehicle* veh =
static_cast<MEVehicle*
>(&v);
381 while (segment != 0 && !result) {
382 result = segment->initialise(veh, time);
383 segment = segment->getNextSegment();
386 result = segment->initialise(veh, time);
394 return insertionLane != 0 && insertionLane->
insertVehicle(static_cast<MSVehicle&>(v));
409 #ifdef HAVE_INTERNAL_LANES
411 MSEdge::getInternalFollowingEdge(
MSEdge* followerAfterInternal)
const {
413 for (std::vector<MSLane*>::const_iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
416 for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
419 if (link->getViaLane() != 0) {
420 return &link->getViaLane()->getEdge();
434 assert(minSpeed > 0);
438 MESegment* first = MSGlobals::gMesoNet->getSegmentForEdge(*
this);
439 unsigned segments = 0;
441 v += first->getMeanSpeed();
442 first = first->getNextSegment();
444 }
while (first != 0);
448 for (std::vector<MSLane*>::iterator i =
myLanes->begin(); i !=
myLanes->end(); ++i) {
449 v += (*i)->getMeanSpeed();
455 v =
MAX2(minSpeed, v);
462 DictType::iterator it =
myDict.find(
id);
478 DictType::iterator it =
myDict.find(
id);
508 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
517 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
518 into.push_back((*i).first);
525 const std::string& rid) {
527 std::istringstream in(desc, std::ios::binary);
540 const std::string& rid) {
541 for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
545 throw ProcessError(
"The edge '" + *i +
"' within the route " + rid +
" is not known."
546 +
"\n The route can not be build.");
548 into.push_back(edge);
556 return getLanes()[0]->getShape()[-1].distanceTo2D(other->
getLanes()[0]->getShape()[0]);
572 return getLanes()[0]->getSpeedLimit();
579 return getLanes()[0]->getVehicleMaxSpeed(veh);
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
virtual const std::vector< LaneQ > & getBestLanes(bool forceRebuild=false, MSLane *startLane=0) const
Returns the description of best lanes to use in order to continue the route.
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.
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
MSEdge(const std::string &id, int numericalID, const EdgeBasicFunction function, const std::string &streetName="")
Constructor.
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()
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.
MSLane * getParallelLane(int offset) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
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.
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 SVCPermissions SVCFreeForAll
Base class for objects which have an id.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
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.
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_UNKNOWN) const
Get the allowed lanes to reach the destination-edge.
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Structure representing possible vehicle parameter.
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.
MSLane * getViaLaneOrLane() const
return the via lane if it exists and the lane otherwise
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
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
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.
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
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.