Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tutosrive/Constellations/llms.txt

Use this file to discover all available pages before exploring further.

Graph and Vertex are the core data model powering all controllers and algorithms in Constellations. Together they implement a weighted, undirected graph using an adjacency-dictionary approach: each Vertex holds a dict mapping neighbour labels to edge weights, and Graph acts as the top-level registry that creates vertices and wires them together. Every traversal, pathfinding, and simulation feature in the project operates on an instance of Graph.

Vertex

Vertex represents a single node in the graph — typically a star in the constellation map. It stores the node’s identifier, an optional properties dict, and its adjacency mapping.

Constructor

Vertex(id, data=None)
id
any
required
The unique label for this vertex (e.g. a star name or integer index). Used as the key in Graph.vertex_list and in every adjacency dict of neighbouring vertices.
data
dict | None
default:"None"
An optional dictionary of arbitrary properties attached to this vertex. In the Constellations project this is typically a star-properties dict (e.g. {"name": "Sirius", "hypergiant": False}). Defaults to an empty dict {} when not supplied.
Instance attributes set by the constructor
AttributeTypeDescription
idanyThe vertex label passed at construction.
datadictStar-properties dict (empty {} if none provided).
adjacentdictMaps neighbour id → edge weight. Starts empty.

Methods

add_neighbor(neighbor, weight=0)

Registers neighbor as an adjacent node with the given weight.
neighbor
any
required
The id of the neighbouring vertex.
weight
any
default:"0"
The edge weight to store. In this project, weights are dicts (see note below), but the method accepts any value.
Returns: None

get_connections()dict

Returns the full adjacency dictionary: {neighbour_id: weight, ...}. Returns: dict

get_id()any

Returns the vertex’s identifier (self.id). Returns: any

Full class source

class Vertex:
    def __init__(self, id, data=None):
        self.id = id
        self.adjacent = {}
        self.data = data or {}

    def add_neighbor(self, neighbor, weight=0):
        self.adjacent[neighbor] = weight

    def get_connections(self):
        return self.adjacent

    def get_id(self):
        return self.id

Graph

Graph is the top-level container. It holds a dict of all Vertex objects and exposes helpers to add vertices, create edges, and look up nodes by label.

Constructor

Graph()
No arguments are required. The constructor initialises two attributes:
AttributeTypeDescription
vertex_listdictMaps vertex idVertex instance.
num_vertexintRunning count of vertices added (starts at 0).

Methods

add_vertex(id, data=None)Vertex

Adds a new vertex for id if it does not already exist, incrementing num_vertex. If the vertex already exists and data is provided, its data attribute is updated in place. Always returns the Vertex object.
id
any
required
Label for the vertex to add or update.
data
dict | None
default:"None"
Property dict to attach to the vertex. Ignored when the vertex already exists and data is None.
Returns: Vertex

add_edge(from_id, to_id, weight=0)

Creates an undirected edge between from_id and to_id with the given weight. If either vertex does not exist it is created automatically via add_vertex. Calls add_neighbor on both sides to maintain the undirected invariant.
from_id
any
required
Label of the source vertex.
to_id
any
required
Label of the destination vertex.
weight
any
default:"0"
Value stored on both half-edges. Typically a dict in this project (see note below).
Returns: None

get_vertex(id)Vertex | None

Looks up a vertex by its label. Returns None when id is not present.
id
any
required
The label of the vertex to retrieve.
Returns: Vertex | None

get_vertices()KeysView

Returns a live view of all vertex labels currently stored in vertex_list. Returns: KeysView (equivalent to dict.keys())

Full class source

class Graph:
    def __init__(self):
        self.vertex_list = {}
        self.num_vertex = 0

    def add_vertex(self, id, data=None):
        if id not in self.vertex_list:
            self.num_vertex += 1
            new_vertex = Vertex(id, data)
            self.vertex_list[id] = new_vertex
            return new_vertex
        else:
            v = self.vertex_list[id]
            if data:
                v.data = data
            return v

    def get_vertex(self, id):
        return self.vertex_list.get(id)

    def add_edge(self, from_id, to_id, weight=0):
        if from_id not in self.vertex_list:
            self.add_vertex(from_id)
        if to_id not in self.vertex_list:
            self.add_vertex(to_id)
        self.vertex_list[from_id].add_neighbor(to_id, weight)
        self.vertex_list[to_id].add_neighbor(from_id, weight)

    def get_vertices(self):
        return self.vertex_list.keys()

Edge weights in Constellations are dicts, not plain numbers. A typical weight passed to add_edge looks like {"distance": 5, "blocked": False}. The weight parameter on both add_edge and add_neighbor accepts any value, so this convention is purely by project agreement rather than enforced by the class.

Build docs developers (and LLMs) love