Changeset 3096 for trunk/sources/HeuristicLab.Selection
- Timestamp:
- 03/18/10 04:11:49 (15 years ago)
- 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 20 20 #endregion 21 21 22 using System; 23 using System.Linq; 22 24 using System.Collections.Generic; 23 25 using HeuristicLab.Core; 24 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Data; 25 28 26 29 namespace HeuristicLab.Selection { 27 30 /// <summary> 28 /// A n operator which selects sub-scopes from left to right.31 /// A selection operator which considers a single double quality value and selects the best. 29 32 /// </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.")] 31 34 [StorableClass] 32 35 [Creatable("Test")] 33 public sealed class LeftSelector :Selector {34 public LeftSelector() : base() { }36 public sealed class BestSelector : SingleObjectiveSelector { 37 public BestSelector() : base() { } 35 38 36 39 protected override IScope[] Select(List<IScope> scopes) { 37 40 int count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 38 41 bool copy = CopySelectedParameter.Value.Value; 42 bool maximization = MaximizationParameter.ActualValue.Value; 43 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 39 44 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(); 40 53 41 54 int j = 0; 42 55 for (int i = 0; i < count; i++) { 43 56 if (copy) { 44 selected[i] = (IScope)scopes[ j].Clone();57 selected[i] = (IScope)scopes[list[j].index].Clone(); 45 58 j++; 46 if (j >= scopes.Count) j = 0;59 if (j >= list.Count) j = 0; 47 60 } 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); 50 64 } 51 65 } -
trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.3.csproj
r2900 r3096 82 82 <ItemGroup> 83 83 <None Include="HeuristicLabSelectionPlugin.cs.frame" /> 84 <Compile Include="BestSelector.cs" /> 85 <Compile Include="SingleObjectiveSelector.cs" /> 84 86 <Compile Include="LeftReducer.cs" /> 85 87 <Compile Include="MergingReducer.cs" /> … … 88 90 <Compile Include="ProportionalSelector.cs" /> 89 91 <Compile Include="RightReducer.cs" /> 90 <Compile Include="RightSelector.cs" />91 92 <Compile Include="StochasticSelector.cs" /> 92 <Compile Include="LeftSelector.cs" />93 93 <Compile Include="RandomSelector.cs" /> 94 94 <Compile Include="StochasticSingleObjectiveSelector.cs" /> … … 97 97 <Compile Include="Selector.cs" /> 98 98 <Compile Include="TournamentSelector.cs" /> 99 <Compile Include="WorstSelector.cs" /> 99 100 </ItemGroup> 100 101 <ItemGroup> -
trunk/sources/HeuristicLab.Selection/3.3/LinearRankSelector.cs
r3048 r3096 34 34 [Creatable("Test")] 35 35 public sealed class LinearRankSelector : StochasticSingleObjectiveSelector { 36 public LinearRankSelector() 37 : base() { 38 CopySelected.Value = true; 39 } 36 public LinearRankSelector() : base() { } 40 37 41 38 protected override IScope[] Select(List<IScope> scopes) { -
trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs
r3048 r3096 48 48 : base() { 49 49 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;51 50 } 52 51 -
trunk/sources/HeuristicLab.Selection/3.3/Selector.cs
r3048 r3096 59 59 protected Selector() 60 60 : 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))); 62 62 Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfSelectedSubScopes", "The number of sub-scopes which should be selected.")); 63 63 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 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data;24 23 using HeuristicLab.Optimization; 25 24 using HeuristicLab.Parameters; … … 32 31 [Item("StochasticSingleObjectiveSelector", "A base class for stochastic selection operators which consider a single double quality value for selection.")] 33 32 [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"]; } 40 36 } 41 37 42 38 protected StochasticSingleObjectiveSelector() 43 39 : 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.")); 46 41 } 47 42 } -
trunk/sources/HeuristicLab.Selection/3.3/TournamentSelector.cs
r3048 r3096 41 41 public TournamentSelector() : base() { 42 42 Parameters.Add(new ValueLookupParameter<IntValue>("GroupSize", "The size of the tournament group.", new IntValue(2))); 43 CopySelected.Value = true;44 43 } 45 44 -
trunk/sources/HeuristicLab.Selection/3.3/WorstSelector.cs
r3093 r3096 20 20 #endregion 21 21 22 using System.Linq; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Data; 25 27 26 28 namespace HeuristicLab.Selection { 27 29 /// <summary> 28 /// A n operator which selects sub-scopes from right to left.30 /// A selection operator which considers a single double quality value and selects the worst. 29 31 /// </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.")] 31 33 [StorableClass] 32 34 [Creatable("Test")] 33 public sealed class RightSelector :Selector {34 public RightSelector() : base() { }35 public sealed class WorstSelector : SingleObjectiveSelector { 36 public WorstSelector() : base() { } 35 37 36 38 protected override IScope[] Select(List<IScope> scopes) { 37 39 int count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 38 40 bool copy = CopySelectedParameter.Value.Value; 41 bool maximization = MaximizationParameter.ActualValue.Value; 42 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 39 43 IScope[] selected = new IScope[count]; 40 44 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; 42 54 for (int i = 0; i < count; i++) { 43 55 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; 47 59 } 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); 50 63 } 51 64 }
Note: See TracChangeset
for help on using the changeset viewer.