Changeset 2805 for trunk/sources/HeuristicLab.Selection/3.3
- Timestamp:
- 02/16/10 06:50:14 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Selection/3.3
- Files:
-
- 3 added
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.3.csproj
r2790 r2805 82 82 <ItemGroup> 83 83 <None Include="HeuristicLabSelectionPlugin.cs.frame" /> 84 <Compile Include="RightSelector.cs" /> 85 <Compile Include="StochasticSelector.cs" /> 86 <Compile Include="LeftSelector.cs" /> 87 <Compile Include="RandomSelector.cs" /> 88 <Compile Include="StochasticSingleObjectiveSelector.cs" /> 84 89 <Compile Include="HeuristicLabSelectionPlugin.cs" /> 85 90 <Compile Include="Properties\AssemblyInfo.cs" /> 91 <Compile Include="Selector.cs" /> 92 <Compile Include="TournamentSelector.cs" /> 86 93 </ItemGroup> 87 94 <ItemGroup> … … 90 97 </ItemGroup> 91 98 <ItemGroup> 99 <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> 100 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> 101 <Name>HeuristicLab.Collections-3.3</Name> 102 </ProjectReference> 92 103 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> 93 104 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> … … 101 112 <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project> 102 113 <Name>HeuristicLab.Operators-3.3</Name> 114 </ProjectReference> 115 <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj"> 116 <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project> 117 <Name>HeuristicLab.Parameters-3.3</Name> 118 </ProjectReference> 119 <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj"> 120 <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project> 121 <Name>HeuristicLab.Persistence-3.3</Name> 103 122 </ProjectReference> 104 123 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj"> -
trunk/sources/HeuristicLab.Selection/3.3/HeuristicLabSelectionPlugin.cs.frame
r2790 r2805 31 31 [Plugin("HeuristicLab.Selection", "3.3.0.$WCREV$")] 32 32 [PluginFile("HeuristicLab.Selection-3.3.dll", PluginFileType.Assembly)] 33 [PluginDependency("HeuristicLab.Collections", "3.3")] 33 34 [PluginDependency("HeuristicLab.Core", "3.3")] 34 35 [PluginDependency("HeuristicLab.Data", "3.3")] 35 36 [PluginDependency("HeuristicLab.Operators", "3.3")] 37 [PluginDependency("HeuristicLab.Parameters", "3.3")] 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] 36 39 public class HeuristicLabSelectionPlugin : PluginBase { 37 40 } -
trunk/sources/HeuristicLab.Selection/3.3/LeftSelector.cs
r1530 r2805 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Text;25 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Selection { 28 29 /// <summary> 29 /// Copies or moves a defined number of sub scopes from a source scope to a target scope, starting at 30 /// the left side of the tree. 30 /// An operator which selects sub-scopes from left to right. 31 31 /// </summary> 32 public class LeftSelector : StochasticSelectorBase {33 /// <inheritdoc select="summary"/>34 public override string Description {35 get { return @"TODO\r\nOperator description still missing ..."; }36 }32 [Item("LeftSelector", "An operator which selects sub-scopes from left to right.")] 33 [EmptyStorableClass] 34 [Creatable("Test")] 35 public sealed class LeftSelector : Selector { 36 public LeftSelector() : base() { } 37 37 38 /// <summary> 39 /// Copies or moves a number of sub scopes (<paramref name="selected"/>) from <paramref name="source"/> 40 /// starting at the left end to the <paramref name="target"/>. 41 /// </summary> 42 /// <param name="random">A random number generator.</param> 43 /// <param name="source">The source scope from which to copy/move the sub scopes.</param> 44 /// <param name="selected">The number of sub scopes to move. Can be also bigger than the total 45 /// number of sub scopes in <paramref name="source"/>, then the copying process starts again from the 46 /// beginning.</param> 47 /// <param name="target">The target where to copy/move the sub scopes.</param> 48 /// <param name="copySelected">Boolean flag whether the sub scopes shall be copied or moved.</param> 49 protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) { 50 int index = 0; 51 for (int i = 0; i < selected; i++) { 52 if (copySelected) { 53 target.AddSubScope((IScope)source.SubScopes[index].Clone()); 54 index++; 55 if (index >= source.SubScopes.Count) index = 0; 38 protected override void Select(ScopeList source, ScopeList target) { 39 int count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 40 bool copy = CopySelectedParameter.Value.Value; 41 42 int j = 0; 43 for (int i = 0; i < count; i++) { 44 if (copy) { 45 target.Add((IScope)source[j].Clone()); 46 j++; 47 if (j >= source.Count) j = 0; 56 48 } else { 57 IScope s = source.SubScopes[0]; 58 source.RemoveSubScope(s); 59 target.AddSubScope(s); 49 target.Add(source[0]); 50 source.RemoveAt(0); 60 51 } 61 52 } -
trunk/sources/HeuristicLab.Selection/3.3/RandomSelector.cs
r1530 r2805 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Text;25 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Selection { 28 29 /// <summary> 29 /// Copies or moves a defined number of sub scopes from a source scope to a target scope, being selected 30 /// randomly. 30 /// A random selection operator. 31 31 /// </summary> 32 public class RandomSelector : StochasticSelectorBase {33 /// <inheritdoc select="summary"/>34 public override string Description {35 get { return @"TODO\r\nOperator description still missing ..."; }36 }32 [Item("RandomSelector", "A random selection operator.")] 33 [EmptyStorableClass] 34 [Creatable("Test")] 35 public sealed class RandomSelector : StochasticSelector { 36 public RandomSelector() : base() { } 37 37 38 /// <summary> 39 /// Copies or moves a number of sub scopes (<paramref name="selected"/>) from <paramref name="source"/> 40 /// to the <paramref name="target"/>, chosen randomly. 41 /// </summary> 42 /// <param name="random">The random number generator.</param> 43 /// <param name="source">The source scope from which to copy/move the sub scopes.</param> 44 /// <param name="selected">The number of sub scopes to move.</param> 45 /// <param name="target">The target where to copy/move the sub scopes.</param> 46 /// <param name="copySelected">Boolean flag whether the sub scopes shall be copied or moved.</param> 47 protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) { 48 for (int i = 0; i < selected; i++) { 49 if (copySelected) { 50 target.AddSubScope((IScope)source.SubScopes[random.Next(source.SubScopes.Count)].Clone()); 51 } else { 52 IScope s = source.SubScopes[random.Next(source.SubScopes.Count)]; 53 source.RemoveSubScope(s); 54 target.AddSubScope(s); 38 protected override void Select(ScopeList source, ScopeList target) { 39 int count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 40 bool copy = CopySelectedParameter.Value.Value; 41 IRandom random = RandomParameter.ActualValue; 42 43 for (int i = 0; i < count; i++) { 44 if (copy) 45 target.Add((IScope)source[random.Next(source.Count)].Clone()); 46 else { 47 int index = random.Next(source.Count); 48 target.Add(source[index]); 49 source.RemoveAt(index); 55 50 } 56 51 } -
trunk/sources/HeuristicLab.Selection/3.3/RightSelector.cs
r1530 r2805 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Text;25 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace HeuristicLab.Selection { 28 29 /// <summary> 29 /// Copies or moves a defined number of sub scopes from a source scope to a target scope, starting at 30 /// the right side of the tree. 30 /// An operator which selects sub-scopes from right to left. 31 31 /// </summary> 32 public class RightSelector : StochasticSelectorBase {33 /// <inheritdoc select="summary"/>34 public override string Description {35 get { return @"TODO\r\nOperator description still missing ..."; }36 }32 [Item("RightSelector", "An operator which selects sub-scopes from right to left.")] 33 [EmptyStorableClass] 34 [Creatable("Test")] 35 public sealed class RightSelector : Selector { 36 public RightSelector() : base() { } 37 37 38 /// <summary> 39 /// Copies or moves a number of sub scopes (<paramref name="selected"/>) from <paramref name="source"/> 40 /// starting at the right end to the <paramref name="target"/>. 41 /// </summary> 42 /// <param name="random">A random number generator.</param> 43 /// <param name="source">The source scope from which to copy/move the sub scopes.</param> 44 /// <param name="selected">The number of sub scopes to move. Can be also bigger than the total 45 /// number of sub scopes in <paramref name="source"/>, then the copying process starts again from the 46 /// beginning.</param> 47 /// <param name="target">The target where to copy/move the sub scopes.</param> 48 /// <param name="copySelected">Boolean flag whether the sub scopes shall be copied or moved.</param> 49 protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) { 50 int index = source.SubScopes.Count - 1; 51 for (int i = 0; i < selected; i++) { 52 if (copySelected) { 53 target.AddSubScope((IScope)source.SubScopes[index].Clone()); 54 index--; 55 if (index < 0) index = source.SubScopes.Count - 1; 38 protected override void Select(ScopeList source, ScopeList target) { 39 int count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 40 bool copy = CopySelectedParameter.Value.Value; 41 42 int j = source.Count - 1; 43 for (int i = 0; i < count; i++) { 44 if (copy) { 45 target.Add((IScope)source[j].Clone()); 46 j--; 47 if (j < 0) j = source.Count - 1; 56 48 } else { 57 IScope s = source.SubScopes[source.SubScopes.Count - 1]; 58 source.RemoveSubScope(s); 59 target.AddSubScope(s); 49 target.Add(source[source.Count - 1]); 50 source.RemoveAt(source.Count - 1); 60 51 } 61 52 } -
trunk/sources/HeuristicLab.Selection/3.3/TournamentSelector.cs
r1530 r2805 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Text;25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 28 namespace HeuristicLab.Selection { 29 29 /// <summary> 30 /// Moves or copies a defined number of the best sub scopes from a source scope to a target scope.30 /// A tournament selection operator which considers a single double quality value for selection. 31 31 /// </summary> 32 public class TournamentSelector : StochasticSelectorBase { 33 /// <inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"TODO\r\nOperator description still missing ..."; } 32 [Item("TournamentSelector", "A tournament selection operator which considers a single double quality value for selection.")] 33 [EmptyStorableClass] 34 [Creatable("Test")] 35 public sealed class TournamentSelector : StochasticSingleObjectiveSelector { 36 public ValueLookupParameter<IntData> GroupSizeParameter { 37 get { return (ValueLookupParameter<IntData>)Parameters["GroupSize"]; } 36 38 } 37 39 38 /// <summary> 39 /// Initializes a new instance of <see cref="TournamentSelector"/> with three variable infos 40 /// (<c>Maximization</c>, <c>Quality</c> and <c>GroupSize</c>, being a local variable and set to 41 /// <c>2</c>) with <c>CopySelected</c> set to <c>true</c>. 42 /// </summary> 43 public TournamentSelector() { 44 AddVariableInfo(new VariableInfo("Maximization", "Maximization problem", typeof(BoolData), VariableKind.In)); 45 AddVariableInfo(new VariableInfo("Quality", "Quality value", typeof(DoubleData), VariableKind.In)); 46 AddVariableInfo(new VariableInfo("GroupSize", "Size of the tournament group", typeof(IntData), VariableKind.In)); 47 GetVariableInfo("GroupSize").Local = true; 48 AddVariable(new Variable("GroupSize", new IntData(2))); 49 GetVariable("CopySelected").GetValue<BoolData>().Data = true; 40 public TournamentSelector() : base() { 41 Parameters.Add(new ValueLookupParameter<IntData>("GroupSize", "The size of the tournament group.", new IntData(2))); 50 42 } 51 43 52 /// <summary> 53 /// Copies or moves the best sub scopes from the given <paramref name="source"/> to the specified 54 /// <paramref name="target"/>. 55 /// </summary> 56 /// <exception cref="InvalidOperationException">Thrown when no source sub scopes are available.</exception> 57 /// <param name="random">The random number generator.</param> 58 /// <param name="source">The source scope from where to copy/move the sub scopes.</param> 59 /// <param name="selected">The number of sub scopes to copy/move.</param> 60 /// <param name="target">The target scope where to add the sub scopes.</param> 61 /// <param name="copySelected">Boolean flag whether the sub scopes shall be moved or copied.</param> 62 protected override void Select(IRandom random, IScope source, int selected, IScope target, bool copySelected) { 63 IVariableInfo qualityInfo = GetVariableInfo("Quality"); 64 bool maximization = GetVariableValue<BoolData>("Maximization", source, true).Data; 65 int groupSize = GetVariableValue<IntData>("GroupSize", source, true).Data; 66 for (int i = 0; i < selected; i++) { 67 if (source.SubScopes.Count < 1) throw new InvalidOperationException("No source scopes available to select."); 44 protected override void Select(ScopeList source, ScopeList target) { 45 int count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 46 bool copy = CopySelectedParameter.Value.Value; 47 IRandom random = RandomParameter.ActualValue; 48 bool maximization = MaximizationParameter.ActualValue.Value; 49 List<DoubleData> qualities = new List<DoubleData>(QualityParameter.ActualValue); 50 int groupSize = GroupSizeParameter.ActualValue.Value; 68 51 69 IScope selectedScope = source.SubScopes[random.Next(source.SubScopes.Count)]; 70 double best = selectedScope.GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data; 52 for (int i = 0; i < count; i++) { 53 int best = random.Next(source.Count); 54 int index; 71 55 for (int j = 1; j < groupSize; j++) { 72 IScope scope = source.SubScopes[random.Next(source.SubScopes.Count)]; 73 double quality = scope.GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data; 74 if (((maximization) && (quality > best)) || 75 ((!maximization) && (quality < best))) { 76 best = quality; 77 selectedScope = scope; 56 index = random.Next(source.Count); 57 if (((maximization) && (qualities[index].Value > qualities[best].Value)) || 58 ((!maximization) && (qualities[index].Value < qualities[best].Value))) { 59 best = index; 78 60 } 79 61 } 80 62 81 if (copy Selected)82 target.Add SubScope((IScope)selectedScope.Clone());63 if (copy) 64 target.Add((IScope)source[best].Clone()); 83 65 else { 84 source.RemoveSubScope(selectedScope); 85 target.AddSubScope(selectedScope); 66 target.Add(source[best]); 67 source.RemoveAt(best); 68 qualities.RemoveAt(best); 86 69 } 87 70 }
Note: See TracChangeset
for help on using the changeset viewer.