Newer
Older
mod expand_n_contract;
mod expand_n_contract_sqlite;
let args: Vec<String> = env::args().collect();
"Usage: {} <number-of-spokes-in-wheel> <output-filename.txt | output-filename.db>",
process::exit(1);
}
let num_spokes_maybe: Result<usize, std::num::ParseIntError> = args[1].parse::<usize>();
if num_spokes_maybe.is_err() {
eprintln!("Error parsing the first argument as a natural number.");
process::exit(1);
}
let num_spokes: usize = num_spokes_maybe.unwrap();
if num_spokes < 2 {
eprintln!("Error: A wheel graph without tadpoles must have at least two spokes.");
process::exit(1);
}
if num_spokes % 2 == 0 {
eprintln!("Error: The {}-wheel graph has an automorphism that induces an odd permutation on edges, so it is equal to zero in the graph complex.", num_spokes);
process::exit(1);
}
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
72
73
74
75
76
77
let filename: &String = &args[2];
if filename.ends_with(".db") {
let result: Result<(usize, usize, usize), rusqlite::Error> =
expand_n_contract_sqlite::expand_n_contract(num_spokes, filename);
match result {
Ok((num_rows, num_columns, num_nonzeros)) => {
eprintln!(
"Sparse {} x {} matrix with {} non-zero entries",
num_rows, num_columns, num_nonzeros
);
Ok(())
}
Err(e) => {
eprintln!("{}", e);
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Database error",
))
}
}
} else if filename.ends_with(".txt") {
let sparse_matrix_file_res: Result<File, std::io::Error> = File::create(filename);
if sparse_matrix_file_res.is_err() {
eprintln!("Error opening file: {}", filename);
process::exit(1);
}
let mut sparse_matrix_file: File = sparse_matrix_file_res.unwrap();
let result: Result<(usize, usize, usize), std::io::Error> =
expand_n_contract::expand_n_contract(num_spokes, &mut sparse_matrix_file);
match result {
Ok((num_rows, num_columns, num_nonzeros)) => {
eprintln!(
"Sparse {} x {} matrix with {} non-zero entries",
num_rows, num_columns, num_nonzeros
);
Ok(())
}
Err(e) => Err(e),
} else {
Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"File extension not recognized.",
))