Added command line argument parsing.
This commit is contained in:
parent
5abe93a0dc
commit
e6570cf4b7
8 changed files with 103 additions and 62 deletions
|
@ -5,4 +5,5 @@ authors = ["Jacob VanDomelen <Jacob.Vandome15@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
uuid = { version = "0.7", features = ["serde", "v4"] }
|
uuid = { version = "0.7", features = ["serde", "v4"] }
|
||||||
|
clap = { version = "~2.27.0", features = ["yaml"] }
|
9
gemla/cli.yml
Normal file
9
gemla/cli.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
name: GEMLA
|
||||||
|
version: "0.1"
|
||||||
|
autor: Jacob VanDomelen <jacob.vandome15@gmail.com>
|
||||||
|
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
|
|
@ -3,29 +3,38 @@ mod state;
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
// pub struct Bracket {
|
||||||
|
// tree: tree::Tree,
|
||||||
|
// directory: String
|
||||||
|
// }
|
||||||
|
|
||||||
fn build_tree(h: u32) -> Option<Box<tree::Tree>> {
|
fn build_tree(h: u32) -> Option<Box<tree::Tree>> {
|
||||||
let mut result: Option<Box<tree::Tree>> = None;
|
let mut result: Option<Box<tree::Tree>> = None;
|
||||||
|
|
||||||
if h != 0 {
|
if h != 0 {
|
||||||
result = Some(tree::concat_trees(Uuid::new_v4(), build_tree(h - 1), build_tree(h - 1)));
|
result = Some(Box::new(tree::combine_trees(Uuid::new_v4(), build_tree(h - 1), build_tree(h - 1))));
|
||||||
match &result {
|
match &result {
|
||||||
Some(r) => (*r).run_simulation(),
|
Some(r) => (*r).run_simulation(),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_bracket() {
|
pub fn run_bracket() {
|
||||||
let mut height = 1;
|
let mut height = 1;
|
||||||
let mut tree: tree::Tree = *build_tree(height).expect("Error getting result from build_tree.");
|
let mut tree: tree::Tree = *build_tree(height).expect("Error getting result from build_tree.");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("=========================================");
|
println!("=========================================");
|
||||||
println!("Running bracket...");
|
println!("Running bracket...");
|
||||||
height += 1;
|
height += 1;
|
||||||
tree = *tree::concat_trees(Uuid::new_v4(), Some(Box::new(tree)), build_tree(height));
|
tree = tree::combine_trees(Uuid::new_v4(), Some(Box::new(tree)), build_tree(height));
|
||||||
tree.run_simulation();
|
tree.run_simulation();
|
||||||
}
|
|
||||||
|
if height == 3 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,18 @@
|
||||||
use uuid::Uuid;
|
// use uuid::Uuid;
|
||||||
use std::fmt;
|
// use std::fmt;
|
||||||
|
|
||||||
pub struct State {
|
// pub struct State {
|
||||||
id: Uuid
|
// id: Uuid
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl fmt::Display for State {
|
// impl fmt::Display for State {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", self.id)
|
// write!(f, "{}", self.id)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn create(id: &Uuid) -> State {
|
// pub fn create(id: &Uuid) -> State {
|
||||||
State {
|
// State {
|
||||||
id: id.clone()
|
// id: id.clone()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
|
@ -2,43 +2,43 @@ use std::fmt;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct Tree {
|
pub struct Tree {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
left: Option<Box<Tree>>,
|
left: Option<Box<Tree>>,
|
||||||
right: Option<Box<Tree>>
|
right: Option<Box<Tree>>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn concat_trees(id: Uuid, l: Option<Box<Tree>>, r: Option<Box<Tree>>) -> Box<Tree> {
|
pub fn combine_trees(id: Uuid, l: Option<Box<Tree>>, r: Option<Box<Tree>>) -> Tree {
|
||||||
Box::new(Tree {
|
Tree {
|
||||||
id: id,
|
id: id,
|
||||||
left: l,
|
left: l,
|
||||||
right: r
|
right: r
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Tree {
|
impl fmt::Display for Tree {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let node_str = |t: &Option<Box<Tree>>| -> String {
|
let node_str = |t: &Option<Box<Tree>>| -> String {
|
||||||
match t {
|
match t {
|
||||||
Some(n) => format!("{}", *n),
|
Some(n) => format!("{}", *n),
|
||||||
_ => String::from("_")
|
_ => 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<Box<Tree>>) -> String {
|
fn fmt_node(t: &Option<Box<Tree>>) -> String {
|
||||||
match t {
|
match t {
|
||||||
Some(n) => format!("{}", (*n).id),
|
Some(n) => format!("{}", (*n).id),
|
||||||
_ => String::from("_")
|
_ => String::from("_")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tree {
|
impl Tree {
|
||||||
pub fn run_simulation(&self) {
|
pub fn run_simulation(&self) {
|
||||||
println!("================================");
|
println!("================================");
|
||||||
println!("Running simulation for node: {}", self.id);
|
println!("Running simulation for node: {}", self.id);
|
||||||
println!("With children {} and {}", fmt_node(&self.left), fmt_node(&self.right));
|
println!("With children {} and {}", fmt_node(&self.left), fmt_node(&self.right));
|
||||||
}
|
}
|
||||||
}
|
}
|
1
gemla/src/constants/args.rs
Normal file
1
gemla/src/constants/args.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub const DIRECTORY: &str = "DIRECTORY";
|
1
gemla/src/constants/mod.rs
Normal file
1
gemla/src/constants/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod args;
|
|
@ -1,5 +1,25 @@
|
||||||
mod bracket;
|
mod bracket;
|
||||||
|
mod constants;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate clap;
|
||||||
|
use clap::App;
|
||||||
|
use std::fs::metadata;
|
||||||
|
|
||||||
fn main() {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue