Example #1
0
        public void InitializePopulation()
        {
            Population = new List<Genome>();

            for (int i = 0; i < _populationSize; i++)
            {
                Genome genome = new Genome(_geneSize);
                genome.RandomizeGeneValues();

                Population.Add(genome);
            }
        }
Example #2
0
		/// <summary>
		/// Creates a <see cref="Genome"/> from a string of bits.
		/// </summary>
		/// <param name="bitString">A bit string, e.g. 100 001</param>
		/// <returns></returns>
		public static Genome FromString(string bitString)
		{
			if (string.IsNullOrEmpty(bitString))
				throw new ArgumentNullException("bitString", "bitString parameter is empty");

			bitString = bitString.Replace(" ", "");

			Genome genome = new Genome(bitString.Length);
			for (int i = 0; i < bitString.Length; i++)
			{
				if (bitString[i] != '0')
					genome.SetGeneOn(i);
			}

			return genome;
		}
Example #3
0
        public virtual int FitnessFunction(Genome genome)
        {
			return genome.Total;
        }
Example #4
0
		public Genome Clone()
		{
			Genome clonedGenome = new Genome(_genes.Length);
			List<bool> genes = Genes.ToList();
			for (int i = 0; i < _genes.Length; i++)
			{
				clonedGenome._genes[i] = genes[i];
			}

			return clonedGenome;
		}
Example #5
0
		public void SwapWith(Genome genome, int toPosition)
		{
			List<bool> sourceGenes = genome.Genes.ToList();
			for (int i = 0; i < toPosition; i++)
			{
				_genes[i] = sourceGenes[i];
			}
		}
Example #6
0
 public virtual int FitnessFunction(Genome genome)
 {
     return(genome.Total);
 }