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..links
a dictionary contains all the links (mtldp.mtlmap.Link
) in the network..segments
a dictionary contains all the segments (mtldp.mtlmap.Segment
) in the network..lanesets
a dictionary contains all the lanesets (mtldp.mtlmap.LaneSet
) in the network.
- Classes for the nodes
.nodes
a dictionary contains all the nodes (mtldp.mtlmap.Node
) in the network
- Others
.bounds
the bounding box of the network.networkx_graph
networkx 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_tags
a dictionary contains all the tags in the original osm data..osm_attrib
a dictionary contains all the attributes in the original osm data..way_id
a integer for OSM way ID.node_list
a list of nodes on the way.length
length of the way in meters.geometry
the GPS coordinates along the way.forward_heading
the heading angle at the start of the way (range: (-180,180])).backward_heading
the heading angle at the end of the way (range: (-180,180])).lane_number
number of lanes.forward_lanes
number of lanes from the start of the way to the end of the way.backward_lanes
number of lanes from the end of the way to the start of the way.name
name of the way.speed_limit
speed 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_id
a 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_list
the list of segments that belong to the link.geometry
the GPS coordinates along the link.node_list
a list of nodes on the link.upstream_node
the upstream node of the link.downstream_node
the downstream node of the link.heading
the heading angle of the link (range: (-180,180])).from_direction
the direction from which the segment originates. For example, if the segment originates from south, this value is “S”..length
length 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_id
a integer for segment ID. 0 or 1 (denotes the direction ) is added at the end of the.osm_way_id
as the.segment_id
.osm_way_id
a integer for the original OSM way ID.osm_tags
a dictionary contains all the tags in the original osm data..osm_attrib
a dictionary contains all the attributes in the original osm data..belonged_link
the link ID that the segment belongs to.laneset_list
the list of lane sets that belong to the segment.laneset_num
the number of lane sets that belong to the segment.speed_limit
speed limit of the segment in m/s.length
length of the segment in meters.geometry
the GPS coordinates along the segment.lane_number
number of lanes of the segment.lane_assignment
the 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..heading
the heading angle of the segment (range: (-180,180])).from_direction
the direction from which the segment originates. For example, if the segment originates from south, this value is “S”..node_list
a list of nodes on the segment.upstream_node
the upstream node of the segment.downstream_node
the downstream node of the segment.upstream_segment
a list of the upstream segment ID of this segment.downstream_segment
a list of the downstream segment ID of this segment.downstream_direction_info
a 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_id
a 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”.type
type of the road. Could be “internal”, “source”, or “destination”.belonged_segment
the segment ID that this lane set belongs to.belonged_link
the link ID that this lane set belongs to.turning_direction
the 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’.length
length of the lane set in meters.speed_limit
speed limit of the lane set in m/s.lane_number
number of lanes of the lane sets.heading
the heading angle of the lane sets (range: (-180,180])).from_direction
the direction from which the lane set originates. For example, if the lane set originates from south, this value is “S”..geometry
the GPS coordinates along the lane set.downstream_lanesets
the downstream lane sets that it connects to.turning_ratio_list
the list of turning ratio information. The value is None if unavailable.upstream_node
the upstream node of the lane set.downstream_node
the downstream node of the lane set.phase_id
the 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.SignalizedNode
MTTTrajectoryData.mimap.SignalizedNode
MTTTrajectoryData.mimap.UnSignalizedNode
MTTTrajectoryData.mimap.EndNode
- Main attributes
.node_id
unique id of the node..osm_attrib
attributes of the node in the original osm data (dict).osm_tags
tags of the node in the original osm data (dict).type
type of the node (“ordinary”, “connector”, “signalized”, “unsignalized”, “end”).latitude
and.longitude
node GPS coordinate.upstream_segments
upstream segments of this node (list of str).downstream_segments
downstream 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.Node
Additional Attributes
.timing_plan
the signal controller of this node,mimap.SignalTimingPlan
.