Network classes¶
Network class¶
This is the test for the cross reference: 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.networkx_graphnetworkx graph
-
build_networkx_graph(mode=<GraphMode.SEGMENT: 1>, graph_mode=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.
- There are two different modes:
Mode 0 (“segment”): convert the segment to edge, while the intersection node and the segment connection node will be converted to the node in the networkx graph object
Mode 1 (“link”): convert each link to an edge, while only the intersection node will be converted to a valid node
- Mode 2 (“LaneSet”): convert each laneset to an edge
In the laneset mode, the route feasibility is considered. Each laneset is converted to a node while laneset->laneset is converted to a edge in the networkx.
- Parameters
graph_mode (int) – graph type, 0: MultiDiGraph, 1: DiGraph
mode (mtldp.mtlmap.map_modes.GraphMode) – the chosen mode, see details as aforementioned
-
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.
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
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”..lengthlength of the link in meters
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_way_idas the.segment_id.osm_way_ida 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
-
generate_lanesets(assignments=None)¶ initiate the lane sets of the segment
- Returns
-
classmethod
init_from_way(osmway, direction)¶ initiate a segment using the osm way
- Parameters
osmway –
direction – “backward” or “forward”
- Returns
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 –
- Returns
-
compute_travel_time()¶ compute the travel time according to the link performance function :return:
-
classmethod
init_from_segment(segment, direction, lane_number, insegment_offset)¶ - Parameters
segment –
direction –
lane_number –
insegment_offset –
- Returns
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)
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.