Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1688


Ignore:
Timestamp:
04/28/09 15:25:09 (15 years ago)
Author:
epitzer
Message:

Migrate HL.Random to new persistence library. (#603)

Location:
trunk/sources/HeuristicLab.Random/3.3
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Random/3.3/HeuristicLab.Random-3.3.csproj

    r1687 r1688  
    55    <ProductVersion>9.0.30729</ProductVersion>
    66    <SchemaVersion>2.0</SchemaVersion>
    7     <ProjectGuid>{47019A74-F7F7-482E-83AA-D3F4F777E879}</ProjectGuid>
     7    <ProjectGuid>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</ProjectGuid>
    88    <OutputType>Library</OutputType>
    99    <AppDesignerFolder>Properties</AppDesignerFolder>
    1010    <RootNamespace>HeuristicLab.Random</RootNamespace>
    11     <AssemblyName>HeuristicLab.Random-3.2</AssemblyName>
     11    <AssemblyName>HeuristicLab.Random-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' ">
     
    3637    <ErrorReport>prompt</ErrorReport>
    3738    <WarningLevel>4</WarningLevel>
    38     <DocumentationFile>bin\Release\HeuristicLab.Random-3.2.XML</DocumentationFile>
     39    <DocumentationFile>bin\Release\HeuristicLab.Random-3.3.xml</DocumentationFile>
    3940    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
    4041  </PropertyGroup>
     
    7576  <ItemGroup>
    7677    <Reference Include="System" />
     78    <Reference Include="System.Core">
     79      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     80    </Reference>
    7781    <Reference Include="System.Data" />
    7882    <Reference Include="System.Drawing" />
  • trunk/sources/HeuristicLab.Random/3.3/HeuristicLabRandomPlugin.cs

    r1530 r1688  
    2929  /// Plugin class for HeuristicLab.Random plugin.
    3030  /// </summary>
    31   [ClassInfo(Name = "HeuristicLab.Random-3.2")]
    32   [PluginFile(Filename = "HeuristicLab.Random-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.Random-3.3")]
     32  [PluginFile(Filename = "HeuristicLab.Random-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 = "HeuristicLab.Persistence-3.3")]
    3637  public class HeuristicLabRandomPlugin : PluginBase {
    3738  }
  • trunk/sources/HeuristicLab.Random/3.3/MersenneTwister.cs

    r1530 r1688  
    3737using System.Xml;
    3838using HeuristicLab.Core;
     39using HeuristicLab.Persistence.Default.Decomposers.Storable;
    3940
    4041namespace HeuristicLab.Random {
     
    4647
    4748    private object locker = new object();
     49    [Storable]
    4850    private uint[] state = new uint[n];
     51    [Storable]
    4952    private int p = 0;
     53    [Storable]
    5054    private bool init = false;
    5155
     
    154158      }
    155159    }
    156 
    157     #region Persistence Methods
    158     /// <summary>
    159     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    160     /// </summary>
    161     /// <remarks>The state(s) are saved as child node with the tag <c>State</c>, each state separaated with
    162     /// a semicolon. Also the elements <c>p</c> and the <c>init</c> flag are saved as child nodes with
    163     /// tag names <c>P</c> and <c>Init</c> respectively.</remarks>
    164     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    165     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    166     /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    167     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    168     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    169       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    170 
    171       StringBuilder builder = new StringBuilder();
    172       builder.Append(state[0]);
    173       for (int i = 1; i < state.Length; i++) {
    174         builder.Append(';');
    175         builder.Append(state[i]);
    176       }
    177       XmlNode stateNode = document.CreateNode(XmlNodeType.Element, "State", null);
    178       stateNode.InnerText = builder.ToString();
    179       node.AppendChild(stateNode);
    180 
    181       XmlNode pNode = document.CreateNode(XmlNodeType.Element, "P", null);
    182       pNode.InnerText = p.ToString();
    183       node.AppendChild(pNode);
    184 
    185       XmlNode initNode = document.CreateNode(XmlNodeType.Element, "Init", null);
    186       initNode.InnerText = init.ToString();
    187       node.AppendChild(initNode);
    188 
    189       return node;
    190     }
    191     /// <summary>
    192     /// Loads the persisted random number generator from the specified <paramref name="node"/>.
    193     /// </summary>
    194     /// <remarks>The elements of the current instance must be saved in a special way, see
    195     /// <see cref="GetXmlNode"/>.</remarks>
    196     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    197     /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    198     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    199       base.Populate(node, restoredObjects);
    200 
    201       string stateString = node.SelectSingleNode("State").InnerText;
    202       string[] tokens = stateString.Split(';');
    203       for (int i = 0; i < tokens.Length; i++)
    204         state[i] = uint.Parse(tokens[i]);
    205       p = int.Parse(node.SelectSingleNode("P").InnerText);
    206       init = bool.Parse(node.SelectSingleNode("Init").InnerText);
    207     }
    208     #endregion
    209160
    210161    #region Seed Methods
  • trunk/sources/HeuristicLab.Random/3.3/NormalDistributedRandom.cs

    r1530 r1688  
    2626using System.Xml;
    2727using System.Globalization;
     28using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2829
    2930namespace HeuristicLab.Random {
     
    3637  public class NormalDistributedRandom : ItemBase, IRandom {
    3738
     39    [Storable]
    3840    private double mu;
    39 
    4041    /// <summary>
    4142    /// Gets or sets the value for µ.
     
    4546      set { mu = value; }
    4647    }
     48
     49    [Storable]
    4750    private double sigma;
    48 
    4951    /// <summary>
    5052    /// Gets or sets the value for sigma.
     
    5456      set { sigma = value; }
    5557    }
     58
     59    [Storable]
    5660    private IRandom uniform;
     61
    5762    private double[] w = new double[] {
    5863      1.7290404664e-09,
     
    513518    /// <returns>A double random number.</returns>
    514519    public double NextDouble() {
    515       double signFactor = uniform.Next()%2==0?1.0:-1.0;
    516       return sigma* signFactor * NextPositiveDouble() + mu;
     520      double signFactor = uniform.Next() % 2 == 0 ? 1.0 : -1.0;
     521      return sigma * signFactor * NextPositiveDouble() + mu;
    517522    }
    518523
     
    520525      int j = uniform.Next();
    521526      int i = (j & 127);
    522       if(Math.Abs(j) < k[i]) {
     527      if (Math.Abs(j) < k[i]) {
    523528        return j * w[i];
    524529      } else {
     
    526531        double x, y;
    527532        x = j * w[i];
    528         if(i == 0) {
     533        if (i == 0) {
    529534          do {
    530535            x = -Math.Log(ScaledUniform()) * 0.2904764;
    531536            y = -Math.Log(ScaledUniform());
    532           } while(y + y < x * x);
     537          } while (y + y < x * x);
    533538          return (j > 0) ? r + x : -r - x;
    534539        }
    535         if(f[i] + ScaledUniform() * (f[i - 1] - f[i]) < Math.Exp(-0.5 * x * x)) {
     540        if (f[i] + ScaledUniform() * (f[i - 1] - f[i]) < Math.Exp(-0.5 * x * x)) {
    536541          return x;
    537542        } else {
     
    548553
    549554    #endregion
    550 
    551     #region persistence
    552     /// <summary>
    553     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    554     /// </summary>
    555     /// <remarks>The value of µ and sigma are saved as child nodes with tag names <c>Mu</c> and <c>Sigma</c>,
    556     /// also the random number generator is saved as a child node with tag name <c>UniformRandom</c>.</remarks>
    557     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    558     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    559     /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    560     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    561     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    562       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    563 
    564       XmlNode muNode = document.CreateNode(XmlNodeType.Element, "Mu", null);
    565       muNode.InnerText = mu.ToString("r", CultureInfo.InvariantCulture);
    566       node.AppendChild(muNode);
    567 
    568       XmlNode sigmaNode = document.CreateNode(XmlNodeType.Element, "Sigma", null);
    569       sigmaNode.InnerText = sigma.ToString("r", CultureInfo.InvariantCulture);
    570       node.AppendChild(sigmaNode);
    571 
    572       node.AppendChild(PersistenceManager.Persist("UniformRandom", uniform, document, persistedObjects));
    573 
    574       return node;
    575     }
    576 
    577     /// <summary>
    578     /// Loads the persisted normally distributed random variable from the specified <paramref name="node"/>.
    579     /// </summary>
    580     /// <remarks>The elements of the current instance must be saved in a special way, see
    581     /// <see cref="GetXmlNode"/>.</remarks>
    582     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    583     /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    584     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    585       base.Populate(node, restoredObjects);
    586 
    587       mu = double.Parse(node.SelectSingleNode("Mu").InnerText, CultureInfo.InvariantCulture);
    588       sigma = double.Parse(node.SelectSingleNode("Sigma").InnerText, CultureInfo.InvariantCulture);
    589       uniform = (IRandom)PersistenceManager.Restore(node.SelectSingleNode("UniformRandom"), restoredObjects);
    590     }
    591555
    592556    /// <summary>
     
    602566      return clone;
    603567    }
    604 
    605     #endregion
    606568  }
    607569}
  • trunk/sources/HeuristicLab.Random/3.3/Properties/AssemblyInfo.frame

    r581 r1688  
    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$")]
Note: See TracChangeset for help on using the changeset viewer.