sbml_rs/structs/
function_definitions.rs1use mathml_rs::{evaluate_lambda, MathNode};
2
3use super::math::MathTag;
4use super::model::Model;
5use super::tag::{Tag, TagIndex};
6use std::collections::HashMap;
7
8#[derive(Clone, Debug, Default)]
9pub struct ListOfFunctionDefinitions {
10 pub function_definitions: Vec<TagIndex>,
11 pub parent: Option<TagIndex>,
12}
13
14#[derive(Clone, Debug, Default)]
15pub struct FunctionDefinition {
16 pub id: Option<String>,
17 pub name: Option<String>,
18 pub sbo_term: Option<String>,
19 pub math: Option<TagIndex>,
20 pub parent: Option<TagIndex>,
21}
22
23impl FunctionDefinition {
24 pub fn math_tag(&self, model: &Model) -> Option<MathTag> {
25 let mut result = None;
26 if let Some(math_tag_idx) = self.math {
27 if let Tag::MathTag(math_tag) = &model.nodes[math_tag_idx] {
28 result = Some(math_tag.clone());
29 }
30 }
31 result
32 }
33
34 pub fn evaluate(
35 &self,
36 model: &Model,
37 argument_values: &[f64],
38 functions: &HashMap<String, Vec<MathNode>>,
39 ) -> Result<f64, String> {
40 let math_tag = self.math_tag(model).unwrap();
41 evaluate_lambda(
42 &math_tag.nodes,
43 0,
44 &argument_values,
45 &HashMap::new(),
46 functions,
47 )
48 }
49}