parent
fa25e1fd75
commit
c2a86cfccd
@ -0,0 +1,45 @@ |
||||
use std::collections::HashMap; |
||||
use petgraph::prelude::*; |
||||
|
||||
use crate::node; |
||||
use crate::params; |
||||
use crate::network; |
||||
|
||||
|
||||
|
||||
pub struct CtbnParams { |
||||
cim: Option<params::CIM>, |
||||
transitions: Option<params::M>, |
||||
residence_time: Option<params::T> |
||||
} |
||||
|
||||
impl CtbnParams { |
||||
fn init() -> CtbnParams { |
||||
CtbnParams { |
||||
cim: Option::None, |
||||
transitions: Option::None, |
||||
residence_time: Option::None |
||||
} |
||||
} |
||||
} |
||||
|
||||
pub struct CtbnNetwork { |
||||
network: petgraph::stable_graph::StableGraph<node::Node, u64>, |
||||
params: HashMap<petgraph::graph::NodeIndex,CtbnParams>, |
||||
} |
||||
|
||||
impl network::Network for CtbnNetwork { |
||||
fn add_node(&mut self, n: node::Node) -> Result<petgraph::graph::NodeIndex, network::NetworkError> { |
||||
match &n.domain { |
||||
node::DomainType::Discrete(_) => { |
||||
let idx = self.network.add_node(n); |
||||
self.params.insert(idx, CtbnParams::init()); |
||||
Ok(idx) |
||||
}, |
||||
_ => Err(network::NetworkError::InsertionError(String::from("unsupported node"))) |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,15 @@ |
||||
use petgraph::prelude::*; |
||||
use crate::node; |
||||
use thiserror::Error; |
||||
|
||||
#[derive(Error, Debug)] |
||||
pub enum NetworkError { |
||||
#[error("Error during node insertion")] |
||||
InsertionError(String) |
||||
} |
||||
|
||||
pub trait Network { |
||||
fn add_node(&mut self, n: node::Node) -> Result<petgraph::graph::NodeIndex, NetworkError>; |
||||
} |
||||
|
||||
|
@ -0,0 +1,11 @@ |
||||
|
||||
pub enum DomainType { |
||||
Discrete(Vec<String>) |
||||
} |
||||
|
||||
pub struct Node { |
||||
pub domain: DomainType, |
||||
pub label: String |
||||
} |
||||
|
||||
|
@ -0,0 +1,15 @@ |
||||
use ndarray::prelude::*; |
||||
|
||||
pub struct CIM { |
||||
cim: Array3<f64>, |
||||
} |
||||
|
||||
pub struct M { |
||||
transitions: Array3<u64>, |
||||
} |
||||
|
||||
pub struct T { |
||||
residence_time: Array2<f64>, |
||||
} |
||||
|
||||
|
Loading…
Reference in new issue