Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/27/09 15:29:27 (15 years ago)
Author:
epitzer
Message:

Migrate HL.Constraints-3.3 to new persistence library. (#603)

Location:
trunk/sources/HeuristicLab.Constraints/3.3
Files:
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Constraints/3.3/AllSubOperatorsTypeConstraint.cs

    r1529 r1672  
    2727using System.Xml;
    2828using System.Diagnostics;
     29using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2930
    3031namespace HeuristicLab.Constraints {
     
    3435  public class AllSubOperatorsTypeConstraint : ConstraintBase {
    3536
     37    [Storable]
    3638    private SubOperatorTypeConstraint groupConstraint;
    3739    /// <summary>
     
    8688    public override bool Check(IItem data) {
    8789      IOperator op = data as IOperator;
    88       if(data == null) return false;
     90      if (data == null) return false;
    8991
    90       for(int i = 0; i < op.SubOperators.Count; i++) {
     92      for (int i = 0; i < op.SubOperators.Count; i++) {
    9193        groupConstraint.SubOperatorIndex.Data = i;
    92         if(groupConstraint.Check(data) == false) {
     94        if (groupConstraint.Check(data) == false) {
    9395          return false;
    9496        }
     
    126128      return new AllSubOperatorsTypeConstraintView(groupConstraint);
    127129    }
    128 
    129     #region persistence
    130     /// <summary>
    131     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    132     /// </summary>
    133     /// <remarks>The sub-operators are saved as a child node with tag name
    134     /// <c>SubOperatorsGroupConstraint</c>.</remarks>
    135     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    136     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    137     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    138     /// (Needed to avoid cycles.)</param>
    139     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    140     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    141       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    142       XmlNode subOperatorsNode = PersistenceManager.Persist("SubOperatorsGroupConstraint", groupConstraint, document, persistedObjects);
    143       node.AppendChild(subOperatorsNode);
    144 
    145       return node;
    146     }
    147 
    148     /// <summary>
    149     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    150     /// </summary>
    151     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    152     /// more information.</remarks>
    153     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    154     /// <param name="restoredObjects">The dictionary of all already restored objects.
    155     /// (Needed to avoid cycles.)</param>
    156     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    157       base.Populate(node, restoredObjects);
    158       groupConstraint = (SubOperatorTypeConstraint)PersistenceManager.Restore(node.SelectSingleNode("SubOperatorsGroupConstraint"), restoredObjects);
    159     }
    160     #endregion persistence
    161130  }
    162131}
  • trunk/sources/HeuristicLab.Constraints/3.3/AndConstraint.cs

    r1529 r1672  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2829
    2930namespace HeuristicLab.Constraints {
     
    3233  /// </summary>
    3334  public class AndConstraint : ConstraintBase, IViewable {
     35
     36    [Storable]
    3437    private ItemList<IConstraint> clauses;
    3538    /// <summary>
     
    6770    public override bool Check(IItem data) {
    6871      bool result = true;
    69       for (int i = 0 ; i < clauses.Count ; i++) {
     72      for (int i = 0; i < clauses.Count; i++) {
    7073        result = clauses[i].Check(data);
    7174        if (!result) return false;
     
    9699      return clone;
    97100    }
    98 
    99     #region persistence
    100     /// <summary>
    101     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    102     /// </summary>
    103     /// <remarks>The sub-constraints are saved as a child node with tag name
    104     /// <c>Clauses</c>.</remarks>
    105     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    106     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    107     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    108     /// (Needed to avoid cycles.)</param>
    109     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    110     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    111       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    112       XmlNode clausesNode = PersistenceManager.Persist("Clauses", Clauses, document, persistedObjects);
    113       node.AppendChild(clausesNode);
    114 
    115       return node;
    116     }
    117 
    118     /// <summary>
    119     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    120     /// </summary>
    121     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    122     /// more information.</remarks>
    123     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    124     /// <param name="restoredObjects">The dictionary of all already restored objects.
    125     /// (Needed to avoid cycles.)</param>
    126     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    127       base.Populate(node, restoredObjects);
    128       clauses = (ItemList<IConstraint>)PersistenceManager.Restore(node.SelectSingleNode("Clauses"), restoredObjects);
    129     }
    130     #endregion persistence
    131101  }
    132102}
  • trunk/sources/HeuristicLab.Constraints/3.3/ConstraintBase.cs

    r1529 r1672  
    2525using System.Xml;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2728
    2829namespace HeuristicLab.Constraints {
     
    3132  /// </summary>
    3233  public abstract class ConstraintBase : ItemBase, IConstraint {
    33     /// <inheritdoc select="summary"/>
     34
     35    /// <inheritdoc select="summary"/>   
    3436    public virtual string Description {
    3537      get { return "No constraint description available."; }
  • trunk/sources/HeuristicLab.Constraints/3.3/DoubleBoundedConstraint.cs

    r1529 r1672  
    2727using HeuristicLab.Data;
    2828using System.Globalization;
     29using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2930
    3031namespace HeuristicLab.Constraints {
     
    3334  /// </summary>
    3435  public class DoubleBoundedConstraint : ConstraintBase {
     36
     37    [Storable]
    3538    private double lowerBound;
    3639    /// <summary>
     
    4649      }
    4750    }
     51
     52    [Storable]
    4853    private bool lowerBoundIncluded;
    4954    /// <summary>
     
    5964      }
    6065    }
     66
     67    [Storable]
    6168    private bool lowerBoundEnabled;
    6269    /// <summary>
     
    7279      }
    7380    }
     81
     82    [Storable]
    7483    private double upperBound;
    7584    /// <summary>
     
    8594      }
    8695    }
     96
     97    [Storable]
    8798    private bool upperBoundIncluded;
    8899    /// <summary>
     
    98109      }
    99110    }
     111
     112    [Storable]
    100113    private bool upperBoundEnabled;
    101114    /// <summary>
     
    191204      return clone;
    192205    }
    193 
    194     #region persistence
    195     /// <summary>
    196     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    197     /// </summary>
    198     /// <remarks>The properties of the current instance are saved as attributes with special tag names.</remarks>
    199     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    200     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    201     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    202     /// (Needed to avoid cycles.)</param>
    203     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    204     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    205       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    206       XmlAttribute lb = document.CreateAttribute("LowerBound");
    207       lb.Value = LowerBound.ToString("r", CultureInfo.InvariantCulture);
    208       XmlAttribute lbi = document.CreateAttribute("LowerBoundIncluded");
    209       lbi.Value = lowerBoundIncluded.ToString();
    210       XmlAttribute lbe = document.CreateAttribute("LowerBoundEnabled");
    211       lbe.Value = lowerBoundEnabled.ToString();
    212       XmlAttribute ub = document.CreateAttribute("UpperBound");
    213       ub.Value = upperBound.ToString("r", CultureInfo.InvariantCulture);
    214       XmlAttribute ubi = document.CreateAttribute("UpperBoundIncluded");
    215       ubi.Value = upperBoundIncluded.ToString();
    216       XmlAttribute ube = document.CreateAttribute("UpperBoundEnabled");
    217       ube.Value = upperBoundEnabled.ToString();
    218       node.Attributes.Append(lb);
    219       if (!lowerBoundIncluded) node.Attributes.Append(lbi);
    220       if (!lowerBoundEnabled) node.Attributes.Append(lbe);
    221       node.Attributes.Append(ub);
    222       if (!upperBoundIncluded) node.Attributes.Append(ubi);
    223       if (!upperBoundEnabled) node.Attributes.Append(ube);
    224       return node;
    225     }
    226 
    227     /// <summary>
    228     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    229     /// </summary>
    230     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    231     /// more information.</remarks>
    232     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    233     /// <param name="restoredObjects">The dictionary of all already restored objects.
    234     /// (Needed to avoid cycles.)</param>
    235     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    236       base.Populate(node, restoredObjects);
    237       lowerBound = double.Parse(node.Attributes["LowerBound"].Value, CultureInfo.InvariantCulture);
    238       if (node.Attributes["LowerBoundIncluded"] != null) {
    239         lowerBoundIncluded = bool.Parse(node.Attributes["LowerBoundIncluded"].Value);
    240       } else {
    241         lowerBoundIncluded = true;
    242       }
    243       if (node.Attributes["LowerBoundEnabled"] != null) {
    244         lowerBoundEnabled = bool.Parse(node.Attributes["LowerBoundEnabled"].Value);
    245       } else {
    246         lowerBoundEnabled = true;
    247       }
    248 
    249       upperBound = double.Parse(node.Attributes["UpperBound"].Value, CultureInfo.InvariantCulture);
    250       if (node.Attributes["UpperBoundIncluded"] != null) {
    251         upperBoundIncluded = bool.Parse(node.Attributes["UpperBoundIncluded"].Value);
    252       } else {
    253         upperBoundIncluded = true;
    254       }
    255       if (node.Attributes["UpperBoundEnabled"] != null) {
    256         upperBoundEnabled = bool.Parse(node.Attributes["UpperBoundEnabled"].Value);
    257       } else {
    258         upperBoundEnabled = true;
    259       }
    260     }
    261     #endregion
    262206  }
    263207}
  • trunk/sources/HeuristicLab.Constraints/3.3/HeuristicLab.Constraints-3.3.csproj

    r1671 r1672  
    55    <ProductVersion>9.0.30729</ProductVersion>
    66    <SchemaVersion>2.0</SchemaVersion>
    7     <ProjectGuid>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</ProjectGuid>
     7    <ProjectGuid>{19C1E42A-4B48-4EFD-B697-899016F1C198}</ProjectGuid>
    88    <OutputType>Library</OutputType>
    99    <AppDesignerFolder>Properties</AppDesignerFolder>
    1010    <RootNamespace>HeuristicLab.Constraints</RootNamespace>
    11     <AssemblyName>HeuristicLab.Constraints-3.2</AssemblyName>
     11    <AssemblyName>HeuristicLab.Constraints-3.3</AssemblyName>
    1212    <SignAssembly>true</SignAssembly>
    1313    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
     
    1717    <UpgradeBackupLocation>
    1818    </UpgradeBackupLocation>
     19    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    1920  </PropertyGroup>
    2021  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     
    3435    <ErrorReport>prompt</ErrorReport>
    3536    <WarningLevel>4</WarningLevel>
    36     <DocumentationFile>bin\Release\HeuristicLab.Constraints-3.2.XML</DocumentationFile>
     37    <DocumentationFile>bin\Release\HeuristicLab.Constraints-3.3.xml</DocumentationFile>
    3738  </PropertyGroup>
    3839  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     
    7273  <ItemGroup>
    7374    <Reference Include="System" />
     75    <Reference Include="System.Core">
     76      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     77    </Reference>
    7478    <Reference Include="System.Data" />
    7579    <Reference Include="System.Drawing" />
     
    155159  </ItemGroup>
    156160  <ItemGroup>
    157     <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
    158       <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    159       <Name>HeuristicLab.Core-3.2</Name>
    160     </ProjectReference>
    161     <ProjectReference Include="..\..\HeuristicLab.Data\3.2\HeuristicLab.Data-3.2.csproj">
    162       <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
    163       <Name>HeuristicLab.Data-3.2</Name>
     161    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
     162      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
     163      <Name>HeuristicLab.Core-3.3</Name>
     164    </ProjectReference>
     165    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     166      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
     167      <Name>HeuristicLab.Data-3.3</Name>
     168    </ProjectReference>
     169    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
     170      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
     171      <Name>HeuristicLab.Persistence-3.3</Name>
    164172    </ProjectReference>
    165173    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
  • trunk/sources/HeuristicLab.Constraints/3.3/HeuristicLabConstraintsPlugin.cs

    r1529 r1672  
    2929  /// Plugin class for HeuristicLab.Constraints plugin.
    3030  /// </summary>
    31   [ClassInfo(Name = "HeuristicLab.Constraints-3.2")]
    32   [PluginFile(Filename = "HeuristicLab.Constraints-3.2.dll", Filetype = PluginFileType.Assembly)]
    33   [Dependency(Dependency = "HeuristicLab.Core-3.2")]
    34   [Dependency(Dependency = "HeuristicLab.Data-3.2")]
    35   [Dependency(Dependency = "HeuristicLab.Operators-3.2")]
     31  [ClassInfo(Name = "HeuristicLab.Constraints-3.3")]
     32  [PluginFile(Filename = "HeuristicLab.Constraints-3.3.dll", Filetype = PluginFileType.Assembly)]
     33  [Dependency(Dependency = "HeuristicLab.Core-3.3")]
     34  [Dependency(Dependency = "HeuristicLab.Data-3.3")]
     35  [Dependency(Dependency = "HeuristicLab.Operators-3.3")]
     36  [Dependency(Dependency = "HeurisitcLab.Persistence-3.3")]
    3637  public class HeuristicLabConstraintsPlugin : PluginBase {
    3738  }
  • trunk/sources/HeuristicLab.Constraints/3.3/IntBoundedConstraint.cs

    r1529 r1672  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2829
    2930namespace HeuristicLab.Constraints {
     
    3233  /// </summary>
    3334  public class IntBoundedConstraint : ConstraintBase {
     35
     36    [Storable]
    3437    private int lowerBound;
    3538    /// <summary>
     
    4548      }
    4649    }
     50
     51    [Storable]
    4752    private bool lowerBoundIncluded;
    4853    /// <summary>
     
    5863      }
    5964    }
     65
     66    [Storable]
    6067    private bool lowerBoundEnabled;
    6168    /// <summary>
     
    7178      }
    7279    }
     80
     81    [Storable]
    7382    private int upperBound;
    7483    /// <summary>
     
    8493      }
    8594    }
     95
     96    [Storable]
    8697    private bool upperBoundIncluded;
    8798    /// <summary>
     
    97108      }
    98109    }
     110
     111    [Storable]
    99112    private bool upperBoundEnabled;
    100113    /// <summary>
     
    128141    /// <param name="low">The lower bound of the constraint.</param>
    129142    /// <param name="high">The upper bound of the constraint.</param>
    130     public IntBoundedConstraint(int low, int high) : base() {
     143    public IntBoundedConstraint(int low, int high)
     144      : base() {
    131145      lowerBound = low;
    132146      lowerBoundIncluded = false;
     
    177191      return clone;
    178192    }
    179 
    180     #region persistence
    181     /// <summary>
    182     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    183     /// </summary>
    184     /// <remarks>The properties of the current instance are saved as attributes with special tag names.</remarks>
    185     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    186     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    187     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    188     /// (Needed to avoid cycles.)</param>
    189     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    190     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    191       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    192       XmlAttribute lb = document.CreateAttribute("LowerBound");
    193       lb.Value = LowerBound + "";
    194       XmlAttribute lbi = document.CreateAttribute("LowerBoundIncluded");
    195       lbi.Value = lowerBoundIncluded + "";
    196       XmlAttribute lbe = document.CreateAttribute("LowerBoundEnabled");
    197       lbe.Value = lowerBoundEnabled + "";
    198       XmlAttribute ub = document.CreateAttribute("UpperBound");
    199       ub.Value = upperBound + "";
    200       XmlAttribute ubi = document.CreateAttribute("UpperBoundIncluded");
    201       ubi.Value = upperBoundIncluded + "";
    202       XmlAttribute ube = document.CreateAttribute("UpperBoundEnabled");
    203       ube.Value = upperBoundEnabled + "";
    204       node.Attributes.Append(lb);
    205       if (!lowerBoundIncluded) node.Attributes.Append(lbi);
    206       if (!lowerBoundEnabled) node.Attributes.Append(lbe);
    207       node.Attributes.Append(ub);
    208       if (!upperBoundIncluded) node.Attributes.Append(ubi);
    209       if (!upperBoundEnabled) node.Attributes.Append(ube);
    210       return node;
    211     }
    212 
    213     /// <summary>
    214     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    215     /// </summary>
    216     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    217     /// more information.</remarks>
    218     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    219     /// <param name="restoredObjects">The dictionary of all already restored objects.
    220     /// (Needed to avoid cycles.)</param>
    221     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    222       base.Populate(node, restoredObjects);
    223       lowerBound = int.Parse(node.Attributes["LowerBound"].Value);
    224       if (node.Attributes["LowerBoundIncluded"] != null) {
    225         lowerBoundIncluded = bool.Parse(node.Attributes["LowerBoundIncluded"].Value);
    226       } else {
    227         lowerBoundIncluded = true;
    228       }
    229       if (node.Attributes["LowerBoundEnabled"] != null) {
    230         lowerBoundEnabled = bool.Parse(node.Attributes["LowerBoundEnabled"].Value);
    231       } else {
    232         lowerBoundEnabled = true;
    233       }
    234 
    235       upperBound = int.Parse(node.Attributes["UpperBound"].Value);
    236       if (node.Attributes["UpperBoundIncluded"] != null) {
    237         upperBoundIncluded = bool.Parse(node.Attributes["UpperBoundIncluded"].Value);
    238       } else {
    239         upperBoundIncluded = true;
    240       }
    241       if (node.Attributes["UpperBoundEnabled"] != null) {
    242         upperBoundEnabled = bool.Parse(node.Attributes["UpperBoundEnabled"].Value);
    243       } else {
    244         upperBoundEnabled = true;
    245       }
    246     }
    247     #endregion
    248193  }
    249194}
  • trunk/sources/HeuristicLab.Constraints/3.3/IsIntegerConstraint.cs

    r1529 r1672  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2728
    2829namespace HeuristicLab.Constraints {
     
    3031  /// Constraint that allows only integer values.
    3132  /// </summary>
    32   public class IsIntegerConstraint : ConstraintBase{
     33  [EmptyStorableClass]
     34  public class IsIntegerConstraint : ConstraintBase {
    3335    /// <inheritdoc select="summary"/>
    3436    public override string Description {
     
    4345    public override bool Check(IItem item) {
    4446      // ConstrainedIntData is always integer => just return true
    45       if(item is ConstrainedIntData)
     47      if (item is ConstrainedIntData)
    4648        return true;
    4749
    4850      // if we have an item of ConstrainedDoubleData then we check if it is integer or not
    49       if(item is ConstrainedDoubleData) {
     51      if (item is ConstrainedDoubleData) {
    5052        ConstrainedDoubleData d = (ConstrainedDoubleData)item;
    51         if(d.Data == Math.Truncate(d.Data)) {
     53        if (d.Data == Math.Truncate(d.Data)) {
    5254          return true;
    5355        } else {
  • trunk/sources/HeuristicLab.Constraints/3.3/ItemTypeConstraint.cs

    r1529 r1672  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2829
    2930namespace HeuristicLab.Constraints {
     
    3435  /// the type and not the <see cref="ConstrainedItemList"/> itself.</remarks>
    3536  public class ItemTypeConstraint : ConstraintBase {
     37
     38    [Storable]
    3639    private Type type;
    3740    /// <summary>
     
    9699    }
    97100
    98     #region clone & persistence
    99101    /// <summary>
    100102    /// Clones the current instance (deep clone).
     
    107109      return clone;
    108110    }
    109 
    110     /// <summary>
    111     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    112     /// </summary>
    113     /// <remarks>The type of the current instance is saved as attribute with tag name <c>ItemType</c>.</remarks>
    114     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    115     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    116     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    117     /// (Needed to avoid cycles.)</param>
    118     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    119     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    120       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    121       XmlAttribute itemTypeAttribute = document.CreateAttribute("ItemType");
    122       itemTypeAttribute.Value = PersistenceManager.BuildTypeString(Type);
    123       node.Attributes.Append(itemTypeAttribute);
    124       return node;
    125     }
    126 
    127     /// <summary>
    128     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    129     /// </summary>
    130     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    131     /// more information.</remarks>
    132     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    133     /// <param name="restoredObjects">The dictionary of all already restored objects.
    134     /// (Needed to avoid cycles.)</param>
    135     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    136       base.Populate(node, restoredObjects);
    137       XmlAttribute itemTypeAttribute = node.Attributes["ItemType"];
    138       type = Type.GetType(itemTypeAttribute.Value);
    139     }
    140     #endregion
    141111  }
    142112}
  • trunk/sources/HeuristicLab.Constraints/3.3/NotConstraint.cs

    r1529 r1672  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2829
    2930namespace HeuristicLab.Constraints {
     
    3233  /// </summary>
    3334  public class NotConstraint : ConstraintBase {
     35
     36    [Storable]
    3437    private ConstraintBase subConstraint;
    3538    /// <summary>
     
    8891      return clone;
    8992    }
    90 
    91     #region persistence
    92     /// <summary>
    93     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    94     /// </summary>
    95     /// <remarks>The sub-constraint is saved as a child node with tag name
    96     /// <c>SubConstraint</c>.</remarks>
    97     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    98     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    99     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    100     /// (Needed to avoid cycles.)</param>
    101     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    102     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    103       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    104       if (subConstraint != null) {
    105         XmlNode sub = PersistenceManager.Persist("SubConstraint", SubConstraint, document, persistedObjects);
    106         node.AppendChild(sub);
    107       }
    108       return node;
    109     }
    110 
    111     /// <summary>
    112     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    113     /// </summary>
    114     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    115     /// more information.</remarks>
    116     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    117     /// <param name="restoredObjects">The dictionary of all already restored objects.
    118     /// (Needed to avoid cycles.)</param>
    119     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    120       base.Populate(node, restoredObjects);
    121       XmlNode subNode =  node.SelectSingleNode("SubConstraint");
    122       if(subNode!=null)
    123         subConstraint = (ConstraintBase)PersistenceManager.Restore(subNode, restoredObjects);
    124     }
    125     #endregion
    12693  }
    12794}
  • trunk/sources/HeuristicLab.Constraints/3.3/NumberOfSubOperatorsConstraint.cs

    r1529 r1672  
    2727using HeuristicLab.Data;
    2828using System.Xml;
     29using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2930
    3031namespace HeuristicLab.Constraints {
     
    3334  /// </summary>
    3435  public class NumberOfSubOperatorsConstraint : ConstraintBase {
     36
     37    [Storable]
    3538    private IntData minOperators;
     39
     40    [Storable]
    3641    private IntData maxOperators;
    3742
     
    5964    /// </summary>
    6065    public NumberOfSubOperatorsConstraint()
    61       : this(0,0) {
     66      : this(0, 0) {
    6267    }
    6368
     
    6873    /// <param name="min">The minimum number of sub-operators.</param>
    6974    /// <param name="max">The maximum number of sub-operators.</param>
    70     public NumberOfSubOperatorsConstraint(int min, int max) : base() {
     75    public NumberOfSubOperatorsConstraint(int min, int max)
     76      : base() {
    7177      minOperators = new IntData(min);
    7278      maxOperators = new IntData(max);
     
    106112      return new NumberOfSubOperatorsConstraintView(this);
    107113    }
    108 
    109     #region persistence
    110     /// <summary>
    111     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    112     /// </summary>
    113     /// <remarks>The minimum and the maximum number of sub-operators are saved as child nodes with tag
    114     /// names <c>min</c> and <c>max</c>.</remarks>
    115     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    116     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    117     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    118     /// (Needed to avoid cycles.)</param>
    119     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    120     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    121       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    122       XmlNode minNode = PersistenceManager.Persist("min", minOperators, document, persistedObjects);
    123       XmlNode maxNode = PersistenceManager.Persist("max", maxOperators, document, persistedObjects);
    124       node.AppendChild(minNode);
    125       node.AppendChild(maxNode);
    126       return node;
    127     }
    128 
    129     /// <summary>
    130     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    131     /// </summary>
    132     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    133     /// more information.</remarks>
    134     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    135     /// <param name="restoredObjects">The dictionary of all already restored objects.
    136     /// (Needed to avoid cycles.)</param>
    137     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    138       base.Populate(node, restoredObjects);
    139       minOperators = (IntData)PersistenceManager.Restore(node.SelectSingleNode("min"), restoredObjects);
    140       maxOperators = (IntData)PersistenceManager.Restore(node.SelectSingleNode("max"), restoredObjects);
    141     }
    142     #endregion persistence
    143 
    144114  }
    145115}
  • trunk/sources/HeuristicLab.Constraints/3.3/OrConstraint.cs

    r1529 r1672  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2829
    2930namespace HeuristicLab.Constraints {
     
    3233  /// </summary>
    3334  public class OrConstraint : ConstraintBase, IViewable {
     35
     36    [Storable]
    3437    private ItemList<IConstraint> clauses;
    3538    /// <summary>
     
    6770    public override bool Check(IItem data) {
    6871      bool result = false;
    69       for (int i = 0 ; i < clauses.Count ; i++) {
     72      for (int i = 0; i < clauses.Count; i++) {
    7073        result = clauses[i].Check(data);
    7174        if (result) return true;
     
    9699      return clone;
    97100    }
    98 
    99     #region persistence
    100     /// <summary>
    101     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    102     /// </summary>
    103     /// <remarks>The sub-constraints are saved as a child node with tag name
    104     /// <c>Clauses</c>.</remarks>
    105     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    106     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    107     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    108     /// (Needed to avoid cycles.)</param>
    109     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    110     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    111       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    112       XmlNode clausesNode = PersistenceManager.Persist("Clauses", Clauses, document, persistedObjects);
    113       node.AppendChild(clausesNode);
    114 
    115       return node;
    116     }
    117 
    118     /// <summary>
    119     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    120     /// </summary>
    121     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    122     /// more information.</remarks>
    123     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    124     /// <param name="restoredObjects">The dictionary of all already restored objects.
    125     /// (Needed to avoid cycles.)</param>
    126     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    127       base.Populate(node, restoredObjects);
    128       clauses = (ItemList<IConstraint>)PersistenceManager.Restore(node.SelectSingleNode("Clauses"), restoredObjects);
    129     }
    130     #endregion persistence
    131101  }
    132102}
  • trunk/sources/HeuristicLab.Constraints/3.3/Properties/AssemblyInfo.frame

    r581 r1672  
    5454// You can specify all the values or you can default the Revision and Build Numbers
    5555// by using the '*' as shown below:
    56 [assembly: AssemblyVersion("3.2.0.$WCREV$")]
    57 [assembly: AssemblyFileVersion("3.2.0.$WCREV$")]
     56[assembly: AssemblyVersion("3.3.0.$WCREV$")]
     57[assembly: AssemblyFileVersion("3.3.0.$WCREV$")]
    5858[assembly: AssemblyBuildDate("$WCNOW$")]
  • trunk/sources/HeuristicLab.Constraints/3.3/SubOperatorsTypeConstraint.cs

    r1529 r1672  
    2727using System.Diagnostics;
    2828using System.Xml;
     29using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2930
    3031namespace HeuristicLab.Constraints {
     
    3334  /// </summary>
    3435  public class SubOperatorTypeConstraint : ConstraintBase {
     36
     37    [Storable]
    3538    private IntData subOperatorIndex;
    3639    /// <summary>
     
    4144    }
    4245
     46    [Storable]
    4347    private List<IOperator> subOperators;
    4448    /// <summary>
     
    7074    /// </summary>
    7175    /// <param name="index">The index of the sub-operator.</param>
    72     public SubOperatorTypeConstraint(int index) : base() {
     76    public SubOperatorTypeConstraint(int index)
     77      : base() {
    7378      subOperatorIndex = new IntData(index);
    7479      subOperators = new List<IOperator>();
     
    8186    /// <param name="op">The operator to add.</param>
    8287    public void AddOperator(IOperator op) {
    83       if(!subOperators.Contains(op)) {
     88      if (!subOperators.Contains(op)) {
    8489        subOperators.Add(op);
    8590        FireChanged();
     
    9398    /// <param name="op">The operator to remove.</param>
    9499    public void RemoveOperator(IOperator op) {
    95       if(subOperators.Contains(op)) {
     100      if (subOperators.Contains(op)) {
    96101        subOperators.Remove(op);
    97102        FireChanged();
     
    113118    public override bool Check(IItem data) {
    114119      IOperator op = data as IOperator;
    115       if(data == null) return false;
     120      if (data == null) return false;
    116121
    117       if(op.SubOperators.Count <= subOperatorIndex.Data) {
     122      if (op.SubOperators.Count <= subOperatorIndex.Data) {
    118123        return false;
    119124      }
     
    132137      clonedObjects.Add(Guid, clone);
    133138      clone.subOperatorIndex.Data = subOperatorIndex.Data;
    134       foreach(IOperator op in subOperators) {
     139      foreach (IOperator op in subOperators) {
    135140        clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
    136141      }
     
    146151      return new SubOperatorsTypeConstraintView(this);
    147152    }
    148 
    149     #region persistence
    150     /// <summary>
    151     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    152     /// </summary>
    153     /// <remarks>The index and the list of sub-operators are saved as child nodes with tag names
    154     /// <c>SubOperatorIndex</c> and <c>AllowedSubOperators</c>.</remarks>
    155     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    156     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    157     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    158     /// (Needed to avoid cycles.)</param>
    159     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    160     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    161       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    162       XmlNode indexNode = PersistenceManager.Persist("SubOperatorIndex", subOperatorIndex, document, persistedObjects);
    163       node.AppendChild(indexNode);
    164       XmlNode listNode = document.CreateNode(XmlNodeType.Element, "AllowedSubOperators", document.NamespaceURI);
    165       foreach(IOperator op in subOperators) {
    166         XmlNode opNode = PersistenceManager.Persist(op, document, persistedObjects);
    167         listNode.AppendChild(opNode);
    168       }
    169       node.AppendChild(listNode);
    170       return node;
    171     }
    172 
    173     /// <summary>
    174     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    175     /// </summary>
    176     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    177     /// more information.</remarks>
    178     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    179     /// <param name="restoredObjects">The dictionary of all already restored objects.
    180     /// (Needed to avoid cycles.)</param>
    181     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    182       base.Populate(node, restoredObjects);
    183       subOperatorIndex = (IntData)PersistenceManager.Restore(node.SelectSingleNode("SubOperatorIndex"), restoredObjects);
    184       subOperators = new List<IOperator>();
    185       foreach(XmlNode childNode in node.SelectSingleNode("AllowedSubOperators").ChildNodes) {
    186         subOperators.Add((IOperator)PersistenceManager.Restore(childNode, restoredObjects));
    187       }
    188     }
    189     #endregion persistence
    190153  }
    191154}
  • trunk/sources/HeuristicLab.Constraints/3.3/VariableComparisonConstraint.cs

    r1529 r1672  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2829
    2930namespace HeuristicLab.Constraints {
     
    3233  /// </summary>
    3334  public class VariableComparisonConstraint : ConstraintBase {
     35
     36    [Storable]
    3437    private StringData leftVarName;
    3538    /// <summary>
     
    4144    }
    4245
     46    [Storable]
    4347    private StringData rightVarName;
    4448    /// <summary>
     
    5054    }
    5155
     56    [Storable]
    5257    private IntData comparer;
    5358    /// <summary>
     
    125130    }
    126131
    127     #region clone & persistence
    128132    /// <summary>
    129133    /// Clones the current instance (deep clone).
     
    141145      return clone;
    142146    }
    143 
    144     /// <summary>
    145     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    146     /// </summary>
    147     /// <remarks>The variable names and the comparer are saved as child nodes with tag names
    148     /// <c>LeftVarName</c>, <c>RightVarName</c> and <c>Comparer</c>.</remarks>
    149     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    150     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    151     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    152     /// (Needed to avoid cycles.)</param>
    153     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    154     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    155       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    156       XmlNode leftNode = PersistenceManager.Persist("LeftVarName", LeftVarName, document, persistedObjects);
    157       node.AppendChild(leftNode);
    158       XmlNode rightNode = PersistenceManager.Persist("RightVarName", RightVarName, document, persistedObjects);
    159       node.AppendChild(rightNode);
    160       XmlNode comparerNode = PersistenceManager.Persist("Comparer", Comparer, document, persistedObjects);
    161       node.AppendChild(comparerNode);
    162       return node;
    163     }
    164 
    165     /// <summary>
    166     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    167     /// </summary>
    168     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    169     /// more information.</remarks>
    170     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    171     /// <param name="restoredObjects">The dictionary of all already restored objects.
    172     /// (Needed to avoid cycles.)</param>
    173     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    174       base.Populate(node, restoredObjects);
    175       leftVarName = (StringData)PersistenceManager.Restore(node.SelectSingleNode("LeftVarName"), restoredObjects);
    176       rightVarName = (StringData)PersistenceManager.Restore(node.SelectSingleNode("RightVarName"), restoredObjects);
    177       comparer = (IntData)PersistenceManager.Restore(node.SelectSingleNode("Comparer"), restoredObjects);
    178     }
    179     #endregion
    180147  }
    181148}
Note: See TracChangeset for help on using the changeset viewer.