66 lines
2.2 KiB
Rust
66 lines
2.2 KiB
Rust
// Workspace: stats
|
|
// File: stats/src/stats.rs
|
|
//! The module `stats` handles stats disparity between all origins
|
|
//!
|
|
//! # Usage
|
|
//!
|
|
//! - [stat_solver]: Main solver function, in charge of selecting algorithms and handling all program flow
|
|
//!
|
|
//! It consists of several submodules:
|
|
//!
|
|
//! - `stat_algo`: Contains the algorithm implementations for finding solutions to the statistics problem.
|
|
//! - `stat_structs`: Defines data structures used for managing statistical weights and matrix operations.
|
|
//! - `stat_io`: Handles input/output operations, such as loading stat records from configuration files.
|
|
use crate::{
|
|
stat_algo::{Mode, find_all_fits},
|
|
stat_structs::StatWeightList,
|
|
};
|
|
|
|
use crate::stat_io::{AffName, CharacCharMatrix, load_stat_records};
|
|
use anyhow::Result;
|
|
use cli_parser::Config;
|
|
use config::statsolver::StatConfig;
|
|
|
|
/// Main solver function, in charge of selecting algorithms and handling all program flow
|
|
pub fn stat_solver(args: &StatConfig, config: &Config) -> Result<()> {
|
|
let _ = config;
|
|
let mut statmatrix = load_stat_records(&args.config_path, args.clone()).unwrap();
|
|
solution_from_empty(&mut statmatrix).unwrap();
|
|
if args.verbosity {
|
|
println!("{:?}", statmatrix.print_weights());
|
|
}
|
|
statmatrix.print_solutions();
|
|
Ok(())
|
|
}
|
|
|
|
/// Find a solution from an empty solution (algo1)
|
|
fn solution_from_empty(statmatrix: &mut CharacCharMatrix) -> Result<()> {
|
|
// while statmatrix.not_filled() {}
|
|
let stats_desired = vec![
|
|
(AffName::F, 4),
|
|
(AffName::Ag, 3),
|
|
(AffName::Per, 3),
|
|
(AffName::Psy, 3),
|
|
(AffName::Int, 1),
|
|
(AffName::Vol, 1),
|
|
];
|
|
let stats_undesirable = vec![
|
|
(AffName::Int, 3),
|
|
(AffName::Vol, 3),
|
|
(AffName::Chr, 2),
|
|
(AffName::Chn, 2),
|
|
(AffName::F, 1),
|
|
(AffName::Ag, 1),
|
|
(AffName::Per, 1),
|
|
(AffName::Psy, 1),
|
|
];
|
|
|
|
let sw = StatWeightList::from(stats_desired).iter_cycle();
|
|
let nsw = StatWeightList::from(stats_undesirable).iter_cycle();
|
|
find_all_fits(statmatrix, sw, Mode::Positive).unwrap();
|
|
find_all_fits(statmatrix, nsw, Mode::Negative).unwrap();
|
|
// find_all_negative_fits(statmatrix, nsw).unwrap();
|
|
|
|
Ok(())
|
|
}
|