Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2003-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file NGEdge.cpp 15 : /// @author Markus Hartinger 16 : /// @author Daniel Krajzewicz 17 : /// @author Michael Behrisch 18 : /// @author Jakob Erdmann 19 : /// @date Mar, 2003 20 : /// 21 : // A netgen-representation of an edge 22 : /****************************************************************************/ 23 : #include <config.h> 24 : 25 : #include <algorithm> 26 : #include <utils/common/RandHelper.h> 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> 32 : #include <netbuild/NBTrafficLightLogicCont.h> 33 : #include <netbuild/NBNetBuilder.h> 34 : #include <utils/common/UtilExceptions.h> 35 : #include <utils/common/ToString.h> 36 : #include <utils/geom/GeoConvHelper.h> 37 : #include <utils/options/OptionsCont.h> 38 : #include <utils/options/Option.h> 39 : #include "NGEdge.h" 40 : #include "NGNode.h" 41 : 42 : 43 : // =========================================================================== 44 : // method definitions 45 : // =========================================================================== 46 : // --------------------------------------------------------------------------- 47 : // NGEdge-definitions 48 : // --------------------------------------------------------------------------- 49 45232 : NGEdge::NGEdge(const std::string& id, NGNode* startNode, NGNode* endNode, const std::string& reverseID) : 50 45232 : Named(id), myStartNode(startNode), myEndNode(endNode), myReverseID(reverseID == "" ? "-" + id : reverseID) { 51 45232 : myStartNode->addLink(this); 52 45232 : myEndNode->addLink(this); 53 45232 : } 54 : 55 : 56 90464 : NGEdge::~NGEdge() { 57 45232 : myStartNode->removeLink(this); 58 45232 : myEndNode->removeLink(this); 59 90464 : } 60 : 61 : 62 : NBEdge* 63 15750 : NGEdge::buildNBEdge(NBNetBuilder& nb, std::string type, const bool reversed) const { 64 15750 : const OptionsCont& oc = OptionsCont::getOptions(); 65 31500 : if (oc.getBool("random-type") && nb.getTypeCont().size() > 1) { 66 24 : auto it = nb.getTypeCont().begin(); 67 24 : std::advance(it, RandHelper::rand((int)nb.getTypeCont().size())); 68 24 : type = it->first; 69 : } 70 15750 : int priority = nb.getTypeCont().getEdgeTypePriority(type); 71 16430 : if (priority > 1 && oc.getBool("rand.random-priority")) { 72 584 : priority = RandHelper::rand(priority) + 1; 73 : } 74 15750 : int lanenumber = nb.getTypeCont().getEdgeTypeNumLanes(type); 75 17954 : if (lanenumber > 1 && oc.getBool("rand.random-lanenumber")) { 76 584 : lanenumber = RandHelper::rand(lanenumber) + 1; 77 : } 78 : 79 15750 : SVCPermissions permissions = nb.getTypeCont().getEdgeTypePermissions(type); 80 15750 : LaneSpreadFunction lsf = nb.getTypeCont().getEdgeTypeSpreadType(type); 81 15750 : if (isRailway(permissions) && nb.getTypeCont().getEdgeTypeIsOneWay(type)) { 82 : lsf = LaneSpreadFunction::CENTER; 83 : } 84 31500 : const double maxSegmentLength = oc.getFloat("geometry.max-segment-length"); 85 15750 : NBNode* from = nb.getNodeCont().retrieve(reversed ? myEndNode->getID() : myStartNode->getID()); 86 15750 : NBNode* to = nb.getNodeCont().retrieve(reversed ? myStartNode->getID() : myEndNode->getID()); 87 15750 : PositionVector shape; 88 15750 : if (maxSegmentLength > 0) { 89 24 : shape.push_back(from->getPosition()); 90 24 : shape.push_back(to->getPosition()); 91 : // shape is already cartesian but we must use a copy because the original will be modified 92 24 : NBNetBuilder::addGeometrySegments(shape, PositionVector(shape), maxSegmentLength); 93 : } 94 : NBEdge* result = new NBEdge( 95 : reversed ? myReverseID : myID, 96 : from, to, 97 15750 : type, nb.getTypeCont().getEdgeTypeSpeed(type), NBEdge::UNSPECIFIED_FRICTION, lanenumber, 98 47250 : priority, nb.getTypeCont().getEdgeTypeWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape, lsf); 99 15750 : result->setPermissions(permissions); 100 15750 : return result; 101 15750 : } 102 : 103 : 104 : /****************************************************************************/