50 #ifdef CHECK_MEMORY_LEAKS
52 #endif // CHECK_MEMORY_LEAKS
65 if (!oc.
isSet(
"output-file")) {
69 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\"");
80 bool origNames = oc.
getBool(
"output.original-names");
81 if (!oc.
getBool(
"no-internal-links")) {
83 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
92 bool noNames = !oc.
getBool(
"output.street-names");
93 for (std::map<std::string, NBEdge*>::const_iterator i = ec.
begin(); i != ec.
end(); ++i) {
94 writeEdge(device, *(*i).second, noNames, origNames);
102 std::set<NBNode*> roundaboutNodes;
103 const bool checkLaneFoesAll = oc.
getBool(
"check-lane-foes.all");
104 const bool checkLaneFoesRoundabout = !checkLaneFoesAll && oc.
getBool(
"check-lane-foes.roundabout");
105 if (checkLaneFoesRoundabout) {
107 for (std::vector<EdgeVector>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
108 for (EdgeVector::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
109 roundaboutNodes.insert((*j)->getToNode());
113 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
114 const bool checkLaneFoes = checkLaneFoesAll || (checkLaneFoesRoundabout && roundaboutNodes.count((*i).second) > 0);
118 const bool includeInternal = !oc.
getBool(
"no-internal-links");
119 if (includeInternal) {
122 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
131 unsigned int numConnections = 0;
132 for (std::map<std::string, NBEdge*>::const_iterator it_edge = ec.
begin(); it_edge != ec.
end(); it_edge++) {
133 NBEdge* from = it_edge->second;
135 const std::vector<NBEdge::Connection> connections = from->
getConnections();
136 numConnections += (
unsigned int)connections.size();
137 for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) {
141 if (numConnections > 0) {
144 if (includeInternal) {
147 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) {
162 std::vector<std::vector<std::string> > edgeIDs;
163 for (std::vector<EdgeVector>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
164 std::vector<std::string> tEdgeIDs;
165 for (EdgeVector::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
166 tEdgeIDs.push_back((*j)->getID());
168 std::sort(tEdgeIDs.begin(), tEdgeIDs.end());
169 edgeIDs.push_back(tEdgeIDs);
171 std::sort(edgeIDs.begin(), edgeIDs.end());
173 for (std::vector<std::vector<std::string> >::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
176 if (roundabouts.size() != 0) {
181 for (std::map<std::string, NBDistrict*>::const_iterator i = dc.
begin(); i != dc.
end(); i++) {
184 if (dc.
size() != 0) {
195 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
196 const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
197 if (elv.size() > 0) {
198 bool haveVia =
false;
200 std::string internalEdgeID =
"";
202 std::map<NBEdge*, SUMOReal> lengthSum;
203 std::map<NBEdge*, int> numLanes;
204 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
206 numLanes[(*k).toEdge] += 1;
209 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
210 if ((*k).toEdge == 0) {
214 if (toEdge != (*k).toEdge) {
215 internalEdgeID = (*k).id;
220 toEdge = (*k).toEdge;
228 const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane];
229 const SUMOReal length = lengthSum[toEdge] / numLanes[toEdge];
230 writeLane(into, internalEdgeID, (*k).getInternalLaneID(), (*k).vmax,
233 length, (*k).internalLaneIndex, origNames);
234 haveVia = haveVia || (*k).haveVia;
240 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
244 if ((*k).toEdge == 0) {
291 const std::vector<NBEdge::Lane>& lanes = e.
getLanes();
304 for (
unsigned int i = 0; i < (
unsigned int) lanes.size(); i++) {
308 length, i, origNames);
319 const std::string& origID,
SUMOReal length,
unsigned int index,
bool origNames) {
330 }
else if (speed < 0) {
334 length = length - offset;
346 if (origNames && origID !=
"") {
365 std::string incLanes;
367 for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
368 unsigned int noLanes = (*i)->getNumLanes();
369 for (
unsigned int j = 0; j < noLanes; j++) {
370 incLanes += (*i)->getLaneID(j);
371 if (i != incoming.end() - 1 || j < noLanes - 1) {
378 std::string intLanes;
381 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
382 const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
383 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
384 if ((*k).toEdge == 0) {
391 intLanes += (*k).getInternalLaneID();
393 intLanes += (*k).viaID +
"_0";
417 std::vector<std::string> internalLaneIDs;
418 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
419 const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
420 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
421 if ((*k).toEdge != 0) {
422 internalLaneIDs.push_back((*k).getInternalLaneID());
427 for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
428 const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
429 for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
430 if ((*k).toEdge == 0 || !(*k).haveVia) {
437 std::string incLanes = (*k).getInternalLaneID();
438 if ((*k).foeIncomingLanes.length() != 0) {
439 incLanes +=
" " + (*k).foeIncomingLanes;
442 const std::vector<unsigned int>& foes = (*k).foeInternalLinks;
443 std::vector<std::string> foeIDs;
444 for (std::vector<unsigned int>::const_iterator it = foes.begin(); it != foes.end(); ++it) {
445 foeIDs.push_back(internalLaneIDs[*it]);
468 if (style !=
PLAIN) {
469 if (includeInternal) {
496 for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
498 const std::vector<NBEdge::Connection>& connections = from->
getConnections();
499 for (std::vector<NBEdge::Connection>::const_iterator j = connections.begin(); j != connections.end(); ++j) {
519 const std::string& from,
const std::string& to,
520 int fromLane,
int toLane,
const std::string& via) {
538 std::vector<std::string> nodeIDs;
539 for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
542 std::sort(nodeIDs.begin(), nodeIDs.end());
564 for (i = 0; i < sources.size(); i++) {
571 for (i = 0; i < sinks.size(); i++) {
584 if (time == std::floor(time)) {
594 for (NBConnectionProhibits::const_iterator j = prohibitions.begin(); j != prohibitions.end(); j++) {
597 for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
616 std::vector<NBTrafficLightLogic*> logics = tllCont.
getComputed();
617 for (std::vector<NBTrafficLightLogic*>::iterator it = logics.begin(); it != logics.end(); it++) {
624 const std::map<std::string, std::string>& params = (*it)->getMap();
625 for (std::map<std::string, std::string>::const_iterator i = params.begin(); i != params.end(); ++i) {
632 const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = (*it)->getPhases();
633 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator j = phases.begin(); j != phases.end(); ++j) {
641 if (logics.size() > 0) {
670 }
else if (permissions == 0) {
676 if (encoding.second) {
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.
static void writeLane(OutputDevice &into, const std::string &eID, const std::string &lID, SUMOReal speed, SVCPermissions permissions, SVCPermissions preferred, SUMOReal offset, SUMOReal width, const PositionVector &shape, const std::string &origID, SUMOReal length, unsigned int index, bool origNames)
Writes a lane (<lane ...) of an edge.
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.
static void writeLocation(OutputDevice &into)
writes the location element
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
#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.
std::string getAllowedVehicleClassNames(SVCPermissions permissions)
Returns the ids of the given classes, divided using a ' '.
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.
the weight of a district's source or sink
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
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.
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.
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 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
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.
std::pair< std::string, bool > getPermissionEncoding(SVCPermissions permissions)
returns the shorter encoding of the given permissions (selects automatically wether to use allow or d...
SumoXMLNodeType getType() const
Returns the type of this node.
SUMOReal offset
This lane's offset to the intersection begin.
static void writeEdge(OutputDevice &into, const NBEdge &e, bool noNames, bool origNames)
Writes an edge (<edge ...)
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.
const Boundary & getConvBoundary() const
Returns the converted boundary.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
const PositionVector & getShape() const
const SVCPermissions SVCFreeForAll
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)
Writes internal edges (<edge ... with id[0]==':') of the given node.
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.
std::vector< NBEdge * > EdgeVector
static bool writeInternalNodes(OutputDevice &into, const NBNode &n)
Writes internal junctions (<junction with id[0]==':' ...) of the given node.
const PositionVector & getGeometry() const
Returns the geometry of the edge.
bool isMacroscopicConnector() const
Returns whether this edge was marked as a macroscopic connector.
A storage for options typed value containers)
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)
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)
Writes a junction (<junction ...)
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.
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)
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.