From b1978b70dd6ab6abdb03a591f0fc74807b3fc345 Mon Sep 17 00:00:00 2001 From: AlessandroBregoli Date: Wed, 2 Mar 2022 09:46:54 +0100 Subject: [PATCH] Added enum_dipatch for Params --- src/params.rs | 51 ++------------------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/src/params.rs b/src/params.rs index d77ef2a..964351d 100644 --- a/src/params.rs +++ b/src/params.rs @@ -22,6 +22,7 @@ pub enum StateType { /// Parameters /// The Params trait is the core element for building different types of nodes. The goal is to /// define the set of method required to describes a generic node. +#[enum_dispatch(Params)] pub trait ParamsTrait { fn reset_params(&mut self); @@ -46,59 +47,11 @@ pub trait ParamsTrait { /// The Params enum is the core element for building different types of nodes. The goal is to /// define all the supported type of parameters. +#[enum_dispatch] pub enum Params { DiscreteStatesContinousTime(DiscreteStatesContinousTimeParams), } -impl ParamsTrait for Params { - fn reset_params(&mut self) { - match self { - Params::DiscreteStatesContinousTime(p) => p.reset_params() - } - } - - fn get_random_state_uniform(&self) -> StateType{ - match self { - Params::DiscreteStatesContinousTime(p) => p.get_random_state_uniform() - } - } - - - /// Randomly generate a residence time for the given node taking into account the node state - /// and its parent set. - fn get_random_residence_time(&self, state: usize, u: usize) -> Result { - match self { - Params::DiscreteStatesContinousTime(p) => p.get_random_residence_time(state, u) - } - } - - - /// Randomly generate a possible state for the given node taking into account the node state - /// and its parent set. - fn get_random_state(&self, state: usize, u: usize) -> Result { - match self { - Params::DiscreteStatesContinousTime(p) => p.get_random_state(state, u) - } - } - - - /// Used by childern of the node described by this parameters to reserve spaces in their CIMs. - fn get_reserved_space_as_parent(&self) -> usize { - match self { - Params::DiscreteStatesContinousTime(p) => p.get_reserved_space_as_parent() - } - } - - - /// Index used by discrete node to represents their states as usize. - fn state_to_index(&self, state: &StateType) -> usize { - match self { - Params::DiscreteStatesContinousTime(p) => p.state_to_index(state) - } - } - - -} /// DiscreteStatesContinousTime. /// This represents the parameters of a classical discrete node for ctbn and it's composed by the