Changeset 3404 for trunk/sources/HeuristicLab.Operators
- Timestamp:
- 04/19/10 01:51:50 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Operators/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified 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" /> -
TabularUnified 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 }
Note: See TracChangeset
for help on using the changeset viewer.