[7128] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Operators;
|
---|
| 6 | using HeuristicLab.Parameters;
|
---|
| 7 | using HeuristicLab.Data;
|
---|
| 8 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 9 | using HeuristicLab.Core;
|
---|
| 10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 11 | using HeuristicLab.Common;
|
---|
| 12 |
|
---|
| 13 | namespace 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 | }
|
---|