Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs @ 11399

Last change on this file since 11399 was 11399, checked in by abeham, 8 years ago

#2174: fixed bug in particle creator/updater wiring

File size: 50.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Linq;
26using HeuristicLab.Analysis;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Encodings.BinaryVectorEncoding;
31using HeuristicLab.Encodings.IntegerVectorEncoding;
32using HeuristicLab.Encodings.PermutationEncoding;
33using HeuristicLab.Encodings.RealVectorEncoding;
34using HeuristicLab.Optimization;
35using HeuristicLab.Parameters;
36using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
37using HeuristicLab.PluginInfrastructure;
38
39namespace HeuristicLab.Problems.Programmable {
40  [Item("Programmable Problem (single-objective)", "Represents a single-objective problem that can be programmed.")]
41  [Creatable("Problems")]
42  [StorableClass]
43  public class SingleObjectiveProgrammableProblem : SingleObjectiveHeuristicOptimizationProblem<ISingleObjectiveProgrammableProblemEvaluator, ISolutionCreator>, IParameterizedNamedItem, IStorableContent {
44    public string Filename { get; set; }
45
46    public static new Image StaticItemImage {
47      get { return Common.Resources.VSImageLibrary.Script; }
48    }
49
50    public new ParameterCollection Parameters {
51      get { return base.Parameters; }
52    }
53    IKeyedItemCollection<string, IParameter> IParameterizedItem.Parameters {
54      get { return Parameters; }
55    }
56
57    public IValueParameter<ISingleObjectiveProblemDefinitionHost> ProblemDefinitionParameter {
58      get { return (IValueParameter<ISingleObjectiveProblemDefinitionHost>)Parameters["ProblemDefinition"]; }
59    }
60
61    protected IValueParameter<Configuration> ConfigurationParameter {
62      get { return (IValueParameter<Configuration>)Parameters["Configuration"]; }
63    }
64
65    public ISingleObjectiveProblemDefinitionHost ProblemDefinition {
66      get { return ProblemDefinitionParameter.Value; }
67      set { ProblemDefinitionParameter.Value = value; }
68    }
69
70    [Storable]
71    protected List<IParameter> DynamicConfigurationParameters;
72
73    [StorableConstructor]
74    protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
75
76    protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)
77      : base(original, cloner) {
78      DynamicConfigurationParameters = original.DynamicConfigurationParameters.Select(cloner.Clone).ToList();
79      RegisterEventHandlers();
80    }
81    public SingleObjectiveProgrammableProblem()
82      : base(new SingleObjectiveEvaluator(), new ParameterVectorCreater()) {
83      Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinitionHost>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemDefinitionScript() { Name = Name }));
84      Parameters.Add(new ValueParameter<Configuration>("Configuration", "Describes which parameters exist, what they're called, what type they are and their bounds if any."));
85
86      DynamicConfigurationParameters = new List<IParameter>();
87
88      Operators.Add(new BestScopeSolutionAnalyzer());
89      Operators.Add(new SingleObjectiveAnalyzer());
90      Operators.Add(Evaluator);
91      Operators.Add(SolutionCreator);
92
93      RegisterEventHandlers();
94    }
95
96    public override IDeepCloneable Clone(Cloner cloner) {
97      return new SingleObjectiveProgrammableProblem(this, cloner);
98    }
99
100    [StorableHook(HookType.AfterDeserialization)]
101    // ReSharper disable UnusedMember.Local
102    private void AfterDeserialization() {
103      RegisterEventHandlers();
104    }
105    // ReSharper restore UnusedMember.Local
106
107    private void RegisterEventHandlers() {
108      ProblemDefinitionParameter.ValueChanged += ProblemDefinitionParameterOnValueChanged;
109      RegisterHostInstanceChanges();
110    }
111
112    private void ProblemDefinitionParameterOnValueChanged(object sender, EventArgs eventArgs) {
113      RegisterHostInstanceChanges();
114      Parameterize();
115    }
116
117    private void RegisterHostInstanceChanges() {
118      ProblemDefinitionParameter.Value.InstanceChanged += ProblemDefinitionHostOnInstanceChanged;
119      ProblemDefinitionParameter.Value.NameChanged += ProblemDefinitionHostOnNameChanged;
120    }
121
122    private void ProblemDefinitionHostOnNameChanged(object sender, EventArgs eventArgs) {
123      if (sender != ProblemDefinitionParameter.Value) return;
124      Name = ProblemDefinitionParameter.Value.Name;
125    }
126
127    protected override void OnNameChanged() {
128      base.OnNameChanged();
129      ProblemDefinitionParameter.Value.Name = Name;
130    }
131
132    protected override void OnEvaluatorChanged() {
133      base.OnEvaluatorChanged();
134      Parameterize();
135    }
136
137    protected virtual void ProblemDefinitionHostOnInstanceChanged(object sender, EventArgs eventArgs) {
138      Parameterize();
139    }
140
141    protected virtual void Parameterize() {
142      var instance = ProblemDefinitionParameter.Value.Instance;
143      if (instance == null) return;
144
145      Configuration configuration;
146      try {
147        configuration = instance.GetConfiguration();
148      } catch { return; }
149      ConfigurationParameter.Value = configuration;
150      Maximization.Value = instance.IsMaximizationProblem;
151
152      Evaluator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
153      Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
154      foreach (var evalOp in Operators.OfType<ISingleObjectiveProgrammableProblemEvaluator>()) {
155        evalOp.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
156        evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
157      }
158      foreach (var analyzeOp in Operators.OfType<ISingleObjectiveProgrammableProblemAnalyzer>()) {
159        analyzeOp.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
160        analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
161        analyzeOp.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
162      }
163
164      var solutionCreators = UpdateDynamicConfigurationParameters(configuration);
165
166      if (solutionCreators.Count == 1) {
167        Operators.RemoveAll(x => x is ParameterVectorCrossover
168                              || x is ParameterVectorManipulator);
169        UpdateSingleVectorEncodingOperators(solutionCreators, configuration);
170      } else {
171        UpdateMultiVectorEncodingOperators(solutionCreators, configuration);
172      }
173      UpdateMoveOperators();
174    }
175
176    protected virtual List<ISolutionCreator> UpdateDynamicConfigurationParameters(Configuration configuration) {
177      foreach (var param in DynamicConfigurationParameters)
178        if (Parameters.Contains(param)) Parameters.Remove(param);
179      DynamicConfigurationParameters.Clear();
180
181      var solutionCreators = new List<ISolutionCreator>();
182      foreach (var param in configuration.Parameters) {
183        #region Configure BinaryVector Creator
184        var binConfig = param.Value as BinaryParameterConfiguration;
185        if (binConfig != null) {
186          var p = new ValueParameter<IntValue>(param.Key + "Length", binConfig.Length);
187          DynamicConfigurationParameters.Add(p);
188
189          var creator = new RandomBinaryVectorCreator();
190          creator.BinaryVectorParameter.ActualName = param.Key;
191          creator.LengthParameter.ActualName = p.Name;
192          solutionCreators.Add(creator);
193        }
194        #endregion
195        #region Configure IntegerVector Creator
196        var intConfig = param.Value as IntegerParameterConfiguration;
197        if (intConfig != null) {
198          var l = new ValueParameter<IntValue>(param.Key + "Length", intConfig.Length);
199          var b = new ValueParameter<IntMatrix>(param.Key + "Bounds", intConfig.Bounds);
200          DynamicConfigurationParameters.Add(l);
201          DynamicConfigurationParameters.Add(b);
202
203          var creator = new UniformRandomIntegerVectorCreator();
204          creator.IntegerVectorParameter.ActualName = param.Key;
205          creator.LengthParameter.ActualName = l.Name;
206          creator.BoundsParameter.ActualName = b.Name;
207          solutionCreators.Add(creator);
208        }
209        #endregion
210        #region Configure RealVector Creator
211        var realConfig = param.Value as RealParameterConfiguration;
212        if (realConfig != null) {
213          var l = new ValueParameter<IntValue>(param.Key + "Length", realConfig.Length);
214          var b = new ValueParameter<DoubleMatrix>(param.Key + "Bounds", realConfig.Bounds);
215          DynamicConfigurationParameters.Add(l);
216          DynamicConfigurationParameters.Add(b);
217
218          var creator = new UniformRandomRealVectorCreator();
219          creator.RealVectorParameter.ActualName = param.Key;
220          creator.LengthParameter.ActualName = l.Name;
221          creator.BoundsParameter.ActualName = b.Name;
222          solutionCreators.Add(creator);
223        }
224        #endregion
225        #region Configure Permutation Creator
226        var permConfig = param.Value as PermutationParameterConfiguration;
227        if (permConfig != null) {
228          var l = new ValueParameter<IntValue>(param.Key + "Length", permConfig.Length);
229          DynamicConfigurationParameters.Add(l);
230
231          var creator = new RandomPermutationCreator();
232          creator.PermutationParameter.ActualName = param.Key;
233          creator.LengthParameter.ActualName = l.Name;
234          creator.PermutationTypeParameter.Value = permConfig.Type;
235          solutionCreators.Add(creator);
236        }
237        #endregion
238      }
239
240      foreach (var param in DynamicConfigurationParameters) {
241        param.Hidden = true;
242        Parameters.Add(param);
243      }
244      return solutionCreators;
245    }
246
247    protected virtual void UpdateSingleVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) {
248      var newCreator = solutionCreators.Single();
249      #region Configure Operators for BinaryVectorEncoding
250      var binCreator = newCreator as IBinaryVectorCreator;
251      if (binCreator != null) {
252        var paramName = binCreator.BinaryVectorParameter.ActualName;
253        // do not replace a binary vector creator that was manually set
254        if (!(SolutionCreator is IBinaryVectorCreator) || ((IBinaryVectorCreator)SolutionCreator).BinaryVectorParameter.ActualName != paramName) {
255          Operators.Remove(SolutionCreator);
256          SolutionCreator = newCreator;
257          Operators.Add(SolutionCreator);
258        }
259
260        #region Wire BinaryVector Crossovers
261        Operators.RemoveAll(x => x is IBinaryVectorCrossover && ((IBinaryVectorCrossover)x).ChildParameter.ActualName != paramName);
262        var crossovers = ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>().ToList();
263        foreach (var xo in crossovers) {
264          xo.ChildParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
265          xo.ChildParameter.Hidden = true;
266          xo.ParentsParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
267          xo.ParentsParameter.Hidden = true;
268        }
269        Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));
270        #endregion
271        #region Wire BinaryVector Manipulators
272        Operators.RemoveAll(x => x is IBinaryVectorManipulator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName);
273        var manipulators = ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>().ToList();
274        foreach (var m in manipulators) {
275          m.BinaryVectorParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
276          m.BinaryVectorParameter.Hidden = true;
277        }
278        Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
279        #endregion
280        #region Wire BinaryVector ShakingOperators
281        Operators.RemoveAll(x => x is IBinaryVectorMultiNeighborhoodShakingOperator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName);
282        var shakingOperators = ApplicationManager.Manager.GetInstances<IBinaryVectorMultiNeighborhoodShakingOperator>().ToList();
283        foreach (var so in shakingOperators) {
284          so.BinaryVectorParameter.ActualName = paramName;
285          so.BinaryVectorParameter.Hidden = true;
286        }
287        Operators.AddRange(shakingOperators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
288        #endregion
289      } else {
290        Operators.RemoveAll(x => x is IBinaryVectorCrossover
291          || x is IBinaryVectorManipulator
292          || x is IBinaryVectorMultiNeighborhoodShakingOperator);
293      }
294      #endregion
295      #region Configure Operators for IntegerVectorEncoding
296      var intCreator = newCreator as IIntegerVectorCreator;
297      if (intCreator != null) {
298        var paramName = intCreator.IntegerVectorParameter.ActualName;
299        // do not replace an integer vector creator that was manually set
300        if (!(SolutionCreator is IIntegerVectorCreator)
301          || ((IIntegerVectorCreator)SolutionCreator).IntegerVectorParameter.ActualName != intCreator.IntegerVectorParameter.ActualName) {
302          Operators.Remove(SolutionCreator);
303          SolutionCreator = newCreator;
304          Operators.Add(SolutionCreator);
305        }
306
307        #region Wire IntegerVector Crossovers
308        Operators.RemoveAll(x => x is IIntegerVectorCrossover && ((IIntegerVectorCrossover)x).ChildParameter.ActualName != paramName);
309        var crossovers = ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>().ToList();
310        foreach (var xo in crossovers) {
311          xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
312          xo.ChildParameter.Hidden = true;
313          xo.ParentsParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
314          xo.ParentsParameter.Hidden = true;
315          var bx = xo as IBoundedIntegerVectorOperator;
316          if (bx != null) {
317            bx.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName;
318            bx.BoundsParameter.Hidden = true;
319          }
320        }
321        Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));
322        #endregion
323        #region Wire IntegerVector Manipulators
324        Operators.RemoveAll(x => x is IIntegerVectorManipulator && ((IIntegerVectorManipulator)x).IntegerVectorParameter.ActualName != paramName);
325        var manipulators = ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>().ToList();
326        foreach (var m in manipulators) {
327          m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
328          m.IntegerVectorParameter.Hidden = true;
329          var sm = m as ISelfAdaptiveManipulator;
330          if (sm != null) {
331            var p = sm.StrategyParameterParameter as ILookupParameter;
332            if (p != null) {
333              p.ActualName = paramName + "Strategy";
334              p.Hidden = true;
335            }
336          }
337          var bm = m as IBoundedIntegerVectorOperator;
338          if (bm != null) {
339            bm.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName;
340            bm.BoundsParameter.Hidden = true;
341          }
342        }
343        Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
344        #region Wire IntegerVector StrategyParameters for SelfAdaptiveManipulators
345        Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IIntegerVectorStdDevStrategyParameterCreator) || x is IIntegerVectorStdDevStrategyParameterCreator && ((IIntegerVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy");
346        Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IIntegerVectorStdDevStrategyParameterManipulator) || x is IIntegerVectorStdDevStrategyParameterManipulator && ((IIntegerVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy");
347        Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IIntegerVectorStdDevStrategyParameterCrossover) || x is IIntegerVectorStdDevStrategyParameterCrossover && ((IIntegerVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy");
348        var strategyOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorStdDevStrategyParameterOperator>().ToList();
349        if (!(configuration.Parameters.First().Value is IntegerParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with integervector creator that is not an integer-coded problem.");
350        var problemSize = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Length.Value;
351        var b = ((IntegerParameterConfiguration)configuration.Parameters.First().Value).Bounds;
352        var bounds = new DoubleMatrix(b.Rows, b.Columns);
353        for (var i = 0; i < bounds.Rows; i++) {
354          bounds[i, 1] = (int)Math.Ceiling(0.33 * (b[i, 1] - b[i, 0]));
355          bounds[i, 0] = 0;
356          if (bounds.Columns > 2) bounds[i, 2] = b[i, 2];
357        }
358        foreach (var s in strategyOperators) {
359          var c = s as IIntegerVectorStdDevStrategyParameterCreator;
360          if (c != null) {
361            c.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
362            c.LengthParameter.ActualName = intCreator.LengthParameter.ActualName;
363            c.StrategyParameterParameter.ActualName = paramName + "Strategy";
364          }
365          var m = s as IIntegerVectorStdDevStrategyParameterManipulator;
366          if (m != null) {
367            m.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
368            m.StrategyParameterParameter.ActualName = paramName + "Strategy";
369          }
370          var mm = s as Encodings.IntegerVectorEncoding.StdDevStrategyVectorManipulator;
371          if (mm != null) {
372            mm.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * problemSize));
373            mm.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(problemSize)));
374          }
375          var x = s as IIntegerVectorStdDevStrategyParameterCrossover;
376          if (x != null) {
377            x.ParentsParameter.ActualName = paramName + "Strategy";
378            x.StrategyParameterParameter.ActualName = paramName + "Strategy";
379          }
380        }
381        Operators.AddRange(strategyOperators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
382        #endregion
383        #endregion
384        #region Wire IntegerVector ShakingOperators
385        Operators.RemoveAll(x => x is IIntegerVectorMultiNeighborhoodShakingOperator && ((IIntegerVectorMultiNeighborhoodShakingOperator)x).IntegerVectorParameter.ActualName != paramName);
386        var shakingOperators = ApplicationManager.Manager.GetInstances<IIntegerVectorMultiNeighborhoodShakingOperator>().ToList();
387        foreach (var so in shakingOperators) {
388          so.IntegerVectorParameter.ActualName = paramName;
389          so.IntegerVectorParameter.Hidden = true;
390        }
391        Operators.AddRange(shakingOperators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
392        #endregion
393      } else {
394        Operators.RemoveAll(x => x is IIntegerVectorCrossover
395          || x is IIntegerVectorManipulator
396          || x is IIntegerVectorStdDevStrategyParameterOperator
397          || x is IIntegerVectorMultiNeighborhoodShakingOperator);
398      }
399      #endregion
400      #region Configure Operators for RealVectorEncoding
401      var realCreator = newCreator as IRealVectorCreator;
402      if (realCreator != null) {
403        var paramName = realCreator.RealVectorParameter.ActualName;
404        // do not replace a real vector creator that was manually set
405        if (!(SolutionCreator is IRealVectorCreator)
406            || ((IRealVectorCreator)SolutionCreator).RealVectorParameter.ActualName != realCreator.RealVectorParameter.ActualName) {
407          Operators.Remove(SolutionCreator);
408          SolutionCreator = newCreator;
409          Operators.Add(SolutionCreator);
410        }
411
412        #region Wire RealVector Crossovers
413        Operators.RemoveAll(x => x is IRealVectorCrossover && ((IRealVectorCrossover)x).ChildParameter.ActualName != paramName);
414        var crossovers = ApplicationManager.Manager.GetInstances<IRealVectorCrossover>().ToList();
415        foreach (var xo in crossovers) {
416          xo.ChildParameter.ActualName = paramName;
417          xo.ChildParameter.Hidden = true;
418          xo.ParentsParameter.ActualName = paramName;
419          xo.ParentsParameter.Hidden = true;
420          xo.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
421          xo.BoundsParameter.Hidden = true;
422        }
423        Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));
424        #endregion
425        #region Wire RealVector Manipulators
426        Operators.RemoveAll(x => x is IRealVectorManipulator && ((IRealVectorManipulator)x).RealVectorParameter.ActualName != paramName);
427        var manipulators = ApplicationManager.Manager.GetInstances<IRealVectorManipulator>().ToList();
428        foreach (var m in manipulators) {
429          m.RealVectorParameter.ActualName = paramName;
430          m.RealVectorParameter.Hidden = true;
431          m.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
432          m.BoundsParameter.Hidden = true;
433          var sm = m as ISelfAdaptiveManipulator;
434          if (sm != null) {
435            var p = sm.StrategyParameterParameter as ILookupParameter;
436            if (p != null) {
437              p.ActualName = paramName + "Strategy";
438              p.Hidden = true;
439            }
440          }
441        }
442        Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
443        #region Wire RealVector Strategy Parameters for SelfAdaptiveManipulators
444
445        Operators.RemoveAll(x => x is IStrategyParameterCreator && !(x is IRealVectorStdDevStrategyParameterCreator) || x is IRealVectorStdDevStrategyParameterCreator && ((IRealVectorStdDevStrategyParameterCreator)x).StrategyParameterParameter.ActualName != paramName + "Strategy");
446        Operators.RemoveAll(x => x is IStrategyParameterManipulator && !(x is IRealVectorStdDevStrategyParameterManipulator) || x is IRealVectorStdDevStrategyParameterManipulator && ((IRealVectorStdDevStrategyParameterManipulator)x).StrategyParameterParameter.ActualName != paramName + "Strategy");
447        Operators.RemoveAll(x => x is IStrategyParameterCrossover && !(x is IRealVectorStdDevStrategyParameterCrossover) || x is IRealVectorStdDevStrategyParameterCrossover && ((IRealVectorStdDevStrategyParameterCrossover)x).StrategyParameterParameter.ActualName != paramName + "Strategy");
448        var strategyOperators = ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>().ToList();
449        if (!(configuration.Parameters.First().Value is RealParameterConfiguration)) throw new InvalidOperationException("Single-encoded problem with realvector creator that is not a real-coded problem.");
450        var problemSize = ((RealParameterConfiguration)configuration.Parameters.First().Value).Length.Value;
451        var bounds = (DoubleMatrix)((RealParameterConfiguration)configuration.Parameters.First().Value).Bounds.Clone();
452        for (var i = 0; i < bounds.Rows; i++) {
453          bounds[i, 1] = 0.1 * (bounds[i, 1] - bounds[i, 0]);
454          bounds[i, 0] = 0;
455        }
456        foreach (var s in strategyOperators) {
457          var c = s as IRealVectorStdDevStrategyParameterCreator;
458          if (c != null) {
459            c.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
460            c.LengthParameter.ActualName = realCreator.LengthParameter.ActualName;
461            c.StrategyParameterParameter.ActualName = paramName + "Strategy";
462          }
463          var m = s as IRealVectorStdDevStrategyParameterManipulator;
464          if (m != null) {
465            m.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
466            m.StrategyParameterParameter.ActualName = paramName + "Strategy";
467          }
468          var mm = s as Encodings.RealVectorEncoding.StdDevStrategyVectorManipulator;
469          if (mm != null) {
470            mm.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * problemSize));
471            mm.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(problemSize)));
472          }
473          var x = s as IRealVectorStdDevStrategyParameterCrossover;
474          if (x != null) {
475            x.ParentsParameter.ActualName = paramName + "Strategy";
476            x.StrategyParameterParameter.ActualName = paramName + "Strategy";
477          }
478        }
479        Operators.AddRange(strategyOperators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
480        #endregion
481        #endregion
482        #region Wire RealVector ParticleCreators
483        Operators.RemoveAll(x => x is IRealVectorParticleCreator && ((IRealVectorParticleCreator)x).RealVectorParameter.ActualName != paramName);
484        var particleCreators = ApplicationManager.Manager.GetInstances<IRealVectorParticleCreator>().ToList();
485        foreach (var pc in particleCreators) {
486          pc.RealVectorParameter.ActualName = paramName;
487          pc.RealVectorParameter.Hidden = true;
488          pc.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
489          pc.BoundsParameter.Hidden = true;
490          pc.ProblemSizeParameter.ActualName = realCreator.LengthParameter.ActualName;
491          pc.ProblemSizeParameter.Hidden = true;
492        }
493        Operators.AddRange(particleCreators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
494        #endregion
495        #region Wire RealVector ParticleUpdaters
496        Operators.RemoveAll(x => x is IRealVectorParticleUpdater && ((IRealVectorParticleUpdater)x).RealVectorParameter.ActualName != paramName);
497        var particleUpdaters = ApplicationManager.Manager.GetInstances<IRealVectorParticleUpdater>().ToList();
498        foreach (var pu in particleUpdaters) {
499          pu.RealVectorParameter.ActualName = paramName;
500          pu.RealVectorParameter.Hidden = true;
501          pu.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
502          pu.BoundsParameter.Hidden = true;
503        }
504        Operators.AddRange(particleUpdaters.Where(x => Operators.All(y => x.GetType() != y.GetType())));
505        #endregion
506        #region Wire RealVector SwarmUpdaters
507        Operators.RemoveAll(x => x is IRealVectorSwarmUpdater && ((IRealVectorSwarmUpdater)x).RealVectorParameter.ActualName != paramName);
508        var swarmUpdaters = ApplicationManager.Manager.GetInstances<IRealVectorSwarmUpdater>().ToList();
509        foreach (var su in swarmUpdaters) {
510          su.RealVectorParameter.ActualName = paramName;
511          su.RealVectorParameter.Hidden = true;
512          su.MaximizationParameter.ActualName = MaximizationParameter.Name;
513          su.MaximizationParameter.Hidden = true;
514        }
515        Operators.AddRange(swarmUpdaters.Where(x => Operators.All(y => x.GetType() != y.GetType())));
516        #endregion
517        #region Wire RealVector ShakingOperators
518        Operators.RemoveAll(x => x is IRealVectorMultiNeighborhoodShakingOperator && ((IRealVectorMultiNeighborhoodShakingOperator)x).RealVectorParameter.ActualName != paramName);
519        var shakingOperators = ApplicationManager.Manager.GetInstances<IRealVectorMultiNeighborhoodShakingOperator>().ToList();
520        foreach (var so in shakingOperators) {
521          so.RealVectorParameter.ActualName = paramName;
522          so.RealVectorParameter.Hidden = true;
523        }
524        Operators.AddRange(shakingOperators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
525        #endregion
526      } else {
527        Operators.RemoveAll(x => x is IRealVectorCrossover
528          || x is IRealVectorManipulator
529          || x is IRealVectorStdDevStrategyParameterOperator
530          || x is IRealVectorParticleCreator
531          || x is IRealVectorParticleUpdater
532          || x is IRealVectorSwarmUpdater
533          || x is IRealVectorMultiNeighborhoodShakingOperator);
534      }
535      #endregion
536      #region Configure Operators for PermutationEncoding
537      var permCreator = newCreator as IPermutationCreator;
538      if (permCreator != null) {
539        var paramName = permCreator.PermutationParameter.ActualName;
540        // do not replace a permutation creator that was manually set
541        if (!(SolutionCreator is IPermutationCreator)
542            || ((IPermutationCreator)SolutionCreator).PermutationParameter.ActualName != permCreator.PermutationParameter.ActualName) {
543          Operators.Remove(SolutionCreator);
544          SolutionCreator = newCreator;
545          Operators.Add(SolutionCreator);
546        }
547
548        #region Wire Permutation Crossovers
549        Operators.RemoveAll(x => x is IPermutationCrossover && ((IPermutationCrossover)x).ChildParameter.ActualName != paramName);
550        var crossovers = ApplicationManager.Manager.GetInstances<IPermutationCrossover>().ToList();
551        foreach (var xo in crossovers) {
552          xo.ChildParameter.ActualName = permCreator.PermutationParameter.ActualName;
553          xo.ChildParameter.Hidden = true;
554          xo.ParentsParameter.ActualName = permCreator.PermutationParameter.ActualName;
555          xo.ParentsParameter.Hidden = true;
556        }
557        Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));
558        #endregion
559        #region Wire Permutation Manipulators
560        Operators.RemoveAll(x => x is IPermutationManipulator && ((IPermutationManipulator)x).PermutationParameter.ActualName != paramName);
561        var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList();
562        foreach (var m in manipulators) {
563          m.PermutationParameter.ActualName = permCreator.PermutationParameter.ActualName;
564          m.PermutationParameter.Hidden = true;
565        }
566        Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
567        #endregion
568        #region Wire ShakingOperators
569        Operators.RemoveAll(x => x is IPermutationMultiNeighborhoodShakingOperator && ((IPermutationMultiNeighborhoodShakingOperator)x).PermutationParameter.ActualName != paramName);
570        var shakingOperators = ApplicationManager.Manager.GetInstances<IPermutationMultiNeighborhoodShakingOperator>().ToList();
571        foreach (var op in shakingOperators) {
572          op.PermutationParameter.ActualName = paramName;
573          op.PermutationParameter.Hidden = true;
574        }
575        Operators.AddRange(shakingOperators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
576        #endregion
577      } else {
578        Operators.RemoveAll(x => x is IPermutationCrossover
579          || x is IPermutationManipulator
580          || x is IPermutationMultiNeighborhoodShakingOperator);
581      }
582      #endregion
583    }
584
585    protected virtual void UpdateMultiVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) {
586      var oldCreator = SolutionCreator as ParameterVectorCreater;
587      var newCreator = new ParameterVectorCreater();
588
589      #region Configure BinaryVector Creator
590      var newBinParams = new HashSet<string>(solutionCreators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName));
591      if (oldCreator != null) {
592        // we want to reuse the old creator
593        var oldParams = new HashSet<string>(oldCreator.Operators.OfType<IBinaryVectorCreator>()
594          .Select(x => x.BinaryVectorParameter.ActualName));
595        foreach (var toAdd in newBinParams.Except(oldParams)) {
596          var paramName = toAdd;
597          oldCreator.Operators.Add(
598            solutionCreators.OfType<IBinaryVectorCreator>().Single(x => x.BinaryVectorParameter.ActualName == paramName));
599        }
600        foreach (var toRemove in oldParams.Except(newBinParams)) {
601          var paramName = toRemove;
602          var op =
603            oldCreator.Operators.OfType<IBinaryVectorCreator>()
604              .SingleOrDefault(x => x.BinaryVectorParameter.ActualName == paramName);
605          if (op != null) oldCreator.Operators.Remove(op);
606        }
607      } else {
608        // we will use the new creator
609        foreach (var binCreator in solutionCreators.OfType<IBinaryVectorCreator>()) {
610          newCreator.Operators.Add(binCreator);
611        }
612      }
613      #endregion
614      #region Configure IntegerVector Creator
615      var newIntParams = new HashSet<string>(solutionCreators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName));
616      if (oldCreator != null) {
617        // we want to reuse the old creator
618        var oldParams = new HashSet<string>(oldCreator
619          .Operators.OfType<IIntegerVectorCreator>()
620          .Select(x => x.IntegerVectorParameter.ActualName));
621        foreach (var toAdd in newIntParams.Except(oldParams)) {
622          var paramName = toAdd;
623          oldCreator.Operators.Add(
624            solutionCreators.OfType<IIntegerVectorCreator>().Single(x => x.IntegerVectorParameter.ActualName == paramName));
625        }
626        foreach (var toRemove in oldParams.Except(newIntParams)) {
627          var paramName = toRemove;
628          var op =
629            oldCreator.Operators.OfType<IIntegerVectorCreator>()
630              .SingleOrDefault(x => x.IntegerVectorParameter.ActualName == paramName);
631          if (op != null) oldCreator.Operators.Remove(op);
632        }
633      } else {
634        // we will use the new creator
635        foreach (var intCreator in solutionCreators.OfType<IIntegerVectorCreator>()) {
636          newCreator.Operators.Add(intCreator);
637        }
638      }
639      #endregion
640      #region Configure RealVector Creator
641      var newRealParams = new HashSet<string>(solutionCreators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName));
642      if (oldCreator != null) {
643        // we want to reuse the old creator
644        var oldParams = new HashSet<string>(oldCreator
645          .Operators.OfType<IRealVectorCreator>()
646          .Select(x => x.RealVectorParameter.ActualName));
647        foreach (var toAdd in newRealParams.Except(oldParams)) {
648          var paramName = toAdd;
649          oldCreator.Operators.Add(
650            solutionCreators.OfType<IRealVectorCreator>().Single(x => x.RealVectorParameter.ActualName == paramName));
651        }
652        foreach (var toRemove in oldParams.Except(newRealParams)) {
653          var paramName = toRemove;
654          var op =
655            oldCreator.Operators.OfType<IRealVectorCreator>()
656              .SingleOrDefault(x => x.RealVectorParameter.ActualName == paramName);
657          if (op != null) oldCreator.Operators.Remove(op);
658        }
659      } else {
660        // we will use the new creator
661        foreach (var realCreator in solutionCreators.OfType<IRealVectorCreator>()) {
662          newCreator.Operators.Add(realCreator);
663        }
664      }
665      #endregion
666      #region Configure Permutation Creator
667      var newPermParams = new HashSet<string>(solutionCreators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName));
668      if (oldCreator != null) {
669        // we want to reuse the old creator
670        var oldParams = new HashSet<string>(oldCreator
671          .Operators.OfType<IPermutationCreator>()
672          .Select(x => x.PermutationParameter.ActualName));
673        foreach (var toAdd in newPermParams.Except(oldParams)) {
674          var paramName = toAdd;
675          oldCreator.Operators.Add(
676            solutionCreators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == paramName));
677        }
678        foreach (var toRemove in oldParams.Except(newPermParams)) {
679          var paramName = toRemove;
680          var op =
681            oldCreator.Operators.OfType<IPermutationCreator>()
682              .SingleOrDefault(x => x.PermutationParameter.ActualName == paramName);
683          if (op != null) oldCreator.Operators.Remove(op);
684        }
685        // we also have to sync the permutation type (in case this changes, as it is a value parameter)
686        foreach (var intersect in newPermParams.Intersect(oldParams)) {
687          var paramName = intersect;
688          var oldPermCreator = oldCreator.Operators.OfType<IPermutationCreator>()
689            .Single(x => x.PermutationParameter.ActualName == paramName);
690          var newPermCreator = solutionCreators.OfType<IPermutationCreator>()
691            .Single(x => x.PermutationParameter.ActualName == paramName);
692          oldPermCreator.PermutationTypeParameter.Value = newPermCreator.PermutationTypeParameter.Value;
693        }
694      } else {
695        // we will use the new creator
696        foreach (var permCreator in solutionCreators.OfType<IPermutationCreator>()) {
697          newCreator.Operators.Add(permCreator);
698        }
699      }
700      #endregion
701
702      if (oldCreator == null) SolutionCreator = newCreator;
703
704      // crossover and manipulator for multi-vector encoding
705      // the condition checks if a multi-vector encoding is to be updated (there already exists ParameterVectorCrossover and ParameterVectorManipulator)
706      if (Operators.OfType<ParameterVectorCrossover>().Any() && Operators.OfType<ParameterVectorManipulator>().Any()) {
707        #region Update existing multi-vector encoding
708        #region Update ParameterVector Crossover ...
709        foreach (var oldXo in Operators.OfType<ParameterVectorCrossover>()) {
710          #region ... for binary parameters
711          var oldBinParams = new HashSet<string>(oldXo.Operators.OfType<IBinaryVectorCrossover>()
712            .Select(x => x.ChildParameter.ActualName));
713          foreach (var toAdd in newBinParams.Except(oldBinParams))
714            oldXo.Operators.Add(GetDefaultBinaryCrossover(toAdd, configuration));
715          foreach (var toRemove in oldBinParams.Except(newBinParams)) {
716            var op =
717              oldXo.Operators.OfType<IBinaryVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
718            if (op != null) oldXo.Operators.Remove(op);
719          }
720          #endregion
721          #region ... for integer parameters
722          var oldIntParams = new HashSet<string>(oldXo.Operators.OfType<IIntegerVectorCrossover>()
723            .Select(x => x.ChildParameter.ActualName));
724          foreach (var toAdd in newIntParams.Except(oldIntParams))
725            oldXo.Operators.Add(GetDefaultIntegerCrossover(toAdd, configuration));
726          foreach (var toRemove in oldIntParams.Except(newIntParams)) {
727            var op =
728              oldXo.Operators.OfType<IIntegerVectorCrossover>()
729                .SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
730            if (op != null) oldXo.Operators.Remove(op);
731          }
732          #endregion
733          #region ... for real parameters
734          var oldRealParams = new HashSet<string>(oldXo.Operators.OfType<IRealVectorCrossover>()
735            .Select(x => x.ChildParameter.ActualName));
736          foreach (var toAdd in newRealParams.Except(oldRealParams))
737            oldXo.Operators.Add(GetDefaultRealCrossover(toAdd, configuration));
738          foreach (var toRemove in oldRealParams.Except(newRealParams)) {
739            var op =
740              oldXo.Operators.OfType<IRealVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
741            if (op != null) oldXo.Operators.Remove(op);
742          }
743          #endregion
744          #region ... for permutation parameters
745          var oldPermParams = new HashSet<string>(oldXo.Operators.OfType<IPermutationCrossover>()
746            .Select(x => x.ChildParameter.ActualName));
747          foreach (var toAdd in newPermParams.Except(oldPermParams))
748            oldXo.Operators.Add(GetDefaultPermutationCrossover(toAdd, configuration));
749          foreach (var toRemove in oldPermParams.Except(newPermParams)) {
750            var op =
751              oldXo.Operators.OfType<IPermutationCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
752            if (op != null) oldXo.Operators.Remove(op);
753          }
754          #endregion
755        }
756        #endregion
757        #region Update ParameterVector Manipulator ...
758        foreach (var oldM in Operators.OfType<ParameterVectorManipulator>()) {
759          #region ... for binary parameters
760          var oldBinParams = new HashSet<string>(oldM.Operators.OfType<IBinaryVectorManipulator>()
761            .Select(x => x.BinaryVectorParameter.ActualName));
762          foreach (var toAdd in newBinParams.Except(oldBinParams))
763            oldM.Operators.Add(GetDefaultBinaryManipulator(toAdd, configuration));
764          foreach (var toRemove in oldBinParams.Except(newBinParams)) {
765            var op =
766              oldM.Operators.OfType<IBinaryVectorManipulator>()
767                .SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove);
768            if (op != null) oldM.Operators.Remove(op);
769          }
770          #endregion
771          #region ... for integer parameters
772          var oldIntParams = new HashSet<string>(oldM.Operators.OfType<IIntegerVectorManipulator>()
773            .Select(x => x.IntegerVectorParameter.ActualName));
774          foreach (var toAdd in newIntParams.Except(oldIntParams))
775            oldM.Operators.Add(GetDefaultIntegerManipulator(toAdd, configuration));
776          foreach (var toRemove in oldIntParams.Except(newIntParams)) {
777            var op =
778              oldM.Operators.OfType<IIntegerVectorManipulator>()
779                .SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove);
780            if (op != null) oldM.Operators.Remove(op);
781          }
782          #endregion
783          #region ... for real parameters
784          var oldRealParams = new HashSet<string>(oldM.Operators.OfType<IRealVectorManipulator>()
785            .Select(x => x.RealVectorParameter.ActualName));
786          foreach (var toAdd in newRealParams.Except(oldRealParams))
787            oldM.Operators.Add(GetDefaultRealManipulator(toAdd, configuration));
788          foreach (var toRemove in oldRealParams.Except(newRealParams)) {
789            var op =
790              oldM.Operators.OfType<IRealVectorManipulator>()
791                .SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove);
792            if (op != null) oldM.Operators.Remove(op);
793          }
794          #endregion
795          #region ... for permutation parameters
796          var oldPermParams = new HashSet<string>(oldM.Operators.OfType<IPermutationManipulator>()
797            .Select(x => x.PermutationParameter.ActualName));
798          foreach (var toAdd in newPermParams.Except(oldPermParams))
799            oldM.Operators.Add(GetDefaultPermutationManipulator(toAdd, configuration));
800          foreach (var toRemove in oldPermParams.Except(newPermParams)) {
801            var op =
802              oldM.Operators.OfType<IPermutationManipulator>()
803                .SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove);
804            if (op != null) oldM.Operators.Remove(op);
805          }
806          #endregion
807        }
808        #endregion
809        #endregion
810      } else {
811        #region Handle transition from single-vector to multi-vector encoding
812        Operators.RemoveAll(x => x is ICrossover);
813        Operators.RemoveAll(x => x is IManipulator);
814        Operators.RemoveAll(x => x is IStrategyParameterCreator || x is IStrategyParameterManipulator || x is IStrategyParameterCrossover);
815        Operators.RemoveAll(x => x is IParticleCreator);
816        Operators.RemoveAll(x => x is IParticleUpdater);
817        Operators.RemoveAll(x => x is ISwarmUpdater);
818        Operators.RemoveAll(x => x is IMultiNeighborhoodShakingOperator);
819
820        var crossover = new ParameterVectorCrossover();
821        var manipulator = new ParameterVectorManipulator();
822        foreach (var param in configuration.Parameters) {
823          if (param.Value is BinaryParameterConfiguration) {
824            crossover.Operators.Add(GetDefaultBinaryCrossover(param.Key, configuration));
825            manipulator.Operators.Add(GetDefaultBinaryManipulator(param.Key, configuration));
826            continue;
827          }
828          var intConfig = param.Value as IntegerParameterConfiguration;
829          if (intConfig != null) {
830            crossover.Operators.Add(GetDefaultIntegerCrossover(param.Key, configuration));
831            manipulator.Operators.Add(GetDefaultIntegerManipulator(param.Key, configuration));
832            continue;
833          }
834          var realConfig = param.Value as RealParameterConfiguration;
835          if (realConfig != null) {
836            crossover.Operators.Add(GetDefaultRealCrossover(param.Key, configuration));
837            manipulator.Operators.Add(GetDefaultRealManipulator(param.Key, configuration));
838            continue;
839          }
840          var permConfig = param.Value as PermutationParameterConfiguration;
841          if (permConfig != null) {
842            crossover.Operators.Add(GetDefaultPermutationCrossover(param.Key, configuration));
843            manipulator.Operators.Add(GetDefaultPermutationManipulator(param.Key, configuration));
844            continue;
845          }
846          throw new InvalidOperationException("Unknown type for parameter " + param.Key);
847        }
848        Operators.Add(crossover);
849        Operators.Add(manipulator);
850        #endregion
851      }
852    }
853
854    protected virtual void UpdateMoveOperators() {
855      Operators.RemoveAll(x => x is IParameterVectorMoveOperator);
856      var generator = new ParameterVectorMoveGenerator();
857      generator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
858      generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
859
860      var evaluator = new ParameterVectorMoveEvaluator();
861      evaluator.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
862      evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
863      evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
864
865      var maker = new ParameterVectorMoveMaker();
866      maker.ConfigurationParameter.ActualName = ConfigurationParameter.Name;
867      maker.MoveQualityParameter.ActualName = evaluator.MoveQualityParameter.ActualName;
868      maker.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
869
870      Operators.AddRange(new IItem[] { generator, evaluator, maker });
871    }
872
873    #region GetDefaultOperators for Crossovers and Manipulators
874    // ReSharper disable RedundantNameQualifier
875    protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, Configuration config) {
876      var binConfig = (BinaryParameterConfiguration)config.Parameters[paramName];
877      IBinaryVectorCrossover binXo;
878      if (binConfig.Length.Value > 3) binXo = new Encodings.BinaryVectorEncoding.SinglePointCrossover();
879      else binXo = new Encodings.BinaryVectorEncoding.UniformCrossover();
880      binXo.ChildParameter.ActualName = paramName;
881      binXo.ParentsParameter.ActualName = paramName;
882      return binXo;
883    }
884
885    protected virtual IBinaryVectorManipulator GetDefaultBinaryManipulator(string paramName, Configuration config) {
886      var binM = new Encodings.BinaryVectorEncoding.SomePositionsBitflipManipulator();
887      binM.BinaryVectorParameter.ActualName = paramName;
888      binM.MutationProbabilityParameter.Value = new DoubleValue(0.1);
889      return binM;
890    }
891
892    protected virtual IIntegerVectorCrossover GetDefaultIntegerCrossover(string paramName, Configuration config) {
893      var intXo = new Encodings.IntegerVectorEncoding.RoundedBlendAlphaBetaCrossover();
894      intXo.ChildParameter.ActualName = paramName;
895      intXo.ParentsParameter.ActualName = paramName;
896      intXo.BoundsParameter.ActualName = paramName + "Bounds";
897      intXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
898      intXo.MaximizationParameter.ActualName = MaximizationParameter.Name;
899      return intXo;
900    }
901
902    protected virtual IIntegerVectorManipulator GetDefaultIntegerManipulator(string paramName, Configuration configuration) {
903      var intM = new Encodings.IntegerVectorEncoding.UniformSomePositionsManipulator();
904      intM.IntegerVectorParameter.ActualName = paramName;
905      intM.BoundsParameter.ActualName = paramName + "Bounds";
906      intM.ProbabilityParameter.Value = new DoubleValue(0.1);
907      return intM;
908    }
909
910    protected virtual IRealVectorCrossover GetDefaultRealCrossover(string paramName, Configuration configuration) {
911      var realXo = new Encodings.RealVectorEncoding.BlendAlphaBetaCrossover();
912      realXo.ChildParameter.ActualName = paramName;
913      realXo.ParentsParameter.ActualName = paramName;
914      realXo.BoundsParameter.ActualName = paramName + "Bounds";
915      realXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
916      realXo.MaximizationParameter.ActualName = MaximizationParameter.Name;
917      return realXo;
918    }
919
920    protected virtual IRealVectorManipulator GetDefaultRealManipulator(string paramName, Configuration configuration) {
921      var realM = new Encodings.RealVectorEncoding.BreederGeneticAlgorithmManipulator();
922      realM.RealVectorParameter.ActualName = paramName;
923      realM.BoundsParameter.ActualName = paramName + "Bounds";
924      return realM;
925    }
926
927    protected virtual IPermutationCrossover GetDefaultPermutationCrossover(string paramName, Configuration configuration) {
928      var permXo = new Encodings.PermutationEncoding.PartiallyMatchedCrossover();
929      permXo.ChildParameter.ActualName = paramName;
930      permXo.ParentsParameter.ActualName = paramName;
931      return permXo;
932    }
933
934    protected virtual IPermutationManipulator GetDefaultPermutationManipulator(string paramName, Configuration configuration) {
935      var permM = new Encodings.PermutationEncoding.Swap2Manipulator();
936      permM.PermutationParameter.ActualName = paramName;
937      return permM;
938    }
939    // ReSharper restore RedundantNameQualifier
940    #endregion
941  }
942}
Note: See TracBrowser for help on using the repository browser.