pub struct WorldGraph { /* private fields */ }Expand description
The typed environmental digital twin (ADR-139). Wraps a petgraph
StableDiGraph and exposes a domain API; stable WorldId → NodeIndex
mapping survives node removal.
Implementations§
Source§impl WorldGraph
impl WorldGraph
Sourcepub fn new(registration: GeoRegistration) -> Self
pub fn new(registration: GeoRegistration) -> Self
Create an empty graph registered to an installation origin.
Sourcepub fn registration(&self) -> &GeoRegistration
pub fn registration(&self) -> &GeoRegistration
Installation geo-registration (ADR-044).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of live nodes.
Sourcepub fn upsert_node(&mut self, node: WorldNode) -> WorldId
pub fn upsert_node(&mut self, node: WorldNode) -> WorldId
Insert or replace a node, returning its stable WorldId. If the node’s
embedded id is UNASSIGNED, a fresh id is allocated; if it names an
existing id, that node’s weight is replaced in place (upsert).
Sourcepub fn add_edge(
&mut self,
from: WorldId,
to: WorldId,
edge: WorldEdge,
) -> Result<(), WorldGraphError>
pub fn add_edge( &mut self, from: WorldId, to: WorldId, edge: WorldEdge, ) -> Result<(), WorldGraphError>
Add a typed edge between two known nodes.
§Errors
WorldGraphError::UnknownNode if either endpoint is unknown.
Sourcepub fn remove_node(&mut self, id: WorldId) -> Option<WorldNode>
pub fn remove_node(&mut self, id: WorldId) -> Option<WorldNode>
Remove a node and its incident edges (e.g. a person leaves).
Sourcepub fn neighbors(&self, id: WorldId) -> Vec<(WorldId, WorldEdge)>
pub fn neighbors(&self, id: WorldId) -> Vec<(WorldId, WorldEdge)>
Outgoing neighbours of a node with the connecting edge.
Sourcepub fn room_for_area(&self, area_id: &str) -> Option<WorldId>
pub fn room_for_area(&self, area_id: &str) -> Option<WorldId>
Resolve a HomeCore area_id to its Room node (entity linkage, ADR-127).
Sourcepub fn observed_by(&self, sensor: WorldId) -> Vec<WorldId>
pub fn observed_by(&self, sensor: WorldId) -> Vec<WorldId>
Observability chain: which nodes a sensor currently observes.
Sourcepub fn contents_of(&self, container: WorldId) -> Vec<WorldId>
pub fn contents_of(&self, container: WorldId) -> Vec<WorldId>
Location query: contents of a room/zone (incoming located_in edges).
Sourcepub fn add_semantic_state(
&mut self,
statement: String,
confidence: f32,
valid_from_unix_ms: i64,
provenance: SemanticProvenance,
evidence_sources: &[WorldId],
) -> WorldId
pub fn add_semantic_state( &mut self, statement: String, confidence: f32, valid_from_unix_ms: i64, provenance: SemanticProvenance, evidence_sources: &[WorldId], ) -> WorldId
Append-with-provenance: insert a SemanticState and wire DerivedFrom
edges to its evidence sources (ADR-139 §2.3). Sources unknown to the
graph are skipped (evidence may be raw frames not modelled as nodes).
Sourcepub fn add_contradiction(
&mut self,
a: WorldId,
b: WorldId,
magnitude: f32,
flag: String,
) -> Result<(), WorldGraphError>
pub fn add_contradiction( &mut self, a: WorldId, b: WorldId, magnitude: f32, flag: String, ) -> Result<(), WorldGraphError>
Record a contradiction between two still-live beliefs (ADR-139 §2.3). Neither node is deleted — the disagreement stays queryable.
§Errors
WorldGraphError::UnknownNode if either node is unknown.
Sourcepub fn apply_privacy_mode<F>(
&mut self,
mode: &str,
action: &str,
policy: F,
) -> PrivacyRollup
pub fn apply_privacy_mode<F>( &mut self, mode: &str, action: &str, policy: F, ) -> PrivacyRollup
Recompute PrivacyLimitedBy edges for the active mode (ADR-139 §2.4).
policy(modality_kind, node_kind) -> allowed decides, for each existing
Observes edge, whether the sensor may still observe the target under
mode. A matching PrivacyLimitedBy edge is appended recording the
decision; denied pairs are rolled up.
Sourcepub fn snapshot(&self) -> WorldGraphSnapshot
pub fn snapshot(&self) -> WorldGraphSnapshot
Snapshot the graph for persistence.
Sourcepub fn to_json(&self) -> Result<Vec<u8>, WorldGraphError>
pub fn to_json(&self) -> Result<Vec<u8>, WorldGraphError>
Serialize to deterministic JSON bytes (RVF payload).
§Errors
WorldGraphError::Serde on serialisation failure.