[3150] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
| 29 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 30 | using HeuristicLab.Optimization;
|
---|
| 31 | using HeuristicLab.Parameters;
|
---|
| 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 33 | using HeuristicLab.PluginInfrastructure;
|
---|
| 34 |
|
---|
[3170] | 35 | namespace HeuristicLab.Problems.TestFunctions {
|
---|
[3221] | 36 | [Item("Single Objective Test Function", "Test function with real valued inputs and a single objective.")]
|
---|
[3150] | 37 | [StorableClass]
|
---|
| 38 | [Creatable("Problems")]
|
---|
[3170] | 39 | public sealed class SingleObjectiveTestFunctionProblem : ParameterizedNamedItem, ISingleObjectiveProblem {
|
---|
[3336] | 40 | [Storable]
|
---|
[3450] | 41 | private StdDevStrategyVectorCreator strategyVectorCreator;
|
---|
[3336] | 42 | [Storable]
|
---|
[3450] | 43 | private StdDevStrategyVectorCrossover strategyVectorCrossover;
|
---|
[3336] | 44 | [Storable]
|
---|
[3450] | 45 | private StdDevStrategyVectorManipulator strategyVectorManipulator;
|
---|
[3336] | 46 |
|
---|
[3150] | 47 | public override Image ItemImage {
|
---|
| 48 | get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | #region Parameter Properties
|
---|
| 52 | public ValueParameter<BoolValue> MaximizationParameter {
|
---|
| 53 | get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 54 | }
|
---|
| 55 | IParameter ISingleObjectiveProblem.MaximizationParameter {
|
---|
| 56 | get { return MaximizationParameter; }
|
---|
| 57 | }
|
---|
| 58 | public ValueParameter<DoubleMatrix> BoundsParameter {
|
---|
| 59 | get { return (ValueParameter<DoubleMatrix>)Parameters["Bounds"]; }
|
---|
| 60 | }
|
---|
| 61 | public ValueParameter<IntValue> ProblemSizeParameter {
|
---|
| 62 | get { return (ValueParameter<IntValue>)Parameters["ProblemSize"]; }
|
---|
| 63 | }
|
---|
| 64 | public ValueParameter<IRealVectorCreator> SolutionCreatorParameter {
|
---|
| 65 | get { return (ValueParameter<IRealVectorCreator>)Parameters["SolutionCreator"]; }
|
---|
| 66 | }
|
---|
| 67 | IParameter IProblem.SolutionCreatorParameter {
|
---|
| 68 | get { return SolutionCreatorParameter; }
|
---|
| 69 | }
|
---|
[3170] | 70 | public ValueParameter<ISingleObjectiveTestFunctionProblemEvaluator> EvaluatorParameter {
|
---|
| 71 | get { return (ValueParameter<ISingleObjectiveTestFunctionProblemEvaluator>)Parameters["Evaluator"]; }
|
---|
[3150] | 72 | }
|
---|
| 73 | IParameter IProblem.EvaluatorParameter {
|
---|
| 74 | get { return EvaluatorParameter; }
|
---|
| 75 | }
|
---|
| 76 | public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
|
---|
| 77 | get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
| 78 | }
|
---|
| 79 | IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
|
---|
| 80 | get { return BestKnownQualityParameter; }
|
---|
| 81 | }
|
---|
[3781] | 82 | public OptionalValueParameter<RealVector> BestKnownSolutionParameter {
|
---|
| 83 | get { return (OptionalValueParameter<RealVector>)Parameters["BestKnownSolution"]; }
|
---|
| 84 | }
|
---|
[3150] | 85 | #endregion
|
---|
| 86 |
|
---|
| 87 | #region Properties
|
---|
[3154] | 88 | public BoolValue Maximization {
|
---|
| 89 | get { return MaximizationParameter.Value; }
|
---|
| 90 | set { MaximizationParameter.Value = value; }
|
---|
| 91 | }
|
---|
[3150] | 92 | public DoubleMatrix Bounds {
|
---|
| 93 | get { return BoundsParameter.Value; }
|
---|
| 94 | set { BoundsParameter.Value = value; }
|
---|
| 95 | }
|
---|
| 96 | public IntValue ProblemSize {
|
---|
| 97 | get { return ProblemSizeParameter.Value; }
|
---|
| 98 | set { ProblemSizeParameter.Value = value; }
|
---|
| 99 | }
|
---|
| 100 | public IRealVectorCreator SolutionCreator {
|
---|
| 101 | get { return SolutionCreatorParameter.Value; }
|
---|
| 102 | set { SolutionCreatorParameter.Value = value; }
|
---|
| 103 | }
|
---|
| 104 | ISolutionCreator IProblem.SolutionCreator {
|
---|
| 105 | get { return SolutionCreatorParameter.Value; }
|
---|
| 106 | }
|
---|
[3170] | 107 | public ISingleObjectiveTestFunctionProblemEvaluator Evaluator {
|
---|
[3150] | 108 | get { return EvaluatorParameter.Value; }
|
---|
| 109 | set { EvaluatorParameter.Value = value; }
|
---|
| 110 | }
|
---|
| 111 | ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
|
---|
| 112 | get { return EvaluatorParameter.Value; }
|
---|
| 113 | }
|
---|
| 114 | IEvaluator IProblem.Evaluator {
|
---|
| 115 | get { return EvaluatorParameter.Value; }
|
---|
| 116 | }
|
---|
| 117 | public DoubleValue BestKnownQuality {
|
---|
| 118 | get { return BestKnownQualityParameter.Value; }
|
---|
| 119 | set { BestKnownQualityParameter.Value = value; }
|
---|
| 120 | }
|
---|
| 121 | public IEnumerable<IOperator> Operators {
|
---|
[3187] | 122 | get { return operators; }
|
---|
[3150] | 123 | }
|
---|
[3789] | 124 | private BestSingleObjectiveTestFunctionSolutionAnalyzer BestSingleObjectiveTestFunctionSolutionAnalyzer {
|
---|
| 125 | get { return operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); }
|
---|
[3647] | 126 | }
|
---|
[3150] | 127 | #endregion
|
---|
| 128 |
|
---|
[4098] | 129 | [Storable]
|
---|
| 130 | private List<IOperator> operators;
|
---|
| 131 |
|
---|
[3150] | 132 | [StorableConstructor]
|
---|
[4118] | 133 | private SingleObjectiveTestFunctionProblem(bool deserializing) : base(deserializing) { }
|
---|
[3170] | 134 | public SingleObjectiveTestFunctionProblem()
|
---|
[3150] | 135 | : base() {
|
---|
| 136 | UniformRandomRealVectorCreator creator = new UniformRandomRealVectorCreator();
|
---|
| 137 | AckleyEvaluator evaluator = new AckleyEvaluator();
|
---|
| 138 |
|
---|
| 139 | Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as most test functions are minimization problems.", new BoolValue(evaluator.Maximization)));
|
---|
| 140 | Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", evaluator.Bounds));
|
---|
| 141 | Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(2)));
|
---|
[3685] | 142 | Parameters.Add(new ValueParameter<IRealVectorCreator>("SolutionCreator", "The operator which should be used to create new test function solutions.", creator));
|
---|
| 143 | Parameters.Add(new ValueParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator", "The operator which should be used to evaluate test function solutions.", evaluator));
|
---|
| 144 | Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this test function.", new DoubleValue(evaluator.BestKnownQuality)));
|
---|
[3781] | 145 | Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance."));
|
---|
[3150] | 146 |
|
---|
[3450] | 147 | strategyVectorCreator = new StdDevStrategyVectorCreator();
|
---|
[3336] | 148 | strategyVectorCreator.LengthParameter.ActualName = ProblemSizeParameter.Name;
|
---|
[3450] | 149 | strategyVectorCrossover = new StdDevStrategyVectorCrossover();
|
---|
| 150 | strategyVectorManipulator = new StdDevStrategyVectorManipulator();
|
---|
| 151 | strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(0.5);
|
---|
| 152 | strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(0.5);
|
---|
[3336] | 153 |
|
---|
[3150] | 154 | creator.RealVectorParameter.ActualName = "Point";
|
---|
| 155 | ParameterizeSolutionCreator();
|
---|
| 156 | ParameterizeEvaluator();
|
---|
| 157 |
|
---|
[4098] | 158 | InitializeOperators();
|
---|
| 159 | AttachEventHandlers();
|
---|
[3783] | 160 | UpdateStrategyVectorBounds();
|
---|
[3150] | 161 | }
|
---|
| 162 |
|
---|
| 163 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[3170] | 164 | SingleObjectiveTestFunctionProblem clone = (SingleObjectiveTestFunctionProblem)base.Clone(cloner);
|
---|
[4098] | 165 | clone.operators = operators.Where(x => IsNotFieldReferenced(x)).Select(x => (IOperator)cloner.Clone(x)).ToList();
|
---|
[3751] | 166 | clone.strategyVectorCreator = (StdDevStrategyVectorCreator)cloner.Clone(strategyVectorCreator);
|
---|
[4098] | 167 | clone.operators.Add(clone.strategyVectorCreator);
|
---|
[3751] | 168 | clone.strategyVectorCrossover = (StdDevStrategyVectorCrossover)cloner.Clone(strategyVectorCrossover);
|
---|
[4098] | 169 | clone.operators.Add(strategyVectorCrossover);
|
---|
[3751] | 170 | clone.strategyVectorManipulator = (StdDevStrategyVectorManipulator)cloner.Clone(strategyVectorManipulator);
|
---|
[4098] | 171 | clone.operators.Add(strategyVectorManipulator);
|
---|
| 172 | clone.AttachEventHandlers();
|
---|
[3150] | 173 | return clone;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[4098] | 176 | private bool IsNotFieldReferenced(IOperator x) {
|
---|
| 177 | return !(x == strategyVectorCreator
|
---|
| 178 | || x == strategyVectorCrossover
|
---|
| 179 | || x == strategyVectorManipulator);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[3150] | 182 | #region Events
|
---|
| 183 | public event EventHandler SolutionCreatorChanged;
|
---|
| 184 | private void OnSolutionCreatorChanged() {
|
---|
[3739] | 185 | EventHandler handler = SolutionCreatorChanged;
|
---|
| 186 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3150] | 187 | }
|
---|
| 188 | public event EventHandler EvaluatorChanged;
|
---|
| 189 | private void OnEvaluatorChanged() {
|
---|
[3739] | 190 | EventHandler handler = EvaluatorChanged;
|
---|
| 191 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3150] | 192 | }
|
---|
| 193 | public event EventHandler OperatorsChanged;
|
---|
| 194 | private void OnOperatorsChanged() {
|
---|
[3739] | 195 | EventHandler handler = OperatorsChanged;
|
---|
| 196 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3150] | 197 | }
|
---|
[3739] | 198 | public event EventHandler Reset;
|
---|
| 199 | private void OnReset() {
|
---|
| 200 | EventHandler handler = Reset;
|
---|
| 201 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[3150] | 204 | private void ProblemSizeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 205 | ProblemSize.ValueChanged += new EventHandler(ProblemSize_ValueChanged);
|
---|
| 206 | ProblemSize_ValueChanged(null, EventArgs.Empty);
|
---|
| 207 | }
|
---|
| 208 | private void ProblemSize_ValueChanged(object sender, EventArgs e) {
|
---|
[3336] | 209 | if (ProblemSize.Value < 1) ProblemSize.Value = 1;
|
---|
[3150] | 210 | ParameterizeSolutionCreator();
|
---|
[3781] | 211 | ParameterizeEvaluator();
|
---|
[3336] | 212 | strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * ProblemSize.Value));
|
---|
| 213 | strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(ProblemSize.Value)));
|
---|
[3781] | 214 | OnReset();
|
---|
[3150] | 215 | }
|
---|
| 216 | private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 217 | ParameterizeSolutionCreator();
|
---|
[3647] | 218 | ParameterizeAnalyzers();
|
---|
[3150] | 219 | SolutionCreator_RealVectorParameter_ActualNameChanged(null, EventArgs.Empty);
|
---|
[3865] | 220 | OnSolutionCreatorChanged();
|
---|
[3150] | 221 | }
|
---|
| 222 | private void SolutionCreator_RealVectorParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 223 | ParameterizeEvaluator();
|
---|
| 224 | ParameterizeOperators();
|
---|
[3647] | 225 | ParameterizeAnalyzers();
|
---|
[3150] | 226 | }
|
---|
| 227 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 228 | ParameterizeEvaluator();
|
---|
[3187] | 229 | UpdateMoveEvaluators();
|
---|
[3647] | 230 | ParameterizeAnalyzers();
|
---|
[3154] | 231 | Maximization.Value = Evaluator.Maximization;
|
---|
| 232 | BoundsParameter.Value = Evaluator.Bounds;
|
---|
| 233 | if (ProblemSize.Value < Evaluator.MinimumProblemSize)
|
---|
| 234 | ProblemSize.Value = Evaluator.MinimumProblemSize;
|
---|
| 235 | else if (ProblemSize.Value > Evaluator.MaximumProblemSize)
|
---|
| 236 | ProblemSize.Value = Evaluator.MaximumProblemSize;
|
---|
| 237 | BestKnownQuality = new DoubleValue(Evaluator.BestKnownQuality);
|
---|
[3150] | 238 | Evaluator_QualityParameter_ActualNameChanged(null, EventArgs.Empty);
|
---|
[3865] | 239 | OnEvaluatorChanged();
|
---|
[3781] | 240 | OnReset();
|
---|
[3150] | 241 | }
|
---|
| 242 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 243 | ParameterizeOperators();
|
---|
| 244 | }
|
---|
[3154] | 245 | private void BoundsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 246 | Bounds.ToStringChanged += new EventHandler(Bounds_ToStringChanged);
|
---|
| 247 | Bounds_ToStringChanged(null, EventArgs.Empty);
|
---|
| 248 | }
|
---|
| 249 | private void Bounds_ToStringChanged(object sender, EventArgs e) {
|
---|
| 250 | if (Bounds.Columns != 2 || Bounds.Rows < 1)
|
---|
| 251 | Bounds = new DoubleMatrix(1, 2);
|
---|
[3781] | 252 | ParameterizeOperators();
|
---|
| 253 | UpdateStrategyVectorBounds();
|
---|
[3154] | 254 | }
|
---|
| 255 | private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
| 256 | if (e.Value2 == 0 && Bounds[e.Value, 1] <= Bounds[e.Value, 0])
|
---|
| 257 | Bounds[e.Value, 1] = Bounds[e.Value, 0] + 0.1;
|
---|
| 258 | if (e.Value2 == 1 && Bounds[e.Value, 0] >= Bounds[e.Value, 1])
|
---|
| 259 | Bounds[e.Value, 0] = Bounds[e.Value, 1] - 0.1;
|
---|
[3781] | 260 | ParameterizeOperators();
|
---|
| 261 | UpdateStrategyVectorBounds();
|
---|
[3154] | 262 | }
|
---|
[3187] | 263 | private void MoveGenerator_AdditiveMoveParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 264 | string name = ((ILookupParameter<AdditiveMove>)sender).ActualName;
|
---|
| 265 | foreach (IAdditiveRealVectorMoveOperator op in Operators.OfType<IAdditiveRealVectorMoveOperator>()) {
|
---|
| 266 | op.AdditiveMoveParameter.ActualName = name;
|
---|
| 267 | }
|
---|
[3182] | 268 | }
|
---|
[3318] | 269 | private void SphereEvaluator_Parameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 270 | SphereEvaluator eval = (Evaluator as SphereEvaluator);
|
---|
| 271 | if (eval != null) {
|
---|
| 272 | foreach (ISphereMoveEvaluator op in Operators.OfType<ISphereMoveEvaluator>()) {
|
---|
| 273 | op.C = eval.C;
|
---|
| 274 | op.Alpha = eval.Alpha;
|
---|
| 275 | }
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 | private void RastriginEvaluator_Parameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 279 | RastriginEvaluator eval = (Evaluator as RastriginEvaluator);
|
---|
| 280 | if (eval != null) {
|
---|
| 281 | foreach (IRastriginMoveEvaluator op in Operators.OfType<IRastriginMoveEvaluator>()) {
|
---|
| 282 | op.A = eval.A;
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
[3336] | 286 | private void strategyVectorCreator_BoundsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[3781] | 287 | strategyVectorManipulator.BoundsParameter.Value = (DoubleMatrix)strategyVectorCreator.BoundsParameter.Value.Clone();
|
---|
[3336] | 288 | }
|
---|
| 289 | private void strategyVectorCreator_StrategyParameterParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 290 | string name = strategyVectorCreator.StrategyParameterParameter.ActualName;
|
---|
| 291 | strategyVectorCrossover.ParentsParameter.ActualName = name;
|
---|
| 292 | strategyVectorCrossover.StrategyParameterParameter.ActualName = name;
|
---|
| 293 | strategyVectorManipulator.StrategyParameterParameter.ActualName = name;
|
---|
| 294 | }
|
---|
[3150] | 295 | #endregion
|
---|
| 296 |
|
---|
| 297 | #region Helpers
|
---|
| 298 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4118] | 299 | private void AfterDeserializationHook() {
|
---|
| 300 | // BackwardsCompatibility3.3
|
---|
| 301 | #region Backwards compatible code (remove with 3.4)
|
---|
| 302 | if (operators == null) InitializeOperators();
|
---|
| 303 | #endregion
|
---|
| 304 | AttachEventHandlers();
|
---|
| 305 | }
|
---|
| 306 |
|
---|
[4098] | 307 | private void AttachEventHandlers() {
|
---|
[3150] | 308 | ProblemSizeParameter.ValueChanged += new EventHandler(ProblemSizeParameter_ValueChanged);
|
---|
| 309 | ProblemSize.ValueChanged += new EventHandler(ProblemSize_ValueChanged);
|
---|
[3154] | 310 | BoundsParameter.ValueChanged += new EventHandler(BoundsParameter_ValueChanged);
|
---|
| 311 | Bounds.ToStringChanged += new EventHandler(Bounds_ToStringChanged);
|
---|
| 312 | Bounds.ItemChanged += new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
|
---|
[3150] | 313 | SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
|
---|
| 314 | SolutionCreator.RealVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_RealVectorParameter_ActualNameChanged);
|
---|
| 315 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
| 316 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[3336] | 317 | strategyVectorCreator.BoundsParameter.ValueChanged += new EventHandler(strategyVectorCreator_BoundsParameter_ValueChanged);
|
---|
| 318 | strategyVectorCreator.StrategyParameterParameter.ActualNameChanged += new EventHandler(strategyVectorCreator_StrategyParameterParameter_ActualNameChanged);
|
---|
[3150] | 319 | }
|
---|
[3647] | 320 | private void ParameterizeAnalyzers() {
|
---|
[3789] | 321 | BestSingleObjectiveTestFunctionSolutionAnalyzer.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
| 322 | BestSingleObjectiveTestFunctionSolutionAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
| 323 | BestSingleObjectiveTestFunctionSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
| 324 | BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
| 325 | BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
|
---|
| 326 | BestSingleObjectiveTestFunctionSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 327 | BestSingleObjectiveTestFunctionSolutionAnalyzer.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
[3894] | 328 | BestSingleObjectiveTestFunctionSolutionAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
[3647] | 329 | }
|
---|
[3150] | 330 | private void InitializeOperators() {
|
---|
[3187] | 331 | operators = new List<IOperator>();
|
---|
[3647] | 332 | operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer());
|
---|
| 333 | ParameterizeAnalyzers();
|
---|
[3303] | 334 | operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
|
---|
[3336] | 335 | operators.Add(strategyVectorCreator);
|
---|
| 336 | operators.Add(strategyVectorCrossover);
|
---|
| 337 | operators.Add(strategyVectorManipulator);
|
---|
[3209] | 338 | UpdateMoveEvaluators();
|
---|
| 339 | ParameterizeOperators();
|
---|
[3187] | 340 | InitializeMoveGenerators();
|
---|
[3150] | 341 | }
|
---|
[3187] | 342 | private void InitializeMoveGenerators() {
|
---|
| 343 | foreach (IAdditiveRealVectorMoveOperator op in Operators.OfType<IAdditiveRealVectorMoveOperator>()) {
|
---|
[3150] | 344 | if (op is IMoveGenerator) {
|
---|
[3187] | 345 | op.AdditiveMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_AdditiveMoveParameter_ActualNameChanged);
|
---|
[3150] | 346 | }
|
---|
| 347 | }
|
---|
[3187] | 348 | }
|
---|
| 349 | private void UpdateMoveEvaluators() {
|
---|
[3303] | 350 | foreach (ISingleObjectiveTestFunctionMoveEvaluator op in Operators.OfType<ISingleObjectiveTestFunctionMoveEvaluator>().ToList())
|
---|
| 351 | operators.Remove(op);
|
---|
| 352 | foreach (ISingleObjectiveTestFunctionMoveEvaluator op in ApplicationManager.Manager.GetInstances<ISingleObjectiveTestFunctionMoveEvaluator>())
|
---|
| 353 | if (op.EvaluatorType == Evaluator.GetType()) {
|
---|
| 354 | operators.Add(op);
|
---|
[3318] | 355 | #region Synchronize evaluator specific parameters with the parameters of the corresponding move evaluators
|
---|
| 356 | if (op is ISphereMoveEvaluator) {
|
---|
| 357 | SphereEvaluator e = (Evaluator as SphereEvaluator);
|
---|
| 358 | e.AlphaParameter.ValueChanged += new EventHandler(SphereEvaluator_Parameter_ValueChanged);
|
---|
| 359 | e.CParameter.ValueChanged += new EventHandler(SphereEvaluator_Parameter_ValueChanged);
|
---|
| 360 | ISphereMoveEvaluator em = (op as ISphereMoveEvaluator);
|
---|
| 361 | em.C = e.C;
|
---|
| 362 | em.Alpha = e.Alpha;
|
---|
| 363 | } else if (op is IRastriginMoveEvaluator) {
|
---|
| 364 | RastriginEvaluator e = (Evaluator as RastriginEvaluator);
|
---|
| 365 | e.AParameter.ValueChanged += new EventHandler(RastriginEvaluator_Parameter_ValueChanged);
|
---|
| 366 | IRastriginMoveEvaluator em = (op as IRastriginMoveEvaluator);
|
---|
| 367 | em.A = e.A;
|
---|
| 368 | }
|
---|
| 369 | #endregion
|
---|
[3303] | 370 | }
|
---|
| 371 | ParameterizeOperators();
|
---|
| 372 | OnOperatorsChanged();
|
---|
[3187] | 373 | }
|
---|
[3150] | 374 | private void ParameterizeSolutionCreator() {
|
---|
| 375 | SolutionCreator.LengthParameter.Value = new IntValue(ProblemSize.Value);
|
---|
| 376 | }
|
---|
| 377 | private void ParameterizeEvaluator() {
|
---|
| 378 | Evaluator.PointParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
[3781] | 379 | BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);
|
---|
[3150] | 380 | }
|
---|
| 381 | private void ParameterizeOperators() {
|
---|
| 382 | foreach (IRealVectorCrossover op in Operators.OfType<IRealVectorCrossover>()) {
|
---|
| 383 | op.ParentsParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
| 384 | op.ChildParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
[3182] | 385 | op.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
[3150] | 386 | }
|
---|
| 387 | foreach (IRealVectorManipulator op in Operators.OfType<IRealVectorManipulator>()) {
|
---|
| 388 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
[3182] | 389 | op.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
[3150] | 390 | }
|
---|
[3187] | 391 | foreach (IRealVectorMoveOperator op in Operators.OfType<IRealVectorMoveOperator>()) {
|
---|
| 392 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
[3150] | 393 | }
|
---|
[3187] | 394 | foreach (IRealVectorMoveGenerator op in Operators.OfType<IRealVectorMoveGenerator>()) {
|
---|
| 395 | op.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
| 396 | }
|
---|
| 397 | foreach (ISingleObjectiveTestFunctionAdditiveMoveEvaluator op in Operators.OfType<ISingleObjectiveTestFunctionAdditiveMoveEvaluator>()) {
|
---|
| 398 | op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
| 399 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
| 400 | }
|
---|
[3682] | 401 | foreach (IRealVectorPSOEncoder op in Operators.OfType<IRealVectorPSOEncoder>()) {
|
---|
[3719] | 402 | ((ILookupParameter)op.OriginalRealVectorParameter).ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
| 403 | op.BoundsParameter.Value = (DoubleMatrix)BoundsParameter.Value.Clone();
|
---|
[4068] | 404 | op.BoundsParameter.ActualName = "ParticleBounds";
|
---|
[3682] | 405 | }
|
---|
[3150] | 406 | }
|
---|
[3781] | 407 | private void UpdateStrategyVectorBounds() {
|
---|
| 408 | DoubleMatrix strategyBounds = (DoubleMatrix)Bounds.Clone();
|
---|
| 409 | for (int i = 0; i < strategyBounds.Rows; i++)
|
---|
| 410 | if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0;
|
---|
| 411 | strategyVectorCreator.BoundsParameter.Value = strategyBounds;
|
---|
| 412 | }
|
---|
[3150] | 413 | #endregion
|
---|
| 414 | }
|
---|
| 415 | }
|
---|