- Timestamp:
- 04/19/10 01:51:50 (15 years ago)
- 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 98 98 <Compile Include="StochasticBranch.cs" /> 99 99 <Compile Include="SubScopesCreator.cs" /> 100 <Compile Include="SubScopesMixer.cs" /> 100 101 <Compile Include="SubScopesProcessor.cs" /> 101 102 <Compile Include="SubScopesRemover.cs" /> -
trunk/sources/HeuristicLab.Operators/3.3/SubScopesMixer.cs
r1530 r3404 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. … … 21 21 22 22 using System; 23 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.Operators { … … 30 30 /// Mixes the sub scopes of a specified scope according to a specified number of partitions. 31 31 /// </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"]; } 36 37 } 38 39 public IntValue Partitions { 40 get { return PartitionsParameter.Value; } 41 set { PartitionsParameter.Value = value; } 42 } 43 37 44 /// <summary> 38 45 /// Initializes a new instance of <see cref="SubScopesMixer"/> with one variable infos … … 41 48 public SubScopesMixer() 42 49 : 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))); 46 51 } 47 52 48 53 /// <summary> 49 /// Mixes the sub scopes of the given <paramref name="scope"/>.54 /// Mixes the sub-scopes of the scope this operator is applied on. 50 55 /// </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/> 58 62 /// In the end the new sorting of the sub scopes is 1-5-9-2-6-10-3-7-11-4-8-12. 59 63 /// </example> … … 63 67 /// <param name="scope">The scope whose sub scopes should be mixed.</param> 64 68 /// <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]; 71 78 72 79 // mix sub-scopes -> alternately take one sub-scope from each partition 73 80 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 } 76 84 } 77 scope.ReorderSubScopes(sequence); 85 scope.SubScopes.Clear(); 86 scope.SubScopes.AddRange(reorderedSubScopes); 78 87 79 return null;88 return base.Apply(); 80 89 } 81 90 } -
trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj
r3384 r3404 139 139 <None Include="app.config" /> 140 140 <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" />144 141 <None Include="HeuristicLab.snk" /> 145 142 <None Include="Properties\AssemblyInfo.frame" /> -
trunk/sources/HeuristicLab.Selection/3.3/HeuristicLab.Selection-3.3.csproj
r3384 r3404 83 83 <None Include="HeuristicLabSelectionPlugin.cs.frame" /> 84 84 <Compile Include="BestSelector.cs" /> 85 <Compile Include="GenderSpecificSelector.cs" /> 86 <Compile Include="RightChildReducer.cs" /> 85 87 <Compile Include="SingleObjectiveSelector.cs" /> 86 88 <Compile Include="LeftReducer.cs" /> -
trunk/sources/HeuristicLab.Selection/3.3/RightChildReducer.cs
r1530 r3404 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 using HeuristicLab.Operators; 24 using HeuristicLab.Optimization; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 26 28 27 namespace HeuristicLab.Selection { 29 28 /// <summary> 30 /// Reduces the sub scopes by one level, so that the right sub scope contains also the right child scopes31 /// 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). 32 31 /// <pre> 33 /// scopescope34 /// / |\ / \35 /// L ... R => A R36 /// / | \ \ / /\\37 /// A ... LR C C D EF38 /// 39 /// D EF32 /// scope scope 33 /// / \ / \ 34 /// R S(1) => R S 35 /// / \ \ /|\ /|\ 36 /// R(3) S(2) C ABCDEF CDEF 37 /// /|\ /|\ 38 /// ABCDEF DEF 40 39 /// </pre> 41 40 /// </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 { 48 44 /// <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. 51 47 /// </summary> 52 48 /// <param name="scope">The current scope to reduce.</param> 53 49 /// <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]; 58 55 59 // merge right children60 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]); 62 59 63 leftChild = leftChild.SubScopes[0];64 60 leftChild = leftChild.SubScopes[0]; 61 } 65 62 List<IScope> subScopes = new List<IScope>(); 66 63 subScopes.Add(leftChild);
Note: See TracChangeset
for help on using the changeset viewer.