Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17279


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.

Location:
branches/2521_ProblemRefactoring
Files:
2 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
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs

    r17270 r17279  
    9393    public ExternalEvaluationProblem(TEncoding encoding)
    9494      : base(encoding) {
    95       MaximizationParameter.ReadOnly = false;
    96       MaximizationParameter.Value = new BoolValue(); // is a read-only boolvalue in base class
     95      MaximizationParameter.Value = new BoolValue(); // is a read-only bool value in base class
    9796      Parameters.Add(new OptionalValueParameter<EvaluationCache>("Cache", "Cache of previously evaluated solutions."));
    9897      Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() }));
     
    148147      try {
    149148        return client.Evaluate(message, GetQualityMessageExtensions());
    150       }
    151       finally {
     149      } finally {
    152150        lock (clientLock) {
    153151          activeClients.Remove(client);
     
    166164          try {
    167165            MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder);
    168           }
    169           catch (ArgumentException ex) {
     166          } catch (ArgumentException ex) {
    170167            throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex);
    171168          }
Note: See TracChangeset for help on using the changeset viewer.