Changeset 17612


Ignore:
Timestamp:
06/19/20 16:38:33 (3 weeks ago)
Author:
mkommend
Message:

#2521: Added first version of problem results.

Location:
branches/2521_ProblemRefactoring
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r17594 r17612  
    4545  public class HillClimber : BasicAlgorithm {
    4646    [Storable]
    47     private IRandom random;
     47    private readonly IRandom random;
    4848
    4949    [Storable] public IFixedValueParameter<IntValue> MaximumIterationsParameter { get; private set; }
     
    6565      get { return MaximumIterationsParameter.Value.Value; }
    6666      set { MaximumIterationsParameter.Value.Value = value; }
     67    }
     68
     69    private int Iterations {
     70      get => IterationsResult.Value.Value;
     71      set => IterationsResult.Value.Value = value;
     72    }
     73
     74    private double BestQuality {
     75      get => BestQualityResult.Value.Value;
     76      set => BestQualityResult.Value.Value = value;
    6777    }
    6878
     
    8898    }
    8999
     100    protected override void Initialize(CancellationToken cancellationToken) {
     101      base.Initialize(cancellationToken);
     102
     103      IterationsResult.Value = new IntValue();
     104      BestQualityResult.Value = new DoubleValue(double.NaN);
     105    }
     106
    90107
    91108
    92109    protected override void Run(CancellationToken cancellationToken) {
    93       IterationsResult.Value = new IntValue();
    94       BestQualityResult.Value = new DoubleValue(double.NaN);
    95 
    96110      while (IterationsResult.Value.Value < MaximumIterations) {
    97111        cancellationToken.ThrowIfCancellationRequested();
     
    106120
    107121        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
    108         var bestSoFar = BestQualityResult.Value.Value;
     122        var bestSoFar = BestQuality;
    109123        if (double.IsNaN(bestSoFar) || Problem.IsBetter(fitness, bestSoFar)) {
    110           BestQualityResult.Value.Value = fitness;
     124          BestQuality = fitness;
    111125        }
    112126
    113         IterationsResult.Value.Value++;
     127        Iterations++;
    114128      }
    115129    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBProblem.cs

    r17334 r17612  
    7272    }
    7373
     74    public ResultCollection Results { get => Problem.Results; }
     75
    7476    [Storable]
    75     private ItemList<OKBSolution> solutions; 
     77    private ItemList<OKBSolution> solutions;
    7678    public ItemList<OKBSolution> Solutions {
    7779      get { return solutions; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorMultiObjectiveProblem.cs

    r17594 r17612  
    3333  public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
    3434    [Storable] protected IResultParameter<ParetoFrontScatterPlot<BinaryVector>> BestResultParameter { get; private set; }
    35     //public IResultDefinition<ParetoFrontScatterPlot<BinaryVector>> BestResult { get { return BestResultParameter; }}
    3635    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3736
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs

    r17594 r17612  
    3333  [StorableType("2F6FEB34-BD19-47AF-9484-7F48565C0C43")]
    3434  public abstract class BinaryVectorProblem : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
    35     [Storable] protected IResultParameter<ISingleObjectiveSolutionContext<BinaryVector>> BestResultParameter { get; private set; }
    36     //public IResultDefinition<ISingleObjectiveSolutionContext<BinaryVector>> BestResult => BestResultParameter;
    3735    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     36    [Storable] public IResult<ISingleObjectiveSolutionContext<BinaryVector>> BestSolutionResult { get; private set; }
     37
     38    private ISingleObjectiveSolutionContext<BinaryVector> BestSolution {
     39      get => BestSolutionResult.Value;
     40      set => BestSolutionResult.Value = value;
     41    }
    3842
    3943    public int Dimension {
     
    5155    protected BinaryVectorProblem(BinaryVectorProblem original, Cloner cloner)
    5256      : base(original, cloner) {
    53       BestResultParameter = cloner.Clone(original.BestResultParameter);
    5457      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     58      BestSolutionResult = cloner.Clone(original.BestSolutionResult);
    5559      RegisterEventHandlers();
    5660    }
     
    5963    protected BinaryVectorProblem(BinaryVectorEncoding encoding) : base(encoding) {
    6064      EncodingParameter.ReadOnly = true;
    61       Parameters.Add(BestResultParameter = new ResultParameter<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution", "The best solution."));
    6265      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter));
     66      Results.Add(BestSolutionResult = new Result<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution"));
    6367
    6468      Operators.Add(new HammingSimilarityCalculator());
     
    7377      base.Analyze(solutionContexts, results, random);
    7478      var best = GetBest(solutionContexts);
    75       var currentBest = BestResultParameter.ActualValue;
    76       if (currentBest == null || IsBetter(best.EvaluationResult.Quality, currentBest.EvaluationResult.Quality))
    77         BestResultParameter.ActualValue = best.Clone() as SingleObjectiveSolutionContext<BinaryVector>;
     79      if (BestSolution == null || IsBetter(best, BestSolution))
     80        BestSolution = best.Clone() as SingleObjectiveSolutionContext<BinaryVector>;
    7881    }
    7982
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs

    r17594 r17612  
    3535  public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
    3636    [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; }
    37     //public IResultDefinition<ParetoFrontScatterPlot<IntegerVector>> BestResult { get { return BestResultParameter; } }
    3837    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3938    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs

    r17594 r17612  
    3636  public abstract class IntegerVectorProblem : SingleObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
    3737    [Storable] protected IResultParameter<IntegerVector> BestResultParameter { get; private set; }
    38     //public IResultDefinition<IntegerVector> BestResult { get => BestResultParameter; }
    3938    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    4039    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r17594 r17612  
    8686        if (problem != value) {
    8787          if ((value != null) && !ProblemType.IsInstanceOfType(value)) throw new ArgumentException("Invalid problem type.");
    88           if (problem != null) DeregisterProblemEvents();
     88          if (problem != null) {
     89            Results.RemoveRange(problem.Results);
     90            DeregisterProblemEvents();
     91          }
    8992          problem = value;
    90           if (problem != null) RegisterProblemEvents();
     93          if (problem != null) {
     94            Results.AddRange(problem.Results);
     95            RegisterProblemEvents();
     96          }
    9197          OnProblemChanged();
    9298          Prepare();
     
    203209        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    204210
     211      //TODO Reset all results
    205212      Results.Reset();
    206213    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IProblem.cs

    r17513 r17612  
    3232  /// </summary>
    3333  public interface IProblem : IParameterizedNamedItem, IStorableContent {
     34    //TODO extract into interface? ResultsProducingItems? Problem and Algorithm
     35    ResultCollection Results { get; }
    3436
    3537    event EventHandler Reset;
     
    4850  public interface IProblem<TEncoding, TEncodedSolution> : IHeuristicOptimizationProblem
    4951    where TEncoding : class, IEncoding<TEncodedSolution>
    50     where TEncodedSolution : class, IEncodedSolution { }
     52    where TEncodedSolution : class, IEncodedSolution {
     53  }
    5154}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IProblemDefinition.cs

    r17586 r17612  
    3434    where TEncodedSolution : class, IEncodedSolution {
    3535    TEncoding Encoding { get; }
    36 
    3736  }
    3837}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs

    r17610 r17612  
    5252    }
    5353
     54
    5455    ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator {
    5556      get { return Encoding.SolutionCreator; }
     
    6768    }
    6869
    69     //TODO is a parameter for the evaluator really necessary, only single-objective or multi-objective evulators calling the func are possible
     70    //TODO is a parameter for the evaluator really necessary, only single-objective or multi-objective evaluators calling the func are possible
    7071    public ValueParameter<TEvaluator> EvaluatorParameter {
    7172      get { return (ValueParameter<TEvaluator>)Parameters["Evaluator"]; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r17610 r17612  
    130130    public virtual bool IsBetter(double quality, double bestQuality) {
    131131      return IsBetter(Maximization, quality, bestQuality);
     132    }
     133
     134    public virtual bool IsBetter(ISingleObjectiveSolutionContext<TEncodedSolution> solution, ISingleObjectiveSolutionContext<TEncodedSolution> otherSolution) {
     135      return IsBetter(Maximization, solution.EvaluationResult.Quality, otherSolution.EvaluationResult.Quality);
    132136    }
    133137
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/Problem.cs

    r17570 r17612  
    3939    }
    4040
    41 
     41    [Storable]
     42    public ResultCollection Results { get; } = new ResultCollection();
    4243
    4344    [StorableConstructor]
    4445    protected Problem(StorableConstructorFlag _) : base(_) { }
    45     protected Problem(Problem original, Cloner cloner) : base(original, cloner) { }
     46    protected Problem(Problem original, Cloner cloner) : base(original, cloner) {
     47      Results = cloner.Clone(original.Results);
     48    }
    4649    public Problem() : base() { }
    4750
     
    157160
    158161
    159     protected virtual void ParameterizeOperators() {
    160 
    161     }
     162    protected virtual void ParameterizeOperators() { }
    162163
    163164
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/UserDefinedProblem.cs

    r17226 r17612  
    4040  [Creatable(CreatableAttribute.Categories.Problems, Priority = 120)]
    4141  [StorableType("9F18A098-A8B8-4F70-93CF-79FF1496AC8A")]
    42   public sealed class UserDefinedProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent {
    43     public string Filename { get; set; }
     42  public sealed class UserDefinedProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent {
    4443
    4544    public static new Image StaticItemImage {
     
    170169    private void OnOperatorsChanged() {
    171170      EventHandler handler = OperatorsChanged;
    172       if (handler != null) handler(this, EventArgs.Empty);
    173     }
    174     public event EventHandler Reset;
    175     private void OnReset() {
    176       EventHandler handler = Reset;
    177171      if (handler != null) handler(this, EventArgs.Empty);
    178172    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisProblem.cs

    r17226 r17612  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
    24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2525using HeuristicLab.Optimization;
    26 using HEAL.Attic;
    2726
    2827namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    5150
    5251  [StorableType("07b08ca0-40cb-433e-8aed-72df06a87d62")]
    53   public interface ISymbolicDataAnalysisSingleObjectiveProblem : ISymbolicDataAnalysisProblem, ISingleObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { }
     52  public interface ISymbolicDataAnalysisSingleObjectiveProblem : ISymbolicDataAnalysisProblem, ISingleObjectiveHeuristicOptimizationProblem
     53    //ISingleObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree>
     54    { }
    5455  [StorableType("1c5a0cf4-1286-45d8-b126-a6f5ddccf7bf")]
    55   public interface ISymbolicDataAnalysisMultiObjectiveProblem : ISymbolicDataAnalysisProblem, IMultiObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree> { }
     56  public interface ISymbolicDataAnalysisMultiObjectiveProblem : ISymbolicDataAnalysisProblem, IMultiObjectiveHeuristicOptimizationProblem
     57    //IMultiObjectiveProblem<SymbolicExpressionTreeEncoding, ISymbolicExpressionTree>
     58    { }
    5659}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r17594 r17612  
    4747    [Storable] public OptionalValueParameter<OrienteeringSolution> BestKnownSolutionParameter { get; private set; }
    4848    [Storable] private IResultParameter<OrienteeringSolution> BestOrienteeringSolutionParameter { get; set; }
    49     //public IResultDefinition<OrienteeringSolution> BestOrienteeringSolution => BestOrienteeringSolutionParameter;
    5049
    5150    public IOrienteeringProblemData OrienteeringProblemData {
     
    122121      }
    123122      var bestSoFar = BestOrienteeringSolutionParameter.ActualValue;
    124      
     123
    125124      if (bestSoFar == null || IsBetter(quality, bestSoFar.Quality.Value)) {
    126125        bestSoFar = data.GetSolution((IntegerVector)best.Clone(), quality, score, travelCosts);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs

    r17594 r17612  
    4848    [Storable] public IValueParameter<ITSPSolution> BestKnownSolutionParameter { get; private set; }
    4949    [Storable] protected IResultParameter<ITSPSolution> BestTSPSolutionParameter { get; private set; }
    50     //public IResultDefinition<ITSPSolution> BestTSPSolution => BestTSPSolutionParameter;
    5150
    5251    public ITSPData TSPData {
Note: See TracChangeset for help on using the changeset viewer.