using System; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Data; using HeuristicLab.Encodings.RealVectorEncoding; using HeuristicLab.Core; using HeuristicLab.Common; using HEAL.Attic; namespace HeuristicLab.Analysis.FitnessLandscape { [Item("RealVectorBoundingBoxUpdater", "Updates a bounding box using a real vector to be enclosed.")] [StorableType("1EBAC56C-83F0-41C1-8E42-365E7187EA0D")] public class RealVectorBoundingBoxUpdater : SingleSuccessorOperator { #region Parameter Properties public LookupParameter BoundingBoxParameter { get { return (LookupParameter)Parameters["BoundingBox"]; } } public LookupParameter RealVectorParameter { get { return (LookupParameter)Parameters["RealVector"]; } } #endregion #region Parameter Values public RealVector RealVector { get { return RealVectorParameter.ActualValue; } } public DoubleMatrix Bounds { get { return BoundingBoxParameter.ActualValue; } set { BoundingBoxParameter.ActualValue = value; } } #endregion #region Construction and Cloning [StorableConstructor] protected RealVectorBoundingBoxUpdater(StorableConstructorFlag _) : base(_) { } protected RealVectorBoundingBoxUpdater(RealVectorBoundingBoxUpdater original, Cloner cloner) : base(original, cloner) { } public RealVectorBoundingBoxUpdater() { Parameters.Add(new LookupParameter("RealVector", "The real vector used to update the bounding box")); Parameters.Add(new LookupParameter("BoundingBox", "The Bounding Box to be updated or created")); } public override IDeepCloneable Clone(Cloner cloner) { return new RealVectorBoundingBoxUpdater(this, cloner); } #endregion public override IOperation Apply() { if (Bounds == null) { Bounds = new DoubleMatrix(RealVector.Length, 2); for (int i = 0; i < RealVector.Length; i++) Bounds[i, 0] = Bounds[i, 1] = RealVector[i]; } else { for (int i = 0; i < RealVector.Length; i++) { Bounds[i, 0] = Math.Min(Bounds[i, 0], RealVector[i]); Bounds[i, 1] = Math.Max(Bounds[i, 1], RealVector[i]); } } return base.Apply(); } } }