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

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs

    r17695 r17747  
    3535  [StorableType("11916b0f-4c34-4ece-acae-e28d11211b43")]
    3636  public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
    37     [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; }
    3837    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3938    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
     39    [Storable] public IResult<ParetoFrontScatterPlot<IntegerVector>> BestParetoFrontResult { get; private set; }
    4040
    4141    public int Dimension {
     
    4949    }
    5050
     51    protected ParetoFrontScatterPlot<IntegerVector> BestParetoFront {
     52      get => BestParetoFrontResult.Value;
     53      set => BestParetoFrontResult.Value = value;
     54    }
     55
    5156    [StorableConstructor]
    5257    protected IntegerVectorMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
     
    5863    protected IntegerVectorMultiObjectiveProblem(IntegerVectorMultiObjectiveProblem original, Cloner cloner)
    5964      : base(original, cloner) {
    60       BestResultParameter = cloner.Clone(original.BestResultParameter);
    6165      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    6266      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
     67      BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult);
    6368      RegisterEventHandlers();
    6469    }
     
    6873      EncodingParameter.ReadOnly = true;
    6974      EvaluatorParameter.ReadOnly = true;
    70       Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found."));
    7175      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter));
    7276      Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounds of the integer vector problem.", Encoding.BoundsParameter));
     77      Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found so far."));
    7378
    7479      Operators.Add(new HammingSimilarityCalculator());
     
    8590      var plot = new ParetoFrontScatterPlot<IntegerVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
    8691
    87       BestResultParameter.ActualValue = plot;
     92      BestParetoFront = plot;
    8893    }
    8994
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs

    r17745 r17747  
    3636  [StorableType("c6081457-a3de-45ce-9f47-e0eb1c851bd2")]
    3737  public abstract class IntegerVectorProblem : SingleObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
    38     [Storable] protected IResultParameter<IntegerVector> BestResultParameter { get; private set; }
    3938    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    4039    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
     40    [Storable] public IResult<ISingleObjectiveSolutionContext<IntegerVector>> BestSolutionResult { get; private set; }
    4141
    4242    public int Dimension {
     
    5050    }
    5151
     52    protected ISingleObjectiveSolutionContext<IntegerVector> BestSolution {
     53      get => BestSolutionResult.Value;
     54      set => BestSolutionResult.Value = value;
     55    }
     56
    5257    [StorableConstructor]
    5358    protected IntegerVectorProblem(StorableConstructorFlag _) : base(_) { }
     
    5964    protected IntegerVectorProblem(IntegerVectorProblem original, Cloner cloner)
    6065      : base(original, cloner) {
    61       BestResultParameter = cloner.Clone(original.BestResultParameter);
    6266      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    6367      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
     68      BestSolutionResult = cloner.Clone(original.BestSolutionResult);
    6469      RegisterEventHandlers();
    6570    }
     
    6974      EncodingParameter.ReadOnly = true;
    7075      EvaluatorParameter.ReadOnly = true;
    71       Parameters.Add(BestResultParameter = new ResultParameter<IntegerVector>("Best Solution", "The best solution."));
    7276      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter));
    7377      Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounding box and step sizes of the values.", Encoding.BoundsParameter));
     78      Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<IntegerVector>>("Best Solution", "The best solution found so far."));
    7479
    7580      Operators.Add(new HammingSimilarityCalculator());
     
    8287    }
    8388
    84     public override void Analyze(ISingleObjectiveSolutionContext<IntegerVector>[] solutionContext, IRandom random) {
    85       base.Analyze(solutionContext, random);
    86 
    87       var best = GetBest(solutionContext);
    88 
    89       //TODO reimplement code below using results directly
    90       //results.AddOrUpdateResult("Best Solution", (IntegerVector)best.EncodedSolution.Clone());
     89    public override void Analyze(ISingleObjectiveSolutionContext<IntegerVector>[] solutionContexts, IRandom random) {
     90      base.Analyze(solutionContexts, random);
     91      var best = GetBest(solutionContexts);
     92      if (BestSolution == null || IsBetter(best, BestSolution))
     93        BestSolution = best.Clone() as SingleObjectiveSolutionContext<IntegerVector>;
    9194    }
    9295
Note: See TracChangeset for help on using the changeset viewer.