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..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, mtldp.utils.BoundingBox.networkx_graph
networkx 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.GraphMode
for 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
.LINK
Convert each intersection to a node while convert each link to an edge
.SEGMENT
Convert non-ordinary node (intersection, segment connection) to a node and each segment to an edge
.LANESET
Convert 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_MATCHING
Segment
,Node
,OsmWay
Trajectory data map matching
.ACCURATE
Link
,Segment
Split trajectory into movements
.ROUGH
LaneSet
,ConflictPoint
Build 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_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
-
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_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
float, 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_id
a integer for segment ID. 0 or 1 (denotes the direction ) is added at the end of the.osm_way
as the.segment_id
.osm_way
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
-
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.Osmway
direction – “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_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 – 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.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)
-
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.Node
Additional Attributes
.timing_plan
the signal controller of this node,mimap.SignalTimingPlan
.