Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/RealVectorBoundingBoxUpdater.cs @ 11194

Last change on this file since 11194 was 7128, checked in by epitzer, 13 years ago

#1696 Integrate fitness landscape analysis plugins from Heureka! repository.

File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Operators;
6using HeuristicLab.Parameters;
7using HeuristicLab.Data;
8using HeuristicLab.Encodings.RealVectorEncoding;
9using HeuristicLab.Core;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using HeuristicLab.Common;
12
13namespace HeuristicLab.Analysis.FitnessLandscape {
14 
15  [Item("RealVectorBoundingBoxUpdater", "Updates a bounding box using a real vector to be enclosed.")]
16  [StorableClass]
17  public class RealVectorBoundingBoxUpdater : SingleSuccessorOperator {
18
19    #region Parameter Properties
20    public LookupParameter<DoubleMatrix> BoundingBoxParameter {
21      get { return (LookupParameter<DoubleMatrix>)Parameters["BoundingBox"]; }
22    }
23    public LookupParameter<RealVector> RealVectorParameter {
24      get { return (LookupParameter<RealVector>)Parameters["RealVector"]; }
25    }
26    #endregion
27
28    #region Parameter Values
29    public RealVector RealVector {
30      get { return RealVectorParameter.ActualValue; }
31    }
32    public DoubleMatrix Bounds {
33      get { return BoundingBoxParameter.ActualValue; }
34      set { BoundingBoxParameter.ActualValue = value; }
35    }
36    #endregion
37
38    #region Construction and Cloning
39
40    [StorableConstructor]
41    protected RealVectorBoundingBoxUpdater(bool deserializing) : base(deserializing) { }
42    protected RealVectorBoundingBoxUpdater(RealVectorBoundingBoxUpdater original, Cloner cloner)
43      : base(original, cloner) {
44    }
45    public RealVectorBoundingBoxUpdater() {
46      Parameters.Add(new LookupParameter<RealVector>("RealVector", "The real vector used to update the bounding box"));
47      Parameters.Add(new LookupParameter<DoubleMatrix>("BoundingBox", "The Bounding Box to be updated or created"));
48    }
49    public override IDeepCloneable Clone(Cloner cloner) {
50      return new RealVectorBoundingBoxUpdater(this, cloner);
51    }
52    #endregion
53
54    public override IOperation Apply() {
55      if (Bounds == null) {
56        Bounds = new DoubleMatrix(RealVector.Length, 2);
57        for (int i = 0; i < RealVector.Length; i++)
58          Bounds[i, 0] = Bounds[i, 1] = RealVector[i];
59      } else {
60        for (int i = 0; i < RealVector.Length; i++) {
61          Bounds[i, 0] = Math.Min(Bounds[i, 0], RealVector[i]);
62          Bounds[i, 1] = Math.Max(Bounds[i, 1], RealVector[i]);
63        }
64      }
65      return base.Apply();
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.