Beispiel #1
0
        /// <summary>
        /// Validates this individual.
        /// </summary>
        /// <param name="problem"></param>
        public override void Validate(GeneticProblem problem)
        {
            if (problem.Along.Count != this.Count)
            {
                throw new Exception("Individual is not valid!");
            }

            // TODO: check for doubles.
        }
        /// <summary>
        /// Calculates the fitness of the given individual.
        /// </summary>
        /// <param name="problem"></param>
        /// <param name="genomes"></param>
        /// <returns></returns>
        public Fitness Fitness(
            GeneticProblem problem,
            List <int> genomes)
        {
            double[][] weights = problem.BaseProblem.WeightMatrix;
            double     weight  = weights[problem.First][genomes[0]];
            int        idx;

            for (idx = 0; idx < genomes.Count - 1; idx++)
            {
                //weight = weight + (weights[genomes[idx]][genomes[idx + 1]]);
                weight = weight + (weights[genomes[idx]][genomes[idx + 1]]);
            }
            weight = weight + (weights[genomes[idx]][problem.Last]);

            return(new Fitness(weight));
        }
 /// <summary>
 /// Calculates the fitness of the given individual.
 /// </summary>
 /// <param name="problem"></param>
 /// <param name="individual"></param>
 /// <param name="validate"></param>
 /// <returns></returns>
 public Fitness Fitness(
     GeneticProblem problem,
     Individual <List <int>, GeneticProblem, Fitness> individual, bool validate)
 {
     return(this.Fitness(problem, individual.Genomes));
 }
        //public Fitness FitnessPart(GeneticProblem problem, int first, int second)
        //{
        //    return new Fitness(problem.Weight(first, second));
        //}

        //public Fitness FitnessFirstPart(GeneticProblem problem, IList<int> genomes)
        //{
        //    float weight = problem.Weight(problem.First, genomes[0]);
        //    int idx;
        //    for (idx = 0; idx < genomes.Count - 1; idx++)
        //    {
        //        weight = weight + (problem.Weight(genomes[idx], genomes[idx + 1]));
        //    }
        //    //weight = weight + (problem.Weight(genomes[idx], problem.Last));

        //    return new Fitness(weight);
        //}

        //public Fitness FitnessLastPart(GeneticProblem problem, IList<int> genomes)
        //{
        //    //float weight = problem.Weight(problem.First, genomes[0]);
        //    float weight = 0;
        //    int idx;
        //    for (idx = 0; idx < genomes.Count - 1; idx++)
        //    {
        //        weight = weight +
        //            (problem.Weight(genomes[idx], genomes[idx + 1]));
        //    }
        //    weight = weight + (problem.Weight(genomes[idx], problem.Last));

        //    return new Fitness(weight);
        //}

        //public Fitness FitnessPart(GeneticProblem problem, IList<int> genome_part)
        //{
        //    float weight = 0;
        //    int idx;
        //    for (idx = 0; idx < genome_part.Count - 1; idx++)
        //    {
        //        weight = weight + (problem.Weight(genome_part[idx], genome_part[idx + 1]));
        //    }
        //    return new Fitness(weight);
        //}

        #endregion

        /// <summary>
        /// Returns the average fitness.
        /// </summary>
        /// <param name="problem"></param>
        /// <param name="population"></param>
        /// <returns></returns>
        public Fitness AverageFitness(GeneticProblem problem, IEnumerable <Individual <List <int>, GeneticProblem, Fitness> > population)
        {
            throw new NotImplementedException();
        }