public bool TryGetFitness(IGenotype <int, int> genotype, out float fitness) { var _fitnessIsCalculated = calculatedFitnesses.TryGetValue(genotype.ToString(), out fitness); if (!_fitnessIsCalculated) { for (int y = 0; y < genotype.GetGenotypeSize(); y++) { for (int x = y + 1; x < genotype.GetGenotypeSize(); x++) { fitness += distance[x, y] * (flow[genotype.GetGene(y).GetValue(), genotype.GetGene(x).GetValue()] + flow[genotype.GetGene(x).GetValue(), genotype.GetGene(y).GetValue()]); } } } return(_fitnessIsCalculated); }
public IIndividual <int, int> Crossover(IIndividual <int, int> parent) { int _crossoverPoint = cache.GetRandomNext() % parent.GetGenotypeSize(); var _childGenotype = new List <IGene <int, int> >(); for (int i = 0; i < GetGenotypeSize(); i++) { if (i < _crossoverPoint) { _childGenotype.Add(new Gene <int, int> (genotype.GetGene(i).GetKey(), genotype.GetGene(i).GetValue())); } else { _childGenotype.Add(new Gene <int, int> (parent.GetGenotype().GetGene(i).GetKey(), parent.GetGenotype().GetGene(i).GetValue())); } } return(new Individual(new Genotype(_childGenotype, 0, cache), cache)); }