coreason-runtime 0.1.0

Kinetic Plane execution engine for the CoReason Tripartite Cybernetic Manifold
Documentation
// Copyright (c) 2026 CoReason, Inc.
// All rights reserved.

use petgraph::graph::{DiGraph, NodeIndex};
use rayon::prelude::*;

/// A node in the Active Inference policy tree representing a state/belief projection
#[derive(Debug, Clone)]
pub struct PolicyNode {
    pub name: String,
    pub expected_free_energy: f64,
}

/// Active Inference Policy Search Tree built on petgraph
pub struct PolicySearchTree {
    pub graph: DiGraph<PolicyNode, ()>,
}

impl PolicySearchTree {
    /// Creates an empty policy tree
    pub fn new() -> Self {
        Self {
            graph: DiGraph::new(),
        }
    }

    /// Adds a policy belief node to the search tree
    pub fn add_node(&mut self, name: &str, efe: f64) -> NodeIndex {
        self.graph.add_node(PolicyNode {
            name: name.to_string(),
            expected_free_energy: efe,
        })
    }

    /// Connects two belief states representing a temporal action transition
    pub fn add_transition(&mut self, from: NodeIndex, to: NodeIndex) {
        self.graph.add_edge(from, to, ());
    }

    /// Evaluates the cumulative Expected Free Energy (EFE) of all nodes in parallel
    /// utilizing Rayon to leverage multi-threaded CPU substrates.
    pub fn evaluate_tree_parallel(&self) -> f64 {
        let raw_nodes: Vec<&PolicyNode> = self.graph.node_weights().collect();
        raw_nodes
            .par_iter()
            .map(|node| node.expected_free_energy)
            .sum()
    }
}