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-2018 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 /****************************************************************************/
18 // A netgen-representation of a node
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <algorithm>
28 #include <netbuild/NBNode.h>
29 #include <netbuild/NBNodeCont.h>
30 #include <netbuild/NBEdge.h>
31 #include <netbuild/NBOwnTLDef.h>
32 #include <netbuild/NBTypeCont.h>
34 #include <netbuild/NBNetBuilder.h>
36 #include <utils/common/ToString.h>
39 #include <utils/options/Option.h>
40 #include "NGNode.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 NGNode::NGNode(const std::string& id)
47  : Named(id), xID(-1), yID(-1), myAmCenter(false) {}
48 
49 
50 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
51  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(false) {}
52 
53 
54 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
55  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(amCenter) {}
56 
57 
59  NGEdgeList::iterator li;
60  while (LinkList.size() != 0) {
61  li = LinkList.begin();
62  delete(*li);
63  }
64 }
65 
66 
67 NBNode*
68 NGNode::buildNBNode(NBNetBuilder& nb, const Position& perturb) const {
69  Position pos(myPosition + perturb);
71  // the center will have no logic!
72  if (myAmCenter) {
73  return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
74  }
75  NBNode* node = nullptr;
76  std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
77  OptionsCont::getOptions().getString("default-junction-type") : "";
78 
79  if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
81  node = new NBNode(myID, pos, type);
82 
83  // check whether it is a traffic light junction
84  if (NBNode::isTrafficLight(type)) {
86  OptionsCont::getOptions().getString("tls.default-type"));
87  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, type);
88  if (!nb.getTLLogicCont().insert(tlDef)) {
89  // actually, nothing should fail here
90  delete tlDef;
91  throw ProcessError();
92  }
93  }
94  } else {
95  // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
96  node = new NBNode(myID, pos, NODETYPE_PRIORITY);
97  }
98 
99  return node;
100 }
101 
102 
103 void
105  LinkList.push_back(link);
106 }
107 
108 
109 void
111  LinkList.remove(link);
112 }
113 
114 
115 bool
116 NGNode::connected(NGNode* node) const {
117  for (NGEdgeList::const_iterator i = LinkList.begin(); i != LinkList.end(); ++i) {
118  if (find(node->LinkList.begin(), node->LinkList.end(), *i) != node->LinkList.end()) {
119  return true;
120  }
121  }
122  return false;
123 }
124 
125 
126 /****************************************************************************/
127 
static StringBijection< SumoXMLNodeType > NodeTypes
node types
A netgen-representation of an edge.
Definition: NGEdge.h:55
int xID
Integer x-position (x-id)
Definition: NGNode.h:185
bool myAmCenter
Information whether this is the center of a cpider-net.
Definition: NGNode.h:200
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:84
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
int yID
Integer y-position (y-id)
Definition: NGNode.h:188
The base class for traffic light logic definitions.
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:110
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
~NGNode()
Destructor.
Definition: NGNode.cpp:58
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
bool connected(NGNode *node) const
Returns whether the other node is connected.
Definition: NGNode.cpp:116
T get(const std::string &str) const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Base class for objects which have an id.
Definition: Named.h:58
Position myPosition
The position of the node.
Definition: NGNode.h:194
std::string myID
The name of the object.
Definition: Named.h:130
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
NGNode(const std::string &id)
Constructor.
Definition: NGNode.cpp:46
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:165
Represents a single node (junction) during network building.
Definition: NBNode.h:68
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
A netgen-representation of a node.
Definition: NGNode.h:51
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:47
NBNode * buildNBNode(NBNetBuilder &nb, const Position &perturb) const
Builds and returns this node&#39;s netbuild-representation.
Definition: NGNode.cpp:68
NGEdgeList LinkList
List of connected links.
Definition: NGNode.h:191
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:104
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:3102
TrafficLightType