First Structure

main
AlessandroBregoli 3 years ago
parent fa25e1fd75
commit c2a86cfccd
  1. 4
      Cargo.toml
  2. 45
      src/ctbn.rs
  3. 5
      src/lib.rs
  4. 15
      src/network.rs
  5. 11
      src/node.rs
  6. 15
      src/params.rs

@ -6,3 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
petgraph = "*"
ndarray = "*"
thiserror = "*"

@ -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")))
}
}
}

@ -1,3 +1,8 @@
mod node;
mod params;
mod network;
mod ctbn;
#[cfg(test)]
mod tests {
#[test]

@ -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…
Cancel
Save