Eclipse SUMO - Simulation of Urban MObility
NGNode.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A netgen-representation of a node
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <algorithm>
27 #include <netbuild/NBNode.h>
28 #include <netbuild/NBNodeCont.h>
29 #include <netbuild/NBEdge.h>
30 #include <netbuild/NBOwnTLDef.h>
31 #include <netbuild/NBTypeCont.h>
33 #include <netbuild/NBNetBuilder.h>
35 #include <utils/common/ToString.h>
38 #include <utils/options/Option.h>
39 #include "NGNode.h"
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 NGNode::NGNode(const std::string& id)
46  : Named(id), xID(-1), yID(-1), myAmCenter(false) {}
47 
48 
49 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
50  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(false) {}
51 
52 
53 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
54  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(amCenter) {}
55 
56 
58  NGEdgeList::iterator li;
59  while (LinkList.size() != 0) {
60  li = LinkList.begin();
61  delete (*li);
62  }
63 }
64 
65 
66 NBNode*
67 NGNode::buildNBNode(NBNetBuilder& nb, const Position& perturb) const {
68  Position pos(myPosition + perturb);
70  // the center will have no logic!
71  if (myAmCenter) {
72  return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
73  }
74  NBNode* node = nullptr;
75  std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
76  OptionsCont::getOptions().getString("default-junction-type") : "";
77 
78  if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
80  node = new NBNode(myID, pos, type);
81 
82  // check whether it is a traffic light junction
83  if (NBNode::isTrafficLight(type)) {
85  OptionsCont::getOptions().getString("tls.default-type"));
86  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, type);
87  if (!nb.getTLLogicCont().insert(tlDef)) {
88  // actually, nothing should fail here
89  delete tlDef;
90  throw ProcessError();
91  }
92  }
93  } else {
94  // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
95  node = new NBNode(myID, pos, NODETYPE_PRIORITY);
96  }
97 
98  return node;
99 }
100 
101 
102 void
104  LinkList.push_back(link);
105 }
106 
107 
108 void
110  LinkList.remove(link);
111 }
112 
113 
114 bool
115 NGNode::connected(NGNode* node) const {
116  for (NGEdgeList::const_iterator i = LinkList.begin(); i != LinkList.end(); ++i) {
117  if (find(node->LinkList.begin(), node->LinkList.end(), *i) != node->LinkList.end()) {
118  return true;
119  }
120  }
121  return false;
122 }
123 
124 
125 /****************************************************************************/
126 
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
NODETYPE_PRIORITY
@ NODETYPE_PRIORITY
Definition: SUMOXMLDefinitions.h:1061
ToString.h
Named
Base class for objects which have an id.
Definition: Named.h:56
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
NGNode::~NGNode
~NGNode()
Destructor.
Definition: NGNode.cpp:57
NGNode::LinkList
NGEdgeList LinkList
List of connected links.
Definition: NGNode.h:190
OptionsCont.h
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
GeoConvHelper::getProcessing
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:86
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
GeoConvHelper.h
NGEdge
A netgen-representation of an edge.
Definition: NGEdge.h:54
NBOwnTLDef
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:46
NGNode::connected
bool connected(NGNode *node) const
Returns whether the other node is connected.
Definition: NGNode.cpp:115
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
NGNode::removeLink
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:109
NGNode::NGNode
NGNode(const std::string &id)
Constructor.
Definition: NGNode.cpp:45
GeoConvHelper::x2cartesian
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
Definition: GeoConvHelper.cpp:326
NGNode::addLink
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:103
SumoXMLNodeType
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Definition: SUMOXMLDefinitions.h:1054
StringBijection::get
T get(const std::string &str) const
Definition: StringBijection.h:97
NBTypeCont.h
NBNetBuilder.h
ProcessError
Definition: UtilExceptions.h:39
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
UtilExceptions.h
NGNode::myAmCenter
bool myAmCenter
Information whether this is the center of a cpider-net.
Definition: NGNode.h:199
NGNode::myPosition
Position myPosition
The position of the node.
Definition: NGNode.h:193
NBNodeCont.h
Option.h
NBNetBuilder::getTLLogicCont
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:165
NBNode::isTrafficLight
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:3250
SUMOXMLDefinitions::TrafficLightTypes
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
Definition: SUMOXMLDefinitions.h:1392
config.h
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBOwnTLDef.h
NBTrafficLightLogicCont.h
Named::myID
std::string myID
The name of the object.
Definition: Named.h:133
NBTrafficLightLogicCont::insert
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
Definition: NBTrafficLightLogicCont.cpp:73
NBNode.h
NGNode.h
NGNode::buildNBNode
NBNode * buildNBNode(NBNetBuilder &nb, const Position &perturb) const
Builds and returns this node's netbuild-representation.
Definition: NGNode.cpp:67
NGNode
A netgen-representation of a node.
Definition: NGNode.h:50
SUMOXMLDefinitions::NodeTypes
static StringBijection< SumoXMLNodeType > NodeTypes
node types
Definition: SUMOXMLDefinitions.h:1368
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:67
NBEdge.h
NODETYPE_NOJUNCTION
@ NODETYPE_NOJUNCTION
Definition: SUMOXMLDefinitions.h:1067