Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3404


Ignore:
Timestamp:
04/19/10 01:51:50 (14 years ago)
Author:
abeham
Message:

Added gender specific selection and ported the necessary operators RightChildReducer and SubScopesMixer #976

Location:
trunk/sources
Files:
1 added
5 edited

Legend:

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

    r3384 r3404  
    9898    <Compile Include="StochasticBranch.cs" />
    9999    <Compile Include="SubScopesCreator.cs" />
     100    <Compile Include="SubScopesMixer.cs" />
    100101    <Compile Include="SubScopesProcessor.cs" />
    101102    <Compile Include="SubScopesRemover.cs" />
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesMixer.cs

    r1530 r3404  
    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;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    2828namespace HeuristicLab.Operators {
     
    3030  /// Mixes the sub scopes of a specified scope according to a specified number of partitions.
    3131  /// </summary>
    32   public class SubScopesMixer : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
     32  [Item("SubScopesMixer", "Changes the order of the sub-scopes by repartitioning the sub-scopes such that each new partition contains one scope from each old partition.")]
     33  [StorableClass]
     34  public class SubScopesMixer : SingleSuccessorOperator {
     35    public ValueParameter<IntValue> PartitionsParameter {
     36      get { return (ValueParameter<IntValue>)Parameters["Partitions"]; }
    3637    }
     38
     39    public IntValue Partitions {
     40      get { return PartitionsParameter.Value; }
     41      set { PartitionsParameter.Value = value; }
     42    }
     43
    3744    /// <summary>
    3845    /// Initializes a new instance of <see cref="SubScopesMixer"/> with one variable infos
     
    4148    public SubScopesMixer()
    4249      : base() {
    43       AddVariableInfo(new VariableInfo("Partitions", "Number of partitions to mix", typeof(IntData), VariableKind.In));
    44       GetVariableInfo("Partitions").Local = true;
    45       AddVariable(new Variable("Partitions", new IntData(2)));
     50      Parameters.Add(new ValueParameter<IntValue>("Partitions", "The number of equal-sized partitions.", new IntValue(2)));
    4651    }
    4752
    4853    /// <summary>
    49     /// Mixes the subscopes of the given <paramref name="scope"/>.
     54    /// Mixes the sub-scopes of the scope this operator is applied on.
    5055    /// </summary>
    51     /// <remarks>Calls <see cref="IScope.ReorderSubScopes"/>.<br/>
    52     /// Mixing of sub scopes is based on the number of partitions.
    53     /// <example>12 sub scopes and 3 partitions:<br/>
    54     /// Partition 1 contains sub scopes 1-4, partition 2 sub scopes 5-8 and partition 3 sub scopes 9-12. <br/>
    55     /// Mixing is realized by selecting at the beginning the first sub scope from partition one, then the
    56     /// first sub scope from partition 2, afterwards first sub scope from partition 3,
    57     /// then the second sub scope from the first partition and so on. <br/>
     56    /// <remarks>Mixing of sub-scopes is based on the number of partitions.
     57    /// <example>12 sub-scopes and 3 partitions:<br/>
     58    /// Partition 1 contains scopes 1-4, partition 2 scopes 5-8 and partition 3 scopes 9-12. <br/>
     59    /// Mixing is realized by selecting at the beginning the first scope from partition one, then the
     60    /// first scope from partition 2, afterwards first scope from partition 3,
     61    /// then the second scope from the first partition and so on. <br/>
    5862    /// In the end the new sorting of the sub scopes is 1-5-9-2-6-10-3-7-11-4-8-12.
    5963    /// </example>
     
    6367    /// <param name="scope">The scope whose sub scopes should be mixed.</param>
    6468    /// <returns><c>null</c>.</returns>
    65     public override IOperation Apply(IScope scope) {
    66       int partitions = GetVariableValue<IntData>("Partitions", scope, true).Data;
    67       int[] sequence = new int[scope.SubScopes.Count];
    68       if ((sequence.Length % partitions) != 0)
    69         throw new ArgumentException("The number of subScopes is not divisible by the number of partitions without remainder.");
    70       int partitionSize = sequence.Length / partitions;
     69    public override IOperation Apply() {
     70      int partitions = Partitions.Value;
     71      IScope scope = ExecutionContext.Scope;
     72      int count = scope.SubScopes.Count;
     73      if ((count % partitions) != 0)
     74        throw new ArgumentException(Name + ": The number of sub-scopes is not divisible by the number of partitions without remainder.");
     75      int partitionSize = count / partitions;
     76
     77      IScope[] reorderedSubScopes = new IScope[count];
    7178
    7279      // mix sub-scopes -> alternately take one sub-scope from each partition
    7380      for (int i = 0; i < partitionSize; i++) {
    74         for (int j = 0; j < partitions; j++)
    75           sequence[i * partitions + j] = j * partitionSize + i;
     81        for (int j = 0; j < partitions; j++) {
     82          reorderedSubScopes[i * partitions + j] = scope.SubScopes[j * partitionSize + i];
     83        }
    7684      }
    77       scope.ReorderSubScopes(sequence);
     85      scope.SubScopes.Clear();
     86      scope.SubScopes.AddRange(reorderedSubScopes);
    7887
    79       return null;
     88      return base.Apply();
    8089    }
    8190  }
  • trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj

    r3384 r3404  
    139139    <None Include="app.config" />
    140140    <EmbeddedResource Include="Documents\FirstSteps.rtf" />
    141     <EmbeddedResource Include="Documents\LS_OneMax.hl" />
    142     <EmbeddedResource Include="Documents\SA_Rastrigin.hl" />
    143     <EmbeddedResource Include="Documents\TS_TSP.hl" />
    144141    <None Include="HeuristicLab.snk" />
    145142    <None Include="Properties\AssemblyInfo.frame" />
  • trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.3.csproj

    r3384 r3404  
    8383    <None Include="HeuristicLabSelectionPlugin.cs.frame" />
    8484    <Compile Include="BestSelector.cs" />
     85    <Compile Include="GenderSpecificSelector.cs" />
     86    <Compile Include="RightChildReducer.cs" />
    8587    <Compile Include="SingleObjectiveSelector.cs" />
    8688    <Compile Include="LeftReducer.cs" />
  • trunk/sources/HeuristicLab.Selection/3.3/RightChildReducer.cs

    r1530 r3404  
    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;
    2322using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    26 using HeuristicLab.Operators;
     24using HeuristicLab.Optimization;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2726
    2827namespace HeuristicLab.Selection {
    2928  /// <summary>
    30   /// Reduces the sub scopes by one level, so that the right sub scope contains also the right child scopes
    31   /// of the left sub scope and the left sub scope represents its left child scope.
     29  /// Reduces the sub-scopes, so that the selected sub-scope contains all selected leaves (1) and (2)
     30  /// and the remaining sub-scope contains the sub-scopes of the bottom-most remaining scope (3).
    3231  /// <pre>                                                     
    33   ///                   scope             scope 
    34   ///                   / | \             /   \     
    35   ///                  L ... R   =>      A     R                 
    36   ///                / | \    \              / /\ \       
    37   ///               A ... LR   C             C D E F     
    38   ///                     /|\                             
    39   ///                    D E F                             
     32  ///                  scope            scope 
     33  ///                   / \             /   \     
     34  ///                  R   S(1)   =>   R     S                 
     35  ///                 / \     \       /|\   /|\       
     36  ///               R(3) S(2)  C     ABCDEF  CDEF     
     37  ///               /|\  /|\                             
     38  ///             ABCDEF DEF                             
    4039  /// </pre>
    4140  /// </summary>
    42   public class RightChildReducer : ReducerBase {
    43     /// <inheritdoc select="summary"/>
    44     public override string Description {
    45       get { return @"TODO\r\nOperator description still missing ..."; }
    46     }
    47 
     41  [Item("RightChildReducer", "Merges all sub-scopes generated by successively selecting sub-scopes of the remaining part.")]
     42  [StorableClass]
     43  public class RightChildReducer : Reducer, IReducer {
    4844    /// <summary>
    49     /// Reduces the right child of the left sub scope and adds its sub scopes to the right sub scope.
    50     /// The left sub scope is also narrowed, which means it represents then its left child.
     45    ///  Reduces the sub-scopes, so that the selected sub-scope contains all selected leaves
     46    /// and the remaining sub-scope contains the sub-scopes of the bottom-most remaining scope.
    5147    /// </summary>
    5248    /// <param name="scope">The current scope to reduce.</param>
    5349    /// <returns>A list of the new reduced sub scopes.</returns>
    54     protected override ICollection<IScope> Reduce(IScope scope) {
    55       IScope rightChild = scope.SubScopes[scope.SubScopes.Count - 1];
    56       IScope leftChild = scope.SubScopes[0];
    57       IScope leftRightChild = leftChild.SubScopes[leftChild.SubScopes.Count - 1];
     50    protected override List<IScope> Reduce(List<IScope> scopes) {
     51      IScope rightChild = scopes[scopes.Count - 1];
     52      IScope leftChild = scopes[0];
     53      while (leftChild.SubScopes.Count > 1 && leftChild.SubScopes[0].SubScopes.Count > 0) {
     54        IScope leftRightChild = leftChild.SubScopes[leftChild.SubScopes.Count - 1];
    5855
    59       // merge right children
    60       for (int i = 0; i < leftRightChild.SubScopes.Count; i++)
    61         rightChild.AddSubScope(leftRightChild.SubScopes[i]);
     56        // merge right children
     57        while (leftRightChild.SubScopes.Count > 0)
     58          rightChild.SubScopes.Add(leftRightChild.SubScopes[0]);
    6259
    63       leftChild = leftChild.SubScopes[0];
    64 
     60        leftChild = leftChild.SubScopes[0];
     61      }
    6562      List<IScope> subScopes = new List<IScope>();
    6663      subScopes.Add(leftChild);
Note: See TracChangeset for help on using the changeset viewer.