use fixedbitset::{Block, FixedBitSet}; use genetic_algorithm::chromosome::{BitChromosome, GenesOwner}; use genetic_algorithm::fitness::FitnessValue; use genetic_algorithm::population::Population; #[allow(dead_code)] pub fn genes_to_str(genes: &FixedBitSet) -> String { format!("{:b}", genes) } #[allow(dead_code)] pub fn genes_to_blocks(genes: &FixedBitSet) -> &[Block] { genes.as_slice() } #[allow(dead_code)] pub fn chromosome(chromosome: &C) -> C::Genes { chromosome.genes().clone() } #[allow(dead_code)] pub fn chromosome_to_str(chromosome: &BitChromosome) -> String { format!("{:b}", chromosome.genes) } #[allow(dead_code)] pub fn chromosome_to_blocks(chromosome: &BitChromosome) -> &[Block] { chromosome.genes.as_slice() } #[allow(dead_code)] pub fn chromosome_with_fitness_score( chromosome: &C, ) -> (C::Genes, Option) { (chromosome.genes().clone(), chromosome.fitness_score()) } #[allow(dead_code)] pub fn chromosomes(chromosomes: &[C]) -> Vec { chromosomes.iter().map(chromosome).collect() } #[allow(dead_code)] pub fn chromosomes_to_str(chromosomes: &[BitChromosome]) -> Vec { chromosomes.iter().map(chromosome_to_str).collect() } #[allow(dead_code)] pub fn chromosomes_to_blocks(chromosomes: &[BitChromosome]) -> Vec<&[Block]> { chromosomes.iter().map(chromosome_to_blocks).collect() } #[allow(dead_code)] pub fn chromosomes_with_fitness_score( chromosomes: &[C], ) -> Vec<(C::Genes, Option)> { chromosomes .iter() .map(chromosome_with_fitness_score) .collect() } #[allow(dead_code)] pub fn population(population: &Population) -> Vec { population.chromosomes.iter().map(chromosome).collect() } #[allow(dead_code)] pub fn population_to_str(population: &Population) -> Vec { population .chromosomes .iter() .map(chromosome_to_str) .collect() } #[allow(dead_code)] pub fn population_with_fitness_scores( population: &Population, ) -> Vec<(C::Genes, Option)> { population .chromosomes .iter() .map(chromosome_with_fitness_score) .collect() }