Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/27/19 17:51:35 (5 years ago)
Author:
mkommend
Message:

#2521: Updated single-objective problem to include a static is better method and fixed setter of maximization property.

File:
1 edited

Legend:

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

    r17270 r17279  
    3838    where TEncodedSolution : class, IEncodedSolution {
    3939
    40     [Storable] protected IValueParameter<DoubleValue> BestKnownQualityParameter { get; set; }
    41     [Storable] protected IValueParameter<BoolValue> MaximizationParameter { get; set; }
     40    [Storable] protected IValueParameter<DoubleValue> BestKnownQualityParameter { get; }
     41    [Storable] protected IValueParameter<BoolValue> MaximizationParameter { get; }
    4242
    4343    public double BestKnownQuality {
     
    6060      protected set {
    6161        if (MaximizationParameter.Value.Value == value) return;
     62        MaximizationParameter.ReadOnly = false;
    6263        MaximizationParameter.Value = new BoolValue(value).AsReadOnly();
     64        MaximizationParameter.ReadOnly = true;
    6365      }
    6466    }
     
    7375      ParameterizeOperators();
    7476    }
    75  
     77
    7678    protected SingleObjectiveProblem() : base() {
    77       Parameters.Add(MaximizationParameter = new ValueParameter<BoolValue>("Maximization", "Whether the problem should be maximized (True) or minimized (False).", new BoolValue(false).AsReadOnly()) { Hidden = true, ReadOnly = true });
    78       Parameters.Add(BestKnownQualityParameter = new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
     79
     80      MaximizationParameter = new ValueParameter<BoolValue>("Maximization", "Whether the problem should be maximized (True) or minimized (False).", new BoolValue(false).AsReadOnly()) { Hidden = true, ReadOnly = true };
     81      BestKnownQualityParameter = new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.");
     82
     83      Parameters.Add(MaximizationParameter);
     84      Parameters.Add(BestKnownQualityParameter);
    7985
    8086      Operators.Add(Evaluator);
     
    113119    }
    114120
     121    public static bool IsBetter(bool maximization, double quality, double bestQuality) {
     122      return (maximization && quality > bestQuality || !maximization && quality < bestQuality);
     123    }
     124
    115125    public virtual bool IsBetter(double quality, double bestQuality) {
    116       return (Maximization && quality > bestQuality || !Maximization && quality < bestQuality);
     126      return IsBetter(Maximization, quality, bestQuality);
    117127    }
    118128
Note: See TracChangeset for help on using the changeset viewer.