pub struct GalaxyModel {
pub graph: StableGraph<SystemId, f64, Undirected>,
pub spatial: RTree<SystemPoint>,
pub systems: HashMap<SystemId, System>,
pub planets: HashMap<PlanetKey, Planet>,
pub bases: HashMap<String, PlayerBase>,
pub biome_index: HashMap<Biome, Vec<PlanetKey>>,
pub name_index: HashMap<String, SystemId>,
pub address_to_id: HashMap<u64, SystemId>,
pub node_map: HashMap<SystemId, NodeIndex>,
pub player_state: Option<PlayerState>,
}Expand description
The in-memory galactic model.
Three parallel data structures kept in sync:
- petgraph – topology (pathfinding, routing)
- R-tree – spatial (nearest-neighbor, radius queries)
- HashMaps – associative (name, biome, address lookups)
Fields§
§graph: StableGraph<SystemId, f64, Undirected>Graph topology: nodes are systems, edge weights are distance in ly.
spatial: RTree<SystemPoint>3D spatial index of system positions.
systems: HashMap<SystemId, System>System data by ID.
planets: HashMap<PlanetKey, Planet>Planet data by (SystemId, planet_index).
bases: HashMap<String, PlayerBase>Base lookup by name (lowercase).
biome_index: HashMap<Biome, Vec<PlanetKey>>Biome -> list of planets with that biome.
name_index: HashMap<String, SystemId>System name -> SystemId (lowercase, only for named systems).
address_to_id: HashMap<u64, SystemId>Packed address (planet bits zeroed) -> SystemId.
node_map: HashMap<SystemId, NodeIndex>SystemId -> petgraph NodeIndex.
player_state: Option<PlayerState>Current player state (position, currencies).
Implementations§
Source§impl GalaxyModel
impl GalaxyModel
Sourcepub fn build_edges(&mut self, strategy: EdgeStrategy)
pub fn build_edges(&mut self, strategy: EdgeStrategy)
Build edges using the given strategy. Clears existing edges first.
Sourcepub fn connect_new_system(&mut self, sys_id: SystemId, k: usize)
pub fn connect_new_system(&mut self, sys_id: SystemId, k: usize)
Add KNN edges for a single newly inserted system.
Call this after insert_system() to connect the new node to
its neighbors without rebuilding the entire graph.
Source§impl GalaxyModel
impl GalaxyModel
Sourcepub fn system_count(&self) -> usize
pub fn system_count(&self) -> usize
Number of systems in the model.
Sourcepub fn planet_count(&self) -> usize
pub fn planet_count(&self) -> usize
Number of planets in the model.
Sourcepub fn base_count(&self) -> usize
pub fn base_count(&self) -> usize
Number of bases in the model.
Sourcepub fn system_by_name(&self, name: &str) -> Option<(&SystemId, &System)>
pub fn system_by_name(&self, name: &str) -> Option<(&SystemId, &System)>
Look up a system by name (case-insensitive).
Sourcepub fn base(&self, name: &str) -> Option<&PlayerBase>
pub fn base(&self, name: &str) -> Option<&PlayerBase>
Look up a base by name (case-insensitive).
Sourcepub fn player_position(&self) -> Option<&GalacticAddress>
pub fn player_position(&self) -> Option<&GalacticAddress>
Get the player’s current position, if available.
Sourcepub fn planets_by_biome(&self, biome: Biome) -> Vec<&Planet>
pub fn planets_by_biome(&self, biome: Biome) -> Vec<&Planet>
Get all planets with a given biome.
Sourcepub fn insert_system(&mut self, system: System)
pub fn insert_system(&mut self, system: System)
Insert a new system into all indexes.
Sourcepub fn insert_base(&mut self, base: PlayerBase)
pub fn insert_base(&mut self, base: PlayerBase)
Insert a base into the model.
Source§impl GalaxyModel
impl GalaxyModel
Sourcepub fn resolve_position(
&self,
address: Option<&GalacticAddress>,
base_name: Option<&str>,
) -> Result<GalacticAddress, GraphError>
pub fn resolve_position( &self, address: Option<&GalacticAddress>, base_name: Option<&str>, ) -> Result<GalacticAddress, GraphError>
Resolve a reference point to a GalacticAddress.
Accepts:
- A direct address (returned as-is)
- A base name (looked up in the base index)
- None for both (uses player position)
Sourcepub fn nearest_systems(
&self,
from: &GalacticAddress,
n: usize,
) -> Vec<(SystemId, f64)>
pub fn nearest_systems( &self, from: &GalacticAddress, n: usize, ) -> Vec<(SystemId, f64)>
Find the N nearest systems to a reference point.
Returns (SystemId, distance_in_ly) pairs sorted by distance ascending.
Sourcepub fn systems_within_radius(
&self,
from: &GalacticAddress,
radius_ly: f64,
) -> Vec<(SystemId, f64)>
pub fn systems_within_radius( &self, from: &GalacticAddress, radius_ly: f64, ) -> Vec<(SystemId, f64)>
Find all systems within a radius (in light-years) of a reference point.
Returns (SystemId, distance_in_ly) pairs sorted by distance ascending.
Sourcepub fn nearest_planets<'a>(
&'a self,
from: &GalacticAddress,
n: usize,
filter: &BiomeFilter,
) -> Vec<(PlanetKey, &'a Planet, f64)>
pub fn nearest_planets<'a>( &'a self, from: &GalacticAddress, n: usize, filter: &BiomeFilter, ) -> Vec<(PlanetKey, &'a Planet, f64)>
Find the N nearest planets to a reference point, with optional filtering.
Iterates systems by proximity, then checks their planets against the filter.
Returns (PlanetKey, &Planet, system_distance_ly) tuples.
Sourcepub fn planets_within_radius<'a>(
&'a self,
from: &GalacticAddress,
radius_ly: f64,
filter: &BiomeFilter,
) -> Vec<(PlanetKey, &'a Planet, f64)>
pub fn planets_within_radius<'a>( &'a self, from: &GalacticAddress, radius_ly: f64, filter: &BiomeFilter, ) -> Vec<(PlanetKey, &'a Planet, f64)>
Find all planets within a radius that match a filter.
Source§impl GalaxyModel
impl GalaxyModel
Sourcepub fn shortest_path(
&self,
from: SystemId,
to: SystemId,
) -> Result<Route, RouteError>
pub fn shortest_path( &self, from: SystemId, to: SystemId, ) -> Result<Route, RouteError>
Find the shortest path between two systems using A* (Dijkstra with zero heuristic).
If no graph path exists, falls back to a direct Euclidean hop.
Sourcepub fn tsp_nearest_neighbor(
&self,
start: SystemId,
targets: &[SystemId],
return_to_start: bool,
) -> Result<Route, RouteError>
pub fn tsp_nearest_neighbor( &self, start: SystemId, targets: &[SystemId], return_to_start: bool, ) -> Result<Route, RouteError>
Plan a route visiting all targets using nearest-neighbor greedy.
Uses Euclidean distances directly (not graph edges) for the TSP ordering.
Sourcepub fn build_route_from_order(&self, order: &[SystemId]) -> Route
pub fn build_route_from_order(&self, order: &[SystemId]) -> Route
Convert an ordered list of SystemIds into a Route.
Sourcepub fn two_opt_improve(&self, order: Vec<SystemId>) -> Route
pub fn two_opt_improve(&self, order: Vec<SystemId>) -> Route
Improve a route using 2-opt local search.
Iteratively reverses segments when doing so reduces total distance. Runs until no improvement is found (local optimum).
Sourcepub fn tsp_two_opt(
&self,
start: SystemId,
targets: &[SystemId],
return_to_start: bool,
) -> Result<Route, RouteError>
pub fn tsp_two_opt( &self, start: SystemId, targets: &[SystemId], return_to_start: bool, ) -> Result<Route, RouteError>
Plan a route using nearest-neighbor + 2-opt.
Sourcepub fn constrain_hops(&self, route: &Route, max_ly: f64) -> Route
pub fn constrain_hops(&self, route: &Route, max_ly: f64) -> Route
Constrain a route so no hop exceeds max_ly.
Inserts intermediate known systems as waypoints when a hop is too long.
Waypoints are marked with is_waypoint: true.
Sourcepub fn warp_jump_count(route: &Route, warp_range: f64) -> usize
pub fn warp_jump_count(route: &Route, warp_range: f64) -> usize
Count the number of warp jumps needed for a route at a given range.
Sourcepub fn reachable_systems(
&self,
start: SystemId,
warp_range: f64,
) -> Result<Vec<SystemId>, RouteError>
pub fn reachable_systems( &self, start: SystemId, warp_range: f64, ) -> Result<Vec<SystemId>, RouteError>
Find all systems reachable from start within a given warp range.
Uses DFS over the spatial index (no graph clone needed).