Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17747


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
Files:
5 deleted
29 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.CMAEvolutionStrategy/3.4/CMAAnalyzer.cs

    r17226 r17747  
    2222using System;
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Analysis;
    2526using HeuristicLab.Common;
     
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    32 using HEAL.Attic;
    3333
    3434namespace HeuristicLab.Algorithms.CMAEvolutionStrategy {
     
    9898        progress.Rows.Add(new DataRow("Avg Quality"));
    9999        progress.VisualProperties.YAxisLogScale = true;
    100         results.Add(new Result("Progress", progress));
     100        results.Add(new Result("Progress", "The quality progress over time on a log scale.", progress));
    101101      }
    102102      progress.Rows["AxisRatio"].Values.Add(sp.AxisRatio);
     
    114114        for (int i = 0; i < sp.C.GetLength(0); i++)
    115115          scaling.Rows.Add(new DataRow("Axis" + i.ToString()));
    116         results.Add(new Result("Scaling", scaling));
     116        results.Add(new Result("Scaling", "The extent to which the individual dimensions are scaled by the mutation.", scaling));
    117117      }
    118118      for (int i = 0; i < sp.C.GetLength(0); i++)
     
    126126        for (int i = 0; i < vector.Length; i++)
    127127          realVector.Rows.Add(new DataRow("Axis" + i.ToString()));
    128         results.Add(new Result("Object Variables", realVector));
     128        results.Add(new Result("Object Variables", "The value of the centroid point.", realVector));
    129129      }
    130130      for (int i = 0; i < vector.Length; i++)
     
    141141        for (int i = 0; i < vector.Length; i++)
    142142          stdDevs.Rows.Add(new DataRow("Axis" + i.ToString()));
    143         results.Add(new Result("Standard Deviations", stdDevs));
     143        results.Add(new Result("Standard Deviations", "The standard deviations of the various axis, as well as the minimum and maximum standard deviation.", stdDevs));
    144144      }
    145145      for (int i = 0; i < vector.Length; i++)
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r17745 r17747  
    9494      Parameters.Add(MaximumIterationsParameter = new FixedValueParameter<IntValue>("Maximum Iterations", "", new IntValue(100)));
    9595
    96       Results.Add(BestQualityResult = new Result<DoubleValue>("Best Quality"));
    97       Results.Add(IterationsResult = new Result<IntValue>("Iterations"));
     96      Results.Add(BestQualityResult = new Result<DoubleValue>("Best Quality", "The best quality found so far."));
     97      Results.Add(IterationsResult = new Result<IntValue>("Iterations", "The current iteration."));
    9898    }
    9999
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs

    r17680 r17747  
    229229      // Set up the results display
    230230      if (!Results.TryGetValue("Iterations", out var result))
    231         Results.Add(new Result("Iterations", resultsIterations = new IntValue(0)));
     231        Results.Add(new Result("Iterations", "The current iteration.", resultsIterations = new IntValue(0)));
    232232      else result.Value = resultsIterations = new IntValue(0);
    233233      if (!Results.TryGetValue("Evaluations", out var result2))
    234         Results.Add(new Result("Evaluations", resultsEvaluations = new IntValue(0)));
     234        Results.Add(new Result("Evaluations", "The number of evaluations that have been performed.", resultsEvaluations = new IntValue(0)));
    235235      else result2.Value = resultsEvaluations = new IntValue(0);
    236236      if (!Results.TryGetValue("Best Quality", out var result4))
    237         Results.Add(new Result("Best Quality", resultsBestQuality = new DoubleValue(tracker.BestQuality)));
     237        Results.Add(new Result("Best Quality", "The best quality that has been observed so far.", resultsBestQuality = new DoubleValue(tracker.BestQuality)));
    238238      else result4.Value = resultsBestQuality = new DoubleValue(tracker.BestQuality);
    239239      if (!Results.TryGetValue("Evaluation Best Solution Was Found", out var result5))
    240         Results.Add(new Result("Evaluation Best Solution Was Found", resultsBestFoundOnEvaluation = new IntValue(tracker.BestFoundOnEvaluation)));
     240        Results.Add(new Result("Evaluation Best Solution Was Found", "The number of evaluations at which the best solution was found.", resultsBestFoundOnEvaluation = new IntValue(tracker.BestFoundOnEvaluation)));
    241241      else result5.Value = resultsBestFoundOnEvaluation = new IntValue(tracker.BestFoundOnEvaluation);
    242242      var table = new DataTable("Qualities");
     
    245245      ResultsQualitiesIteration.VisualProperties.LineStyle = DataRowVisualProperties.DataRowLineStyle.Dot;
    246246      if (!Results.TryGetValue("Qualities", out var result6))
    247         Results.Add(new Result("Qualities", table));
     247        Results.Add(new Result("Qualities", "An analysis of the quality progress over time.", table));
    248248      else result6.Value = table;
    249249
     
    251251      table.Rows.Add(ResultsLevels = new DataRow("Levels"));
    252252      if (!Results.TryGetValue("Pyramid Levels", out var result7))
    253         Results.Add(new Result("Pyramid Levels", table));
     253        Results.Add(new Result("Pyramid Levels", "The number of levels of the pyramid.", table));
    254254      else result7.Value = table;
    255255
     
    257257      table.Rows.Add(ResultsSolutions = new DataRow("Solutions"));
    258258      if (!Results.TryGetValue("Stored Solutions", out var result8))
    259         Results.Add(new Result("Stored Solutions", table));
     259        Results.Add(new Result("Stored Solutions", "The number of solutions that are found over time.", table));
    260260      else result8.Value = table;
    261261
  • branches/2521_ProblemRefactoring/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalysis/AlleleFrequencyAnalyzer.cs

    r17226 r17747  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    2930using HeuristicLab.Optimization;
    3031using HeuristicLab.Parameters;
    31 using HEAL.Attic;
    3232
    3333namespace HeuristicLab.Analysis {
     
    165165        if (!ResultsParameter.ActualValue.ContainsKey(Name + " Results")) {
    166166          results = new ResultCollection();
    167           ResultsParameter.ActualValue.Add(new Result(Name + " Results", results));
     167          ResultsParameter.ActualValue.Add(new Result(Name + " Results", "Collection of allele frequency analysis results", results));
    168168        } else {
    169169          results = (ResultCollection)ResultsParameter.ActualValue[Name + " Results"].Value;
     
    173173        AlleleFrequencyCollection frequenciesCollection = new AlleleFrequencyCollection(frequencies);
    174174        if (!results.ContainsKey("Allele Frequencies"))
    175           results.Add(new Result("Allele Frequencies", frequenciesCollection));
     175          results.Add(new Result("Allele Frequencies", "Displays for all alleles in the population the frequencies with which these occur.", frequenciesCollection));
    176176        else
    177177          results["Allele Frequencies"].Value = frequenciesCollection;
     
    182182            AlleleFrequencyCollectionHistory history = new AlleleFrequencyCollectionHistory();
    183183            history.Add(frequenciesCollection);
    184             results.Add(new Result("Allele Frequencies History", history));
     184            results.Add(new Result("Allele Frequencies History", "Snapshots of the allele frequency of each generation.", history));
    185185          } else {
    186186            ((AlleleFrequencyCollectionHistory)results["Allele Frequencies History"].Value).Add(frequenciesCollection);
     
    215215          allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
    216216
    217           results.Add(new Result("Alleles", allelesTable));
     217          results.Add(new Result("Alleles", "Tabular summary of the allele frequency analysis", allelesTable));
    218218        } else {
    219219          allelesTable = (DataTable)results["Alleles"].Value;
     
    234234        // store alleles values
    235235        if (!results.ContainsKey("Unique Alleles"))
    236           results.Add(new Result("Unique Alleles", new DoubleValue(frequenciesCollection.Count)));
     236          results.Add(new Result("Unique Alleles", "The number of unique alleles currently in the population.", new DoubleValue(frequenciesCollection.Count)));
    237237        else
    238238          ((DoubleValue)results["Unique Alleles"].Value).Value = frequenciesCollection.Count;
    239239
    240240        if (!results.ContainsKey("Unique Alleles of Best Known Solution"))
    241           results.Add(new Result("Unique Alleles of Best Known Solution", new DoubleValue(uniqueRelevantAllelesCount)));
     241          results.Add(new Result("Unique Alleles of Best Known Solution", "The number of alleles from the best-known solution that are currently present in the population.", new DoubleValue(uniqueRelevantAllelesCount)));
    242242        else
    243243          ((DoubleValue)results["Unique Alleles of Best Known Solution"].Value).Value = uniqueRelevantAllelesCount;
    244244
    245245        if (!results.ContainsKey("Fixed Alleles"))
    246           results.Add(new Result("Fixed Alleles", new DoubleValue(fixedAllelesCount)));
     246          results.Add(new Result("Fixed Alleles", "The number of alleles, that are present in every individual of the population.", new DoubleValue(fixedAllelesCount)));
    247247        else
    248248          ((DoubleValue)results["Fixed Alleles"].Value).Value = fixedAllelesCount;
    249249
    250250        if (!results.ContainsKey("Fixed Alleles of Best Known Solution"))
    251           results.Add(new Result("Fixed Alleles of Best Known Solution", new DoubleValue(fixedRelevantAllelesCount)));
     251          results.Add(new Result("Fixed Alleles of Best Known Solution", "The number of alles from the best-known solution that are present in every individual of the population.", new DoubleValue(fixedRelevantAllelesCount)));
    252252        else
    253253          ((DoubleValue)results["Fixed Alleles of Best Known Solution"].Value).Value = fixedRelevantAllelesCount;
    254254
    255255        if (!results.ContainsKey("Lost Alleles of Best Known Solution"))
    256           results.Add(new Result("Lost Alleles of Best Known Solution", new DoubleValue(lostRelevantAllelesCount)));
     256          results.Add(new Result("Lost Alleles of Best Known Solution", "The number of alles from the best-known solution that are currently not present in the population.", new DoubleValue(lostRelevantAllelesCount)));
    257257        else
    258258          ((DoubleValue)results["Lost Alleles of Best Known Solution"].Value).Value = lostRelevantAllelesCount;
     
    282282
    283283          if (!results.ContainsKey("Scatter Plot"))
    284             results.Add(new Result("Scatter Plot", plot));
     284            results.Add(new Result("Scatter Plot", "A plot that shows the correlation between number of unique alleles that an individual shares with the best-known solution and its relative quality.", plot));
    285285          else
    286286            results["Scatter Plot"].Value = plot;
    287287          if (storeHistory) {
    288288            if (!results.ContainsKey("Scatter Plot History")) {
    289               results.Add(new Result("Scatter Plot History", new ScatterPlotHistory()));
     289              results.Add(new Result("Scatter Plot History", "Snapshots of the scatter plot that show correlation between shared alleles with best-known solution and relative solution quality.", new ScatterPlotHistory()));
    290290            }
    291291            ((ScatterPlotHistory)results["Scatter Plot History"].Value).Add(plot);
     
    300300
    301301          if (!results.ContainsKey("Average Contained Alleles of Best Known Solution"))
    302             results.Add(new Result("Average Contained Alleles of Best Known Solution", new DoubleValue(avgContainedReleventAlleles)));
     302            results.Add(new Result("Average Contained Alleles of Best Known Solution", "Average number of alleles that individuals share with the best-known solution.", new DoubleValue(avgContainedReleventAlleles)));
    303303          else
    304304            ((DoubleValue)results["Average Contained Alleles of Best Known Solution"].Value).Value = avgContainedReleventAlleles;
  • branches/2521_ProblemRefactoring/HeuristicLab.Analysis/3.3/BestScopeSolutionAnalyzer.cs

    r17383 r17747  
    124124        var solution = cloner.Clone(currentBestScope);
    125125
    126         results.Add(new Result(BestSolutionResultName, solution));
     126        results.Add(new Result(BestSolutionResultName, "The best solution found so far.", solution));
    127127      } else {
    128128        var bestSolution = (IScope)results[BestSolutionResultName].Value;
  • branches/2521_ProblemRefactoring/HeuristicLab.Analysis/3.3/MultiObjective/RankBasedParetoFrontAnalyzer.cs

    r17226 r17747  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    2728using HeuristicLab.Optimization;
    2829using HeuristicLab.Parameters;
    29 using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Analysis {
     
    7272      if (results.ContainsKey("Pareto Front"))
    7373        results["Pareto Front"].Value = front;
    74       else results.Add(new Result("Pareto Front", front));
     74      else results.Add(new Result("Pareto Front", "A tabular presentation of the current Pareto front.", front));
    7575
    7676      if (populationLevel) {
    7777        if (results.ContainsKey("Pareto Archive"))
    7878          results["Pareto Archive"].Value = paretoArchive;
    79         else results.Add(new Result("Pareto Archive", paretoArchive));
     79        else results.Add(new Result("Pareto Archive", "The individual solutions on the Pareto front.", paretoArchive));
    8080      }
    8181    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorMultiObjectiveProblem.cs

    r17695 r17747  
    3333  [StorableType("b64caac0-a23a-401a-bb7e-ffa3e22b80ea")]
    3434  public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
    35     [Storable] protected IResultParameter<ParetoFrontScatterPlot<BinaryVector>> BestResultParameter { get; private set; }
    3635    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     36    [Storable] public IResult<ParetoFrontScatterPlot<BinaryVector>> BestParetoFrontResult { get; private set; }
    3737
    3838    public int Dimension {
    3939      get { return DimensionRefParameter.Value.Value; }
    4040      protected set { DimensionRefParameter.Value.Value = value; }
     41    }
     42
     43    protected ParetoFrontScatterPlot<BinaryVector> BestParetoFront {
     44      get => BestParetoFrontResult.Value;
     45      set => BestParetoFrontResult.Value = value;
    4146    }
    4247
     
    5055    protected BinaryVectorMultiObjectiveProblem(BinaryVectorMultiObjectiveProblem original, Cloner cloner)
    5156      : base(original, cloner) {
    52       BestResultParameter = cloner.Clone(original.BestResultParameter);
    5357      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     58      BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult);
     59
    5460      RegisterEventHandlers();
    5561    }
     
    5965      EncodingParameter.ReadOnly = true;
    6066      EvaluatorParameter.ReadOnly = true;
    61       Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<BinaryVector>>("Best Pareto Front", "The best Pareto front found."));
    6267      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter));
     68      Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<BinaryVector>>("Best Pareto Front", "The best Pareto front found so far."));
    6369
    6470      Operators.Add(new HammingSimilarityCalculator());
     
    7581      var plot = new ParetoFrontScatterPlot<BinaryVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
    7682
    77       BestResultParameter.ActualValue = plot;
     83      BestParetoFront = plot;
    7884    }
    7985
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs

    r17745 r17747  
    3737    [Storable] public IResult<ISingleObjectiveSolutionContext<BinaryVector>> BestSolutionResult { get; private set; }
    3838
    39     private ISingleObjectiveSolutionContext<BinaryVector> BestSolution {
    40       get => BestSolutionResult.Value;
    41       set => BestSolutionResult.Value = value;
    42     }
    43 
    4439    public int Dimension {
    4540      get { return DimensionRefParameter.Value.Value; }
    4641      protected set { DimensionRefParameter.Value.Value = value; }
     42    }
     43
     44    protected ISingleObjectiveSolutionContext<BinaryVector> BestSolution {
     45      get => BestSolutionResult.Value;
     46      set => BestSolutionResult.Value = value;
    4747    }
    4848
     
    6666      EvaluatorParameter.ReadOnly = true;
    6767      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter));
    68       Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution"));
     68      Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution", "The best solution found so far."));
    6969
    7070      Operators.Add(new HammingSimilarityCalculator());
  • 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
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageMultiObjectiveProblem.cs

    r17695 r17747  
    3636  public abstract class LinearLinkageMultiObjectiveProblem : MultiObjectiveProblem<LinearLinkageEncoding, LinearLinkage> {
    3737    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    38     public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     38    [Storable] public IResult<ParetoFrontScatterPlot<LinearLinkage>> BestParetoFrontResult { get; private set; }
    3939
    4040    public int Dimension {
    4141      get { return DimensionRefParameter.Value.Value; }
    4242      set { DimensionRefParameter.Value.Value = value; }
     43    }
     44
     45    protected ParetoFrontScatterPlot<LinearLinkage> BestParetoFront {
     46      get => BestParetoFrontResult.Value;
     47      set => BestParetoFrontResult.Value = value;
    4348    }
    4449
     
    5358      : base(original, cloner) {
    5459      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     60      BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult);
     61
    5562      RegisterEventHandlers();
    5663    }
     
    6168      EvaluatorParameter.ReadOnly = true;
    6269      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the linear linkage problem.", Encoding.LengthParameter));
    63 
     70      Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<LinearLinkage>>("Best Pareto Front", "The best Pareto front found so far."));
    6471
    6572      Operators.Add(new HammingSimilarityCalculator());
     
    7582      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
    7683      var plot = new ParetoFrontScatterPlot<LinearLinkage>(fronts, individuals, qualities, Objectives, BestKnownFront);
    77       results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
     84
     85      BestParetoFront = plot;
    7886    }
    7987
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageProblem.cs

    r17745 r17747  
    3737  public abstract class LinearLinkageProblem : SingleObjectiveProblem<LinearLinkageEncoding, LinearLinkage> {
    3838    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     39    [Storable] public IResult<ISingleObjectiveSolutionContext<LinearLinkage>> BestSolutionResult { get; private set; }
    3940
    4041    public int Dimension {
    4142      get { return DimensionRefParameter.Value.Value; }
    4243      set { DimensionRefParameter.Value.Value = value; }
     44    }
     45
     46    protected ISingleObjectiveSolutionContext<LinearLinkage> BestSolution {
     47      get => BestSolutionResult.Value;
     48      set => BestSolutionResult.Value = value;
    4349    }
    4450
     
    5359      : base(original, cloner) {
    5460      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     61      BestSolutionResult = cloner.Clone(original.BestSolutionResult);
    5562      RegisterEventHandlers();
    5663    }
     
    6168      EvaluatorParameter.ReadOnly = true;
    6269      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the linear linkage problem.", Encoding.LengthParameter));
     70      Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<LinearLinkage>>("Best Solution", "The best solution found so far."));
    6371
    6472      Operators.Add(new HammingSimilarityCalculator());
     
    7381    public override void Analyze(ISingleObjectiveSolutionContext<LinearLinkage>[] solutionContexts, IRandom random) {
    7482      base.Analyze(solutionContexts, random);
    75 
    76       //TODO: reimplement code below using results directly
    77 
    78       //var best = GetBestSolution(vectors, qualities);
    79 
    80       //results.AddOrUpdateResult("Best Solution", (Item)best.Item1.Clone());
     83      var best = GetBest(solutionContexts);
     84      if (BestSolution == null || IsBetter(best, BestSolution))
     85        BestSolution = best.Clone() as SingleObjectiveSolutionContext<LinearLinkage>;
    8186    }
    8287
  • 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
  • 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
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeMultiObjectiveProblem.cs

    r17695 r17747  
    3838    [Storable] private ReferenceParameter<IntValue> TreeDepthRefParameter { get; set; }
    3939    [Storable] private ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; set; }
     40    [Storable] public IResult<ParetoFrontScatterPlot<ISymbolicExpressionTree>> BestParetoFrontResult { get; private set; }
    4041
    4142    public int TreeLength {
     
    5455    }
    5556
    56     // persistence
     57    protected ParetoFrontScatterPlot<ISymbolicExpressionTree> BestParetoFront {
     58      get => BestParetoFrontResult.Value;
     59      set => BestParetoFrontResult.Value = value;
     60    }
     61
    5762    [StorableConstructor]
    5863    protected SymbolicExpressionTreeMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
     
    6267    }
    6368
    64 
    65     // cloning
    6669    protected SymbolicExpressionTreeMultiObjectiveProblem(SymbolicExpressionTreeMultiObjectiveProblem original, Cloner cloner)
    6770      : base(original, cloner) {
     
    6972      TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter);
    7073      GrammarRefParameter = cloner.Clone(original.GrammarRefParameter);
     74      BestParetoFrontResult = cloner.Clone(original.BestParetoFrontResult);
    7175      RegisterEventHandlers();
    7276    }
     
    7983      Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter));
    8084      Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter));
     85      Results.Add(BestParetoFrontResult = new Result<ParetoFrontScatterPlot<ISymbolicExpressionTree>>("Best Pareto Front", "The best Pareto front found so far."));
    8186
    8287      Parameterize();
     
    9095      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(trees, qualities, Maximization);
    9196      var plot = new ParetoFrontScatterPlot<ISymbolicExpressionTree>(fronts, trees, qualities, Objectives, BestKnownFront);
    92       results.AddOrUpdateResult("Pareto Front Scatter Plot", plot);
     97
     98      BestParetoFront = plot;
    9399    }
    94100
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs

    r17745 r17747  
    3939    [Storable] protected ReferenceParameter<IntValue> TreeDepthRefParameter { get; private set; }
    4040    [Storable] protected ReferenceParameter<ISymbolicExpressionGrammar> GrammarRefParameter { get; private set; }
     41    [Storable] public IResult<ISingleObjectiveSolutionContext<ISymbolicExpressionTree>> BestSolutionResult { get; private set; }
    4142
    4243    public int TreeLength {
     
    5556    }
    5657
     58    protected ISingleObjectiveSolutionContext<ISymbolicExpressionTree> BestSolution {
     59      get => BestSolutionResult.Value;
     60      set => BestSolutionResult.Value = value;
     61    }
     62
    5763    // persistence
    5864    [StorableConstructor]
     
    6975      TreeDepthRefParameter = cloner.Clone(original.TreeDepthRefParameter);
    7076      GrammarRefParameter = cloner.Clone(original.GrammarRefParameter);
     77      BestSolutionResult = cloner.Clone(original.BestSolutionResult);
    7178      RegisterEventHandlers();
    7279    }
     
    8087      Parameters.Add(TreeDepthRefParameter = new ReferenceParameter<IntValue>("TreeDepth", "The maximum depth of the tree.", Encoding.TreeDepthParameter));
    8188      Parameters.Add(GrammarRefParameter = new ReferenceParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that describes a valid tree.", Encoding.GrammarParameter));
     89      Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<ISymbolicExpressionTree>>("Best Solution", "The best solution found so far."));
    8290
    8391      // TODO: These should be added in the SingleObjectiveProblem base class (if they were accessible from there)
     
    9098
    9199    public override void Analyze(ISingleObjectiveSolutionContext<ISymbolicExpressionTree>[] solutionContexts, IRandom random) {
    92       //TODO reimplement code below using results directly
    93 
    94       //if (!results.ContainsKey("Best Solution Quality")) {
    95       //  results.Add(new Result("Best Solution Quality", typeof(DoubleValue)));
    96       //}
    97       //if (!results.ContainsKey("Best Solution")) {
    98       //  results.Add(new Result("Best Solution", typeof(ISymbolicExpressionTree)));
    99       //}
    100 
    101       //var bestQuality = Maximization ? qualities.Max() : qualities.Min();
    102 
    103       //if (results["Best Solution Quality"].Value == null ||
    104       //    IsBetter(bestQuality, ((DoubleValue)results["Best Solution Quality"].Value).Value)) {
    105       //  var bestIdx = Array.IndexOf(qualities, bestQuality);
    106       //  var bestClone = (IItem)trees[bestIdx].Clone();
    107 
    108       //  results["Best Solution"].Value = bestClone;
    109       //  results["Best Solution Quality"].Value = new DoubleValue(bestQuality);
    110       //}
     100      base.Analyze(solutionContexts, random);
     101      var best = GetBest(solutionContexts);
     102      if (BestSolution == null || IsBetter(best, BestSolution))
     103        BestSolution = best.Clone() as SingleObjectiveSolutionContext<ISymbolicExpressionTree>;
    111104    }
    112105
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/Result.cs

    r17595 r17747  
    151151    }
    152152
    153     public Result(string name) : this(name, typeof(T)) { }
    154     public Result(string name, Type dataType) : this(name, string.Empty, dataType) { }
    155     public Result(string name, string description, Type dataType) : base(name, description, dataType) { }
    156 
    157     public Result(string name, T value) : this(name, string.Empty, value.GetType(), value) { }
    158     public Result(string name, string description, T value) : this(name, description, value.GetType(), value) { }
    159     public Result(string name, string description, Type dataType, IItem value) : base(name, description, dataType, value) { }
     153    //public Result(string name) : this(name, string.Empty) { }
     154    public Result(string name, string description) : base(name, description, typeof(T)) { }
     155   
     156    //public Result(string name, T value) : this(name, string.Empty, value) { }
     157    public Result(string name, string description, T value) : base(name, description, typeof(T), value) { }
    160158  }
    161159}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultCollection.cs

    r17594 r17747  
    7575    }
    7676
    77     public void AddOrUpdateResult(string name, IItem value) {
     77    public void AddOrUpdateResult(string name, IItem value, string description = null) {
    7878      IResult res;
    7979      if (!TryGetValue(name, out res)) {
    80         res = new Result(name, value);
     80        res = new Result(name, description ?? string.Empty, value);
    8181        Add(res);
    8282      } else res.Value = value;
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultParameter.cs

    r17718 r17747  
    114114      if (!results.TryGetValue(ActualName, out result)) {
    115115        if (DefaultValue == null) return null;
    116         result = ItemDescription == Description ? new Result(ActualName, (T)DefaultValue.Clone()) : new Result(ActualName, Description, (T)DefaultValue.Clone());
     116        result = new Result(ActualName, Description, (T)DefaultValue.Clone());
    117117        results.Add(result);
    118118      }
     
    143143      IResult result;
    144144      if (!results.TryGetValue(ActualName, out result)) {
    145         result = ItemDescription == Description ? new Result(ActualName, value) : new Result(ActualName, Description, value);
     145        result = new Result(ActualName, Description, value);
    146146        results.Add(result);
    147147      } else result.Value = value;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblem.cs

    r17226 r17747  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626using System.Threading;
    2727using Google.ProtocolBuffers;
     28using HEAL.Attic;
    2829using HeuristicLab.Analysis;
    2930using HeuristicLab.Common;
     
    3233using HeuristicLab.Optimization;
    3334using HeuristicLab.Parameters;
    34 using HEAL.Attic;
    3535
    3636namespace HeuristicLab.Problems.ExternalEvaluation {
     
    4040  // BackwardsCompatibility3.3
    4141  // Rename class to SingleObjectiveExternalEvaluationProblem
    42   public class ExternalEvaluationProblem : SingleObjectiveProblem<IEncoding<IEncodedSolution>, IEncodedSolution>, IExternalEvaluationProblem {
     42  public class ExternalEvaluationProblem<TEncoding, TEncodedSolution> : SingleObjectiveProblem<TEncoding, TEncodedSolution>, IExternalEvaluationProblem
     43    where TEncoding : class, IEncoding
     44    where TEncodedSolution : class, IEncodedSolution {
    4345
    4446    public static new Image StaticItemImage {
     
    5658      get { return (IValueParameter<SolutionMessageBuilder>)Parameters["MessageBuilder"]; }
    5759    }
    58     public IFixedValueParameter<SingleObjectiveOptimizationSupportScript> SupportScriptParameter {
    59       get { return (IFixedValueParameter<SingleObjectiveOptimizationSupportScript>)Parameters["SupportScript"]; }
    60     }
    61 
    62     private IFixedValueParameter<BoolValue> MaximizationParameter {
    63       get { return (IFixedValueParameter<BoolValue>)Parameters["Maximization"]; }
     60    public IFixedValueParameter<SingleObjectiveOptimizationSupportScript<TEncodedSolution>> SupportScriptParameter {
     61      get { return (IFixedValueParameter<SingleObjectiveOptimizationSupportScript<TEncodedSolution>>)Parameters["SupportScript"]; }
    6462    }
    6563    #endregion
    6664
    6765    #region Properties
    68     public new IEncoding<IEncodedSolution> Encoding {
     66    public new TEncoding Encoding {
    6967      get { return base.Encoding; }
    7068      set { base.Encoding = value; }
     
    7977      get { return MessageBuilderParameter.Value; }
    8078    }
    81     public SingleObjectiveOptimizationSupportScript OptimizationSupportScript {
     79    public SingleObjectiveOptimizationSupportScript<TEncodedSolution> OptimizationSupportScript {
    8280      get { return SupportScriptParameter.Value; }
    8381    }
    84     private ISingleObjectiveOptimizationSupport OptimizationSupport {
     82    private ISingleObjectiveOptimizationSupport<TEncodedSolution> OptimizationSupport {
    8583      get { return SupportScriptParameter.Value; }
    8684    }
     
    8987    [StorableConstructor]
    9088    protected ExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    91     protected ExternalEvaluationProblem(ExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     89    protected ExternalEvaluationProblem(ExternalEvaluationProblem<TEncoding, TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    9290    public override IDeepCloneable Clone(Cloner cloner) {
    93       return new ExternalEvaluationProblem(this, cloner);
     91      return new ExternalEvaluationProblem<TEncoding, TEncodedSolution>(this, cloner);
    9492    }
    95     public ExternalEvaluationProblem()
    96       : base() {
    97       Parameters.Remove("Maximization"); // readonly in base class
    98       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue()));
     93    public ExternalEvaluationProblem(TEncoding encoding)
     94      : base(encoding) {
     95      MaximizationParameter.ReadOnly = false;
     96      MaximizationParameter.Value = new BoolValue(); // is a read-only bool value in base class
    9997      Parameters.Add(new OptionalValueParameter<EvaluationCache>("Cache", "Cache of previously evaluated solutions."));
    10098      Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() }));
    10199      Parameters.Add(new ValueParameter<SolutionMessageBuilder>("MessageBuilder", "The message builder that converts from HeuristicLab objects to SolutionMessage representation.", new SolutionMessageBuilder()) { Hidden = true });
    102       Parameters.Add(new FixedValueParameter<SingleObjectiveOptimizationSupportScript>("SupportScript", "A script that can provide neighborhood and analyze the results of the optimization.", new SingleObjectiveOptimizationSupportScript()));
     100      Parameters.Add(new FixedValueParameter<SingleObjectiveOptimizationSupportScript<TEncodedSolution>>("SupportScript", "A script that can provide neighborhood and analyze the results of the optimization.", new SingleObjectiveOptimizationSupportScript<TEncodedSolution>(Results)));
    103101
    104102      Operators.Add(new BestScopeSolutionAnalyzer());
     
    106104
    107105    #region Single Objective Problem Overrides
    108     public override bool Maximization {
    109       get { return Parameters.ContainsKey("Maximization") && ((IValueParameter<BoolValue>)Parameters["Maximization"]).Value.Value; }
     106    public override ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {
     107      var qualityMessage = Evaluate(BuildSolutionMessage(solution), cancellationToken);
     108      if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_))
     109        throw new InvalidOperationException("The received message is not a SingleObjectiveQualityMessage.");
     110      var quality = qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality;
     111      return new SingleObjectiveEvaluationResult(quality);
     112
     113    }
     114    public virtual QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken) {
     115      return Cache == null
     116        ? EvaluateOnNextAvailableClient(solutionMessage, cancellationToken)
     117        : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions(), cancellationToken);
    110118    }
    111119
    112     public virtual void SetMaximization(bool maximization) {
    113       MaximizationParameter.Value.Value = maximization;
     120    public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutions,  IRandom random) {
     121      OptimizationSupport.Analyze(solutions, random);
    114122    }
    115 
    116     public override double Evaluate(IEncodedSolution individual, IRandom random) {
    117       var qualityMessage = Evaluate(BuildSolutionMessage(individual));
    118       if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_))
    119         throw new InvalidOperationException("The received message is not a SingleObjectiveQualityMessage.");
    120       return qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality;
    121     }
    122     public virtual QualityMessage Evaluate(SolutionMessage solutionMessage) {
    123       return Cache == null
    124         ? EvaluateOnNextAvailableClient(solutionMessage)
    125         : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions());
    126     }
    127 
    128     public override void Analyze(IEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    129       OptimizationSupport.Analyze(individuals, qualities, results, random);
    130     }
    131 
    132     public override IEnumerable<IEncodedSolution> GetNeighbors(IEncodedSolution individual, IRandom random) {
    133       return OptimizationSupport.GetNeighbors(individual, random);
     123    public override IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solutions, IRandom random) {
     124      return OptimizationSupport.GetNeighbors(solutions, random);
    134125    }
    135126    #endregion
     
    143134    #region Evaluation
    144135    private HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>();
    145     private object clientLock = new object();
     136    private readonly object clientLock = new object();
    146137
    147     private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message) {
     138    private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message, CancellationToken cancellationToken) {
    148139      IEvaluationServiceClient client = null;
    149140      lock (clientLock) {
     
    158149      try {
    159150        return client.Evaluate(message, GetQualityMessageExtensions());
    160       }
    161       finally {
     151      } finally {
    162152        lock (clientLock) {
    163153          activeClients.Remove(client);
     
    167157    }
    168158
    169     private SolutionMessage BuildSolutionMessage(IEncodedSolution solution, int solutionId = 0) {
     159    private SolutionMessage BuildSolutionMessage(TEncodedSolution solution, int solutionId = 0) {
    170160      lock (clientLock) {
    171161        SolutionMessage.Builder protobufBuilder = SolutionMessage.CreateBuilder();
     
    176166          try {
    177167            MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder);
    178           }
    179           catch (ArgumentException ex) {
     168          } catch (ArgumentException ex) {
    180169            throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex);
    181170          }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/HeuristicLab.Problems.ExternalEvaluation-3.4.csproj

    r16816 r17747  
    138138    <Compile Include="MultiObjectiveExternalEvaluationProblem.cs" />
    139139    <Compile Include="ExternalEvaluationProblemInstances.cs" />
    140     <Compile Include="SingleObjectiveExternalEvaluationProblem.cs" />
     140    <Compile Include="ExternalEvaluationProblem.cs" />
    141141    <Compile Include="Interfaces\IEvaluationServiceClient.cs" />
    142142    <Compile Include="Interfaces\IEvaluationChannel.cs" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/ISingleObjectiveOptimizationSupport.cs

    r17745 r17747  
    3030    where TEncodedSolution : class, IEncodedSolution {
    3131
     32    void InitializeResults();
    3233    void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, IRandom random);
    3334    IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledOptimizationSupport.cs

    r17226 r17747  
    2020#endregion
    2121
     22using HeuristicLab.Optimization;
     23
    2224namespace HeuristicLab.Problems.ExternalEvaluation {
    2325  public abstract class CompiledOptimizationSupport {
    2426
    2527    public dynamic vars { get; set; }
     28    public ResultCollection Results { get; set; }
    2629  }
    2730}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjective/MultiObjectiveOptimizationSupportScript.cs

    r16816 r17747  
    3333    private MultiObjectiveOptimizationSupportScript(StorableConstructorFlag _) : base(_) { }
    3434    private MultiObjectiveOptimizationSupportScript(MultiObjectiveOptimizationSupportScript<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    35     public MultiObjectiveOptimizationSupportScript() {
     35    public MultiObjectiveOptimizationSupportScript() : base() {
    3636      var codeTemplate = Templates.CompiledMultiObjectiveOptimizationSupport;
    3737      codeTemplate = codeTemplate.Replace("ENCODING_NAMESPACE", typeof(TEncodedSolution).Namespace);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScript.cs

    r17226 r17747  
    2323using System.Linq;
    2424using System.Reflection;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    26 using HEAL.Attic;
     27using HeuristicLab.Optimization;
    2728using HeuristicLab.Scripting;
    2829
     
    3839    }
    3940
     41    [Storable]
     42    private ResultCollection results;
     43    public ResultCollection Results {
     44      get { return results; }
     45    }
     46
    4047    [StorableConstructor]
    4148    protected OptimizationSupportScript(StorableConstructorFlag _) : base(_) { }
     
    4350      : base(original, cloner) {
    4451      variableStore = cloner.Clone(original.variableStore);
     52      results = cloner.Clone(original.results);
    4553    }
    46 
    47     protected OptimizationSupportScript()
    48       : base() {
     54   
     55    [Obsolete("Do not use this constructor.")]
     56    protected OptimizationSupportScript() : base() {
    4957      variableStore = new VariableStore();
    5058    }
    5159
    52     protected OptimizationSupportScript(string code)
    53       : base(code) {
     60    protected OptimizationSupportScript(ResultCollection results)
     61      : base() {
    5462      variableStore = new VariableStore();
     63      this.results = results;
    5564    }
    5665
     
    8695        inst = (CompiledOptimizationSupport)Activator.CreateInstance(types.Single(x => typeof(CompiledOptimizationSupport).IsAssignableFrom(x)));
    8796        inst.vars = new Variables(VariableStore);
     97        inst.Results = results;
    8898      } catch (Exception e) {
    8999        compiledInstance = null;
     
    93103      var concreteInst = inst as T;
    94104      if (concreteInst == null)
    95         throw new OptimizationSupportException("The optimization support class does not implement ISingleObjectiveOptimizationSupport." + Environment.NewLine + "Please implement that interface in the subclass of CompiledOptimizationSupport.");
     105        throw new OptimizationSupportException($"The optimization support class does not implement {typeof(T).FullName}." + Environment.NewLine + "Please implement that interface in the subclass of CompiledOptimizationSupport.");
    96106
    97107      CompiledInstance = concreteInst;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjective/CompiledSingleObjectiveOptimizationSupport.cs

    r16816 r17747  
    88  public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport<SOLUTION_CLASS> {
    99
    10     public void Analyze(SOLUTION_CLASS[] solutions, double[] qualities, ResultCollection results, IRandom random) {
     10    // private Result<StringValue> myResult;
     11
     12    public void InitializeResults() {
     13      // Initialize the results that you intend to produce
     14      // Uncomment the field above and the code below to add to the problem's results
     15      // if (!Results.TryGetValue("My Result", out myResult))
     16      //   Results.Add(myResult = new Result<StringValue>("My Result", "My result description."));
     17    }
     18
     19    public void Analyze(ISingleObjectiveSolutionContext<SOLUTION_CLASS>[] solutionContexts, IRandom random) {
    1120      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    1221      // Write or update results given the range of vectors and resulting qualities
    13       // Uncomment the following lines if you want to retrieve the best individual
     22      // Uncomment the following lines if you want to retrieve the current best individual
    1423      // Maximization:
    15       // var bestIndex = qualities.Select((v, i) => Tuple.Create(i, v)).OrderByDescending(x => x.Item2).First().Item1;
     24      // var best = solutionContexts.OrderByDescending(x => x.EvaluationResult.Quality).First();
    1625      // Minimization:
    17       // var bestIndex = qualities.Select((v, i) => Tuple.Create(i, v)).OrderBy(x => x.Item2).First().Item1;
    18       // var best = solutions[bestIndex];
     26      // var best = solutionContexts.OrderBy(x => x.EvaluationResult.Quality).First();
     27      //
     28      // myResult.Value = new StringValue("Custom result");
    1929    }
    2030
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjective/SingleObjectiveOptimizationSupportScript.cs

    r17745 r17747  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HEAL.Attic;
     
    3637    private SingleObjectiveOptimizationSupportScript(StorableConstructorFlag _) : base(_) { }
    3738    private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript<TEncodedSolution> original, Cloner cloner) : base(original, cloner) { }
    38     public SingleObjectiveOptimizationSupportScript() : base() {
     39    [Obsolete("Do not use this constructor.")]
     40    public SingleObjectiveOptimizationSupportScript() : this(null) { }
     41    public SingleObjectiveOptimizationSupportScript(ResultCollection results) : base(results) {
    3942      var codeTemplate = Templates.CompiledSingleObjectiveOptimizationSupport;
    4043      codeTemplate = codeTemplate.Replace("ENCODING_NAMESPACE", typeof(TEncodedSolution).Namespace);
     
    4548    public override IDeepCloneable Clone(Cloner cloner) {
    4649      return new SingleObjectiveOptimizationSupportScript<TEncodedSolution>(this, cloner);
     50    }
     51
     52    void ISingleObjectiveOptimizationSupport<TEncodedSolution>.InitializeResults() {
     53      CompiledInstance.InitializeResults();
    4754    }
    4855
Note: See TracChangeset for help on using the changeset viewer.