Changeset 16608
- Timestamp:
- 02/15/19 17:06:22 (6 years ago)
- Location:
- branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblem.cs
r16607 r16608 59 59 get { return (ValueParameter<IntValue>)Parameters["Peaks"]; } 60 60 } 61 public ValueParameter<DoubleMatrix> InitialPeakLocationsParameter { 62 get { return (ValueParameter<DoubleMatrix>)Parameters["InitialPeakLocations"]; } 63 } 61 64 public ValueParameter<DoubleMatrix> PeakLocationsParameter { 62 65 get { return (ValueParameter<DoubleMatrix>)Parameters["PeakLocations"]; } 63 66 } 67 public ValueParameter<DoubleArray> InitialPeakWidthsParameter { 68 get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakWidths"]; } 69 } 64 70 public ValueParameter<DoubleArray> PeakWidthsParameter { 65 71 get { return (ValueParameter<DoubleArray>)Parameters["PeakWidths"]; } 72 } 73 public ValueParameter<DoubleArray> InitialPeakHeightsParameter { 74 get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakHeights"]; } 66 75 } 67 76 public ValueParameter<DoubleArray> PeakHeightsParameter { … … 86 95 set { PeaksParameter.Value = value; } 87 96 } 97 public DoubleMatrix InitialPeakLocations { 98 get { return InitialPeakLocationsParameter.Value; } 99 set { InitialPeakLocationsParameter.Value = value; } 100 } 88 101 public DoubleMatrix PeakLocations { 89 102 get { return PeakLocationsParameter.Value; } 90 103 set { PeakLocationsParameter.Value = value; } 91 104 } 105 public DoubleArray InitialPeakWidths { 106 get { return InitialPeakWidthsParameter.Value; } 107 set { InitialPeakWidthsParameter.Value = value; } 108 } 92 109 public DoubleArray PeakWidths { 93 110 get { return PeakWidthsParameter.Value; } 94 111 set { PeakWidthsParameter.Value = value; } 112 } 113 public DoubleArray InitialPeakHeights { 114 get { return InitialPeakHeightsParameter.Value; } 115 set { InitialPeakHeightsParameter.Value = value; } 95 116 } 96 117 public DoubleArray PeakHeights { … … 114 135 public MovingPeaksBenchmarkProblem() 115 136 : base(new MovingPeaksBenchmarkProblemEvaluator(), new UniformRandomRealVectorCreator()) { 116 Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", null)); 137 var defaultBounds = new double[,] { 138 { 0.0, 100.0 } 139 }; 140 var defaultPeaks = new double[,] { 141 { 08.0, 64.0, 67.0, 55.0, 04.0 }, 142 { 50.0, 13.0, 76.0, 15.0, 07.0 }, 143 { 09.0, 19.0, 27.0, 67.0, 24.0 }, 144 { 66.0, 87.0, 65.0, 19.0, 43.0 }, 145 { 76.0, 32.0, 43.0, 54.0, 65.0 } 146 }; 147 var defaultWidths = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 }; 148 var defaultHeights = new double[] { 50.0, 50.0, 50.0, 50.0, 50.0 }; 149 150 Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", new DoubleMatrix(defaultBounds))); 117 151 Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(5))); 118 152 Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue(5))); 119 Parameters.Add(new ValueParameter<DoubleMatrix>("PeakLocations", "", null )); 120 Parameters.Add(new ValueParameter<DoubleArray>("PeakWidths", "", new DoubleArray(new double[] { 0, 0, 0, 0, 0 }))); 121 Parameters.Add(new ValueParameter<DoubleArray>("PeakHeights", "", new DoubleArray(new double[] { 0, 0, 0, 0, 0 }))); 122 123 Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance.")); 153 Parameters.Add(new ValueParameter<DoubleMatrix>("InitialPeakLocations", "Initial coordinates of each peaks.", new DoubleMatrix(defaultPeaks))); 154 Parameters.Add(new ValueParameter<DoubleMatrix>("PeakLocations", "Current coordinates of each peaks.", new DoubleMatrix(defaultPeaks))); 155 Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakWidths", "Initial width of each peak.", new DoubleArray(defaultWidths))); 156 Parameters.Add(new ValueParameter<DoubleArray>("PeakWidths", "Current width of each peak.", new DoubleArray(defaultWidths))); 157 Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakHeights", "Initial height of each peak.", new DoubleArray(defaultHeights))); 158 Parameters.Add(new ValueParameter<DoubleArray>("PeakHeights", "Current height of each peak.", new DoubleArray(defaultHeights))); 159 160 //Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance.")); 124 161 125 162 Maximization.Value = true; … … 144 181 public override IDeepCloneable Clone(Cloner cloner) { 145 182 return new MovingPeaksBenchmarkProblem(this, cloner); 183 } 184 185 protected override void OnReset() { 186 base.OnReset(); 187 PeakLocations = InitialPeakLocations.Clone() as DoubleMatrix; 188 PeakWidths = InitialPeakWidths.Clone() as DoubleArray; 189 PeakHeights = InitialPeakHeights.Clone() as DoubleArray; 146 190 } 147 191 … … 156 200 protected override void OnEvaluatorChanged() { 157 201 base.OnEvaluatorChanged(); 158 bool problemSizeChange = ProblemSize.Value < Evaluator.MinimumProblemSize 159 || ProblemSize.Value > Evaluator.MaximumProblemSize; 160 if (problemSizeChange) { 161 ProblemSize.Value = Math.Max(Evaluator.MinimumProblemSize, Math.Min(ProblemSize.Value, Evaluator.MaximumProblemSize)); 162 } else { 163 ParameterizeEvaluator(); 164 } 202 ParameterizeEvaluator(); 165 203 UpdateMoveEvaluators(); 166 204 ParameterizeAnalyzers(); 167 Maximization.Value = Evaluator.Maximization;168 BoundsParameter.Value = Evaluator.Bounds;169 BestKnownQuality = new DoubleValue(Evaluator.BestKnownQuality);170 205 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 171 206 Evaluator_QualityParameter_ActualNameChanged(null, EventArgs.Empty); … … 180 215 ParameterizeSolutionCreator(); 181 216 ParameterizeEvaluator(); 182 strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * ProblemSize.Value));183 strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(ProblemSize.Value)));217 //strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * ProblemSize.Value)); 218 //strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(ProblemSize.Value))); 184 219 OnReset(); 185 220 } … … 233 268 // } 234 269 //} 235 private void strategyVectorCreator_BoundsParameter_ValueChanged(object sender, EventArgs e) {236 strategyVectorManipulator.BoundsParameter.Value = (DoubleMatrix)strategyVectorCreator.BoundsParameter.Value.Clone();237 }238 private void strategyVectorCreator_StrategyParameterParameter_ActualNameChanged(object sender, EventArgs e) {239 string name = strategyVectorCreator.StrategyParameterParameter.ActualName;240 strategyVectorCrossover.ParentsParameter.ActualName = name;241 strategyVectorCrossover.StrategyParameterParameter.ActualName = name;242 strategyVectorManipulator.StrategyParameterParameter.ActualName = name;243 }270 //private void strategyVectorCreator_BoundsParameter_ValueChanged(object sender, EventArgs e) { 271 // strategyVectorManipulator.BoundsParameter.Value = (DoubleMatrix)strategyVectorCreator.BoundsParameter.Value.Clone(); 272 //} 273 //private void strategyVectorCreator_StrategyParameterParameter_ActualNameChanged(object sender, EventArgs e) { 274 // string name = strategyVectorCreator.StrategyParameterParameter.ActualName; 275 // strategyVectorCrossover.ParentsParameter.ActualName = name; 276 // strategyVectorCrossover.StrategyParameterParameter.ActualName = name; 277 // strategyVectorManipulator.StrategyParameterParameter.ActualName = name; 278 //} 244 279 #endregion 245 280 … … 247 282 [StorableHook(HookType.AfterDeserialization)] 248 283 private void AfterDeserialization() { 249 // BackwardsCompatibility3.3250 #region Backwards compatible code (remove with 3.4)251 if (Operators.Count == 0) InitializeOperators();252 #endregion253 284 RegisterEventHandlers(); 254 285 } … … 262 293 SolutionCreator.RealVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_RealVectorParameter_ActualNameChanged); 263 294 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 264 strategyVectorCreator.BoundsParameter.ValueChanged += new EventHandler(strategyVectorCreator_BoundsParameter_ValueChanged);265 strategyVectorCreator.StrategyParameterParameter.ActualNameChanged += new EventHandler(strategyVectorCreator_StrategyParameterParameter_ActualNameChanged);295 //strategyVectorCreator.BoundsParameter.ValueChanged += new EventHandler(strategyVectorCreator_BoundsParameter_ValueChanged); 296 //strategyVectorCreator.StrategyParameterParameter.ActualNameChanged += new EventHandler(strategyVectorCreator_StrategyParameterParameter_ActualNameChanged); 266 297 } 267 298 private void ParameterizeAnalyzers() { … … 287 318 //Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer()); 288 319 //Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 289 //ParameterizeAnalyzers();290 //Operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());320 ParameterizeAnalyzers(); 321 Operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>()); 291 322 //Operators.Add(strategyVectorCreator); 292 323 //Operators.Add(strategyVectorCrossover); 293 324 //Operators.Add(strategyVectorManipulator); 294 //UpdateMoveEvaluators();295 //ParameterizeOperators();296 //InitializeMoveGenerators();325 UpdateMoveEvaluators(); 326 ParameterizeOperators(); 327 InitializeMoveGenerators(); 297 328 } 298 329 private void InitializeMoveGenerators() { … … 325 356 // #endregion 326 357 // } 327 //ParameterizeOperators();328 //OnOperatorsChanged();358 ParameterizeOperators(); 359 OnOperatorsChanged(); 329 360 } 330 361 private void ParameterizeSolutionCreator() { … … 337 368 Evaluator.PointParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName; 338 369 Evaluator.PointParameter.Hidden = true; 339 try {340 BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);341 }342 catch (ArgumentException e) {343 ErrorHandling.ShowErrorDialog(e);344 ProblemSize.Value = Evaluator.MinimumProblemSize;345 }370 //try { 371 // BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value); 372 //} 373 //catch (ArgumentException e) { 374 // ErrorHandling.ShowErrorDialog(e); 375 // ProblemSize.Value = Evaluator.MinimumProblemSize; 376 //} 346 377 } 347 378 private void ParameterizeOperators() { … … 412 443 } 413 444 private void UpdateStrategyVectorBounds() { 414 var strategyBounds = (DoubleMatrix)Bounds.Clone();415 for (int i = 0; i < strategyBounds.Rows; i++) {416 if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0;417 strategyBounds[i, 1] = 0.1 * (Bounds[i, 1] - Bounds[i, 0]);418 }419 strategyVectorCreator.BoundsParameter.Value = strategyBounds;445 //var strategyBounds = (DoubleMatrix)Bounds.Clone(); 446 //for (int i = 0; i < strategyBounds.Rows; i++) { 447 // if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0; 448 // strategyBounds[i, 1] = 0.1 * (Bounds[i, 1] - Bounds[i, 0]); 449 //} 450 //strategyVectorCreator.BoundsParameter.Value = strategyBounds; 420 451 } 421 452 #endregion -
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblemEvaluator.cs
r16607 r16608 74 74 75 75 public double Apply(DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, RealVector point) { 76 return 0; 76 heights[0] *= 1.01; 77 78 double max = 0; 79 double val = 0; 80 81 for (int i = 0; i < widths.Length; i++) { 82 val = 0; 83 for (int j = 0; j < point.Length; j++) { 84 val += (point[j] - peaks[i, j]) * (point[j] - peaks[i, j]); 85 } 86 val = heights[i] / (1 + widths[i] * val); 87 if (val > max) max = val; 88 } 89 return max; 77 90 } 78 91 }
Note: See TracChangeset
for help on using the changeset viewer.