Newer
Older
//! Implementation of an expansion-contraction algorithm to find wheel cohomology classes in the graph complex.
mod expand_n_contract;
mod expand_n_contract_sqlite;
use std::env;
use std::process;
/// Parses and checks command line arguments; runs the expansion-contraction algorithm.
let args: Vec<String> = env::args().collect();
let num_args: usize = args.len();
const NUM_ARGS_FOR_DB: usize = 3;
const NUM_ARGS_FOR_TXT: usize = 5;
if num_args != NUM_ARGS_FOR_DB && num_args != NUM_ARGS_FOR_TXT {
"Usage:\n\
\x20 {} <number-of-spokes-in-wheel> <output-filename.db>\n\
or\n\
\x20 {} <number-of-spokes-in-wheel> <cocycle-graphs.txt> <cocycle-differential-graphs.txt> <cocycle-differential-matrix.txt>",
args[0], args[0]
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);
}
if num_args == NUM_ARGS_FOR_DB {
let filename: &String = &args[2];
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 num_args == NUM_ARGS_FOR_TXT {
let cocycle_graphs_filename: &String = &args[2];
let cocycle_differential_graphs_filename: &String = &args[3];
let cocycle_differential_matrix_filename: &String = &args[4];
let result: Result<(usize, usize, usize), std::io::Error> =
expand_n_contract::expand_n_contract(
num_spokes,
cocycle_graphs_filename,
cocycle_differential_graphs_filename,
cocycle_differential_matrix_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) => Err(e),
} else {
Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"File extension not recognized.",
))