diff --git a/gemla/Cargo.toml b/gemla/Cargo.toml index 5e5d079..ef45a3e 100644 --- a/gemla/Cargo.toml +++ b/gemla/Cargo.toml @@ -5,4 +5,5 @@ authors = ["Jacob VanDomelen "] edition = "2018" [dependencies] -uuid = { version = "0.7", features = ["serde", "v4"] } \ No newline at end of file +uuid = { version = "0.7", features = ["serde", "v4"] } +clap = { version = "~2.27.0", features = ["yaml"] } \ No newline at end of file diff --git a/gemla/cli.yml b/gemla/cli.yml new file mode 100644 index 0000000..e5dbcd1 --- /dev/null +++ b/gemla/cli.yml @@ -0,0 +1,9 @@ +name: GEMLA +version: "0.1" +autor: Jacob VanDomelen +about: Uses a genetic algorithm to generate a machine learning algorithm. +args: + - DIRECTORY: + help: Sets the input/output directory for the program. + required: true + index: 1 \ No newline at end of file diff --git a/gemla/src/bracket/mod.rs b/gemla/src/bracket/mod.rs index 857cf17..dcba0a4 100644 --- a/gemla/src/bracket/mod.rs +++ b/gemla/src/bracket/mod.rs @@ -3,29 +3,38 @@ mod state; use uuid::Uuid; +// pub struct Bracket { +// tree: tree::Tree, +// directory: String +// } + fn build_tree(h: u32) -> Option> { - let mut result: Option> = None; + let mut result: Option> = None; - if h != 0 { - result = Some(tree::concat_trees(Uuid::new_v4(), build_tree(h - 1), build_tree(h - 1))); - match &result { - Some(r) => (*r).run_simulation(), - _ => () - } - } + if h != 0 { + result = Some(Box::new(tree::combine_trees(Uuid::new_v4(), build_tree(h - 1), build_tree(h - 1)))); + match &result { + Some(r) => (*r).run_simulation(), + _ => () + } + } - result + result } pub fn run_bracket() { - let mut height = 1; - let mut tree: tree::Tree = *build_tree(height).expect("Error getting result from build_tree."); + let mut height = 1; + let mut tree: tree::Tree = *build_tree(height).expect("Error getting result from build_tree."); - loop { - println!("========================================="); - println!("Running bracket..."); - height += 1; - tree = *tree::concat_trees(Uuid::new_v4(), Some(Box::new(tree)), build_tree(height)); - tree.run_simulation(); - } + loop { + println!("========================================="); + println!("Running bracket..."); + height += 1; + tree = tree::combine_trees(Uuid::new_v4(), Some(Box::new(tree)), build_tree(height)); + tree.run_simulation(); + + if height == 3 { + break; + } + } } \ No newline at end of file diff --git a/gemla/src/bracket/state.rs b/gemla/src/bracket/state.rs index b1e2820..4c0a24a 100644 --- a/gemla/src/bracket/state.rs +++ b/gemla/src/bracket/state.rs @@ -1,18 +1,18 @@ -use uuid::Uuid; -use std::fmt; +// use uuid::Uuid; +// use std::fmt; -pub struct State { - id: Uuid -} +// pub struct State { +// id: Uuid +// } -impl fmt::Display for State { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.id) - } -} +// impl fmt::Display for State { +// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +// write!(f, "{}", self.id) +// } +// } -pub fn create(id: &Uuid) -> State { - State { - id: id.clone() - } -} \ No newline at end of file +// pub fn create(id: &Uuid) -> State { +// State { +// id: id.clone() +// } +// } \ No newline at end of file diff --git a/gemla/src/bracket/tree.rs b/gemla/src/bracket/tree.rs index a9fea8f..7a728d8 100644 --- a/gemla/src/bracket/tree.rs +++ b/gemla/src/bracket/tree.rs @@ -2,43 +2,43 @@ use std::fmt; use uuid::Uuid; pub struct Tree { - id: Uuid, - left: Option>, - right: Option> + id: Uuid, + left: Option>, + right: Option> } -pub fn concat_trees(id: Uuid, l: Option>, r: Option>) -> Box { - Box::new(Tree { - id: id, - left: l, - right: r - }) +pub fn combine_trees(id: Uuid, l: Option>, r: Option>) -> Tree { + Tree { + id: id, + left: l, + right: r + } } impl fmt::Display for Tree { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let node_str = |t: &Option>| -> String { - match t { - Some(n) => format!("{}", *n), - _ => String::from("_") - } - }; + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let node_str = |t: &Option>| -> String { + match t { + Some(n) => format!("{}", *n), + _ => String::from("_") + } + }; - write!(f, "({} :{}|{})", self.id, node_str(&self.left), node_str(&self.right)) - } + write!(f, "({} :{}|{})", self.id, node_str(&self.left), node_str(&self.right)) + } } fn fmt_node(t: &Option>) -> String { - match t { - Some(n) => format!("{}", (*n).id), - _ => String::from("_") - } + match t { + Some(n) => format!("{}", (*n).id), + _ => String::from("_") + } } impl Tree { - pub fn run_simulation(&self) { - println!("================================"); - println!("Running simulation for node: {}", self.id); - println!("With children {} and {}", fmt_node(&self.left), fmt_node(&self.right)); - } + pub fn run_simulation(&self) { + println!("================================"); + println!("Running simulation for node: {}", self.id); + println!("With children {} and {}", fmt_node(&self.left), fmt_node(&self.right)); + } } \ No newline at end of file diff --git a/gemla/src/constants/args.rs b/gemla/src/constants/args.rs new file mode 100644 index 0000000..431270b --- /dev/null +++ b/gemla/src/constants/args.rs @@ -0,0 +1 @@ +pub const DIRECTORY: &str = "DIRECTORY"; \ No newline at end of file diff --git a/gemla/src/constants/mod.rs b/gemla/src/constants/mod.rs new file mode 100644 index 0000000..8c43337 --- /dev/null +++ b/gemla/src/constants/mod.rs @@ -0,0 +1 @@ +pub mod args; \ No newline at end of file diff --git a/gemla/src/main.rs b/gemla/src/main.rs index 82fe9df..bba6c70 100644 --- a/gemla/src/main.rs +++ b/gemla/src/main.rs @@ -1,5 +1,25 @@ mod bracket; +mod constants; + +#[macro_use] +extern crate clap; +use clap::App; +use std::fs::metadata; fn main() { - bracket::run_bracket(); + let yaml = load_yaml!("../cli.yml"); + let matches = App::from_yaml(yaml).get_matches(); + + let directory = matches.value_of(constants::args::DIRECTORY).unwrap(); + let metadata = metadata(directory); + + match &metadata { + Ok(m) if m.is_dir() == true => { + println!("{} is a valid directory!", directory); + println!("Building tree for {}.", directory); + bracket::run_bracket(); + }, + Ok(_) => println!("{} is not a valid directory!", directory), + _ => println!("{} does not exist!", directory) + } } \ No newline at end of file