now accepts command line arguments

This commit is contained in:
René Fuhry 2023-06-07 22:32:41 +02:00 committed by GitHub
parent 28afa921ad
commit 33f2a0c57f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 10 deletions

View File

@ -3,8 +3,6 @@ name = "graphprogram_rust"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
csv = "1.2.2"
fastrand = "1.9.0"
@ -19,3 +17,4 @@ incremental = true
debug-assertions = false
codegen-units = 64
rpath = false
strip = true

View File

@ -148,13 +148,12 @@ pub fn show(matrix: &Vec<Vec<usize>>) {
}
}
pub fn read_csv(file_name: &str) -> Vec<Vec<usize>> {
pub fn read_csv(file: &str) -> Vec<Vec<usize>> {
let mut matrix: Vec<Vec<usize>> = vec![];
let dir: String = "/home/rene/projects/Java/graphprogram/csv/".into();
let mut csv = csv::ReaderBuilder::new()
.has_headers(false)
.delimiter(b';')
.from_path(dir + file_name)
.from_path(file)
.unwrap();
for (index, result) in csv.records().enumerate() {

View File

@ -6,7 +6,7 @@ mod tests {
#[test]
fn graph() {
let adjazenz_matrix = read_csv("art-brck.csv");
let adjazenz_matrix = read_csv("/home/rene/projects/Java/graphprogram/csv/art-brck.csv");
let distanz_matrix = calculate_distanz_matrix(&adjazenz_matrix);
let weg_matrix = calculate_weg_matrix(&adjazenz_matrix);

View File

@ -1,3 +1,5 @@
use std::env::args;
#[allow(unused_imports)]
use crate::graph::{
matrix::{fill_with_random, read_csv, show},
@ -7,9 +9,14 @@ use crate::graph::{
pub mod graph;
pub fn main() {
let file_name = "24n.csv";
let adjazenz_matrix = read_csv(file_name);
//let adjazenz_matrix = fill_with_random(320); // with 320 verteces, it runs in about 10 seconds on an Intel i5-10300H @4.3 GHz (2023-06-05 15:48)
let args: Vec<String> = args().collect();
let adjazenz_matrix: Vec<Vec<usize>>;
if args[1].trim().parse::<usize>().is_ok() {
adjazenz_matrix = fill_with_random(args[1].parse::<usize>().unwrap()); // with 320 verteces, it runs in about 10 seconds on an Intel i5-10300H @4.3 GHz (2023-06-05 15:48)
} else {
adjazenz_matrix = read_csv(&args[1]);
}
let distanz_matrix = calculate_distanz_matrix(&adjazenz_matrix);
let weg_matrix = calculate_weg_matrix(&adjazenz_matrix);