Changeset 2794


Ignore:
Timestamp:
02/14/10 05:31:49 (11 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on operators
Location:
trunk/sources
Files:
3 added
4 deleted
34 edited
4 moved

Legend:

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

    r2790 r2794  
    8484    <Compile Include="HeuristicLabEvolutionaryPlugin.cs" />
    8585    <Compile Include="Properties\AssemblyInfo.cs" />
     86    <Compile Include="ChildrenCreator.cs" />
    8687  </ItemGroup>
    8788  <ItemGroup>
     
    9091  </ItemGroup>
    9192  <ItemGroup>
     93    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
     94      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
     95      <Name>HeuristicLab.Collections-3.3</Name>
     96    </ProjectReference>
    9297    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
    9398      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
     
    101106      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
    102107      <Name>HeuristicLab.Operators-3.3</Name>
     108    </ProjectReference>
     109    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
     110      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
     111      <Name>HeuristicLab.Parameters-3.3</Name>
     112    </ProjectReference>
     113    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
     114      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
     115      <Name>HeuristicLab.Persistence-3.3</Name>
    103116    </ProjectReference>
    104117    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
  • trunk/sources/HeuristicLab.Evolutionary/3.3/HeuristicLabEvolutionaryPlugin.cs.frame

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.PluginInfrastructure;
    2623
     
    3128  [Plugin("HeuristicLab.Evolutionary", "3.3.0.$WCREV$")]
    3229  [PluginFile("HeuristicLab.Evolutionary-3.3.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3331  [PluginDependency("HeuristicLab.Core", "3.3")]
    3432  [PluginDependency("HeuristicLab.Data", "3.3")]
    3533  [PluginDependency("HeuristicLab.Operators", "3.3")]
     34  [PluginDependency("HeuristicLab.Parameters", "3.3")]
     35  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    3636  public class HeuristicLabEvolutionaryPlugin : PluginBase {
    3737  }
  • trunk/sources/HeuristicLab.Operators/3.3/Assigner.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2723using HeuristicLab.Parameters;
    2824using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
  • trunk/sources/HeuristicLab.Operators/3.3/CombinedOperator.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using System.Drawing;
    25 using System.Text;
    26 using System.Xml;
    2723using HeuristicLab.Collections;
    2824using HeuristicLab.Core;
    29 using HeuristicLab.Data;
    3025using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3126
  • trunk/sources/HeuristicLab.Operators/3.3/Comparator.cs

    r2790 r2794  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     
    3028namespace HeuristicLab.Operators {
    3129  /// <summary>
    32   /// Operator which increments an integer variable.
     30  /// An operator which compares two items.
    3331  /// </summary>
    3432  [Item("Comparator", "An operator which compares two items.")]
  • trunk/sources/HeuristicLab.Operators/3.3/ConditionalBranch.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Operators/3.3/DoubleCounter.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    2623using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Operators/3.3/EmptyOperator.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
     22using HeuristicLab.Core;
    2623using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using HeuristicLab.Core;
    2824
    2925namespace HeuristicLab.Operators {
  • trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r2773 r2794  
    9898    <Compile Include="SequentialSubScopesProcessor.cs" />
    9999    <Compile Include="StochasticBranch.cs" />
     100    <Compile Include="SubScopesCreator.cs" />
    100101    <Compile Include="SubScopesRemover.cs" />
    101102    <Compile Include="SubScopesSorter.cs" />
     
    110111    <Compile Include="Properties\AssemblyInfo.cs" />
    111112    <Compile Include="SingleSuccessorOperator.cs" />
    112     <Compile Include="SubScopesCreater.cs" />
    113113    <Compile Include="ValuesCollector.cs" />
    114     <Compile Include="VariableInjector.cs">
    115       <SubType>Code</SubType>
    116     </Compile>
     114    <Compile Include="VariableCreator.cs" />
    117115  </ItemGroup>
    118116  <ItemGroup>
  • trunk/sources/HeuristicLab.Operators/3.3/HeuristicLabOperatorsPlugin.cs.frame

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.PluginInfrastructure;
    2623
  • trunk/sources/HeuristicLab.Operators/3.3/IntCounter.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    2623using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Operators/3.3/MultipleCallsOperator.cs

    r2790 r2794  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
    26 using System.Xml;
    2724using HeuristicLab.Collections;
    2825using HeuristicLab.Core;
  • trunk/sources/HeuristicLab.Operators/3.3/Operator.cs

    r2793 r2794  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2623using System.Drawing;
     24using HeuristicLab.Collections;
     25using HeuristicLab.Core;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Core;
    29 using HeuristicLab.Collections;
    3027
    3128namespace HeuristicLab.Operators {
  • trunk/sources/HeuristicLab.Operators/3.3/ParallelSubScopesProcessor.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Xml;
    27 using HeuristicLab.Collections;
    2822using HeuristicLab.Core;
    29 using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3123
    3224namespace HeuristicLab.Operators {
  • trunk/sources/HeuristicLab.Operators/3.3/Placeholder.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Parameters;
  • trunk/sources/HeuristicLab.Operators/3.3/ScopeCleaner.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    2623using HeuristicLab.Parameters;
  • trunk/sources/HeuristicLab.Operators/3.3/SequentialSubScopesProcessor.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Xml;
    27 using HeuristicLab.Collections;
    2822using HeuristicLab.Core;
    29 using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3123
    3224namespace HeuristicLab.Operators {
  • trunk/sources/HeuristicLab.Operators/3.3/SingleCallOperator.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Parameters;
  • trunk/sources/HeuristicLab.Operators/3.3/SingleSuccessorOperator.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Parameters;
  • trunk/sources/HeuristicLab.Operators/3.3/StochasticBranch.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesCreator.cs

    r2792 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    2623using HeuristicLab.Data;
     
    3229  /// An operator which adds new and empty sub-scopes to the current scope.
    3330  /// </summary>
    34   [Item("SubScopesCreater", "An operator which adds new and empty sub-scopes to the current scope.")]
     31  [Item("SubScopesCreator", "An operator which adds new and empty sub-scopes to the current scope.")]
    3532  [EmptyStorableClass]
    3633  [Creatable("Test")]
    37   public class SubScopesCreater : SingleSuccessorOperator {
     34  public class SubScopesCreator : SingleSuccessorOperator {
    3835    public ValueLookupParameter<IntData> NumberOfSubScopesParameter {
    3936      get { return (ValueLookupParameter<IntData>)Parameters["NumberOfSubScopes"]; }
     
    4643    }
    4744
    48     public SubScopesCreater()
     45    public SubScopesCreator()
    4946      : base() {
    5047      Parameters.Add(new ValueLookupParameter<IntData>("NumberOfSubScopes", "The number of new and empty sub-scopes which should be added to the current scope."));
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesRemover.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    2623using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesSorter.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    2623using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Operators/3.3/UniformParallelSubScopesProcessor.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Parameters;
  • trunk/sources/HeuristicLab.Operators/3.3/UniformSequentialSubScopesProcessor.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Parameters;
  • trunk/sources/HeuristicLab.Operators/3.3/ValuesCollector.cs

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    2622using HeuristicLab.Collections;
    2723using HeuristicLab.Core;
    28 using HeuristicLab.Parameters;
    2924using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3025
  • trunk/sources/HeuristicLab.Operators/3.3/VariableCreator.cs

    r2792 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Xml;
    27 using HeuristicLab.Collections;
    2822using HeuristicLab.Core;
    2923using HeuristicLab.Parameters;
     
    3428  /// An operator which collects the actual values of parameters and clones them into the current scope.
    3529  /// </summary>
    36   [Item("VariableInjector", "An operator which collects the actual values of parameters and clones them into the current scope.")]
     30  [Item("VariableCreator", "An operator which collects the actual values of parameters and clones them into the current scope.")]
    3731  [Creatable("Test")]
    3832  [EmptyStorableClass]
    39   public class VariableInjector : ValuesCollector {
     33  public class VariableCreator : ValuesCollector {
    4034    protected ScopeParameter CurrentScopeParameter {
    4135      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     
    4539    }
    4640
    47     public VariableInjector()
     41    public VariableCreator()
    4842      : base() {
    4943      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope into which the parameter values are cloned."));
  • trunk/sources/HeuristicLab.Permutation/3.3/HeuristicLab.Permutation-3.3.csproj

    r2790 r2794  
    8282  <ItemGroup>
    8383    <None Include="HeuristicLabPermutationPlugin.cs.frame" />
     84    <Compile Include="InversionManipulator.cs">
     85      <SubType>Code</SubType>
     86    </Compile>
     87    <Compile Include="PermutationManipulator.cs" />
    8488    <Compile Include="HeuristicLabPermutationPlugin.cs" />
     89    <Compile Include="OrderCrossover.cs" />
     90    <Compile Include="PermutationCrossover.cs" />
     91    <Compile Include="Permutation.cs" />
    8592    <Compile Include="Properties\AssemblyInfo.cs" />
     93    <Compile Include="RandomPermutationCreator.cs" />
    8694  </ItemGroup>
    8795  <ItemGroup>
     
    9098  </ItemGroup>
    9199  <ItemGroup>
     100    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
     101      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
     102      <Name>HeuristicLab.Collections-3.3</Name>
     103    </ProjectReference>
     104    <ProjectReference Include="..\..\HeuristicLab.Common\3.2\HeuristicLab.Common-3.2.csproj">
     105      <Project>{1FC004FC-59AF-4249-B1B6-FF25873A20E4}</Project>
     106      <Name>HeuristicLab.Common-3.2</Name>
     107    </ProjectReference>
    92108    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
    93109      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
     
    98114      <Name>HeuristicLab.Data-3.3</Name>
    99115    </ProjectReference>
    100     <ProjectReference Include="..\..\HeuristicLab.Evolutionary\3.3\HeuristicLab.Evolutionary-3.3.csproj">
    101       <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project>
    102       <Name>HeuristicLab.Evolutionary-3.3</Name>
     116    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
     117      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
     118      <Name>HeuristicLab.Operators-3.3</Name>
     119    </ProjectReference>
     120    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
     121      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
     122      <Name>HeuristicLab.Parameters-3.3</Name>
     123    </ProjectReference>
     124    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
     125      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
     126      <Name>HeuristicLab.Persistence-3.3</Name>
    103127    </ProjectReference>
    104128    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
    105129      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    106130      <Name>HeuristicLab.PluginInfrastructure</Name>
    107     </ProjectReference>
    108     <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
    109       <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
    110       <Name>HeuristicLab.Random-3.3</Name>
    111131    </ProjectReference>
    112132  </ItemGroup>
  • trunk/sources/HeuristicLab.Permutation/3.3/HeuristicLabPermutationPlugin.cs.frame

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.PluginInfrastructure;
    2623
     
    3128  [Plugin("HeuristicLab.Permutation", "3.3.0.$WCREV$")]
    3229  [PluginFile("HeuristicLab.Permutation-3.3.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Collections", "3.3")]
     31  [PluginDependency("HeuristicLab.Common", "3.2")]
    3332  [PluginDependency("HeuristicLab.Core", "3.3")]
    3433  [PluginDependency("HeuristicLab.Data", "3.3")]
    35   [PluginDependency("HeuristicLab.Evolutionary", "3.3")]
    36   [PluginDependency("HeuristicLab.Random", "3.3")]
     34  [PluginDependency("HeuristicLab.Operators", "3.3")]
     35  [PluginDependency("HeuristicLab.Parameters", "3.3")]
     36  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    3737  public class HeuristicLabPermutationPlugin : PluginBase {
    3838  }
  • trunk/sources/HeuristicLab.Permutation/3.3/InversionManipulator.cs

    r1530 r2794  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
     23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2624
    2725namespace HeuristicLab.Permutation {
    2826  /// <summary>
    29   /// Manipulates a permutation array by reversing a randomly chosen interval.
     27  /// An operator which inverts a randomly chosen part of a permutation.
    3028  /// </summary>
    31   public class InversionManipulator : PermutationManipulatorBase {
    32     /// <inheritdoc select="summary"/>
    33     public override string Description {
    34       get { return @"TODO\r\nOperator description still missing ..."; }
    35     }
     29  [Item("InversionManipulator", "An operator which inverts a randomly chosen part of a permutation.")]
     30  [EmptyStorableClass]
     31  [Creatable("Test")]
     32  public class InversionManipulator : PermutationManipulator {
    3633
    3734    /// <summary>
    38     /// Reverses the specified <paramref name="permutation"/> between two randomly generated positions.
     35    /// Inverts a randomly chosen part of a permutation.
    3936    /// </summary>
    40     /// <param name="random">The random number generator.</param>
    41     /// <param name="permutation">The permutation array to manipulate.</param>
    42     /// <returns>The new permuation array with the manipulated data.</returns>
    43     public static int[] Apply(IRandom random, int[] permutation) {
    44       int[] result = (int[])permutation.Clone();
     37    /// <param name="random">A random number generator.</param>
     38    /// <param name="permutation">The permutation to manipulate.</param>
     39    /// <returns>The new manipulated permutation.</returns>
     40    public static Permutation Apply(IRandom random, Permutation permutation) {
     41      Permutation result = (Permutation)permutation.Clone();
    4542      int breakPoint1, breakPoint2;
    4643
     
    5148      if (breakPoint2 < breakPoint1) { int h = breakPoint1; breakPoint1 = breakPoint2; breakPoint2 = h; }
    5249
    53       for (int i = 0; i <= (breakPoint2 - breakPoint1); i++) {  // reverse permutation between breakpoints
     50      for (int i = 0; i <= (breakPoint2 - breakPoint1); i++) {  // invert permutation between breakpoints
    5451        result[breakPoint1 + i] = permutation[breakPoint2 - i];
    5552      }
     
    5855
    5956    /// <summary>
    60     /// Reverses the specified <paramref name="permutation"/> between two randomly generated positions.
     57    /// Inverts a randomly chosen part of a permutation.
    6158    /// </summary>
    62     /// <remarks>Calls <see cref="Apply"/>.</remarks>
    63     /// <param name="scope">The current scope.</param>
    64     /// <param name="random">The random number generator.</param>
    65     /// <param name="permutation">The permutation array to manipulate.</param>
    66     /// <returns>The new permuation array with the manipulated data.</returns>
    67     protected override int[] Manipulate(IScope scope, IRandom random, int[] permutation) {
     59    /// <param name="random">A random number generator.</param>
     60    /// <param name="permutation">The permutation to manipulate.</param>
     61    /// <returns>The new manipulated permuation.</returns>
     62    protected override Permutation Manipulate(IRandom random, Permutation permutation) {
    6863      return Apply(random, permutation);
    6964    }
  • trunk/sources/HeuristicLab.Permutation/3.3/OrderCrossover.cs

    r1530 r2794  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    26 using HeuristicLab.Data;
     24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2725
    2826namespace HeuristicLab.Permutation {
    2927  /// <summary>
    30   /// Performs a cross over permutation between two permuation arrays
    31   /// by taking a randomly chosen interval from the frist, preserving the positions,
    32   /// then the missing values from the second array in the order they occur in the second array.
     28  /// An operator which performs an order crossover of two permutations.
    3329  /// </summary>
    34   public class OrderCrossover : PermutationCrossoverBase {
    35     /// <inheritdoc select="summary"/>
    36     public override string Description {
    37       get { return @"TODO\r\nOperator description still missing ..."; }
    38     }
    39 
     30  /// <remarks>
     31  /// Crosses two permutations by taking a randomly chosen interval from the frist permutation, preserving
     32  /// the positions, and then the missing values from the second permutation in the order they occur in the
     33  /// second permutation.
     34  /// </remarks>
     35  [Item("OrderCrossover", "An operator which performs an order crossover of two permutations.")]
     36  [EmptyStorableClass]
     37  [Creatable("Test")]
     38  public class OrderCrossover : PermutationCrossover {
    4039    /// <summary>
    41     /// Performs a cross over permutation of <paramref name="parent1"/> and
    42     /// <paramref name="parent2"/> by taking a randomly chosen interval from <paramref name="parent1"/>,
    43     /// preserving the positions and then the missing values from <paramref name="parent2"/> in the
    44     /// order they occur in <paramref name="parent2"/>.
     40    /// Performs an order crossover of two permutations.
    4541    /// </summary>
    46     /// <param name="random">The random number generator.</param>
    47     /// <param name="parent1">The parent scope 1 to cross over.</param>
    48     /// <param name="parent2">The parent scope 2 to cross over.</param>
    49     /// <returns>The created cross over permutation as int array.</returns>
    50     public static int[] Apply(IRandom random, int[] parent1, int[] parent2) {
    51       int[] result = new int[parent1.Length];
     42    /// <param name="random">A random number generator.</param>
     43    /// <param name="parent1">The first parent permutation to cross.</param>
     44    /// <param name="parent2">The second parent permutation to cross.</param>
     45    /// <returns>The new permutation resulting from the crossover.</returns>
     46    public static Permutation Apply(IRandom random, Permutation parent1, Permutation parent2) {
     47      Permutation result = new Permutation(parent1.Length);
    5248      bool[] copied = new bool[result.Length];
    5349
     
    7470
    7571    /// <summary>
    76     /// Performs an order crossover operation for two given parent permutations.
     72    /// Performs an order crossover of two permutations.
    7773    /// </summary>
    7874    /// <exception cref="InvalidOperationException">Thrown if there are not exactly two parents.</exception>
    79     /// <param name="scope">The current scope.</param>
    8075    /// <param name="random">A random number generator.</param>
    8176    /// <param name="parents">An array containing the two permutations that should be crossed.</param>
    82     /// <returns>The newly created permutation, resulting from the crossover operation.</returns>
    83     protected override int[] Cross(IScope scope, IRandom random, int[][] parents) {
    84       if (parents.Length != 2) throw new InvalidOperationException("ERROR in OrderCrossover: The number of parents is not equal to 2");
     77    /// <returns>The new permutation resulting from the crossover.</returns>
     78    protected override Permutation Cross(IRandom random, ItemArray<Permutation> parents) {
     79      if (parents.Length != 2) throw new InvalidOperationException("Number of parents is not equal to 2.");
    8580      return Apply(random, parents[0], parents[1]);
    8681    }
  • trunk/sources/HeuristicLab.Permutation/3.3/Permutation.cs

    r2526 r2794  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Text;
    25 using System.Xml;
     24using HeuristicLab.Common;
    2625using HeuristicLab.Core;
    2726using HeuristicLab.Data;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    2929namespace HeuristicLab.Permutation {
    30   /// <summary>
    31   /// The base class for a permutation, which is an ordered combination.
    32   /// </summary>
    33   public class Permutation : IntArrayData {
    34     /// <summary>
    35     /// Initializes a new instance of <see cref="Permutation"/>.
    36     /// </summary>
    37     public Permutation()
    38       : base() {
     30  [EmptyStorableClass]
     31  [Item("Permutation", "Represents a permutation of integer values.")]
     32  [Creatable("Test")]
     33  public sealed class Permutation : ValueTypeArrayData<int>, IStringConvertibleMatrixData {
     34    public Permutation() : base() { }
     35    public Permutation(int length)
     36      : base(length) {
     37      for (int i = 0; i < length; i++)
     38        this[i] = i;
    3939    }
    40     /// <summary>
    41     /// Initializes a new instance of <see cref="Permutation"/> with the given
    42     /// <paramref name="permutation"/> array.
    43     /// </summary>
    44     /// <param name="permutation">The permutation array to assign.</param>
    45     public Permutation(int[] permutation)
    46       : base(permutation) {
     40    public Permutation(int length, IRandom random)
     41      : this(length) {
     42      Randomize(random);
    4743    }
     44    public Permutation(int[] elements)
     45      : base(elements) {
     46      if (!Validate()) throw new ArgumentException("Elements do not represent a valid permutation.");
     47    }
     48    private Permutation(Permutation elements) : base(elements) { }
    4849
    49     /// <summary>
    50     /// Clones the current instance.
    51     /// </summary>
    52     /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to
    53     /// avoid cycles.)</param>
    54     /// <returns>The cloned object as <see cref="Permutation"/>.</returns>
    55     public override IItem Clone(ICloner cloner) {
    56       Permutation clone = new Permutation((int[])Data.Clone());
     50    public override IDeepCloneable Clone(Cloner cloner) {
     51      Permutation clone = new Permutation(this);
    5752      cloner.RegisterClonedObject(this, clone);
    5853      return clone;
    5954    }
     55
     56    public bool Validate() {
     57      bool[] values = new bool[Length];
     58      int value;
     59
     60      for (int i = 0; i < values.Length; i++)
     61        values[i] = false;
     62      for (int i = 0; i < Length; i++) {
     63        value = this[i];
     64        if ((value < 0) || (value >= values.Length)) return false;
     65        if (values[value]) return false;
     66        values[value] = true;
     67      }
     68      return true;
     69    }
     70
     71    public void Randomize(IRandom random, int startIndex, int length) {  // Knuth shuffle
     72      int index1, index2;
     73      int val;
     74      for (int i = length - 1; i > 0; i--) {
     75        index1 = startIndex + i;
     76        index2 = startIndex + random.Next(i + 1);
     77        if (index1 != index2) {
     78          val = this[index1];
     79          this[index1] = this[index2];
     80          this[index2] = val;
     81        }
     82      }
     83    }
     84    public void Randomize(IRandom random) {
     85      Randomize(random, 0, Length);
     86    }
     87
     88    #region IStringConvertibleMatrixData Members
     89    StringConvertibleArrayDataDimensions IStringConvertibleMatrixData.Dimensions {
     90      get { return StringConvertibleArrayDataDimensions.Rows; }
     91    }
     92    int IStringConvertibleMatrixData.Rows {
     93      get { return Length; }
     94      set { Length = value; }
     95    }
     96    int IStringConvertibleMatrixData.Columns {
     97      get { return 1; }
     98      set { throw new NotSupportedException("Columns cannot be changed."); }
     99    }
     100
     101    bool IStringConvertibleMatrixData.Validate(string value, out string errorMessage) {
     102      int val;
     103      bool valid = int.TryParse(value, out val);
     104      errorMessage = string.Empty;
     105      if (!valid) {
     106        StringBuilder sb = new StringBuilder();
     107        sb.Append("Invalid Value (Valid Value Format: \"");
     108        sb.Append(FormatPatterns.GetIntFormatPattern());
     109        sb.Append("\")");
     110        errorMessage = sb.ToString();
     111      }
     112      return valid;
     113    }
     114    string IStringConvertibleMatrixData.GetValue(int rowIndex, int columIndex) {
     115      return this[rowIndex].ToString();
     116    }
     117    bool IStringConvertibleMatrixData.SetValue(string value, int rowIndex, int columnIndex) {
     118      int val;
     119      if (int.TryParse(value, out val)) {
     120        this[rowIndex] = val;
     121        return true;
     122      } else {
     123        return false;
     124      }
     125    }
     126    event EventHandler<EventArgs<int, int>> IStringConvertibleMatrixData.ItemChanged {
     127      add { base.ItemChanged += value; }
     128      remove { base.ItemChanged -= value; }
     129    }
     130    event EventHandler IStringConvertibleMatrixData.Reset {
     131      add { base.Reset += value; }
     132      remove { base.Reset -= value; }
     133    }
     134    #endregion
    60135  }
    61136}
  • trunk/sources/HeuristicLab.Permutation/3.3/RandomPermutationCreator.cs

    r2792 r2794  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    2623using HeuristicLab.Data;
     24using HeuristicLab.Operators;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    2828namespace HeuristicLab.Permutation {
    2929  /// <summary>
    30   /// Generates a randomly shuffled permuation.
     30  /// An operator which creates a new random permutation of integer values.
    3131  /// </summary>
    32   public class RandomPermutationGenerator : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
     32  [Item("RandomPermutationCreator", "An operator which creates a new random permutation of integer values.")]
     33  [EmptyStorableClass]
     34  [Creatable("Test")]
     35  public sealed class RandomPermutationCreator : SingleSuccessorOperator {
     36    public LookupParameter<IRandom> RandomParameter {
     37      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     38    }
     39    public ValueLookupParameter<IntData> LengthParameter {
     40      get { return (ValueLookupParameter<IntData>)Parameters["Length"]; }
     41    }
     42    public LookupParameter<Permutation> PermutationParameter {
     43      get { return (LookupParameter<Permutation>)Parameters["Permutation"]; }
    3644    }
    3745
    38     /// <summary>
    39     /// Initializes a new instance of <see cref="RandomPermutationGenerator"/> with three variable infos
    40     /// (<c>Length</c>, <c>Random</c> and <c>Permutation</c>).
    41     /// </summary>
    42     public RandomPermutationGenerator()
     46    public RandomPermutationCreator()
    4347      : base() {
    44       AddVariableInfo(new VariableInfo("Length", "Permutation length", typeof(IntData), VariableKind.In));
    45       AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
    46       AddVariableInfo(new VariableInfo("Permutation", "Created random permutation", typeof(Permutation), VariableKind.New));
     48      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used to initialize the new random permutation."));
     49      Parameters.Add(new ValueLookupParameter<IntData>("Length", "The length of the new random permutation."));
     50      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The new random permutation."));
    4751    }
    4852
    49     /// <summary>
    50     /// Generates a randomly shuffled permutation.
    51     /// </summary>
    52     /// <param name="random">The random number generator.</param>
    53     /// <param name="length">The length of the permutation to create.</param>
    54     /// <returns>The generated permuation as int array.</returns>
    55     public static int[] Apply(IRandom random, int length) {
    56       int[] perm = new int[length];
    57 
    58       for (int i = 0; i < length; i++)
    59         perm[i] = i;
    60 
    61       // Knuth shuffle
    62       int index, tmp;
    63       for (int i = 0; i < length - 1; i++) {
    64         index = random.Next(i, length);
    65         tmp = perm[i];
    66         perm[i] = perm[index];
    67         perm[index] = tmp;
    68       }
    69       return perm;
    70     }
    71 
    72     /// <summary>
    73     /// Generates a randomly shuffled permutation.
    74     /// </summary>
    75     /// <remarks>Calls <see cref="Apply(HeuristicLab.Core.IRandom, int)"/>.</remarks>
    76     /// <param name="scope">The current scope with the variables.</param>
    77     /// <returns><c>null</c>.</returns>
    78     public override IOperation Apply(IScope scope) {
    79       IRandom random = GetVariableValue<IRandom>("Random", scope, true);
    80       IntData length = GetVariableValue<IntData>("Length", scope, true);
    81 
    82       int[] perm = Apply(random, length.Data);
    83       scope.AddVariable(new Variable(scope.TranslateName("Permutation"), new Permutation(perm)));
    84 
    85       return null;
     53    public override IExecutionSequence Apply() {
     54      PermutationParameter.ActualValue = new Permutation(LengthParameter.ActualValue.Value, RandomParameter.ActualValue);
     55      return base.Apply();
    8656    }
    8757  }
  • trunk/sources/HeuristicLab.Random/3.3/HeuristicLab.Random-3.3.csproj

    r2773 r2794  
    8686  <ItemGroup>
    8787    <None Include="HeuristicLabRandomPlugin.cs.frame" />
    88     <Compile Include="RandomInitializer.cs" />
    8988    <Compile Include="HeuristicLabRandomPlugin.cs" />
    9089    <Compile Include="MersenneTwister.cs">
     
    9594    </Compile>
    9695    <Compile Include="Properties\AssemblyInfo.cs" />
     96    <Compile Include="RandomCreator.cs" />
    9797  </ItemGroup>
    9898  <ItemGroup>
  • trunk/sources/HeuristicLab.Random/3.3/HeuristicLabRandomPlugin.cs.frame

    r2790 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.PluginInfrastructure;
    2623
  • trunk/sources/HeuristicLab.Random/3.3/MersenneTwister.cs

    r2790 r2794  
    3333
    3434using System;
    35 using System.Collections.Generic;
    36 using System.Text;
    37 using System.Xml;
    3835using HeuristicLab.Core;
    3936using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
  • trunk/sources/HeuristicLab.Random/3.3/NormalDistributedRandom.cs

    r2790 r2794  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    26 using System.Globalization;
    2723using HeuristicLab.Core;
    2824using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
  • trunk/sources/HeuristicLab.Random/3.3/RandomCreator.cs

    r2792 r2794  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2522using HeuristicLab.Core;
    2623using HeuristicLab.Data;
     
    3128namespace HeuristicLab.Operators {
    3229  /// <summary>
    33   /// An operator which initializes a pseudo random number generator.
     30  /// An operator which creates a new pseudo random number generator.
    3431  /// </summary>
    35   [Item("RandomInitializer", "An operator which initializes a pseudo random number generator.")]
     32  [Item("RandomCreator", "An operator which creates a new pseudo random number generator.")]
    3633  [EmptyStorableClass]
    3734  [Creatable("Test")]
    38   public sealed class RandomInitializer : SingleSuccessorOperator {
     35  public sealed class RandomCreator : SingleSuccessorOperator {
    3936    public ValueLookupParameter<BoolData> SetSeedRandomlyParameter {
    4037      get { return (ValueLookupParameter<BoolData>)Parameters["SetSeedRandomly"]; }
     
    5552    }
    5653
    57     public RandomInitializer()
     54    public RandomCreator()
    5855      : base() {
    5956      Parameters.Add(new ValueLookupParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true)));
    60       Parameters.Add(new ValueLookupParameter<IntData>("Seed", "The random seed used to initialize the pseudo random number generator.", new IntData(0)));
    61       Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be initialized with the given seed."));
     57      Parameters.Add(new ValueLookupParameter<IntData>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntData(0)));
     58      Parameters.Add(new LookupParameter<IRandom>("Random", "The new pseudo random number generator which is initialized with the given seed."));
    6259    }
    6360
Note: See TracChangeset for help on using the changeset viewer.