Skip to content

feat(core): integrate ternary-graph route module — RoomGraph for room routing, communities & topology analysis#5

Closed
SuperInstance wants to merge 1 commit into
mainfrom
feat/ternary-graph-route-integration
Closed

feat(core): integrate ternary-graph route module — RoomGraph for room routing, communities & topology analysis#5
SuperInstance wants to merge 1 commit into
mainfrom
feat/ternary-graph-route-integration

Conversation

@SuperInstance
Copy link
Copy Markdown
Owner

Summary

The RoomGraph gives pincher actual pathfinding — rooms aren't just piles of data anymore. This PR integrates the ternary-graph crate (zero-dependency, #![forbid(unsafe_code)]) into pincher-core as the route module.

What's Added

New module: pincher-core/src/route/mod.rs — a RoomGraph wrapper over the ternary-weighted graph substrate:

Pathfinding

  • distances_from() — Bellman-Ford shortest paths (handles negative edges)
  • all_distances() — all-pairs via Floyd-Warshall
  • route_cost() — single-pair shortest path
  • next_hop() — cheapest forward-progress neighbor

Community Detection

  • detect_communities() — label propagation (positive edges attract, negative repel)
  • cluster_rooms() — spectral clustering via power iteration on signed Laplacian
  • community_modularity() — signed modularity scoring

Topology Analysis

  • trusted_components() — connected components over positive (trusted) edges only
  • degree(), adjacency(), laplacian(), normalized_laplacian(), degree_matrix()

Factory

  • build_routing_graph() — quick construction from room name slices

Why This Matters

Room relationships in PincherOS are naturally ternary: trusted (+1), adversarial (-1), or neutral (0). The ternary-graph ecosystem models this directly, giving us:

  1. Signed shortest paths — route around blocked rooms, prefer trusted corridors
  2. Community structure — discover which rooms naturally cluster via label propagation or spectral clustering
  3. Modularity scoring — evaluate partition quality numerically
  4. Trusted subgraph isolation — identify fully-trusted zones

Build & Test Results

$ cargo check -p pincher-core
    Finished dev profile [unoptimized + debuginfo]

$ cargo test -p pincher-core
    Finished test profile [unoptimized + debuginfo]
    running 140 tests
    test result: ok. 140 passed; 0 failed; 0 ignored; 0 measured

140 tests pass (129 pre-existing + 11 new route module tests). Zero regressions.

Phase 1 Roadmap Progress

This advances the ternary integration roadmap steps:

Step Status
ternary-graph dependency ✅ Merged
Route module (RoomGraph) ✅ This PR
Community detection ✅ In route module
Spectral clustering ✅ In route module
Graph persistence (serde) 🔜 Next — needs ternary-graph serde support
RPC exposure 🔜 Future

Notes

  • Uses directed graphs for blocked edges to avoid automatic negative cycles from undirected Neg edges
  • ternary-graph v0.1.0 at commit fdf1355e — zero transitive dependencies, zero risk of version conflicts
  • All doc examples use ignore to avoid requiring network access for doctest fetching

Add RoomGraph — a ternary-weighted graph-based routing engine for pincher-core
that gives rooms actual pathfinding, community detection, and topology analysis.

Adds:
- pincher-core/src/route/mod.rs: RoomGraph type with trusted/blocked routes,
  shortest paths (Bellman-Ford), all-pairs (Floyd-Warshall), next-hop routing,
  label propagation communities, spectral clustering, signed modularity,
  trusted components, Laplacian/adjacency/degree matrix access
- ternary-graph dependency to pincher-core/Cargo.toml
- pub mod route registration in pincher-core/src/lib.rs

The ternary-graph crate provides zero-dependency, forbid(unsafe_code) signed
graph algorithms. This integration gives pincher a mathematically sound
foundation for room routing — positive edges mean trusted paths, negative
edges mean blocked/adversarial connections.

Build: cargo check -p pincher-core — clean
Tests: 140 passed (129 existing + 11 new route tests), 0 failed

Part of the Phase 1 integration roadmap — validates the ternary ecosystem
composability thesis.
Copy link
Copy Markdown
Owner Author

@SuperInstance SuperInstance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is superseded by #7 (integrate-ternary-types) which takes a more aligned approach: using ternary-types as the lightweight shim crate rather than the full ternary-graph external dependency. The route module in #7 provides the same RoomGraph, pathfinding, and community detection functionality inline.

Closing this PR — the functionality is delivered via the superior architecture.

@SuperInstance
Copy link
Copy Markdown
Owner Author

Superseded by PR #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant