public IChromosome <BitGene> NewInstance(IImmutableSeq <BitGene> genes) { if (genes.IsEmpty) { throw new ArgumentException("The genes sequence must contain at least one gene."); } var chromosome = new BitChromosome(Bits.NewArray(genes.Length), genes.Length); var ones = 0; if (genes is BitGeneImmutableSeq seq) { var iseq = seq; iseq.CopyTo(chromosome._genes); ones = Bits.Count(chromosome._genes); } else { for (var i = genes.Length; --i >= 0;) { if (genes[i].BooleanValue()) { Bits.Set(chromosome._genes, i); ++ones; } } } // TODO: do not match in copy, arrays do (see ChromosomeTester) chromosome._seq = BitGeneMutableSeq.Of(_genes, Length).ToImmutableSeq(); chromosome._p = ones / (double)genes.Length; return(chromosome); }
private BitChromosome(byte[] bits, int length, double p) { _genes = bits; Length = length; _p = p; _seq = BitGeneMutableSeq.Of(_genes, length).ToImmutableSeq(); }
public static IMutableSeq <BitGene> NewSeq(int length) { return(BitGeneMutableSeq.Of(Array.Of(BitGeneStore.OfLength(length)))); }