#region License Information /* HeuristicLab * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Text; using System.Xml; using HeuristicLab.Core; using System.Globalization; namespace HeuristicLab.Data { /// /// Represents a double value having some constraints (e.g. smaller than 5.3). /// public class ConstrainedDoubleData : ConstrainedObjectData { /// /// Gets or sets the double value of the current instance as . /// /// Uses property of base /// class . No own data storage present. public new double Data { get { return ((DoubleData)base.Data).Data; } set { ((DoubleData)base.Data).Data = value; } } /// /// Initializes a new instance of with default value 0.0. /// public ConstrainedDoubleData() : this (0.0) { } /// /// Initializes a new instance of with the specified /// double value as . /// /// The double value to represent. public ConstrainedDoubleData(double data) : base() { base.Data = new DoubleData(data); } /// public virtual bool TrySetData(double data) { return base.TrySetData(new DoubleData(data)); } /// public virtual bool TrySetData(double data, out ICollection violatedConstraints) { return base.TrySetData(new DoubleData(data), out violatedConstraints); } /// /// Creates a new instance of . /// /// The created instance as . public override IView CreateView() { return new ConstrainedDoubleDataView(this); } /// /// Clones the current instance. /// /// Uses the implementation of base class . /// A dictionary of all already cloned objects. /// The cloned instance as . public override object Clone(IDictionary clonedObjects) { ConstrainedDoubleData clone = (ConstrainedDoubleData)base.Clone(clonedObjects); return clone; } /// /// Saves the current instance as in the specified . /// /// Uses the implementation of base class /// . The double value is saved as a /// in a child node having the tag name Value. /// The (tag)name of the . /// The where the data is saved. /// A dictionary of all already persisted objects. (Needed to avoid cycles.) /// The saved . public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary persistedObjects) { XmlNode node = base.GetXmlNode(name, document, persistedObjects); node.AppendChild(PersistenceManager.Persist("Value", (DoubleData) base.Data, document, persistedObjects)); return node; } /// /// Loads the persisted double value from the specified . /// /// The double value must be saved in the child node as a persisted /// having the tag name Value (see ). /// The where the double is saved. /// A dictionary of all already restored objects. (Needed to avoid cycles.) public override void Populate(XmlNode node, IDictionary restoredObjects) { base.Populate(node, restoredObjects); base.Data = (DoubleData)PersistenceManager.Restore(node.SelectSingleNode("Value"), restoredObjects); } } }