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