Example #1
0
        //public Fitness FitnessPart(Problem problem, Genome first, Genome second)
        //{
        //    throw new NotSupportedException();
        //}

        //public Fitness FitnessFirstPart(Problem problem, IList<Genome> genome_part)
        //{
        //    throw new NotSupportedException();
        //}

        //public Fitness FitnessLastPart(Problem problem, IList<Genome> genome_part)
        //{
        //    throw new NotSupportedException();
        //}

        //public Fitness FitnessPart(Problem problem, IList<Genome> genome_part)
        //{
        //    throw new NotSupportedException();
        //}

        #endregion


        public Fitness AverageFitness(Problem problem, IEnumerable <Individual <List <Genome>, Problem, Fitness> > population)
        {
            throw new NotImplementedException();
        }
Example #2
0
 public Fitness Fitness(
     Problem problem,
     Individual <List <Genome>, Problem, Fitness> individual)
 {
     return(this.Fitness(problem, individual, true));
 }
Example #3
0
        /// <summary>
        /// Calculates the rest of the fitness indicators using the times per round.
        /// </summary>
        /// <param name="problem"></param>
        /// <param name="times"></param>
        /// <returns></returns>
        private Fitness Calculate(
            Problem problem,
            List <double> times)
        {
            // TODO: optimize this entire calculation!!!!
            Fitness result = new Fitness();

            result.SmallestRoundCategories = new List <int>();
            result.LargestRoundCategories  = new List <int>();
            result.Vehicles = times.Count;

            // the latest round is taken.
            //int longest_round = 0;
            //int smallest_round = 0;

            double smallest_round_time = double.MaxValue;
            double longest_round_time  = double.MinValue;
            double total_time          = 0;

            // calculate the categories.
            // TODO: save a calculation by calculating this in the contructor.
            double category_size =
                problem.TargetTime.Value / (double)_category_count;

            // find the smallest/largest round and calculate total time.
            for (int round_idx = 0; round_idx < times.Count; round_idx++)
            {
                double round_time = times[round_idx];
                // calculate total time.
                total_time = total_time + round_time;

                // calculate categories
                // calculate the smallest category.
                if (round_time < problem.TargetTime.Value)
                {
                    double smallest_diff =
                        problem.TargetTime.Value - round_time;

                    int temp_smallest_category = (int)System.Math.Floor(smallest_diff / category_size);
                    if (temp_smallest_category < problem.Tolerance)
                    {
                        temp_smallest_category = 0;
                    }
                    result.SmallestRoundCategories
                    .Add(temp_smallest_category);
                }
                else
                {
                    result.SmallestRoundCategories.Add(0);
                }

                // calculate the largest category.
                if (round_time > problem.TargetTime.Value)
                {
                    double largest_diff =
                        round_time - problem.TargetTime.Value;

                    //largest_category = (int)System.Math.Min(System.Math.Floor(largest_diff / category_size),
                    //    _category_count);
                    int temp_largest_category = (int)System.Math.Floor(largest_diff / category_size);
                    if (temp_largest_category < problem.Tolerance)
                    {
                        temp_largest_category = 0;
                    }
                    result.LargestRoundCategories
                    .Add(temp_largest_category);
                }
                else
                {
                    result.LargestRoundCategories.Add(0);
                }

                // find smallest/largest round.
                if (smallest_round_time > round_time)
                {
                    //smallest_round = round_idx;
                    smallest_round_time = round_time;
                }
                if (longest_round_time < round_time)
                {
                    //longest_round = round_idx;
                    longest_round_time = round_time;
                }
            }

            // set longset/shortest time.
            result.MinimumTime = smallest_round_time;
            result.MaximumTime = longest_round_time;

            // calculate the smallest category.
            int smallest_category = 0;

            if (smallest_round_time < problem.TargetTime.Value)
            {
                double smallest_diff =
                    problem.TargetTime.Value - smallest_round_time;

                smallest_category = (int)System.Math.Floor(smallest_diff / category_size);
                if (smallest_category < problem.Tolerance)
                {
                    smallest_category = 0;
                }
            }

            // calculate the largest category.
            int largest_category = 0;

            if (longest_round_time > problem.TargetTime.Value)
            {
                double largest_diff =
                    longest_round_time - problem.TargetTime.Value;

                //largest_category = (int)System.Math.Min(System.Math.Floor(largest_diff / category_size),
                //    _category_count);
                largest_category = (int)System.Math.Floor(largest_diff / category_size);
                if (largest_category < problem.Tolerance)
                {
                    largest_category = 0;
                }
            }

            // create and return the fitness object.
            result.LargestRoundCategory  = largest_category;
            result.SmallestRoundCategory = smallest_category;
            result.TotalTime             = total_time;
            result.Times = times;

            // calculate feasability
            result.Feasable = result.MaximumTime <problem.MaximumTime.Value &&
                                                  result.MinimumTime> problem.MinimumTime.Value;

            return(result);
        }