Changeset 7686


Ignore:
Timestamp:
04/02/12 16:45:39 (7 years ago)
Author:
abeham
Message:

#1775: Updated integer vector encoding

  • Added advanced bounds to all operators
  • Added new operators
  • Changed DiscreteCrossover to work with >= 2 parents
Location:
branches/IntegerVectorEncoding
Files:
9 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/IntegerVectorEncoding

    • Property svn:ignore set to
      *.suo
  • branches/IntegerVectorEncoding/HeuristicLab 3.3.sln

    r7681 r7686  
    55  ProjectSection(SolutionItems) = preProject
    66    Build.cmd = Build.cmd
    7     LocalTestRun.testrunconfig = LocalTestRun.testrunconfig
    87    PreBuildEvent.cmd = PreBuildEvent.cmd
    98  EndProjectSection
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/DiscreteCrossover.cs

    r7259 r7686  
    4545
    4646    /// <summary>
    47     /// Performs a discrete crossover operation of the two given parents.
     47    /// Performs a discrete crossover operation of any number of given parents.
    4848    /// </summary>
    4949    /// <exception cref="ArgumentException">Thrown when the vectors of the parents are of different length.</exception>
    5050    /// <param name="random">A random number generator.</param>
    51     /// <param name="parent1">The first parent for the crossover operation.</param>
    52     /// <param name="parent2">The second parent for the crossover operation.</param>
     51    /// <param name="parents">The list of parents for the crossover operation.</param>
    5352    /// <returns>The newly created integer vector, resulting from the crossover operation.</returns>
    54     public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2) {
    55       if (parent1.Length != parent2.Length)
    56         throw new ArgumentException("DiscreteCrossover: The parents are of different length.");
     53    public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents) {
     54      int length = parents[0].Length;
    5755
    58       int length = parent1.Length;
    59       int[] result = new int[length];
     56      for (int i = 0; i < parents.Length; i++) {
     57        if (parents[i].Length != length)
     58          throw new ArgumentException("DiscreteCrossover: The parents' vectors are of different length.", "parents");
     59      }
    6060
     61      var result = new IntegerVector(length);
    6162      for (int i = 0; i < length; i++) {
    62         if (random.NextDouble() < 0.5)
    63           result[i] = parent1[i];
    64         else
    65           result[i] = parent2[i];
     63        result[i] = parents[random.Next(parents.Length)][i];
    6664      }
    67       return new IntegerVector(result);
     65
     66      return result;
    6867    }
    6968
    7069    /// <summary>
    71     /// Performs a discrete crossover operation for two given parent integer vectors.
     70    /// Performs a discrete crossover operation for any number of given parent integer vectors.
    7271    /// </summary>
    73     /// <exception cref="ArgumentException">Thrown if there are not exactly two parents.</exception>
    7472    /// <param name="random">A random number generator.</param>
    75     /// <param name="parents">An array containing the two integer vectors that should be crossed.</param>
     73    /// <param name="parents">An array containing integer vectors that should be crossed.</param>
    7674    /// <returns>The newly created integer vector, resulting from the crossover operation.</returns>
    7775    protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) {
    78       if (parents.Length != 2) throw new ArgumentException("ERROR in DiscreteCrossover: The number of parents is not equal to 2");
    79       return Apply(random, parents[0], parents[1]);
     76      return Apply(random, parents);
    8077    }
    8178  }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs

    r7681 r7686  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2728using HeuristicLab.Operators;
    2829using HeuristicLab.Optimization;
     
    4243    }
    4344
     45    public IValueLookupParameter<IntMatrix> BoundsParameter {
     46      get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
     47    }
     48
    4449    public ILookupParameter<ItemArray<IntegerVector>> ParentsParameter {
    4550      get { return (ILookupParameter<ItemArray<IntegerVector>>)Parameters["Parents"]; }
     
    5560    public MultiIntegerVectorCrossover()
    5661      : base() {
     62      Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
    5763      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Parents", "The parent integer vector which should be crossed."));
    5864      ParentsParameter.ActualName = "IntegerVector";
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj

    r6866 r7686  
    4141    <DebugType>full</DebugType>
    4242    <Optimize>false</Optimize>
    43     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     43    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    4444    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4545    <ErrorReport>prompt</ErrorReport>
     
    5050    <DebugType>pdbonly</DebugType>
    5151    <Optimize>true</Optimize>
    52     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     52    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    5353    <DefineConstants>TRACE</DefineConstants>
    5454    <ErrorReport>prompt</ErrorReport>
     
    5858  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    5959    <DebugSymbols>true</DebugSymbols>
    60     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     60    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    6161    <DefineConstants>DEBUG;TRACE</DefineConstants>
    6262    <DebugType>full</DebugType>
     
    6666  </PropertyGroup>
    6767  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    68     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     68    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    6969    <DefineConstants>TRACE</DefineConstants>
    7070    <Optimize>true</Optimize>
     
    7676  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    7777    <DebugSymbols>true</DebugSymbols>
    78     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     78    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    7979    <DefineConstants>DEBUG;TRACE</DefineConstants>
    8080    <DebugType>full</DebugType>
     
    8484  </PropertyGroup>
    8585  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    86     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     86    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    8787    <DefineConstants>TRACE</DefineConstants>
    8888    <Optimize>true</Optimize>
     
    9393  </PropertyGroup>
    9494  <ItemGroup>
     95    <Reference Include="HeuristicLab.Collections-3.3">
     96      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     97      <Private>False</Private>
     98    </Reference>
     99    <Reference Include="HeuristicLab.Common-3.3">
     100      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
     101      <Private>False</Private>
     102    </Reference>
     103    <Reference Include="HeuristicLab.Core-3.3">
     104      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
     105      <Private>False</Private>
     106    </Reference>
     107    <Reference Include="HeuristicLab.Data-3.3">
     108      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
     109      <Private>False</Private>
     110    </Reference>
     111    <Reference Include="HeuristicLab.Operators-3.3">
     112      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>
     113      <Private>False</Private>
     114    </Reference>
     115    <Reference Include="HeuristicLab.Optimization-3.3">
     116      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
     117      <Private>False</Private>
     118    </Reference>
     119    <Reference Include="HeuristicLab.Optimization.Operators-3.3">
     120      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath>
     121      <Private>False</Private>
     122    </Reference>
     123    <Reference Include="HeuristicLab.Parameters-3.3">
     124      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
     125      <Private>False</Private>
     126    </Reference>
     127    <Reference Include="HeuristicLab.Persistence-3.3">
     128      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
     129      <Private>False</Private>
     130    </Reference>
     131    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
     132      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     133      <Private>False</Private>
     134    </Reference>
     135    <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     136      <SpecificVersion>False</SpecificVersion>
     137      <Private>False</Private>
     138    </Reference>
    95139    <Reference Include="System" />
    96140    <Reference Include="System.Core">
     
    107151  <ItemGroup>
    108152    <Compile Include="Creators\UniformRandomIntegerVectorCreator.cs" />
     153    <Compile Include="Crossovers\AverageCrossover.cs" />
    109154    <Compile Include="Crossovers\DiscreteCrossover.cs">
    110155      <SubType>Code</SubType>
     
    114159      <SubType>Code</SubType>
    115160    </Compile>
     161    <Compile Include="Crossovers\UniformAllPositionsArithmeticCrossover.cs" />
     162    <Compile Include="Crossovers\UniformSomePositionsArithmeticCrossover.cs" />
     163    <Compile Include="Interfaces\IBoundedIntegerVectorOperator.cs" />
    116164    <Compile Include="Interfaces\IIntegerVectorCreator.cs" />
    117165    <Compile Include="Interfaces\IIntegerVectorCrossover.cs" />
     
    121169    <Compile Include="IntegerVectorCrossover.cs" />
    122170    <Compile Include="IntegerVectorManipulator.cs" />
     171    <Compile Include="Interfaces\IIntegerVectorStdDevStrategyParameterCreator.cs" />
     172    <Compile Include="Interfaces\IIntegerVectorStdDevStrategyParameterCrossover.cs" />
     173    <Compile Include="Interfaces\IIntegerVectorStdDevStrategyParameterManipulator.cs" />
     174    <Compile Include="Interfaces\IIntegerVectorStdDevStrategyParameterOperator.cs" />
     175    <Compile Include="Manipulators\RoundedNormalAllPositionsManipulator.cs" />
     176    <Compile Include="Manipulators\SelfAdaptiveRoundedNormalAllPositionsManipulator.cs" />
     177    <Compile Include="Manipulators\StdDevStrategyVectorCreator.cs" />
     178    <Compile Include="Manipulators\StdDevStrategyVectorCrossover.cs" />
     179    <Compile Include="Manipulators\StdDevStrategyVectorManipulator.cs" />
    123180    <Compile Include="Manipulators\UniformOnePositionManipulator.cs">
    124181      <SubType>Code</SubType>
     
    129186    <Compile Include="IntegerVectorCreator.cs" />
    130187    <Compile Include="ShakingOperators\IntegerVectorShakingOperator.cs" />
    131   </ItemGroup>
    132   <ItemGroup>
    133     <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
    134       <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
    135       <Name>HeuristicLab.Collections-3.3</Name>
    136       <Private>False</Private>
    137     </ProjectReference>
    138     <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
    139       <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
    140       <Name>HeuristicLab.Common-3.3</Name>
    141       <Private>False</Private>
    142     </ProjectReference>
    143     <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
    144       <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
    145       <Name>HeuristicLab.Core-3.3</Name>
    146       <Private>False</Private>
    147     </ProjectReference>
    148     <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
    149       <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
    150       <Name>HeuristicLab.Data-3.3</Name>
    151       <Private>False</Private>
    152     </ProjectReference>
    153     <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
    154       <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
    155       <Name>HeuristicLab.Operators-3.3</Name>
    156       <Private>False</Private>
    157     </ProjectReference>
    158     <ProjectReference Include="..\..\HeuristicLab.Optimization.Operators\3.3\HeuristicLab.Optimization.Operators-3.3.csproj">
    159       <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project>
    160       <Name>HeuristicLab.Optimization.Operators-3.3</Name>
    161       <Private>False</Private>
    162     </ProjectReference>
    163     <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    164       <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
    165       <Name>HeuristicLab.Optimization-3.3</Name>
    166       <Private>False</Private>
    167     </ProjectReference>
    168     <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
    169       <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
    170       <Name>HeuristicLab.Parameters-3.3</Name>
    171       <Private>False</Private>
    172     </ProjectReference>
    173     <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
    174       <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
    175       <Name>HeuristicLab.Persistence-3.3</Name>
    176       <Private>False</Private>
    177     </ProjectReference>
    178     <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    179       <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    180       <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    181       <Private>False</Private>
    182     </ProjectReference>
    183188  </ItemGroup>
    184189  <ItemGroup>
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorCreator.cs

    r7681 r7686  
    6767    private void AfterDeserialization() {
    6868      if (!Parameters.ContainsKey("Bounds")) {
     69        var min = ((IValueLookupParameter<IntValue>)Parameters["Minimum"]).Value as IntValue;
     70        var max = ((IValueLookupParameter<IntValue>)Parameters["Maximum"]).Value as IntValue;
    6971        Parameters.Remove("Minimum");
    7072        Parameters.Remove("Maximum");
    71         Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (inclusive), and step size. If less rows are given the matrix is cycled."));
     73        Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
     74        if (min != null && max != null) {
     75          BoundsParameter.Value = new IntMatrix(new int[,] { { min.Value, max.Value, 1 } });
     76        }
    7277      }
    7378    }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs

    r7259 r7686  
    3636  [Item("UniformOnePositionManipulator", " Uniformly distributed change of a single position of an integer vector. It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
    3737  [StorableClass]
    38   public class UniformOnePositionManipulator : IntegerVectorManipulator {
     38  public class UniformOnePositionManipulator : IntegerVectorManipulator, IBoundedIntegerVectorOperator {
    3939    /// <summary>
    40     /// The lower bound of the values in the int vector.
     40    /// A matrix that specifies the bounds for each dimension in a separate row. The first column denotes the minimum, the second the maximum value, and the third column denotes the step size.
    4141    /// </summary>
    42     public ValueLookupParameter<IntValue> MinimumParameter {
    43       get { return (ValueLookupParameter<IntValue>)Parameters["Minimum"]; }
    44     }
    45     /// <summary>
    46     /// The upper bound of the values in the int vector.
    47     /// </summary>
    48     public ValueLookupParameter<IntValue> MaximumParameter {
    49       get { return (ValueLookupParameter<IntValue>)Parameters["Maximum"]; }
     42    public IValueLookupParameter<IntMatrix> BoundsParameter {
     43      get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
    5044    }
    5145
     
    5953    public UniformOnePositionManipulator()
    6054      : base() {
    61       Parameters.Add(new ValueLookupParameter<IntValue>("Minimum", "Minimum of the sampling range for the vector element (included)"));
    62       Parameters.Add(new ValueLookupParameter<IntValue>("Maximum", "Maximum of the sampling range for the vector element (excluded)"));
     55      Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
    6356    }
    6457
     
    6659      return new UniformOnePositionManipulator(this, cloner);
    6760    }
     61
     62    // BackwardsCompatibility3.3
     63    #region Backwards compatible code, remove with 3.4
     64    [StorableHook(HookType.AfterDeserialization)]
     65    private void AfterDeserialization() {
     66      if (!Parameters.ContainsKey("Bounds")) {
     67        var min = ((IValueLookupParameter<IntValue>)Parameters["Minimum"]).Value as IntValue;
     68        var max = ((IValueLookupParameter<IntValue>)Parameters["Maximum"]).Value as IntValue;
     69        Parameters.Remove("Minimum");
     70        Parameters.Remove("Maximum");
     71        Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
     72        if (min != null && max != null) {
     73          BoundsParameter.Value = new IntMatrix(new int[,] { { min.Value, max.Value, 1 } });
     74        }
     75      }
     76    }
     77    #endregion
    6878
    6979    /// <summary>
     
    7686    /// <param name="max">The maximum value of the sampling range for
    7787    /// the vector element to change (exclusive).</param>
    78     public static void Apply(IRandom random, IntegerVector vector, IntValue min, IntValue max) {
     88    public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds) {
     89      if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("UniformOnePositionManipulator: Invalid bounds specified", "bounds");
    7990      int index = random.Next(vector.Length);
    80       vector[index] = random.Next(min.Value, max.Value);
     91      int min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1], step = 1;
     92      if (bounds.Columns > 2) step = bounds[index % bounds.Rows, 2];
     93      int value = (max - min) / step;
     94      vector[index] = random.Next(value) * step + min;
    8195    }
    8296
     
    88102    /// <param name="vector">The integer vector to manipulate.</param>
    89103    protected override void Manipulate(IRandom random, IntegerVector vector) {
    90       if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
    91       if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found.");
    92       Apply(random, vector, MinimumParameter.ActualValue, MaximumParameter.ActualValue);
     104      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
     105      Apply(random, vector, BoundsParameter.ActualValue);
    93106    }
    94107  }
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Plugin.cs.frame

    r7259 r7686  
    3737  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3838  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     39  [PluginDependency("HeuristicLab.Random", "3.3")]
    3940  public class HeuristicLabEncodingsIntegerVectorEncodingPlugin : PluginBase {
    4041  }
Note: See TracChangeset for help on using the changeset viewer.