Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3894


Ignore:
Timestamp:
06/02/10 21:34:31 (15 years ago)
Author:
abeham
Message:

#1029

  • Added Bounds to SingleObjectiveTestFunctionSolution
  • This would break persistence, so I added a CompatibilityMethod (which can be removed again once moving to 3.4)
Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/SingleObjectiveTestFunctionSolutionView.cs

    r3668 r3894  
    5555      Content.QualityChanged -= new EventHandler(Content_QualityChanged);
    5656      Content.PopulationChanged -= new EventHandler(Content_PopulationChanged);
     57      Content.BoundsChanged -= new EventHandler(Content_BoundsChanged);
    5758      base.DeregisterContentEvents();
    5859    }
     
    6364      Content.QualityChanged += new EventHandler(Content_QualityChanged);
    6465      Content.PopulationChanged += new EventHandler(Content_PopulationChanged);
     66      Content.BoundsChanged += new EventHandler(Content_BoundsChanged);
    6567    }
    6668
     
    99101        GenerateImage();
    100102      }
     103    }
     104
     105    private void Content_BoundsChanged(object sender, EventArgs e) {
     106      if (InvokeRequired)
     107        Invoke(new EventHandler(Content_BoundsChanged), sender, e);
     108      else
     109        GenerateImage();
    101110    }
    102111
     
    139148          }
    140149          pictureBox.Refresh();
    141           DoubleMatrix bounds = Content.Evaluator.Bounds;
     150          DoubleMatrix bounds = Content.Bounds;
     151          if (bounds == null) bounds = Content.Evaluator.Bounds;
    142152          double xMin = bounds[0, 0], xMax = bounds[0, 1], yMin = bounds[1 % bounds.Rows, 0], yMax = bounds[1 % bounds.Rows, 1];
    143153          double xStep = backgroundImage.Width / (xMax - xMin), yStep = backgroundImage.Height / (yMax - yMin);
     
    164174        backgroundImage.Dispose();
    165175      backgroundImage = new Bitmap(pictureBox.Width, pictureBox.Height);
    166       DoubleMatrix bounds = Content.Evaluator.Bounds;
     176      DoubleMatrix bounds = Content.Bounds;
     177      if (bounds == null) bounds = Content.Evaluator.Bounds;
    167178      double xMin = bounds[0, 0], xMax = bounds[0, 1], yMin = bounds[1 % bounds.Rows, 0], yMax = bounds[1 % bounds.Rows, 1];
    168179      double xStep = (xMax - xMin) / backgroundImage.Width, yStep = (yMax - yMin) / backgroundImage.Height;
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs

    r3797 r3894  
    6969      get { return (IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>)Parameters["Evaluator"]; }
    7070    }
     71    public ILookupParameter<DoubleMatrix> BoundsParameter {
     72      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
     73    }
    7174
     75    protected BestSingleObjectiveTestFunctionSolutionAnalyzer(bool deserializing) : base(deserializing) { }
    7276    public BestSingleObjectiveTestFunctionSolutionAnalyzer()
    7377      : base() {
     
    8084      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the SingleObjectiveTestFunction solution should be stored."));
    8185      Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator", "The evaluator with which the solution is evaluated."));
     86      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The bounds of the function."));
     87    }
     88
     89    /// <summary>
     90    /// This method can simply be removed when the plugin version is > 3.3
     91    /// </summary>
     92    [StorableHook(HookType.AfterDeserialization)]
     93    private void CompatibilityMethod() {
     94      // Bounds are introduced in 3.3.0.3894
     95      if (!Parameters.ContainsKey("Bounds"))
     96        Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The bounds of the function."));
    8297    }
    8398
     
    85100      ItemArray<RealVector> realVectors = RealVectorParameter.ActualValue;
    86101      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    87       ResultCollection results = ResultsParameter.ActualValue;
    88       ISingleObjectiveTestFunctionProblemEvaluator evaluator = EvaluatorParameter.ActualValue;
    89102      bool max = MaximizationParameter.ActualValue.Value;
    90103      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
     104      SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue;
    91105
    92106      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     
    97111        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    98112        BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();
     113        if (solution != null)
     114          solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue;
    99115      }
    100116
    101       SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue;
    102117      if (solution == null) {
    103         solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], evaluator);
     118        ResultCollection results = ResultsParameter.ActualValue;
     119        solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], EvaluatorParameter.ActualValue);
    104120        solution.Population = realVectors;
    105121        solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue;
     122        solution.Bounds = BoundsParameter.ActualValue;
    106123        BestSolutionParameter.ActualValue = solution;
    107124        results.Add(new Result("Best Solution", solution));
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Interfaces/IBestSingleObjectiveTestFunctionSolutionAnalyzer.cs

    r3647 r3894  
    2626namespace HeuristicLab.Problems.TestFunctions {
    2727  /// <summary>
    28   /// An interface which represents operators for analyzing the best solution of single objective TestFunction Problems given in bit vector representation.
     28  /// An interface which represents operators for analyzing the best solution of single objective TestFunction Problems given in real vector representation.
    2929  /// </summary>
    3030  public interface IBestSingleObjectiveTestFunctionSolutionAnalyzer : IAnalyzer {
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r3865 r3894  
    307307      BestSingleObjectiveTestFunctionSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
    308308      BestSingleObjectiveTestFunctionSolutionAnalyzer.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
     309      BestSingleObjectiveTestFunctionSolutionAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name;
    309310    }
    310311    private void InitializeOperators() {
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionSolution.cs

    r3665 r3894  
    108108    }
    109109
     110    [Storable]
     111    private DoubleMatrix bounds;
     112    public DoubleMatrix Bounds {
     113      get { return bounds; }
     114      set {
     115        if (bounds != value) {
     116          if (bounds != null) DeregisterBoundsEvents();
     117          bounds = value;
     118          if (bounds != null) RegisterBoundsEvents();
     119          OnBoundsChanged();
     120        }
     121      }
     122    }
     123
    110124    public SingleObjectiveTestFunctionSolution() : base() { }
    111125    public SingleObjectiveTestFunctionSolution(RealVector realVector, DoubleValue quality, ISingleObjectiveTestFunctionProblemEvaluator evaluator)
     
    125139      if (bestQuality != null) RegisterQualityEvents();
    126140      if (population != null) RegisterPopulationEvents();
     141      if (bounds != null) RegisterBoundsEvents();
    127142    }
    128143
     
    135150      clone.population = (ItemArray<RealVector>)cloner.Clone(population);
    136151      clone.evaluator = (ISingleObjectiveTestFunctionProblemEvaluator)cloner.Clone(evaluator);
     152      clone.bounds = (DoubleMatrix)cloner.Clone(bounds);
    137153      clone.Initialize();
    138154      return clone;
     
    175191    }
    176192
     193    public event EventHandler BoundsChanged;
     194    private void OnBoundsChanged() {
     195      var changed = BoundsChanged;
     196      if (changed != null)
     197        changed(this, EventArgs.Empty);
     198    }
     199
    177200    private void RegisterBestKnownRealVectorEvents() {
    178201      BestKnownRealVector.ItemChanged += new EventHandler<EventArgs<int>>(BestKnownRealVector_ItemChanged);
     
    207230      Population.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RealVector>>(Population_ItemsReplaced);
    208231    }
     232    private void RegisterBoundsEvents() {
     233      Bounds.ItemChanged += new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
     234      Bounds.Reset += new EventHandler(Bounds_Reset);
     235    }
     236    private void DeregisterBoundsEvents() {
     237      Bounds.ItemChanged -= new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
     238      Bounds.Reset -= new EventHandler(Bounds_Reset);
     239    }
    209240
    210241    private void BestKnownRealVector_ItemChanged(object sender, EventArgs<int> e) {
     
    231262    private void Population_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<RealVector>> e) {
    232263      OnPopulationChanged();
     264    }
     265    private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
     266      OnBoundsChanged();
     267    }
     268    private void Bounds_Reset(object sender, EventArgs e) {
     269      OnBoundsChanged();
    233270    }
    234271    #endregion
Note: See TracChangeset for help on using the changeset viewer.