Gene, flow and manipulations
This commit is contained in:
parent
6be5d415ab
commit
4ed86fda31
7 changed files with 119 additions and 48 deletions
|
|
@ -15,11 +15,6 @@ impl PlantGenome {
|
|||
}
|
||||
}
|
||||
pub fn from_edges(nodes: Vec<Gene>,edges: Vec<(usize,usize)>) -> Result<Self,PlantCreationError> {
|
||||
// Check for nodes amount and edges amount mismatch
|
||||
if nodes.len() != edges.len() {
|
||||
return Err(PlantCreationError::AmountMismatch);
|
||||
}
|
||||
|
||||
if nodes.len() == 0 {
|
||||
return Err(PlantCreationError::EmptyNodes);
|
||||
}
|
||||
|
|
@ -56,7 +51,7 @@ impl Display for PlantGenome {
|
|||
visited[0] = true;
|
||||
|
||||
while let Some((node, depth)) = queue.pop_front() {
|
||||
result.push((depth, self.genes[node].place.clone()));
|
||||
result.push((depth, self.genes[node].clone()));
|
||||
|
||||
for &next in &adj[node] {
|
||||
if !visited[next] {
|
||||
|
|
@ -69,9 +64,9 @@ impl Display for PlantGenome {
|
|||
result
|
||||
};
|
||||
|
||||
for (depth,name) in indents {
|
||||
for (depth,gene) in indents {
|
||||
let indent = "____".repeat(depth);
|
||||
writeln!(f,"{}{}",indent,name)?;
|
||||
writeln!(f,"{}{}",indent,gene)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
@ -82,5 +77,4 @@ impl Display for PlantGenome {
|
|||
pub enum PlantCreationError {
|
||||
EmptyNodes,
|
||||
EmptyEdges,
|
||||
AmountMismatch,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue