1 | using System;
|
---|
2 | using HeuristicLab.Operators;
|
---|
3 | using HeuristicLab.Parameters;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Common;
|
---|
8 | using HEAL.Attic;
|
---|
9 |
|
---|
10 | namespace 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 | }
|
---|