permu-rs
A collection of utilities for permutations. It contains useful tools to create, manage and experiment with permutations.
Documentation
You can find the documentation with examples here.
Usage
Add this to your Cargo.toml
:
[dependencies]
permu-rs = "0.2.0"
Here's a simple example in order to illustrate how to transform populations from one representation space to another and how to learn and sample distributions:
use permu_rs::permutation::PermuPopulation;
use permu_rs::inversion::InversionPopulation;
use permu_rs::Population;
fn main() {
let length = 5; let pop_size = 5;
let identity = PermuPopulation::<u8>::identity(pop_size, length);
println!("Identity permutation population:\n{}", identity);
let mut invs = InversionPopulation::<u8>::zeros(pop_size, length-1);
identity.to_inversion(&mut invs).unwrap();
println!("Inversion population from permutations:\n{}", invs);
let mut distr = invs.learn();
println!("Distribution of the inversion population:\n{}", distr);
let mut samples = InversionPopulation::<u8>::zeros(pop_size, length-1);
InversionPopulation::sample(&mut distr, &mut samples).unwrap();
println!("Soften distribution of the inversion population:\n{}", distr);
println!("Sampled solutions from the distribution:\n{}", samples);
let mut recovered = PermuPopulation::<u8>::identity(pop_size, length);
samples.to_permus(&mut recovered).unwrap();
println!("Permutation representation of samples:\n{}", recovered);
}
License
This project is licensed under either of
at your option.