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