Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/04/19 16:03:51 (5 years ago)
Author:
abeham
Message:

#2521: refactored multi-objective problems' maximization

  • Add ForceValue method to IValueParameter to perform changes even when it is read-only
  • Add MaximizationChanged event handler
Location:
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IMultiObjectiveProblem.cs

    r17257 r17317  
    2020#endregion
    2121
     22using System;
    2223using HEAL.Attic;
    2324
    2425namespace HeuristicLab.Optimization {
    2526  [StorableType("251d79f1-a065-47f9-85a3-2e8dbdbf685e")]
    26   public interface IMultiObjectiveProblem : IProblem, IMultiObjectiveHeuristicOptimizationProblem { }
     27  public interface IMultiObjectiveProblem : IProblem, IMultiObjectiveHeuristicOptimizationProblem {
     28    event EventHandler MaximizationChanged;
     29  }
    2730
    2831  [StorableType("806fb361-1469-4903-9f54-f8678b0717b9")]
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblem.cs

    r17257 r17317  
    2020#endregion
    2121
    22 
     22using System;
    2323using HEAL.Attic;
    2424
    2525namespace HeuristicLab.Optimization {
    2626  [StorableType("24830fd5-7d97-41a5-9d7e-d84f1b7ab259")]
    27   public interface ISingleObjectiveProblem : ISingleObjectiveHeuristicOptimizationProblem { }
     27  public interface ISingleObjectiveProblem : ISingleObjectiveHeuristicOptimizationProblem {
     28    event EventHandler MaximizationChanged;
     29  }
    2830
    2931  [StorableType("9cc9422f-0bb5-41e8-9d9e-6e0b66a66449")]
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs

    r17315 r17317  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3738    where TEncodedSolution : class, IEncodedSolution {
    3839    #region Parameternames
    39     public const string MaximizationParameterName = "Maximization";
    4040    public const string BestKnownFrontParameterName = "BestKnownFront";
    4141    public const string ReferencePointParameterName = "ReferencePoint";
     
    4343
    4444    #region Parameterproperties
    45     public IValueParameter<BoolArray> MaximizationParameter {
    46       get { return (IValueParameter<BoolArray>)Parameters[MaximizationParameterName]; }
    47     }
     45    [Storable] public IValueParameter<BoolArray> MaximizationParameter { get; }
    4846    public IValueParameter<DoubleMatrix> BestKnownFrontParameter {
    4947      get { return (IValueParameter<DoubleMatrix>)Parameters[BestKnownFrontParameterName]; }
     
    6058    protected MultiObjectiveProblem(MultiObjectiveProblem<TEncoding, TEncodedSolution> original, Cloner cloner)
    6159      : base(original, cloner) {
     60      MaximizationParameter = cloner.Clone(original.MaximizationParameter);
    6261      ParameterizeOperators();
    6362    }
    6463
    6564    protected MultiObjectiveProblem() : base() {
    66       Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()));
     65      MaximizationParameter = new ValueParameter<BoolArray>("Maximization", "The dimensions correspond to the different objectives: False if the objective should be minimized, true if it should be maximized..", new BoolArray(new bool[] { }, @readonly: true));
     66      Parameters.Add(MaximizationParameter);
    6767      Parameters.Add(new OptionalValueParameter<DoubleMatrix>(BestKnownFrontParameterName, "A double matrix representing the best known qualites for this problem (aka points on the Pareto front). Points are to be given in a row-wise fashion."));
    6868      Parameters.Add(new OptionalValueParameter<DoubleArray>(ReferencePointParameterName, "The refrence point for hypervolume calculations on this problem"));
     
    7373
    7474    protected MultiObjectiveProblem(TEncoding encoding) : base(encoding) {
    75       Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()));
     75      MaximizationParameter = new ValueParameter<BoolArray>("Maximization", "The dimensions correspond to the different objectives: False if the objective should be minimized, true if it should be maximized..", new BoolArray(new bool[] { }, @readonly: true));
     76      Parameters.Add(MaximizationParameter);
    7677      Parameters.Add(new OptionalValueParameter<DoubleMatrix>(BestKnownFrontParameterName, "A double matrix representing the best known qualites for this problem (aka points on the Pareto front). Points are to be given in a row-wise fashion."));
    7778      Parameters.Add(new OptionalValueParameter<DoubleArray>(ReferencePointParameterName, "The refrence point for hypervolume calculations on this problem"));
     
    8990      get { return Maximization.Length; }
    9091    }
    91     public abstract bool[] Maximization { get; }
     92    public bool[] Maximization {
     93      get { return MaximizationParameter.Value.CloneAsArray(); }
     94      protected set {
     95        if (MaximizationParameter.Value.SequenceEqual(value)) return;
     96        MaximizationParameter.ForceValue(new BoolArray(value, @readonly: true));
     97        OnMaximizationChanged();
     98      }
     99    }
    92100
    93101    public virtual IReadOnlyList<double[]> BestKnownFront {
     
    168176    #region IMultiObjectiveHeuristicOptimizationProblem Members
    169177    IParameter IMultiObjectiveHeuristicOptimizationProblem.MaximizationParameter {
    170       get { return Parameters[MaximizationParameterName]; }
     178      get { return MaximizationParameter; }
    171179    }
    172180    IMultiObjectiveEvaluator IMultiObjectiveHeuristicOptimizationProblem.Evaluator {
     
    174182    }
    175183    #endregion
     184
     185    public event EventHandler MaximizationChanged;
     186    protected void OnMaximizationChanged() {
     187      MaximizationChanged?.Invoke(this, EventArgs.Empty);
     188    }
    176189  }
    177190}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r17279 r17317  
    5959      get { return MaximizationParameter.Value.Value; }
    6060      protected set {
    61         if (MaximizationParameter.Value.Value == value) return;
    62         MaximizationParameter.ReadOnly = false;
    63         MaximizationParameter.Value = new BoolValue(value).AsReadOnly();
    64         MaximizationParameter.ReadOnly = true;
     61        if (Maximization == value) return;
     62        MaximizationParameter.ForceValue(new BoolValue(value, @readonly: true));
     63        OnMaximizationChanged();
    6564      }
    6665    }
     
    185184    }
    186185    #endregion
     186
     187    public event EventHandler MaximizationChanged;
     188    protected void OnMaximizationChanged() {
     189      MaximizationChanged?.Invoke(this, EventArgs.Empty);
     190    }
    187191  }
    188192}
Note: See TracChangeset for help on using the changeset viewer.