Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/15/20 17:09:10 (4 years ago)
Author:
abeham
Message:

#2521: worked on refactoring

  • add results to problem base classes
  • fix external evaluation problem
  • Add result descriptions
Location:
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorMultiObjectiveProblem.cs

    r17695 r17747  
    3737    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3838    [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; }
     39    [Storable] public IResult<ParetoFrontScatterPlot<RealVector>> BestParetoFrontResult { get; private set; }
    3940
    4041    public int Dimension {
     
    4647      get { return BoundsRefParameter.Value; }
    4748      set { BoundsRefParameter.Value = value; }
     49    }
     50
     51    protected ParetoFrontScatterPlot<RealVector> BestParetoFront {
     52      get => BestParetoFrontResult.Value;
     53      set => BestParetoFrontResult.Value = value;
    4854    }
    4955
     
    5965      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    6066      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
     67      BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult);
    6168      RegisterEventHandlers();
    6269    }
     
    6875      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the real vector problem.", Encoding.LengthParameter));
    6976      Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the values.", Encoding.BoundsParameter));
    70 
     77      Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<RealVector>>("Best Pareto Front", "The best Pareto front found so far."));
    7178
    7279      Operators.Add(new HammingSimilarityCalculator());
     
    8289      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
    8390      var plot = new ParetoFrontScatterPlot<RealVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
    84       results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
     91
     92      BestParetoFront = plot;
    8593    }
    8694
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorProblem.cs

    r17745 r17747  
    3838    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3939    [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; }
     40    [Storable] public IResult<ISingleObjectiveSolutionContext<RealVector>> BestSolutionResult { get; private set; }
    4041
    4142    public int Dimension {
     
    4748      get { return BoundsRefParameter.Value; }
    4849      set { BoundsRefParameter.Value = value; }
     50    }
     51
     52    protected ISingleObjectiveSolutionContext<RealVector> BestSolution {
     53      get => BestSolutionResult.Value;
     54      set => BestSolutionResult.Value = value;
    4955    }
    5056
     
    6066      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    6167      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
     68      BestSolutionResult = cloner.Clone(original.BestSolutionResult);
    6269      RegisterEventHandlers();
    6370    }
     
    6976      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the real vector problem.", Encoding.LengthParameter));
    7077      Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the values.", Encoding.BoundsParameter));
     78      Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<RealVector>>("Best Solution", "The best solution found so far."));
    7179
    7280      Operators.Add(new HammingSimilarityCalculator());
     
    8290    public override void Analyze(ISingleObjectiveSolutionContext<RealVector>[] solutionContexts, IRandom random) {
    8391      base.Analyze(solutionContexts, random);
    84 
    85       //TODO: reimplement code below using results directly
    86 
    87       //var best = GetBestSolution(vectors, qualities);
    88 
    89       //results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone());
     92      var best = GetBest(solutionContexts);
     93      if (BestSolution == null || IsBetter(best, BestSolution))
     94        BestSolution = best.Clone() as SingleObjectiveSolutionContext<RealVector>;
    9095    }
    9196
Note: See TracChangeset for help on using the changeset viewer.