Gigagraph
This commit is contained in:
parent
3491eb28d5
commit
d07c660e2a
6 changed files with 24 additions and 50 deletions
37
src/node/mod.rs
Normal file
37
src/node/mod.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use crate::node::graph_modifier::GraphModifier;
|
||||
|
||||
mod graph_modifier;
|
||||
|
||||
pub struct Node {
|
||||
children: Vec<Node>,
|
||||
function: fn(Vec<f64>) -> f64,
|
||||
}
|
||||
|
||||
impl Node {
|
||||
pub fn new(children: Option<Vec<Node>>, function: Option<fn(Vec<f64>) -> f64>) -> Self {
|
||||
Self {
|
||||
children: children.unwrap_or(vec![]),
|
||||
function: function.unwrap_or(|_| 0f64),
|
||||
}
|
||||
}
|
||||
pub fn empty() -> Self {
|
||||
Self {
|
||||
children: vec![],
|
||||
function: |_| 0f64,
|
||||
}
|
||||
}
|
||||
pub fn get_value(&self) -> f64 {
|
||||
if self.children.len() == 0 {
|
||||
return (self.function)(vec![0f64]);
|
||||
}
|
||||
let mut inputs: Vec<f64> = vec![];
|
||||
for node in &self.children {
|
||||
inputs.push(node.get_value());
|
||||
}
|
||||
|
||||
return (self.function)(inputs);
|
||||
}
|
||||
pub fn modify_tree(&self) -> GraphModifier {
|
||||
GraphModifier::new(self)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue