Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17664


Ignore:
Timestamp:
07/12/20 15:35:34 (4 years ago)
Author:
dleko
Message:

#2825 Add generation count to results. Minor refactoring.

Location:
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/NSGA3.cs

    r17663 r17664  
    5353
    5454        [Storable]
    55         private int generation;
    56 
    57         [Storable]
    5855        private List<Solution> solutions;
    5956
     
    7673
    7774        private const string GeneratedReferencePointsResultName = "Generated Reference Points";
     75        private const string CurrentGenerationResultName = "Generations";
    7876        private const string CurrentFrontResultName = "Pareto Front"; // Do not touch this
    7977
     
    165163        }
    166164
     165        public IntValue ResultsCurrentGeneration
     166        {
     167            get { return (IntValue)Results[CurrentGenerationResultName].Value; }
     168            set { Results[CurrentGenerationResultName].Value = value; }
     169        }
     170
    167171        #endregion ResultsProperties
    168172
     
    173177            Parameters.Add(new FixedValueParameter<IntValue>(SeedName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    174178            Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    175             Parameters.Add(new FixedValueParameter<IntValue>(PopulationSizeName, "The size of the population of Individuals.", new IntValue(ReferencePoint.GetNumberOfGeneratedReferencePoints(NumberOfObjectives))));
     179            Parameters.Add(new FixedValueParameter<IntValue>(PopulationSizeName, "The size of the population of Individuals.", new IntValue(200)));
    176180            Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityName, "The probability that the crossover operator is applied on two parents.", new PercentValue(0.9)));
    177181            Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverContiguityName, "The contiguity value for the Simulated Binary Crossover that specifies how close a child should be to its parents (larger value means closer). The value must be greater than or equal than 0. Typical values are in the range [2;5]."));
     
    209213            base.Initialize(cancellationToken);
    210214
     215            PopulationSize.Value = ReferencePoint.GetNumberOfGeneratedReferencePoints(Problem.Maximization.Length);
    211216            InitResults();
    212217            InitReferencePoints();
     
    225230        {
    226231            random = new MersenneTwister();
    227             generation = 0;
    228232            InitSolutions();
    229233        }
     
    249253            Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", new DoubleMatrix()));
    250254            Results.Add(new Result(CurrentFrontResultName, "The Pareto Front", new DoubleMatrix()));
     255            Results.Add(new Result(CurrentGenerationResultName, "The current generation", new IntValue(0)));
    251256        }
    252257
     
    257262        protected override void Run(CancellationToken cancellationToken)
    258263        {
    259             while (generation != MaximumGenerations.Value)
     264            while (ResultsCurrentGeneration.Value < MaximumGenerations.Value)
    260265            {
    261266                // create copies of generated reference points (to preserve the original ones for
    262267                // the next generation) maybe todo: use cloner?
    263268                ToNextGeneration(CreateCopyOfReferencePoints());
    264                 generation++;
     269                ResultsCurrentGeneration.Value++;
    265270            }
    266271        }
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Utility.cs

    r17658 r17664  
    116116        internal static Tuple<TIn, TOut> MinArgMin<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable
    117117        {
     118            if (func == null) throw new ArgumentNullException(nameof(func));
    118119            if (inputs == null) throw new ArgumentNullException(nameof(inputs));
    119120            var it = inputs.GetEnumerator();
     
    162163        internal static Tuple<TIn, TOut> MaxArgMax<TIn, TOut>(Func<TIn, TOut> func, IEnumerable<TIn> inputs) where TOut : IComparable
    163164        {
     165            if (func == null) throw new ArgumentNullException(nameof(func));
    164166            if (inputs == null) throw new ArgumentNullException(nameof(inputs));
    165167            var it = inputs.GetEnumerator();
Note: See TracChangeset for help on using the changeset viewer.