Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3096


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
Files:
1 added
8 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.LS/3.3/LSMainLoop.cs

    r3078 r3096  
    9797      UniformSequentialSubScopesProcessor moveEvaluationProcessor = new UniformSequentialSubScopesProcessor();
    9898      Placeholder moveEvaluator = new Placeholder();
    99       SubScopesSorter moveQualitySorter = new SubScopesSorter();
    100       LeftSelector leftSelector = new LeftSelector();
     99      BestSelector bestSelector = new BestSelector();
    101100      RightReducer rightReducer = new RightReducer();
    102101      UniformSequentialSubScopesProcessor moveMakingProcessor = new UniformSequentialSubScopesProcessor();
     
    127126      moveEvaluator.OperatorParameter.ActualName = "MoveEvaluator";
    128127
    129       moveQualitySorter.DescendingParameter.ActualName = "Maximization";
    130       moveQualitySorter.ValueParameter.ActualName = "MoveQuality";
    131 
    132       leftSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
     128      bestSelector.CopySelected = new BoolValue(false);
     129      bestSelector.MaximizationParameter.ActualName = "Maximization";
     130      bestSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
     131      bestSelector.QualityParameter.ActualName = "MoveQuality";
    133132
    134133      moveMakingProcessor.Name = "MoveMaking processor (UniformSequentialSubScopesProcessor)";
     
    170169      moveGenerator.Successor = moveEvaluationProcessor;
    171170      moveEvaluationProcessor.Operator = moveEvaluator;
    172       moveEvaluationProcessor.Successor = moveQualitySorter;
    173       moveQualitySorter.Successor = leftSelector;
    174       leftSelector.Successor = rightReducer;
     171      moveEvaluationProcessor.Successor = bestSelector;
     172      bestSelector.Successor = rightReducer;
    175173      rightReducer.Successor = moveMakingProcessor;
    176174      moveMakingProcessor.Operator = qualityComparator;
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGAMainLoop.cs

    r3095 r3096  
    115115      QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator();
    116116      ResultsCollector resultsCollector = new ResultsCollector();
    117       SubScopesSorter subScopesSorter1 = new SubScopesSorter();
    118117      Placeholder selector = new Placeholder();
    119118      SequentialSubScopesProcessor sequentialSubScopesProcessor1 = new SequentialSubScopesProcessor();
     
    125124      Placeholder evaluator = new Placeholder();
    126125      SubScopesRemover subScopesRemover = new SubScopesRemover();
    127       SubScopesSorter subScopesSorter2 = new SubScopesSorter();
    128126      SequentialSubScopesProcessor sequentialSubScopesProcessor2 = new SequentialSubScopesProcessor();
    129       LeftSelector leftSelector = new LeftSelector();
     127      BestSelector bestSelector = new BestSelector();
    130128      RightReducer rightReducer = new RightReducer();
    131129      MergingReducer mergingReducer = new MergingReducer();
     
    178176      resultsCollector.ResultsParameter.ActualName = "Results";
    179177
    180       subScopesSorter1.DescendingParameter.ActualName = "Maximization";
    181       subScopesSorter1.ValueParameter.ActualName = "Quality";
    182 
    183178      selector.Name = "Selector";
    184179      selector.OperatorParameter.ActualName = "Selector";
     
    200195      subScopesRemover.RemoveAllSubScopes = true;
    201196
    202       subScopesSorter2.DescendingParameter.ActualName = "Maximization";
    203       subScopesSorter2.ValueParameter.ActualName = "Quality";
    204 
    205       leftSelector.CopySelected = new BoolValue(false);
    206       leftSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
     197      bestSelector.CopySelected = new BoolValue(false);
     198      bestSelector.MaximizationParameter.ActualName = "Maximization";
     199      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
     200      bestSelector.QualityParameter.ActualName = "Quality";
    207201
    208202      intCounter.Increment = new IntValue(1);
     
    251245      dataTableValuesCollector1.Successor = qualityDifferenceCalculator1;
    252246      qualityDifferenceCalculator1.Successor = resultsCollector;
    253       resultsCollector.Successor = subScopesSorter1;
    254       subScopesSorter1.Successor = selector;
     247      resultsCollector.Successor = selector;
    255248      selector.Successor = sequentialSubScopesProcessor1;
    256249      sequentialSubScopesProcessor1.Operators.Add(new EmptyOperator());
     
    259252      childrenCreator.Successor = uniformSequentialSubScopesProcessor;
    260253      uniformSequentialSubScopesProcessor.Operator = crossover;
    261       uniformSequentialSubScopesProcessor.Successor = subScopesSorter2;
     254      uniformSequentialSubScopesProcessor.Successor = null;
    262255      crossover.Successor = stochasticBranch;
    263256      stochasticBranch.FirstBranch = mutator;
     
    267260      evaluator.Successor = subScopesRemover;
    268261      subScopesRemover.Successor = null;
    269       subScopesSorter2.Successor = null;
    270       sequentialSubScopesProcessor2.Operators.Add(leftSelector);
     262      sequentialSubScopesProcessor2.Operators.Add(bestSelector);
    271263      sequentialSubScopesProcessor2.Operators.Add(new EmptyOperator());
    272264      sequentialSubScopesProcessor2.Successor = mergingReducer;
    273       leftSelector.Successor = rightReducer;
     265      bestSelector.Successor = rightReducer;
    274266      rightReducer.Successor = null;
    275267      mergingReducer.Successor = intCounter;
     
    281273      dataTableValuesCollector2.Successor = qualityDifferenceCalculator2;
    282274      qualityDifferenceCalculator2.Successor = conditionalBranch;
    283       conditionalBranch.FalseBranch = subScopesSorter1;
     275      conditionalBranch.FalseBranch = selector;
    284276      conditionalBranch.TrueBranch = null;
    285277      conditionalBranch.Successor = null;
  • 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.