1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
extern crate radiate; use radiate::models::neat::{ neatenv::NeatEnvironment, neat::Neat, }; use super::populationdto::NeatPopulationBuilder; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TrainDto { pub epochs: i32, pub learning_rate: f32 } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TrainingSetDto { pub inputs: Vec<Vec<f32>>, pub answers: Vec<Vec<f32>>, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct RadiateDto { pub env: Option<NeatEnvironment>, pub train: Option<TrainDto>, pub neat: Option<Neat>, pub population: Option<NeatPopulationBuilder>, pub training_set: Option<TrainingSetDto>, } impl RadiateDto { pub fn new() -> Self { RadiateDto { env: None, train: None, neat: None, population: None, training_set: None, } } pub fn env(mut self, env: NeatEnvironment) -> Self { self.env = Some(env); self } pub fn train(mut self, epochs: i32, learning_rate: f32) -> Self { self.train = Some(TrainDto { epochs, learning_rate }); self } pub fn training_set(mut self, inputs: Vec<Vec<f32>>, answers: Vec<Vec<f32>>) -> Self { self.training_set = Some(TrainingSetDto { inputs, answers }); self } pub fn neat(mut self, neat: Neat) -> Self { self.neat = Some(neat); self } pub fn population(mut self, pop: NeatPopulationBuilder) -> Self { self.population = Some(pop); self } pub fn to_json(&self) -> String { serde_json::to_string_pretty(&self).unwrap() } }