-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ edition = "2021" | |
|
||
[dependencies] | ||
rand = "0.8.4" | ||
serde = { version = "1.0", features = ["derive"] } | ||
toml = "0.8.19" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use serde::Deserialize; | ||
use std::fs; | ||
use toml; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct Config { | ||
pub problem: Problem, | ||
pub algorithm: Algorithm, | ||
pub test: Test, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct Problem { | ||
pub size: i32, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct Algorithm { | ||
pub max_gen: i32, | ||
pub n_neighbors: i32, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct Test { | ||
pub count: i32, | ||
} | ||
|
||
impl Default for Config { | ||
fn default() -> Self { | ||
Config { | ||
problem: Problem { size: 20 }, | ||
algorithm: Algorithm { | ||
max_gen: 1000, | ||
n_neighbors: 10, | ||
}, | ||
test: Test { count: 100 }, | ||
} | ||
} | ||
} | ||
|
||
impl Config { | ||
pub fn get() -> Result<Config, Box<dyn std::error::Error>> { | ||
let config_content = fs::read_to_string("config.toml")?; | ||
let config: Config = toml::from_str(&config_content)?; | ||
Ok(config) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod case; | ||
pub mod config; | ||
pub mod debug; | ||
pub mod qts; | ||
pub mod quantum; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters