Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/RealVectorBoundingBoxUpdater.cs @ 17514

Last change on this file since 17514 was 16995, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.FLA for new persistence

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