Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/26/19 10:02:47 (5 years ago)
Author:
abeham
Message:

#2521: worked on removing virtual from Maximization for single-objective problems

File:
1 edited

Legend:

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

    r17226 r17270  
    3838    where TEncodedSolution : class, IEncodedSolution {
    3939
    40     protected IValueParameter<DoubleValue> BestKnownQualityParameter {
    41       get { return (IValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    42     }
    43 
    44     protected IFixedValueParameter<BoolValue> MaximizationParameter {
    45       get { return (IFixedValueParameter<BoolValue>)Parameters["Maximization"]; }
    46     }
     40    [Storable] protected IValueParameter<DoubleValue> BestKnownQualityParameter { get; set; }
     41    [Storable] protected IValueParameter<BoolValue> MaximizationParameter { get; set; }
    4742
    4843    public double BestKnownQuality {
     
    6156    }
    6257
     58    public bool Maximization {
     59      get { return MaximizationParameter.Value.Value; }
     60      protected set {
     61        if (MaximizationParameter.Value.Value == value) return;
     62        MaximizationParameter.Value = new BoolValue(value).AsReadOnly();
     63      }
     64    }
     65
    6366    [StorableConstructor]
    6467    protected SingleObjectiveProblem(StorableConstructorFlag _) : base(_) { }
     
    6669    protected SingleObjectiveProblem(SingleObjectiveProblem<TEncoding, TEncodedSolution> original, Cloner cloner)
    6770      : base(original, cloner) {
     71      BestKnownQualityParameter = cloner.Clone(original.BestKnownQualityParameter);
     72      MaximizationParameter = cloner.Clone(original.MaximizationParameter);
    6873      ParameterizeOperators();
    6974    }
    7075 
    7176    protected SingleObjectiveProblem() : base() {
    72       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
    73       Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
     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."));
    7479
    7580      Operators.Add(Evaluator);
     
    8489
    8590    protected SingleObjectiveProblem(TEncoding encoding) : base(encoding) {
    86       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
    87       Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
     91      Parameters.Add(MaximizationParameter = new ValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue(false).AsReadOnly()) { Hidden = true, ReadOnly = true });
     92      Parameters.Add(BestKnownQualityParameter = new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
    8893
    8994      Operators.Add(Evaluator);
     
    102107    }
    103108
    104     public abstract bool Maximization { get; }
    105109    public abstract double Evaluate(TEncodedSolution solution, IRandom random);
    106110    public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { }
Note: See TracChangeset for help on using the changeset viewer.