From c2a86cfccd12aa3dd330762be03dc7290c63b0b2 Mon Sep 17 00:00:00 2001 From: AlessandroBregoli Date: Tue, 15 Feb 2022 13:00:20 +0100 Subject: [PATCH] First Structure --- Cargo.toml | 4 ++++ src/ctbn.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 5 +++++ src/network.rs | 15 +++++++++++++++ src/node.rs | 11 +++++++++++ src/params.rs | 15 +++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 src/ctbn.rs create mode 100644 src/network.rs create mode 100644 src/node.rs create mode 100644 src/params.rs diff --git a/Cargo.toml b/Cargo.toml index 848ee11..de0a17b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = "*" diff --git a/src/ctbn.rs b/src/ctbn.rs new file mode 100644 index 0000000..43f973d --- /dev/null +++ b/src/ctbn.rs @@ -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, + transitions: Option, + residence_time: Option +} + +impl CtbnParams { + fn init() -> CtbnParams { + CtbnParams { + cim: Option::None, + transitions: Option::None, + residence_time: Option::None + } + } +} + +pub struct CtbnNetwork { + network: petgraph::stable_graph::StableGraph, + params: HashMap, +} + +impl network::Network for CtbnNetwork { + fn add_node(&mut self, n: node::Node) -> Result { + 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"))) + } + + } +} + + diff --git a/src/lib.rs b/src/lib.rs index 1b4a90c..c14b6fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,8 @@ +mod node; +mod params; +mod network; +mod ctbn; + #[cfg(test)] mod tests { #[test] diff --git a/src/network.rs b/src/network.rs new file mode 100644 index 0000000..9367269 --- /dev/null +++ b/src/network.rs @@ -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; +} + + diff --git a/src/node.rs b/src/node.rs new file mode 100644 index 0000000..cf23dcb --- /dev/null +++ b/src/node.rs @@ -0,0 +1,11 @@ + +pub enum DomainType { + Discrete(Vec) +} + +pub struct Node { + pub domain: DomainType, + pub label: String +} + + diff --git a/src/params.rs b/src/params.rs new file mode 100644 index 0000000..21f8c3d --- /dev/null +++ b/src/params.rs @@ -0,0 +1,15 @@ +use ndarray::prelude::*; + +pub struct CIM { + cim: Array3, +} + +pub struct M { + transitions: Array3, +} + +pub struct T { + residence_time: Array2, +} + +