using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Data; using HeuristicLab.Encodings.RealVectorEncoding; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; namespace HeuristicLab.Analysis.FitnessLandscape { [Item("RealVectorBoundingBoxUpdater", "Updates a bounding box using a real vector to be enclosed.")] [StorableClass] 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(bool deserializing) : base(deserializing) { } 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(); } } }