51 #ifdef CHECK_MEMORY_LEAKS
53 #endif // CHECK_MEMORY_LEAKS
66 if (!oc.
isSet(
"output-file")) {
70 device.
writeXMLHeader(
"net",
NWFrame::MAJOR_VERSION +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/net_file.xsd\"");
81 bool origNames = oc.
getBool(
"output.original-names");
82 if (!oc.
getBool(
"no-internal-links")) {
84 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
93 bool noNames = !oc.
getBool(
"output.street-names");
94 for (std::map<std::string, NBEdge*>::const_iterator i = ec.
begin(); i != ec.
end(); ++i) {
95 writeEdge(device, *(*i).second, noNames, origNames);
103 std::set<NBNode*> roundaboutNodes;
104 const bool checkLaneFoesAll = oc.
getBool(
"check-lane-foes.all");
105 const bool checkLaneFoesRoundabout = !checkLaneFoesAll && oc.
getBool(
"check-lane-foes.roundabout");
106 if (checkLaneFoesRoundabout) {
108 for (std::vector<EdgeVector>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
109 for (EdgeVector::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
110 roundaboutNodes.insert((*j)->getToNode());
114 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
115 const bool checkLaneFoes = checkLaneFoesAll || (checkLaneFoesRoundabout && roundaboutNodes.count((*i).second) > 0);
119 const bool includeInternal = !oc.
getBool(
"no-internal-links");
120 if (includeInternal) {
123 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
132 unsigned int numConnections = 0;
133 for (std::map<std::string, NBEdge*>::const_iterator it_edge = ec.
begin(); it_edge != ec.
end(); it_edge++) {
134 NBEdge* from = it_edge->second;
136 const std::vector<NBEdge::Connection> connections = from->
getConnections();
137 numConnections += (
unsigned int)connections.size();
138 for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) {
142 if (numConnections > 0) {
145 if (includeInternal) {
148 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
155 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
156 NBNode* node = (*i).second;
158 const std::vector<NBNode::Crossing>& crossings = node->
getCrossings();
159 for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
163 const std::vector<NBNode::WalkingArea>& WalkingAreas = node->
getWalkingAreas();
164 for (std::vector<NBNode::WalkingArea>::const_iterator it = WalkingAreas.begin(); it != WalkingAreas.end(); it++) {
165 if ((*it).nextCrossing !=
"") {
173 if ((*it).tlID !=
"") {
183 for (std::vector<std::string>::const_iterator it_sw = (*it).nextSidewalks.begin(); it_sw != (*it).nextSidewalks.end(); ++it_sw) {
186 for (std::vector<std::string>::const_iterator it_sw = (*it).prevSidewalks.begin(); it_sw != (*it).prevSidewalks.end(); ++it_sw) {
193 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
200 std::vector<std::vector<std::string> > edgeIDs;
201 for (std::vector<EdgeVector>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
202 std::vector<std::string> tEdgeIDs;
203 for (EdgeVector::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
204 tEdgeIDs.push_back((*j)->getID());
206 std::sort(tEdgeIDs.begin(), tEdgeIDs.end());
207 edgeIDs.push_back(tEdgeIDs);
209 std::sort(edgeIDs.begin(), edgeIDs.end());
211 for (std::vector<std::vector<std::string> >::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
214 if (roundabouts.size() != 0) {
219 for (std::map<std::string, NBDistrict*>::const_iterator i = dc.
begin(); i != dc.
end(); i++) {
222 if (dc.
size() != 0) {
233 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
234 const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
235 if (elv.size() > 0) {
236 bool haveVia =
false;
238 std::string internalEdgeID =
"";
240 std::map<NBEdge*, SUMOReal> lengthSum;
241 std::map<NBEdge*, int> numLanes;
242 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
244 numLanes[(*k).toEdge] += 1;
247 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
248 if ((*k).toEdge == 0) {
252 if (toEdge != (*k).toEdge) {
253 internalEdgeID = (*k).id;
258 toEdge = (*k).toEdge;
266 const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane];
267 const SUMOReal length = lengthSum[toEdge] / numLanes[toEdge];
271 writeLane(into, internalEdgeID, (*k).getInternalLaneID(), (*k).vmax,
274 length, (*k).internalLaneIndex, origNames);
275 haveVia = haveVia || (*k).haveVia;
281 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
285 if ((*k).toEdge == 0) {
289 const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane];
303 const std::vector<NBNode::Crossing>& crossings = n.
getCrossings();
304 for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
314 const std::vector<NBNode::WalkingArea>& WalkingAreas = n.
getWalkingAreas();
315 for (std::vector<NBNode::WalkingArea>::const_iterator it = WalkingAreas.begin(); it != WalkingAreas.end(); it++) {
355 const std::vector<NBEdge::Lane>& lanes = e.
getLanes();
368 for (
unsigned int i = 0; i < (
unsigned int) lanes.size(); i++) {
372 length, i, origNames);
383 const std::string& origID,
SUMOReal length,
unsigned int index,
bool origNames) {
394 }
else if (speed < 0) {
398 length = length - endOffset;
410 if (origNames && origID !=
"") {
429 std::string incLanes;
431 for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
432 unsigned int noLanes = (*i)->getNumLanes();
433 for (
unsigned int j = 0; j < noLanes; j++) {
434 incLanes += (*i)->getLaneID(j);
435 if (i != incoming.end() - 1 || j < noLanes - 1) {
440 const std::vector<NBNode::Crossing>& crossings = n.
getCrossings();
441 for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
442 incLanes +=
' ' + (*it).prevWalkingArea +
"_0";
446 std::string intLanes;
449 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
450 const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
451 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
452 if ((*k).toEdge == 0) {
459 intLanes += (*k).getInternalLaneID();
461 intLanes += (*k).viaID +
"_0";
467 for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
468 intLanes +=
' ' + (*it).id +
"_0";
488 std::vector<std::string> internalLaneIDs;
489 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
490 const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
491 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
492 if ((*k).toEdge != 0) {
493 internalLaneIDs.push_back((*k).getInternalLaneID());
497 const std::vector<NBNode::Crossing>& crossings = n.
getCrossings();
498 for (std::vector<NBNode::Crossing>::const_iterator it_c = crossings.begin(); it_c != crossings.end(); ++it_c) {
499 internalLaneIDs.push_back((*it_c).id +
"_0");
502 for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
503 const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
504 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
505 if ((*k).toEdge == 0 || !(*k).haveVia) {
512 std::string incLanes = (*k).getInternalLaneID();
513 if ((*k).foeIncomingLanes.length() != 0) {
514 incLanes +=
" " + (*k).foeIncomingLanes;
517 const std::vector<unsigned int>& foes = (*k).foeInternalLinks;
518 std::vector<std::string> foeIDs;
519 for (std::vector<unsigned int>::const_iterator it = foes.begin(); it != foes.end(); ++it) {
520 foeIDs.push_back(internalLaneIDs[*it]);
543 if (style !=
PLAIN) {
544 if (includeInternal) {
571 for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
573 const std::vector<NBEdge::Connection>& connections = from->
getConnections();
574 for (std::vector<NBEdge::Connection>::const_iterator j = connections.begin(); j != connections.end(); ++j) {
594 const std::string& from,
const std::string& to,
595 int fromLane,
int toLane,
const std::string& via) {
613 std::vector<std::string> nodeIDs;
614 for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
617 std::sort(nodeIDs.begin(), nodeIDs.end());
639 for (i = 0; i < sources.size(); i++) {
646 for (i = 0; i < sinks.size(); i++) {
659 if (time == std::floor(time)) {
669 for (NBConnectionProhibits::const_iterator j = prohibitions.begin(); j != prohibitions.end(); j++) {
672 for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
691 std::vector<NBTrafficLightLogic*> logics = tllCont.
getComputed();
692 for (std::vector<NBTrafficLightLogic*>::iterator it = logics.begin(); it != logics.end(); it++) {
699 const std::map<std::string, std::string>& params = (*it)->getMap();
700 for (std::map<std::string, std::string>::const_iterator i = params.begin(); i != params.end(); ++i) {
707 const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = (*it)->getPhases();
708 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator j = phases.begin(); j != phases.end(); ++j) {
716 if (logics.size() > 0) {
743 if (permissions ==
SVCAll) {
745 }
else if (permissions == 0) {
749 size_t num_allowed = 0;
751 if ((mask & permissions) == mask) {
766 if (preferred ==
SVCAll || preferred == 0) {
static void writeRoundabout(OutputDevice &into, const std::vector< std::string > &r, const NBEdgeCont &ec)
Writes a roundabout.
The information about how to spread the lanes from the given position.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges.
void close()
Closes the device and removes it from the dictionary.
SUMOReal endOffset
This lane's offset to the intersection begin.
A structure which describes a connection between edges or lanes.
int toLane
The lane the connections yields in.
Position getCenter() const
Returns a position that is guaranteed to lie within the node shape.
a list of node ids, used for controlling joining
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
PositionVector shape
The lane's shape.
static void writeDistrict(OutputDevice &into, const NBDistrict &d)
Writes a district.
const std::string & getTypeName() const
Returns the type name.
NBEdge * toEdge
The edge the connections yields in.
bool hasDefaultGeometry() const
Returns whether the geometry consists only of the node positions.
size_t size() const
Returns the number of districts inside the container.
A container for traffic light definitions and built programs.
SUMOReal length
This lane's width.
static void writeLocation(OutputDevice &into)
writes the location element
SUMOReal width
This lane's width.
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
const Crossing & getCrossing(const std::string &id) const
return the crossing with the given id
#define GEO_OUTPUT_ACCURACY
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
static void writeProhibitions(OutputDevice &into, const NBConnectionProhibits &prohibitions)
writes the given prohibitions
const std::vector< NBEdge * > & getSinkEdges() const
Returns the sinks.
A container for districts.
const std::vector< Crossing > & getCrossings() const
return this junctions pedestrian crossings
the weight of a district's source or sink
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
std::string id
the (edge)-id of this walkingArea
const SVCPermissions SVCAll
static void writeTrafficLights(OutputDevice &into, const NBTrafficLightLogicCont &tllCont)
writes the traffic light logics to the given device
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
static void writeInternalConnection(OutputDevice &into, const std::string &from, const std::string &to, int fromLane, int toLane, const std::string &via)
Writes a single internal connection.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
static void writePermissions(OutputDevice &into, SVCPermissions permissions)
writes allowed disallowed attributes if needed;
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
bool priority
whether the pedestrians have priority
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
The link is a straight direction.
SUMOReal speed
The speed allowed on this lane.
A class representing a single district.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static std::string prohibitionConnection(const NBConnection &c)
the attribute value for a prohibition
SUMOReal getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
An (internal) definition of a single lane of an edge.
const std::vector< EdgeVector > & getRoundabouts() const
Returns the determined roundabouts.
const std::string & getID() const
Returns the id.
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a SUMO-file.
void push_front_noDoublePos(const Position &p)
const int SUMOVehicleClass_MAX
const Position & getPosition() const
Returns the position of this node.
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
static methods for processing the coordinates conversion for the current net
int getPriority() const
Returns the priority of the edge.
std::map< std::string, NBDistrict * >::const_iterator begin() const
Returns the pointer to the begin of the stored districts.
std::string getLaneID(unsigned int lane) const
const std::vector< NBEdge * > & getSourceEdges() const
Returns the sources.
std::string tlID
The id of the traffic light that controls this connection.
SVCPermissions preferred
List of vehicle types that are preferred on this lane.
std::string getInternalLaneID() const
This is an uncontrolled, minor link, has to brake.
static bool writeInternalConnections(OutputDevice &into, const NBNode &n)
Writes inner connections within the node.
int fromLane
The lane the connections starts at.
A point in 2D or 3D with translation and scaling methods.
std::map< std::string, NBDistrict * >::const_iterator end() const
Returns the pointer to the end of the stored districts.
NBEdgeCont & getEdgeCont()
Returns the edge container.
SumoXMLNodeType getType() const
Returns the type of this node.
static void writeEdge(OutputDevice &into, const NBEdge &e, bool noNames, bool origNames)
bool hasLoadedLength() const
Returns whether a length was set explicitly.
const PositionVector & getShape() const
Returns the shape.
const std::string & getProjString() const
Returns the network offset.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
Storage for edges, including some functionality operating on multiple edges.
static void writePositionLong(const Position &pos, OutputDevice &dev)
Writes the given position to device in long format (one attribute per dimension)
const Position getOffsetBase() const
Returns the network base.
std::vector< NBTrafficLightLogic * > getComputed() const
Returns a list of all computed logics.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
const Boundary & getConvBoundary() const
Returns the converted boundary.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
static void writeLane(OutputDevice &into, const std::string &eID, const std::string &lID, SUMOReal speed, SVCPermissions permissions, SVCPermissions preferred, SUMOReal endOffset, SUMOReal width, const PositionVector &shape, const std::string &origID, SUMOReal length, unsigned int index, bool origNames)
const PositionVector & getShape() const
retrieve the junction shape
std::string getVehicleClassNames(SVCPermissions permissions)
Returns the ids of the given classes, divided using a ' '.
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
static void normaliseSum(std::vector< T > &v, T msum=1.0)
std::string origID
An original ID, if given (.
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
static bool writeInternalEdges(OutputDevice &into, const NBNode &n, bool origNames)
SUMOReal length() const
Returns the length.
NBNode * getToNode() const
Returns the destination node of the edge.
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, bool mayDefinitelyPass, const std::string &tlID) const
NBNodeCont & getNodeCont()
Returns the node container.
Instance responsible for building networks.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
int tlLinkNo
the traffic light index of this crossing (if controlled)
std::vector< NBEdge * > EdgeVector
static bool writeInternalNodes(OutputDevice &into, const NBNode &n)
Writes internal junctions (
const PositionVector & getGeometry() const
Returns the geometry of the edge.
A definition of a pedestrian walking area.
bool isMacroscopicConnector() const
Returns whether this edge was marked as a macroscopic connector.
A storage for options typed value containers)
This is an uncontrolled, major link, may pass.
void sortOutgoingConnectionsByIndex()
sorts the outgoing connections by their from-lane-index and their to-lane-index
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
static void writePreferences(OutputDevice &into, SVCPermissions preferred)
writes allowed disallowed attributes if needed;
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
unsigned int tlLinkNo
The index of this connection within the controlling traffic light.
NBEdge * getTo() const
returns the to-edge (end of the connection)
The abstract direction of a link.
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge's lanes' lateral offset is computed.
Represents a single node (junction) during network building.
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
A definition of a pedestrian crossing.
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
static void writeJunction(OutputDevice &into, const NBNode &n, const bool checkLaneFoes)
bool writeLogic(OutputDevice &into, const bool checkLaneFoes) const
const std::vector< SUMOReal > & getSourceWeights() const
Returns the weights of the sources.
const Boundary & getOrigBoundary() const
Returns the original boundary.
void push_back_noDoublePos(const Position &p)
const std::vector< SUMOReal > & getSinkWeights() const
Returns the weights of the sinks.
Container for nodes during the netbuilding process.
unsigned int internalLaneIndex
The lane index of this internal lane within the internal edge.
const std::vector< WalkingArea > & getWalkingAreas() const
return this junctions pedestrian walking areas
NBDistrictCont & getDistrictCont()
Returns the districts container.
const std::string & getStreetName() const
Returns the street name of this edge.
const std::vector< Connection > & getConnections() const
Returns the connections.
static const std::string MAJOR_VERSION
The version number for written files.
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
static std::string writeSUMOTime(SUMOTime time)
writes a SUMOTime as int if possible, otherwise as a float
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void lf()
writes a line feed if applicable
SUMOReal width
This lane's width.
static void writeConnection(OutputDevice &into, const NBEdge &from, const NBEdge::Connection &c, bool includeInternal, ConnectionStyle style=SUMONET)
Writes connections outgoing from the given edge (also used in NWWriter_XML)
PositionVector shape
The polygonal shape.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
The link has no direction (is a dead end link)
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing) const
Returns the representation of the described stream's direction.
NBNode * getFromNode() const
Returns the origin node of the edge.