simworld.map package

Submodules

simworld.map.map module

Map module: defines Road, Node, Edge, and Map graph structures for navigation.

class simworld.map.map.Edge(node1: Node, node2: Node, type: str = 'sidewalk')

Bases: object

Undirected weighted edge between two nodes.

class simworld.map.map.Map(config: Config, traffic_signals: list | None = None)

Bases: object

Graph of nodes and edges supporting path queries and random access.

add_edge(edge: Edge) None

Add an edge and update adjacency.

Args:

edge: Edge to add.

add_node(node: Node) None

Add a node to the map.

Args:

node: Node to add.

get_adjacency_list() dict

Get the adjacency list mapping each node to its neighbors.

get_adjacent_points(node: Node) List[Vector]

Get neighboring node positions for a given node.

Args:

node: Node to get neighbors for.

Returns:

List of neighboring node positions.

get_closest_node(position: Vector) Node

Find the node nearest to a given position.

Args:

position: Position to find nearest node to.

Returns:

Nearest node.

get_nodes_by_type(type: str) List[Node]

Get all nodes of a given type.

Args:

type: Node type.

Returns:

List of nodes of the given type.

get_random_node(type: str | None = None, exclude: List[Node] | None = None) Node

Get a random node from the map.

Args:

type: Node type. exclude: List of nodes to exclude.

Returns:

A random node from the map.

get_road_at_position(position: Vector) Road

Find the road that contains the given position.

Args:

position: Position vector to check.

Returns:

The Road object if position is on any road.

get_road_info_at_position(position: Vector) dict

Get detailed information about the road at the given position.

Args:

position: Position vector to check.

Returns:

Dictionary containing road information and distance, or None if no road found.

get_shortest_path(start: Node, end: Node)

Get the shortest path between two nodes using A* algorithm. Include the start node and end node in the path.

Args:

start: Start node. end: End node.

Returns:

List of nodes in the shortest path.

has_edge(edge: Edge) bool

Check if an edge exists in the map.

Args:

edge: Edge to check.

Returns:

True if the edge exists, False otherwise.

initialize_map_from_file(roads_file: str | None = None, sidewalk_offset: float | None = None, fine_grained: bool = False, num_waypoints_normal: int = 3, waypoints_distance: float = 900, waypoints_normal_distance: float = 150)

Initialize the map from the input roads file.

Args:

roads_file: Path to the roads file. sidewalk_offset: Sidewalk offset. fine_grained: Whether to use fine-grained map. num_waypoints_normal: Number of waypoints in the normal direction. waypoints_distance: Waypoints distance. waypoints_normal_distance: Waypoints normal distance.

sample_cycle(start_node, min_len=3, max_len=6, max_attempts=1000)

Randomly sample a cycle starting and ending at start_node within [min_len, max_len] length.

Args:

start_node: The starting node. min_len: The minimum length of the cycle. max_len: The maximum length of the cycle. max_attempts: The maximum number of attempts to sample a cycle.

Returns:

A list of Node instances representing the cycle, or None if not found.

visualize_by_type()

Visualize the map by node type.

visualize_path(path)

Visualize the path.

Args:

path: Path to visualize. A list of Node instances.

class simworld.map.map.Node(position: Vector, direction: Vector, type: str = 'sidewalk')

Bases: object

Graph node with a position and type (‘sidewalk’, ‘crosswalk’, or ‘intersection’).

class simworld.map.map.Road(start: Vector, end: Vector)

Bases: object

Represents a road segment between two points.

Module contents

Map management package.

This package provides functionality for managing and interacting with the simulation map. It includes tools for handling map data, coordinates, and spatial relationships within the simulation environment.