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.PermutationEncoding/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationMultiObjectiveProblem.cs

    r17695 r17747  
    3737    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3838    [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; }
     39    [Storable] public IResult<ParetoFrontScatterPlot<Permutation>> BestParetoFrontResult { get; private set; }
    3940
    4041    public int Dimension {
     
    4647      get { return PermutationTypeRefParameter.Value.Value; }
    4748      set { PermutationTypeRefParameter.Value.Value = value; }
     49    }
     50
     51    protected ParetoFrontScatterPlot<Permutation> BestParetoFront {
     52      get => BestParetoFrontResult.Value;
     53      set => BestParetoFrontResult.Value = value;
    4854    }
    4955
     
    5965      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    6066      PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter);
     67      BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult);
     68
    6169      RegisterEventHandlers();
    6270    }
     
    6876      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter));
    6977      Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter));
     78      Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<Permutation>>("Best Pareto Front", "The best Pareto front found so far."));
    7079
    7180      Operators.Add(new HammingSimilarityCalculator());
     
    8190      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
    8291      var plot = new ParetoFrontScatterPlot<Permutation>(fronts, individuals, qualities, Objectives, BestKnownFront);
    83       results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
     92
     93      BestParetoFront = plot;
    8494    }
    8595
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationProblem.cs

    r17745 r17747  
    3838    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3939    [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; }
     40    [Storable] public IResult<ISingleObjectiveSolutionContext<Permutation>> BestSolutionResult { get; private set; }
    4041
    4142    public int Dimension {
     
    4748      get { return PermutationTypeRefParameter.Value.Value; }
    4849      set { PermutationTypeRefParameter.Value.Value = value; }
     50    }
     51
     52    protected ISingleObjectiveSolutionContext<Permutation> BestSolution {
     53      get => BestSolutionResult.Value;
     54      set => BestSolutionResult.Value = value;
    4955    }
    5056
     
    6066      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    6167      PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter);
     68      BestSolutionResult = cloner.Clone(original.BestSolutionResult);
    6269      RegisterEventHandlers();
    6370    }
     
    6976      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter));
    7077      Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter));
     78      Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<Permutation>>("Best Solution", "The best solution found so far."));
    7179
    7280      Operators.Add(new HammingSimilarityCalculator());
     
    8189    public override void Analyze(ISingleObjectiveSolutionContext<Permutation>[] solutionContexts, IRandom random) {
    8290      base.Analyze(solutionContexts, random);
    83 
    84       //TODO reimplement code below using results directly                                                                       solutionContexts
    85       //var best = GetBestSolution(permutations, qualities);
    86       //results.AddOrUpdateResult("Best Solution", (IItem)best.Item1.Clone());
     91      var best = GetBest(solutionContexts);
     92      if (BestSolution == null || IsBetter(best, BestSolution))
     93        BestSolution = best.Clone() as SingleObjectiveSolutionContext<Permutation>;
    8794    }
    8895
Note: See TracChangeset for help on using the changeset viewer.