boolnetevo/evolver/
run.rs1extern crate rand;
2
3use rand::prelude::*;
4
5use crate::base;
6
7use super::Evolver;
8
9impl Evolver {
10 pub fn run(&mut self, bn_ind: usize, inp_hex: &str) -> Result<String, String> {
12 if bn_ind >= self.population.len() {
13 return Err(format!("Boolnet index is larger than {}", self.population.len() - 1));
14 }
15
16 let inp_bytes = base::hex2bytes(inp_hex)?;
17
18 if (inp_bytes.len() << 3) != self.bitran.inp_size() {
19 return Err(format!("Input size in bits {} is wrong for this bitransform, must be {}", inp_bytes.len() << 3, self.bitran.inp_size()));
20 }
21
22 let mut outp_bytes = vec![0u8; self.bitran.outp_size() >> 3];
23
24 let mut rng = thread_rng();
25
26 self.population[bn_ind].run_single(&mut rng, &inp_bytes, &mut outp_bytes);
27
28 base::bytes2hex(&outp_bytes)
29 }
30
31}