Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17719


Ignore:
Timestamp:
08/06/20 14:36:43 (4 years ago)
Author:
dleko
Message:

#2825 Be able to copy and store NSGA3 executions.

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

Legend:

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

    r17707 r17719  
    325325        protected override void Run(CancellationToken cancellationToken)
    326326        {
    327             while (ResultsCurrentGeneration.Value < MaximumGenerations.Value)
    328             {
    329                 try
     327            try
     328            {
     329                while (ResultsCurrentGeneration.Value < MaximumGenerations.Value)
    330330                {
    331331                    // todo: make parameter out of this
     
    336336                    List<Solution> rt = Utility.Concat(solutions, qt);
    337337
     338                    // todo: remove this check
     339                    for (int i = 0; i < rt.Count / 2; i++)
     340                        if (!solutions.Contains(rt[i])) throw new Exception($"This should never happen: !solutions.Contains(rt[{i}])");
     341
    338342                    solutions = NSGA3Selection.SelectSolutionsForNextGeneration(rt, GetCopyOfReferencePoints(), Problem.Maximization, PopulationSize.Value, random);
    339343
    340344                    ResultsCurrentGeneration.Value++;
    341                     Analyze();
    342345                    cancellationToken.ThrowIfCancellationRequested();
    343346                }
    344                 catch (OperationCanceledException ex)
    345                 {
    346                     throw new OperationCanceledException("Optimization process was cancelled.", ex);
    347                 }
    348                 catch (Exception ex)
    349                 {
    350                     throw new Exception($"Failed in generation {ResultsCurrentGeneration}.", ex);
    351                 }
    352                 finally
    353                 {
    354                     Analyze();
    355                 }
     347            }
     348            catch (OperationCanceledException ex)
     349            {
     350                throw new OperationCanceledException("Optimization process was cancelled.", ex);
     351            }
     352            catch (Exception ex)
     353            {
     354                throw new Exception($"Failed in generation {ResultsCurrentGeneration}.", ex);
     355            }
     356            finally
     357            {
     358                Analyze();
    356359            }
    357360        }
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/ReferencePoint.cs

    r17707 r17719  
    22using System.Collections.Generic;
    33using System.Linq;
     4using HEAL.Attic;
    45using HeuristicLab.Common;
    56using HeuristicLab.Core;
     
    78namespace HeuristicLab.Algorithms.NSGA3
    89{
     10    [StorableType("5026513A-F3C7-4A85-95D6-82B5B376E900")]
    911    public class ReferencePoint : IDeepCloneable
    1012    {
     
    1214
    1315        // The potentially associated solutions to this reference point and the distance to that solution
    14         private readonly Dictionary<Solution, double> potentialAssociatedSolutions = new Dictionary<Solution, double>();
    15 
    16         private readonly IRandom random;
    17 
    18         public double[] Values { get; }
     16        private Dictionary<Solution, double> potentialAssociatedSolutions = new Dictionary<Solution, double>();
     17
     18        [Storable]
     19        private IRandom random;
     20
     21        [Storable]
     22        public double[] Values { get; set; }
     23
     24        [Storable]
     25        public int NumberOfAssociatedSolutions { get; set; } = 0;
     26
    1927        public int Objectives => Values.Length;
    20         public int NumberOfAssociatedSolutions { get; set; } = 0;
    2128
    2229        #endregion Properties
    2330
    2431        #region Constructors
     32
     33        [StorableConstructor]
     34        public ReferencePoint(StorableConstructorFlag _)
     35        {
     36        }
    2537
    2638        public ReferencePoint(IRandom random, int obj)
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Solution.cs

    r17692 r17719  
    1010    {
    1111        // Chromosome
     12        [Storable]
    1213        public RealVector Chromosome { get; set; }
    1314
    1415        // actual fitness of solution as given by Problem
     16        [Storable]
    1517        public double[] Fitness { get; set; }
    1618
    1719        // normalized fitness used in selection process (in order to not overwrite the original Fitness)
     20        [Storable]
    1821        public double[] ConvertedFitness { get; set; }
     22
     23        [StorableConstructor]
     24        public Solution(StorableConstructorFlag _)
     25        {
     26        }
    1927
    2028        public Solution(RealVector chromosome)
Note: See TracChangeset for help on using the changeset viewer.