Network classes¶
Network class¶
Static network class¶
-
class
mtldp.mtlmap.Network¶ Class for the general network
- Main Attributes
- Classes for the roads
.ways: a dictionary contains all the OpenStreetMap ways (mtldp.mtlmap.OsmWay) in the network..linksa dictionary contains all the links (mtldp.mtlmap.Link) in the network..segmentsa dictionary contains all the segments (mtldp.mtlmap.Segment) in the network..lanesetsa dictionary contains all the lanesets (mtldp.mtlmap.LaneSet) in the network.
- Classes for the nodes
.nodesa dictionary contains all the nodes (mtldp.mtlmap.Node) in the network
- Others
.boundsthe bounding box of the network, mtldp.utils.BoundingBox.networkx_graphnetworkx graph
-
__init__()¶ Initialize self. See help(type(self)) for accurate signature.
-
build_networkx_graph(graph_mode=<GraphMode.SEGMENT: 1>, networkx_type=0)¶ Build the self to a NetworkX graph object
See reference for networkx: https://networkx.org/, this package will allow you to apply different types of algorithms based on network including shortest path, etc.
- Parameters
networkx_type (int) – graph type, 0: MultiDiGraph, 1: DiGraph
graph_mode (mtldp.mtlmap.GraphMode) – the chosen graph mode, see
mtldp.mtlmap.GraphMode
-
shortest_path_between_nodes(source_node, end_node, weight_attrib='length')¶ Calculate the shortest path between unordinary nodes (the source node and end node should not be an ordinary node). This implementation is based on NetworkX.
Attention
Please pay attention to the NetworkX graph mode, there are different modes for building the networkX graph and the shortest path function also differs under different mode. See
mtldp.mtlmap.GraphModefor more information.
Network of certain TOD (with data)¶
Mode selection¶
-
class
mtldp.mtlmap.GraphMode(value)¶ Mode selection for generating the NetworkX graph object class:mtldp.mtlmap.Network.build_networkx_graph.
Mode
Method
.LINKConvert each intersection to a node while convert each link to an edge
.SEGMENTConvert non-ordinary node (intersection, segment connection) to a node and each segment to an edge
.LANESETConvert each laneset to a node and the edge inherit the properties of the downstream laneset
-
class
mtldp.mtlmap.MapMode(value)¶ Mode selection for parsing the OpenStreetMap data
mtldp.mtlmap.build_network_from_xml().See map parsing flowchart for more information.
The mode in the lower row (more accurate mode) generate more layers than that of upper row, which means that it will also generate the layers that can be generated by the mode in the upper row.
Mode
Output layers
Applications
.MAP_MATCHINGSegment,Node,OsmWayTrajectory data map matching
.ACCURATELink,SegmentSplit trajectory into movements
.ROUGHLaneSet,ConflictPointBuild CTM model, etc.
Roads classes¶
OsmWay¶
-
class
mtldp.mtlmap.OsmWay(way_id=None, node_list=None, osm_attrib=None, osm_tags=None)¶ OsmWay corresponds to the “way” in the original osm data
- Main attributes
.osm_tagsa dictionary contains all the tags in the original osm data..osm_attriba dictionary contains all the attributes in the original osm data..way_ida integer for OSM way ID.node_lista list of nodes on the way.lengthlength of the way in meters.geometrythe GPS coordinates along the way.forward_headingthe heading angle at the start of the way (range: (-180,180])).backward_headingthe heading angle at the end of the way (range: (-180,180])).lane_numbernumber of lanes.forward_lanesnumber of lanes from the start of the way to the end of the way.backward_lanesnumber of lanes from the end of the way to the start of the way.namename of the way.speed_limitspeed limit of the way in m/s
-
generate_basic_info()¶ extract useful information from the osm attrib and tags
- current extracted information includes:
lane information (# and assignment)
speed limit (25mph if null)
name
- Returns
-
update_way_geometry()¶ Update the geometric information of a link
- Returns
None
Link¶
-
class
mtldp.mtlmap.Link¶ A link connects two signalized/unsignalized/origin/destination nodes. It might contain multiple segments
- Main attributes
.link_ida integer for link ID. It has the format: number1_number2. The first number is the original node of the link. The second number is the destination node of the link..segment_listthe list of segments that belong to the link.geometrythe GPS coordinates along the link.node_lista list of nodes on the link.upstream_nodethe upstream node of the link.downstream_nodethe downstream node of the link.headingthe heading angle of the link (range: (-180,180])).from_directionthe direction from which the segment originates. For example, if the segment originates from south, this value is “S”..lengthfloat, length of the link in meters
Movement¶
-
class
mtldp.mtlmap.Movement¶ A movement reflects the user perspective and is defined by the user type and the action that is taken (e.g. through, right turn, left turn)
- Main Attributes
-
index: -movement_id: -upstream_link: -downstream_link: -signal_status: -node: -direction: -upstream_length: -protected: -geometry: -trajectory_collection:
Segment¶
-
class
mtldp.mtlmap.Segment¶ A segment is a proportion of a link that share share the same number of lanes.
- Main attributes
.segment_ida integer for segment ID. 0 or 1 (denotes the direction ) is added at the end of the.osm_wayas the.segment_id.osm_waya integer for the original OSM way ID.osm_tagsa dictionary contains all the tags in the original osm data..osm_attriba dictionary contains all the attributes in the original osm data..belonged_linkthe link ID that the segment belongs to.laneset_listthe list of lane sets that belong to the segment.laneset_numthe number of lane sets that belong to the segment.speed_limitspeed limit of the segment in m/s.lengthlength of the segment in meters.geometrythe GPS coordinates along the segment.lane_numbernumber of lanes of the segment.lane_assignmentthe assignment of the lanes of the segment. For example, “all_through” means all lanes on the segment are through movements. “left|through;right” means the segments include both left turn movement through (right turn) movement. If unavailable, this value is null..headingthe heading angle of the segment (range: (-180,180])).from_directionthe direction from which the segment originates. For example, if the segment originates from south, this value is “S”..node_lista list of nodes on the segment.upstream_nodethe upstream node of the segment.downstream_nodethe downstream node of the segment.upstream_segmenta list of the upstream segment ID of this segment.downstream_segmenta list of the downstream segment ID of this segment.downstream_direction_infoa dictionary that represents the direction of the downstream segments. For example,{'l': '4116329441', 'r': '4126838890', 's': '87279680'}means left turn downstream segment is4116329441. Through movement downstream segment is87279680, and right turn downstream segment is4126838890
-
add_downstream_segment(seg_id)¶ Add an downstream segment if not exists
- Parameters
seg_id – str
- Returns
None
-
add_upstream_segment(seg_id)¶ Add an upstream segment if not exists
- Parameters
seg_id – str
- Returns
None
-
generate_lanesets(assignments=None)¶ Initiate the lane sets of the segment
- Returns
list of :class:mtldp.mtlmap.laneset
-
get_distance_to_intersections()¶ Get the distance to the upstream and downstream intersection (start of the segment)
- Returns
float, float
-
classmethod
init_from_way(osmway, direction)¶ Initiate a segment using the osm way
- Parameters
osmway –
mtldp.mtlmap.Osmwaydirection – “backward” or “forward”
- Returns
None
LaneSet¶
-
class
mtldp.mtlmap.LaneSet¶ - LaneSet is a set of lanes that has the same downstream direction (e.g. through movement, left turn, right turn).
It can be used to build CTM or LTM model.
- Main attributes
.laneset_ida integer for laneset ID. The lane set index within the segment is added to the segment ID. For example, if the segment ID is 1768090910, and the laneset index is 0, this value should be “1768090910_0”.typetype of the road. Could be “internal”, “source”, or “destination”.belonged_segmentthe segment ID that this lane set belongs to.belonged_linkthe link ID that this lane set belongs to.turning_directionthe movement of this lane set. For example, ‘s’ means through movement (straight). ‘r’ means right turn movement, and ‘l’ means left turn movement. The value can also be the combination of ‘s’, ‘r’ and ‘l’.lengthlength of the lane set in meters.speed_limitspeed limit of the lane set in m/s.lane_numbernumber of lanes of the lane sets.headingthe heading angle of the lane sets (range: (-180,180])).from_directionthe direction from which the lane set originates. For example, if the lane set originates from south, this value is “S”..geometrythe GPS coordinates along the lane set.downstream_lanesetsthe downstream lane sets that it connects to.turning_ratio_listthe list of turning ratio information. The value is None if unavailable.upstream_nodethe upstream node of the lane set.downstream_nodethe downstream node of the lane set.phase_idthe ID of the phase associated with the lane set
-
compute_cumulative_travel_time(alpha)¶ Objective function of the BPR link performance function
- Parameters
alpha – float
- Returns
float
-
compute_travel_time()¶ Compute the travel time according to the link performance function
- Returns
None
-
classmethod
init_from_segment(segment, direction, lane_number, insegment_offset)¶ Initialize laneset from the input segment
- Parameters
segment – mtldp.mtlmap.Segment
direction – str
lane_number – int
insegment_offset – int
- Returns
mtldp.mtlmap.Laneset
Nodes classes¶
General Node class¶
-
class
mtldp.mtlmap.Node(node_id=None, osm_attrib=None, osm_tags=None)¶ Node corresponds to the node in osm (xml) data,
- Node is also the father class for the following classes:
MTTTrajectoryData.mimap.SignalizedNodeMTTTrajectoryData.mimap.SignalizedNodeMTTTrajectoryData.mimap.UnSignalizedNodeMTTTrajectoryData.mimap.EndNode
- Main attributes
.node_idunique id of the node..osm_attribattributes of the node in the original osm data (dict).osm_tagstags of the node in the original osm data (dict).typetype of the node (“ordinary”, “connector”, “signalized”, “unsignalized”, “end”).latitudeand.longitudenode GPS coordinate.upstream_segmentsupstream segments of this node (list of str).downstream_segmentsdownstream segments of this node (list of str)
-
add_connector(connector)¶ Add connector to the node
- Parameters
connector – mtldp.mtlmap.Connector
- Returns
None
-
add_movement(movement)¶ Add a movement to the node
- Parameters
movement – mtldp.mtlmap.Movement
- Returns
-
generate_basic_info()¶ Add latitude and longitude attributes
- Returns
None
-
classmethod
init_from_node(node)¶ Initialize a node from the input node
- Parameters
node – mtldp.mtlmap.Node
- Returns
mtldp.mtlmap.Node
-
is_intersection()¶ Check if a node is an intersection
- Returns
True if this node is an intersection
- Return type
Segment connector¶
-
class
mtldp.mtlmap.SegmentConnectionNode¶ The node that connects the segments (all through, no left/right turn)
Signalized node¶
-
class
mtldp.mtlmap.SignalizedNode¶ Class for signalized intersection
Inherit from
MTTTrajectoryData.mimap.NodeAdditional Attributes
.timing_planthe signal controller of this node,mimap.SignalTimingPlan.