- Timestamp:
- 10/15/15 12:18:42 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis/3.3/PopulationSimilarityAnalysis/PopulationSimilarityAnalyzer.cs
r12076 r13005 39 39 public class PopulationSimilarityAnalyzer : SingleSuccessorOperator, IAnalyzer, ISimilarityBasedOperator { 40 40 private const string DiversityResultNameParameterName = "DiversityResultsName"; 41 private const string ExecuteInParallelParameterName = "ExecuteInParallel"; 42 private const string MaxDegreeOfParallelismParameterName = "MaxDegreeOfParallelism"; 41 43 42 44 #region Backwards compatible code, remove with 3.4 … … 71 73 get { return (FixedValueParameter<StringValue>)Parameters[DiversityResultNameParameterName]; } 72 74 } 75 public IFixedValueParameter<BoolValue> ExecuteInParallelParameter { 76 get { return (IFixedValueParameter<BoolValue>)Parameters[ExecuteInParallelParameterName]; } 77 } 78 public IFixedValueParameter<IntValue> MaxDegreeOfParallelismParameter { 79 get { return (IFixedValueParameter<IntValue>)Parameters[MaxDegreeOfParallelismParameterName]; } 80 } 73 81 74 82 public string DiversityResultName { … … 77 85 } 78 86 87 public bool ExecuteInParallel { 88 get { return ExecuteInParallelParameter.Value.Value; } 89 set { ExecuteInParallelParameter.Value.Value = value; } 90 } 91 92 public int MaxDegreeOfParallelism { 93 get { return MaxDegreeOfParallelismParameter.Value.Value; } 94 set { MaxDegreeOfParallelismParameter.Value.Value = value; } 95 } 96 79 97 [StorableConstructor] 80 98 protected PopulationSimilarityAnalyzer(bool deserializing) : base(deserializing) { } 81 protected PopulationSimilarityAnalyzer(PopulationSimilarityAnalyzer original, Cloner cloner) : base(original, cloner) { } 99 100 protected PopulationSimilarityAnalyzer(PopulationSimilarityAnalyzer original, Cloner cloner) 101 : base(original, cloner) { 102 RegisterParametersEventHandlers(); 103 } 104 82 105 public PopulationSimilarityAnalyzer(IEnumerable<ISolutionSimilarityCalculator> validSimilarityCalculators) 83 106 : base() { … … 89 112 Parameters.Add(new LookupParameter<IntValue>("UpdateCounter", "The value which counts how many times the operator was called since the last update.", "PopulationDiversityAnalyzerUpdateCounter")); 90 113 Parameters.Add(new FixedValueParameter<StringValue>(DiversityResultNameParameterName, "Specifies how the diversity results should be named.", new StringValue("PopulationDiversity"))); 114 Parameters.Add(new FixedValueParameter<BoolValue>(ExecuteInParallelParameterName, "Specifies whether similarity calculations should be parallelized.", new BoolValue(false))); 115 Parameters.Add(new FixedValueParameter<IntValue>(MaxDegreeOfParallelismParameterName, "Specifies the maximum number of threads when calculating similarities in parallel.", new IntValue(-1))); 91 116 92 117 var similarityCalculators = SimilarityCalculatorParameter.ValidValues; 93 foreach (var sc in validSimilarityCalculators) 118 foreach (var sc in validSimilarityCalculators) { 94 119 similarityCalculators.Add(sc); 95 120 } 96 121 97 122 ResultsParameter.Hidden = true; 98 123 UpdateCounterParameter.Hidden = true; 124 ExecuteInParallelParameter.Hidden = true; 125 MaxDegreeOfParallelismParameter.Hidden = true; 126 127 RegisterParametersEventHandlers(); 128 } 129 130 private void RegisterParametersEventHandlers() { 131 ExecuteInParallelParameter.Value.ValueChanged += Value_ValueChanged; 132 MaxDegreeOfParallelismParameter.Value.ValueChanged += Value_ValueChanged; 133 } 134 135 private void Value_ValueChanged(object sender, EventArgs e) { 136 var similarityCalculators = SimilarityCalculatorParameter.ValidValues; 137 foreach (var similarityCalculator in similarityCalculators) { 138 similarityCalculator.ExecuteInParallel = ExecuteInParallel; 139 similarityCalculator.MaxDegreeOfParallelism = MaxDegreeOfParallelism; 140 } 99 141 } 100 142 … … 113 155 Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The similarity calculator that should be used to calculate solution similarity.")); 114 156 115 SimilarityCalculatorParameter.ValidValues.Add(oldSimilarityCalculator); 157 if (oldSimilarityCalculator != null) 158 SimilarityCalculatorParameter.ValidValues.Add(oldSimilarityCalculator); 159 160 if (!Parameters.ContainsKey(ExecuteInParallelParameterName)) { 161 Parameters.Add(new FixedValueParameter<BoolValue>(ExecuteInParallelParameterName, 162 "Specifies whether similarity calculations should be parallelized.", new BoolValue(false))); 163 ExecuteInParallelParameter.Hidden = true; 164 } 165 if (!Parameters.ContainsKey(MaxDegreeOfParallelismParameterName)) { 166 Parameters.Add(new FixedValueParameter<IntValue>(MaxDegreeOfParallelismParameterName, 167 "Specifies the maximum number of threads when calculating similarities in parallel.", new IntValue(-1))); 168 MaxDegreeOfParallelismParameter.Hidden = true; 169 } 170 171 RegisterParametersEventHandlers(); 116 172 #endregion 117 173 }
Note: See TracChangeset
for help on using the changeset viewer.