Pain - made to order
This commit is contained in:
parent
ae8e51c053
commit
5e61ee8e70
5 changed files with 95 additions and 61 deletions
|
|
@ -24,39 +24,46 @@ impl Node {
|
|||
max_children_count,
|
||||
}
|
||||
}
|
||||
pub fn get_value(&self) -> f64 {
|
||||
if self.children.len() == 0 {
|
||||
return self.handler.run(vec![0f64]);
|
||||
}
|
||||
let mut inputs: Vec<f64> = vec![];
|
||||
for node in &self.children {
|
||||
inputs.push(node.get_value());
|
||||
}
|
||||
|
||||
return self.handler.run(inputs);
|
||||
}
|
||||
pub fn modify_tree<'a>(&'a mut self) -> NodeModifier<'a> {
|
||||
NodeModifier::from_random(self, None)
|
||||
}
|
||||
pub fn number(n: f64) -> Node {
|
||||
Node {
|
||||
pub fn empty() -> Self {
|
||||
Self {
|
||||
children: vec![],
|
||||
handler: NodeHandler::Number { number: n },
|
||||
handler: NodeHandler::Empty,
|
||||
max_children_count: None,
|
||||
}
|
||||
}
|
||||
pub fn function(func: fn(Vec<f64>) -> f64) -> Node {
|
||||
Node {
|
||||
pub fn number(n: f64) -> Self {
|
||||
Self {
|
||||
children: vec![],
|
||||
handler: NodeHandler::Function { function: func },
|
||||
max_children_count: Some(1),
|
||||
}
|
||||
}
|
||||
pub fn variable(getter: fn() -> f64) -> Node {
|
||||
Node {
|
||||
children: vec![],
|
||||
handler: NodeHandler::Variable { getter },
|
||||
handler: NodeHandler::Number { number: n },
|
||||
max_children_count: Some(0),
|
||||
}
|
||||
}
|
||||
pub fn function(func: fn(Vec<f64>) -> f64, max_children_count: Option<usize>) -> Self {
|
||||
Self {
|
||||
children: vec![],
|
||||
handler: NodeHandler::Function { function: func },
|
||||
max_children_count,
|
||||
}
|
||||
}
|
||||
pub fn variable() -> Self {
|
||||
Self {
|
||||
children: vec![],
|
||||
handler: NodeHandler::Variable,
|
||||
max_children_count: Some(0),
|
||||
}
|
||||
}
|
||||
pub fn get_value(&self, passed_x: f64) -> f64 {
|
||||
if self.children.len() == 0 {
|
||||
return self.handler.run(vec![0f64], passed_x);
|
||||
}
|
||||
let mut inputs: Vec<f64> = vec![];
|
||||
for node in &self.children {
|
||||
inputs.push(node.get_value(passed_x));
|
||||
}
|
||||
|
||||
return self.handler.run(inputs, passed_x);
|
||||
}
|
||||
pub fn modify_tree(&mut self) -> NodeModifier {
|
||||
NodeModifier::from_random(self, None)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue