Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11990 for trunk/sources


Ignore:
Timestamp:
02/12/15 16:32:37 (10 years ago)
Author:
mkommend
Message:

#2282: Added best known quality parameter to single-objective basic problem and new one-max problem.

Location:
trunk/sources
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs

    r11970 r11990  
    3333    ISingleObjectiveProblemDefinition, ISingleObjectiveHeuristicOptimizationProblem
    3434  where TEncoding : class, IEncoding {
     35
     36    protected IValueParameter<DoubleValue> BestKnownQualityParameter {
     37      get { return (IValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     38    }
     39
     40    public double BestKnownQuality {
     41      get {
     42        if (BestKnownQualityParameter.Value == null) return double.NaN;
     43        return BestKnownQualityParameter.Value.Value;
     44      }
     45      set {
     46        if (BestKnownQualityParameter.Value == null) BestKnownQualityParameter.Value = new DoubleValue(value);
     47        else BestKnownQualityParameter.Value.Value = value;
     48      }
     49    }
     50
    3551    [StorableConstructor]
    3652    protected SingleObjectiveBasicProblem(bool deserializing) : base(deserializing) { }
  • trunk/sources/HeuristicLab.Problems.Binary/3.3/BinaryProblem.cs

    r11987 r11990  
    2222#endregion
    2323
     24using System;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    3334  [StorableClass]
    3435  public abstract class BinaryProblem : SingleObjectiveBasicProblem<BinaryVectorEncoding> {
    35 
    3636    public virtual int Length {
    3737      get { return Encoding.Length; }
     
    3939    }
    4040
     41    private IFixedValueParameter<IntValue> LengthParameter {
     42      get { return (IFixedValueParameter<IntValue>)Parameters["Length"]; }
     43    }
     44
    4145    [StorableConstructor]
    4246    protected BinaryProblem(bool deserializing) : base(deserializing) { }
    43     protected BinaryProblem(BinaryProblem original, Cloner cloner) : base(original, cloner) { }
    44     protected BinaryProblem() : base() { }
     47    [StorableHook(HookType.AfterDeserialization)]
     48    private void AfterDeserialization() {
     49      RegisterEventHandlers();
     50    }
     51
     52    protected BinaryProblem(BinaryProblem original, Cloner cloner)
     53      : base(original, cloner) {
     54      RegisterEventHandlers();
     55    }
     56
     57    protected BinaryProblem()
     58      : base() {
     59      var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(10));
     60      Parameters.Add(lengthParameter);
     61      Encoding.LengthParameter = lengthParameter;
     62      RegisterEventHandlers();
     63    }
    4564
    4665    public virtual bool IsBetter(double quality, double bestQuality) {
     
    5372
    5473    public abstract double Evaluate(BinaryVector vector, IRandom random);
     74
     75    protected override void OnEncodingChanged() {
     76      base.OnEncodingChanged();
     77      Encoding.LengthParameter = LengthParameter;
     78    }
     79
     80
     81    private void RegisterEventHandlers() {
     82      LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     83    }
     84
     85    protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
    5586  }
    5687}
  • trunk/sources/HeuristicLab.Problems.Binary/3.3/HeuristicLab.Problems.Binary-3.3.csproj

    r11987 r11990  
    8686    <Compile Include="DeceptiveTrapProblem.cs" />
    8787    <Compile Include="HIFFProblem.cs" />
     88    <Compile Include="OneMaxProblem.cs" />
    8889    <Compile Include="Plugin.cs" />
    8990    <Compile Include="Properties\AssemblyInfo.cs" />
Note: See TracChangeset for help on using the changeset viewer.