Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/10 04:11:49 (15 years ago)
Author:
swagner
Message:

Replaced LeftSelector and RightSelector by BestSelector and WorstSelector (#926)

Location:
trunk/sources/HeuristicLab.Selection/3.3
Files:
1 added
6 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Selection/3.3/BestSelector.cs

    r3093 r3096  
    2020#endregion
    2121
     22using System;
     23using System.Linq;
    2224using System.Collections.Generic;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Data;
    2528
    2629namespace HeuristicLab.Selection {
    2730  /// <summary>
    28   /// An operator which selects sub-scopes from left to right.
     31  /// A selection operator which considers a single double quality value and selects the best.
    2932  /// </summary>
    30   [Item("LeftSelector", "An operator which selects sub-scopes from left to right.")]
     33  [Item("BestSelector", "A selection operator which considers a single double quality value and selects the best.")]
    3134  [StorableClass]
    3235  [Creatable("Test")]
    33   public sealed class LeftSelector : Selector {
    34     public LeftSelector() : base() { }
     36  public sealed class BestSelector : SingleObjectiveSelector {
     37    public BestSelector() : base() { }
    3538
    3639    protected override IScope[] Select(List<IScope> scopes) {
    3740      int count = NumberOfSelectedSubScopesParameter.ActualValue.Value;
    3841      bool copy = CopySelectedParameter.Value.Value;
     42      bool maximization = MaximizationParameter.ActualValue.Value;
     43      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    3944      IScope[] selected = new IScope[count];
     45
     46      // create a list for each scope that contains the scope's index in the original scope list
     47      var temp = qualities.Select((x, index) => new { index, x.Value });
     48      if (maximization)
     49        temp = temp.OrderByDescending(x => x.Value);
     50      else
     51        temp = temp.OrderBy(x => x.Value);
     52      var list = temp.ToList();
    4053
    4154      int j = 0;
    4255      for (int i = 0; i < count; i++) {
    4356        if (copy) {
    44           selected[i] = (IScope)scopes[j].Clone();
     57          selected[i] = (IScope)scopes[list[j].index].Clone();
    4558          j++;
    46           if (j >= scopes.Count) j = 0;
     59          if (j >= list.Count) j = 0;
    4760        } else {
    48           selected[i] = scopes[0];
    49           scopes.RemoveAt(0);
     61          selected[i] = scopes[list[j].index];
     62          scopes.RemoveAt(list[j].index);
     63          list.RemoveAt(j);
    5064        }
    5165      }
  • trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.3.csproj

    r2900 r3096  
    8282  <ItemGroup>
    8383    <None Include="HeuristicLabSelectionPlugin.cs.frame" />
     84    <Compile Include="BestSelector.cs" />
     85    <Compile Include="SingleObjectiveSelector.cs" />
    8486    <Compile Include="LeftReducer.cs" />
    8587    <Compile Include="MergingReducer.cs" />
     
    8890    <Compile Include="ProportionalSelector.cs" />
    8991    <Compile Include="RightReducer.cs" />
    90     <Compile Include="RightSelector.cs" />
    9192    <Compile Include="StochasticSelector.cs" />
    92     <Compile Include="LeftSelector.cs" />
    9393    <Compile Include="RandomSelector.cs" />
    9494    <Compile Include="StochasticSingleObjectiveSelector.cs" />
     
    9797    <Compile Include="Selector.cs" />
    9898    <Compile Include="TournamentSelector.cs" />
     99    <Compile Include="WorstSelector.cs" />
    99100  </ItemGroup>
    100101  <ItemGroup>
  • trunk/sources/HeuristicLab.Selection/3.3/LinearRankSelector.cs

    r3048 r3096  
    3434  [Creatable("Test")]
    3535  public sealed class LinearRankSelector : StochasticSingleObjectiveSelector {
    36     public LinearRankSelector()
    37       : base() {
    38       CopySelected.Value = true;
    39     }
     36    public LinearRankSelector() : base() { }
    4037
    4138    protected override IScope[] Select(List<IScope> scopes) {
  • trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs

    r3048 r3096  
    4848      : base() {
    4949      Parameters.Add(new ValueParameter<BoolValue>("Windowing", "Apply windowing strategy (selection probability is proportional to the quality differences and not to the total quality).", new BoolValue(true)));
    50       CopySelected.Value = true;
    5150    }
    5251
  • trunk/sources/HeuristicLab.Selection/3.3/Selector.cs

    r3048 r3096  
    5959    protected Selector()
    6060      : base() {
    61       Parameters.Add(new ValueParameter<BoolValue>("CopySelected", "True if the selected sub-scopes should be copied, otherwise false.", new BoolValue(false)));
     61      Parameters.Add(new ValueParameter<BoolValue>("CopySelected", "True if the selected sub-scopes should be copied, otherwise false.", new BoolValue(true)));
    6262      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfSelectedSubScopes", "The number of sub-scopes which should be selected."));
    6363      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which sub-scopes should be selected."));
  • trunk/sources/HeuristicLab.Selection/3.3/StochasticSingleObjectiveSelector.cs

    r3048 r3096  
    2121
    2222using HeuristicLab.Core;
    23 using HeuristicLab.Data;
    2423using HeuristicLab.Optimization;
    2524using HeuristicLab.Parameters;
     
    3231  [Item("StochasticSingleObjectiveSelector", "A base class for stochastic selection operators which consider a single double quality value for selection.")]
    3332  [StorableClass]
    34   public abstract class StochasticSingleObjectiveSelector : StochasticSelector, ISingleObjectiveSelector {
    35     public IValueLookupParameter<BoolValue> MaximizationParameter {
    36       get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    37     }
    38     public ILookupParameter<ItemArray<DoubleValue>> QualityParameter {
    39       get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Quality"]; }
     33  public abstract class StochasticSingleObjectiveSelector : SingleObjectiveSelector, IStochasticOperator {
     34    public ILookupParameter<IRandom> RandomParameter {
     35      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    4036    }
    4137
    4238    protected StochasticSingleObjectiveSelector()
    4339      : base() {
    44       Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the current problem is a maximization problem, otherwise false."));
    45       Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The quality value contained in each sub-scope which is used for selection."));
     40      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator used for stochastic selection."));
    4641    }
    4742  }
  • trunk/sources/HeuristicLab.Selection/3.3/TournamentSelector.cs

    r3048 r3096  
    4141    public TournamentSelector() : base() {
    4242      Parameters.Add(new ValueLookupParameter<IntValue>("GroupSize", "The size of the tournament group.", new IntValue(2)));
    43       CopySelected.Value = true;
    4443    }
    4544
  • trunk/sources/HeuristicLab.Selection/3.3/WorstSelector.cs

    r3093 r3096  
    2020#endregion
    2121
     22using System.Linq;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Data;
    2527
    2628namespace HeuristicLab.Selection {
    2729  /// <summary>
    28   /// An operator which selects sub-scopes from right to left.
     30  /// A selection operator which considers a single double quality value and selects the worst.
    2931  /// </summary>
    30   [Item("RightSelector", "An operator which selects sub-scopes from right to left.")]
     32  [Item("WorstSelector", "A selection operator which considers a single double quality value and selects the worst.")]
    3133  [StorableClass]
    3234  [Creatable("Test")]
    33   public sealed class RightSelector : Selector {
    34     public RightSelector() : base() { }
     35  public sealed class WorstSelector : SingleObjectiveSelector {
     36    public WorstSelector() : base() { }
    3537
    3638    protected override IScope[] Select(List<IScope> scopes) {
    3739      int count = NumberOfSelectedSubScopesParameter.ActualValue.Value;
    3840      bool copy = CopySelectedParameter.Value.Value;
     41      bool maximization = MaximizationParameter.ActualValue.Value;
     42      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    3943      IScope[] selected = new IScope[count];
    4044
    41       int j = scopes.Count - 1;
     45      // create a list for each scope that contains the scope's index in the original scope list
     46      var temp = qualities.Select((x, index) => new { index, x.Value });
     47      if (maximization)
     48        temp = temp.OrderBy(x => x.Value);
     49      else
     50        temp = temp.OrderByDescending(x => x.Value);
     51      var list = temp.ToList();
     52
     53      int j = 0;
    4254      for (int i = 0; i < count; i++) {
    4355        if (copy) {
    44           selected[i] = (IScope)scopes[j].Clone();
    45           j--;
    46           if (j < 0) j = scopes.Count - 1;
     56          selected[i] = (IScope)scopes[list[j].index].Clone();
     57          j++;
     58          if (j >= list.Count) j = 0;
    4759        } else {
    48           selected[i] = scopes[scopes.Count - 1];
    49           scopes.RemoveAt(scopes.Count - 1);
     60          selected[i] = scopes[list[j].index];
     61          scopes.RemoveAt(list[j].index);
     62          list.RemoveAt(j);
    5063        }
    5164      }
Note: See TracChangeset for help on using the changeset viewer.