- Timestamp:
- 07/08/16 14:40:02 (8 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj
r11623 r14029 115 115 </ItemGroup> 116 116 <ItemGroup> 117 <Compile Include="ChildrenCopyCreator.cs" /> 117 118 <Compile Include="ExpressionCalculator.cs" /> 118 119 <Compile Include="NoSimilarityCalculator.cs" /> -
branches/crossvalidation-2434/HeuristicLab.Optimization.Operators/3.3/MultiObjective/RankAndCrowdingSorter.cs
r12144 r14029 29 29 30 30 namespace HeuristicLab.Optimization.Operators { 31 [StorableClass] 31 32 public class RankAndCrowdingSorter : AlgorithmOperator, IMultiObjectiveOperator { 32 33 #region Parameter properties -
branches/crossvalidation-2434/HeuristicLab.Optimization.Operators/3.3/Plugin.cs.frame
r12753 r14029 26 26 /// Plugin class for HeuristicLab.Optimization.Operators plugin. 27 27 /// </summary> 28 [Plugin("HeuristicLab.Optimization.Operators", "3.3.1 2.$WCREV$")]28 [Plugin("HeuristicLab.Optimization.Operators", "3.3.13.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Optimization.Operators-3.3.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.Collections", "3.3")] -
branches/crossvalidation-2434/HeuristicLab.Optimization.Operators/3.3/Properties/AssemblyInfo.cs.frame
r12753 r14029 54 54 // by using the '*' as shown below: 55 55 [assembly: AssemblyVersion("3.3.0.0")] 56 [assembly: AssemblyFileVersion("3.3.1 2.$WCREV$")]56 [assembly: AssemblyFileVersion("3.3.13.$WCREV$")] -
branches/crossvalidation-2434/HeuristicLab.Optimization.Operators/3.3/SolutionSimilarityCalculator.cs
r12129 r14029 22 22 using System; 23 23 using System.Linq; 24 using System.Threading.Tasks; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 41 42 [Storable] 42 43 public string QualityVariableName { get; set; } 44 [Storable] 45 public bool ExecuteInParallel { get; set; } 46 [Storable] 47 public int MaxDegreeOfParallelism { get; set; } 43 48 #endregion 44 49 … … 48 53 protected SolutionSimilarityCalculator(SolutionSimilarityCalculator original, Cloner cloner) 49 54 : base(original, cloner) { 50 this.SolutionVariableName = original.SolutionVariableName; 51 this.QualityVariableName = original.QualityVariableName; 52 } 53 protected SolutionSimilarityCalculator() : base() { } 55 SolutionVariableName = original.SolutionVariableName; 56 QualityVariableName = original.QualityVariableName; 57 ExecuteInParallel = original.ExecuteInParallel; 58 MaxDegreeOfParallelism = original.MaxDegreeOfParallelism; 59 } 60 61 protected SolutionSimilarityCalculator() : base() { 62 ExecuteInParallel = false; 63 MaxDegreeOfParallelism = -1; 64 } 65 66 [StorableHook(HookType.AfterDeserialization)] 67 private void AfterDeserialization() { 68 if (MaxDegreeOfParallelism == 0) { 69 ExecuteInParallel = false; 70 MaxDegreeOfParallelism = -1; 71 } 72 } 54 73 55 74 public double[][] CalculateSolutionCrowdSimilarity(IScope leftSolutionCrowd, IScope rightSolutionCrowd) { … … 75 94 76 95 public double[][] CalculateSolutionCrowdSimilarity(IScope solutionCrowd) { 77 if (solutionCrowd == null) 96 if (solutionCrowd == null) { 78 97 throw new ArgumentException("Cannot calculate similarity because the provided crowd is null."); 79 98 } 80 99 var individuals = solutionCrowd.SubScopes; 81 100 82 if (!individuals.Any()) 101 if (!individuals.Any()) { 83 102 throw new ArgumentException("Cannot calculate similarity because the provided crowd is empty."); 103 } 84 104 85 105 var similarityMatrix = new double[individuals.Count][]; 86 for (int i = 0; i < individuals.Count; i++) similarityMatrix[i] = new double[individuals.Count]; 87 88 if (IsCommutative) { 89 for (int i = 0; i < individuals.Count; i++) { 90 for (int j = i; j < individuals.Count; j++) { 91 similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]); 106 for (int i = 0; i < individuals.Count; i++) { 107 similarityMatrix[i] = new double[individuals.Count]; 108 } 109 110 if (ExecuteInParallel) { 111 var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = MaxDegreeOfParallelism }; 112 if (IsCommutative) { 113 Parallel.For(0, individuals.Count, parallelOptions, i => { 114 for (int j = i; j < individuals.Count; j++) { 115 similarityMatrix[i][j] = 116 similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]); 117 } 118 }); 119 } else { 120 Parallel.For(0, individuals.Count, parallelOptions, i => { 121 for (int j = i; j < individuals.Count; j++) { 122 similarityMatrix[i][j] = CalculateSolutionSimilarity(individuals[i], individuals[j]); 123 if (i == j) continue; 124 similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[j], individuals[i]); 125 } 126 }); 127 } 128 } else { 129 if (IsCommutative) { 130 for (int i = 0; i < individuals.Count; i++) { 131 for (int j = i; j < individuals.Count; j++) { 132 similarityMatrix[i][j] = 133 similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]); 134 } 92 135 } 93 } 94 } else{95 for (int i = 0; i < individuals.Count; i++) {96 for (int j = i; j < individuals.Count; j++) {97 similarityMatrix[i][j] = CalculateSolutionSimilarity(individuals[i], individuals[j]);98 if (i == j) continue;99 similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[j], individuals[i]);136 } else { 137 for (int i = 0; i < individuals.Count; i++) { 138 for (int j = i; j < individuals.Count; j++) { 139 similarityMatrix[i][j] = CalculateSolutionSimilarity(individuals[i], individuals[j]); 140 if (i == j) continue; 141 similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[j], individuals[i]); 142 } 100 143 } 101 144 } -
branches/crossvalidation-2434/HeuristicLab.Optimization.Operators/3.3/UnidirectionalRingMigrator.cs
r12012 r14029 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 25 26 using HeuristicLab.Operators; 27 using HeuristicLab.Parameters; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 … … 33 35 [StorableClass] 34 36 public class UnidirectionalRingMigrator : SingleSuccessorOperator, IMigrator { 37 public IValueLookupParameter<BoolValue> ClockwiseMigrationParameter { 38 get { return (IValueLookupParameter<BoolValue>)Parameters["ClockwiseMigration"]; } 39 } 40 35 41 [StorableConstructor] 36 42 protected UnidirectionalRingMigrator(bool deserializing) : base(deserializing) { } 37 43 protected UnidirectionalRingMigrator(UnidirectionalRingMigrator original, Cloner cloner) : base(original, cloner) { } 38 public UnidirectionalRingMigrator() : base() { }39 44 45 public UnidirectionalRingMigrator() 46 : base() { 47 Parameters.Add(new ValueLookupParameter<BoolValue>("ClockwiseMigration", "True to migrate individuals clockwise, false to migrate individuals counterclockwise.", new BoolValue(true))); 48 } 49 50 [StorableHook(HookType.AfterDeserialization)] 51 private void AfterDeserialization() { 52 // BackwardsCompatibility3.3 53 #region Backwards compatible code (remove with 3.4) 54 if (!Parameters.ContainsKey("ClockwiseMigration")) { 55 Parameters.Add(new ValueLookupParameter<BoolValue>("ClockwiseMigration", "True to migrate individuals clockwise, false to migrate individuals counterclockwise.", new BoolValue(false))); 56 } 57 #endregion 58 } 40 59 public override IDeepCloneable Clone(Cloner cloner) { 41 60 return new UnidirectionalRingMigrator(this, cloner); … … 43 62 44 63 /// <summary> 45 /// Migrates every first sub scope of each child to its left neighbour (like a ring). 46 /// <pre> 64 /// Migrates every first sub scope of each child to its right or left neighbour (like a ring). 65 /// If clockwise migration (default) is used the selected scopes A D G becomes G A D, contrary to counterclockwise where A D G becomes D G A. 66 /// <pre> 47 67 /// __ scope __ __ scope __ 48 68 /// / | \ / | \ … … 56 76 /// <returns>The next operation.</returns> 57 77 public override IOperation Apply() { 78 bool clockwise = ClockwiseMigrationParameter.ActualValue.Value; 58 79 IScope scope = ExecutionContext.Scope; 59 80 List<IScope> emigrantsList = new List<IScope>(); … … 65 86 } 66 87 67 // shift first emigrants to end of list 68 emigrantsList.Add(emigrantsList[0]); 69 emigrantsList.RemoveAt(0); 88 if (clockwise) { 89 // shift last emigrants to start of list 90 emigrantsList.Insert(0, emigrantsList[emigrantsList.Count - 1]); 91 emigrantsList.RemoveAt(emigrantsList.Count - 1); 92 } else { 93 // shift first emigrants to end of list 94 emigrantsList.Add(emigrantsList[0]); 95 emigrantsList.RemoveAt(0); 96 } 70 97 71 98 for (int i = 0; i < scope.SubScopes.Count; i++)
Note: See TracChangeset
for help on using the changeset viewer.