Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2174: Major refactoring

  • Removed ProblemDefinitionHosts
  • Renamed ParameterVector to Individual
  • Renamed Configuration to Encoding
  • Changed handling of existing operators that they will not be removed and recreated, but only rewired
File size: 47.0 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<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {
58      get { return (IValueParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
59    }
60
61    protected IValueParameter<Encoding> EncodingParameter {
62      get { return (IValueParameter<Encoding>)Parameters["Encoding"]; }
63    }
64
65    public ISingleObjectiveProblemDefinition ProblemDefinition {
66      get { return ProblemDefinitionParameter.Value; }
67      set { ProblemDefinitionParameter.Value = value; }
68    }
69
70    [Storable]
71    protected List<IParameter> DynamicEncodingParameters;
72
73    [StorableConstructor]
74    protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
75
76    protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem original, Cloner cloner)
77      : base(original, cloner) {
78      DynamicEncodingParameters = original.DynamicEncodingParameters.Select(cloner.Clone).ToList();
79      RegisterEventHandlers();
80    }
81    public SingleObjectiveProgrammableProblem()
82      : base(new SingleObjectiveEvaluator(), new MultiEncodingCreator()) {
83      Parameters.Add(new ValueParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "Defines the problem.", new SingleObjectiveProblemScript() { Name = Name }));
84      Parameters.Add(new ValueParameter<Encoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any."));
85
86      DynamicEncodingParameters = 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.ProblemDefinitionChanged += ProblemDefinitionChanged;
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 ProblemDefinitionChanged(object sender, EventArgs eventArgs) {
138      Parameterize();
139    }
140
141    protected virtual void Parameterize() {
142      var definition = ProblemDefinitionParameter.Value;
143      if (definition == null) return;
144
145      Encoding encoding;
146      try {
147        encoding = definition.Encoding;
148      } catch { return; }
149      EncodingParameter.Value = encoding;
150      Maximization.Value = definition.IsMaximizationProblem;
151
152      Evaluator.EncodingParameter.ActualName = EncodingParameter.Name;
153      Evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
154      foreach (var evalOp in Operators.OfType<ISingleObjectiveProgrammableProblemEvaluator>()) {
155        evalOp.EncodingParameter.ActualName = EncodingParameter.Name;
156        evalOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
157      }
158      foreach (var analyzeOp in Operators.OfType<ISingleObjectiveProgrammableProblemAnalyzer>()) {
159        analyzeOp.EncodingParameter.ActualName = EncodingParameter.Name;
160        analyzeOp.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
161        analyzeOp.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
162      }
163
164      foreach (var param in DynamicEncodingParameters)
165        if (Parameters.Contains(param)) Parameters.Remove(param);
166      DynamicEncodingParameters.Clear();
167
168      var creator = ConfigureCreator(encoding);
169
170      foreach (var param in DynamicEncodingParameters) {
171        param.Hidden = true;
172        Parameters.Add(param);
173      }
174
175      var multiEncoding = encoding as MultiEncoding;
176      if (multiEncoding != null) {
177        ConfigureMultiVectorEncodingOperators((MultiEncodingCreator)creator, multiEncoding);
178      } else {
179        ConfigureSingleEncodingOperators(creator, encoding);
180      }
181      UpdateImprovementOperators();
182      UpdateMoveOperators();
183    }
184
185    protected virtual ISolutionCreator ConfigureCreator(Encoding encoding) {
186      #region Configure MultiEncoding Creator
187      var multiEncoding = encoding as MultiEncoding;
188      if (multiEncoding != null) {
189        var creator = new MultiEncodingCreator();
190        foreach (var enc in multiEncoding.Encodings) {
191          if (enc is MultiEncoding) throw new InvalidOperationException("MultiEncoding within a MultiEncoding is not supported.");
192          creator.Operators.Add(ConfigureCreator(enc));
193        }
194        return creator;
195      }
196      #endregion
197      #region Configure BinaryVector Creator
198      var binEnc = encoding as BinaryEncoding;
199      if (binEnc != null) {
200        var p = new ValueParameter<IntValue>(binEnc.Name + "Length", binEnc.Length);
201        DynamicEncodingParameters.Add(p);
202
203        var creator = new RandomBinaryVectorCreator();
204        creator.BinaryVectorParameter.ActualName = binEnc.Name;
205        creator.LengthParameter.ActualName = p.Name;
206        return creator;
207      }
208      #endregion
209      #region Configure IntegerVector Creator
210      var intEnc = encoding as IntegerEncoding;
211      if (intEnc != null) {
212        var l = new ValueParameter<IntValue>(intEnc.Name + "Length", intEnc.Length);
213        var b = new ValueParameter<IntMatrix>(intEnc.Name + "Bounds", intEnc.Bounds);
214        DynamicEncodingParameters.Add(l);
215        DynamicEncodingParameters.Add(b);
216
217        var creator = new UniformRandomIntegerVectorCreator();
218        creator.IntegerVectorParameter.ActualName = intEnc.Name;
219        creator.LengthParameter.ActualName = l.Name;
220        creator.BoundsParameter.ActualName = b.Name;
221        return creator;
222      }
223      #endregion
224      #region Configure RealVector Creator
225      var realEnc = encoding as RealEncoding;
226      if (realEnc != null) {
227        var l = new ValueParameter<IntValue>(realEnc.Name + "Length", realEnc.Length);
228        var b = new ValueParameter<DoubleMatrix>(realEnc.Name + "Bounds", realEnc.Bounds);
229        DynamicEncodingParameters.Add(l);
230        DynamicEncodingParameters.Add(b);
231
232        var creator = new UniformRandomRealVectorCreator();
233        creator.RealVectorParameter.ActualName = realEnc.Name;
234        creator.LengthParameter.ActualName = l.Name;
235        creator.BoundsParameter.ActualName = b.Name;
236        return creator;
237      }
238      #endregion
239      #region Configure Permutation Creator
240      var permEnc = encoding as PermutationEncoding;
241      if (permEnc != null) {
242        var l = new ValueParameter<IntValue>(permEnc.Name + "Length", permEnc.Length);
243        DynamicEncodingParameters.Add(l);
244
245        var creator = new RandomPermutationCreator();
246        creator.PermutationParameter.ActualName = permEnc.Name;
247        creator.LengthParameter.ActualName = l.Name;
248        creator.PermutationTypeParameter.Value = permEnc.Type;
249        return creator;
250      }
251      #endregion
252      throw new ArgumentException(string.Format("Encoding {0} is unknown.", encoding != null ? encoding.GetType().FullName : "(null)"));
253    }
254
255    protected virtual void ConfigureSingleEncodingOperators(ISolutionCreator newCreator, Encoding encoding) {
256      // remove all multiencoding operators
257      Operators.RemoveAll(x => x is MultiEncodingCrossover
258                            || x is MultiEncodingManipulator
259                            || x is MultiEncodingCreator);
260
261      #region Configure Operators for BinaryVectorEncoding
262      var binCreator = newCreator as IBinaryVectorCreator;
263      if (binCreator != null) {
264        var paramName = binCreator.BinaryVectorParameter.ActualName;
265        // do not replace a binary vector creator that was manually set
266        if (!(SolutionCreator is IBinaryVectorCreator) || ((IBinaryVectorCreator)SolutionCreator).BinaryVectorParameter.ActualName != paramName) {
267          Operators.Remove(SolutionCreator);
268          SolutionCreator = newCreator;
269          Operators.Add(SolutionCreator);
270        }
271
272        #region Wire BinaryVector Crossovers
273        var crossovers = Operators.OfType<IBinaryVectorCrossover>()
274          .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>(), new TypeEqualityComparer<IBinaryVectorCrossover>())
275          .ToList();
276        foreach (var xo in crossovers) {
277          xo.ChildParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
278          xo.ChildParameter.Hidden = true;
279          xo.ParentsParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
280          xo.ParentsParameter.Hidden = true;
281        }
282        Operators.AddRange(crossovers.Except(Operators.OfType<IBinaryVectorCrossover>()));
283        #endregion
284        #region Wire BinaryVector Manipulators
285        var manipulators = Operators.OfType<IBinaryVectorManipulator>()
286          .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>(), new TypeEqualityComparer<IBinaryVectorManipulator>())
287          .ToList();
288        foreach (var m in manipulators) {
289          m.BinaryVectorParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
290          m.BinaryVectorParameter.Hidden = true;
291        }
292        Operators.AddRange(manipulators.Except(Operators.OfType<IBinaryVectorManipulator>()));
293        #endregion
294        #region Wire BinaryVector ShakingOperators
295        var shakingOperators = Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()
296          .Union(ApplicationManager.Manager.GetInstances<IBinaryVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IBinaryVectorMultiNeighborhoodShakingOperator>())
297          .ToList();
298        foreach (var so in shakingOperators) {
299          so.BinaryVectorParameter.ActualName = paramName;
300          so.BinaryVectorParameter.Hidden = true;
301        }
302        Operators.AddRange(shakingOperators.Except(Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()));
303        #endregion
304      } else {
305        Operators.RemoveAll(x => x is IBinaryVectorCrossover
306          || x is IBinaryVectorManipulator
307          || x is IBinaryVectorMultiNeighborhoodShakingOperator);
308      }
309      #endregion
310      #region Configure Operators for IntegerVectorEncoding
311      var intCreator = newCreator as IIntegerVectorCreator;
312      if (intCreator != null) {
313        var paramName = intCreator.IntegerVectorParameter.ActualName;
314        // do not replace an integer vector creator that was manually set
315        if (!(SolutionCreator is IIntegerVectorCreator)
316          || ((IIntegerVectorCreator)SolutionCreator).IntegerVectorParameter.ActualName != intCreator.IntegerVectorParameter.ActualName) {
317          Operators.Remove(SolutionCreator);
318          SolutionCreator = newCreator;
319          Operators.Add(SolutionCreator);
320        }
321
322        #region Wire IntegerVector Crossovers
323        var crossovers = Operators.OfType<IIntegerVectorCrossover>()
324          .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>(), new TypeEqualityComparer<IIntegerVectorCrossover>())
325          .ToList();
326        foreach (var xo in crossovers) {
327          xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
328          xo.ChildParameter.Hidden = true;
329          xo.ParentsParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
330          xo.ParentsParameter.Hidden = true;
331          var bx = xo as IBoundedIntegerVectorOperator;
332          if (bx != null) {
333            bx.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName;
334            bx.BoundsParameter.Hidden = true;
335          }
336        }
337        Operators.AddRange(crossovers.Except(Operators.OfType<IIntegerVectorCrossover>()));
338        #endregion
339        #region Wire IntegerVector Manipulators
340        var manipulators = Operators.OfType<IIntegerVectorManipulator>()
341          .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>(), new TypeEqualityComparer<IIntegerVectorManipulator>())
342          .ToList();
343        foreach (var m in manipulators) {
344          m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
345          m.IntegerVectorParameter.Hidden = true;
346          var sm = m as ISelfAdaptiveManipulator;
347          if (sm != null) {
348            var p = sm.StrategyParameterParameter as ILookupParameter;
349            if (p != null) {
350              p.ActualName = paramName + "Strategy";
351              p.Hidden = true;
352            }
353          }
354          var bm = m as IBoundedIntegerVectorOperator;
355          if (bm != null) {
356            bm.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName;
357            bm.BoundsParameter.Hidden = true;
358          }
359        }
360        Operators.AddRange(manipulators.Except(Operators.OfType<IIntegerVectorManipulator>()));
361        #region Wire IntegerVector StrategyParameters for SelfAdaptiveManipulators
362        var strategyOperators = Operators.OfType<IIntegerVectorStdDevStrategyParameterOperator>()
363          .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorStdDevStrategyParameterOperator>(), new TypeEqualityComparer<IIntegerVectorStdDevStrategyParameterOperator>())
364          .ToList();
365        var problemSize = ((IntegerEncoding)encoding).Length.Value;
366        var b = ((IntegerEncoding)encoding).Bounds;
367        var bounds = new DoubleMatrix(b.Rows, b.Columns);
368        for (var i = 0; i < bounds.Rows; i++) {
369          bounds[i, 1] = (int)Math.Ceiling(0.33 * (b[i, 1] - b[i, 0]));
370          bounds[i, 0] = 0;
371          if (bounds.Columns > 2) bounds[i, 2] = b[i, 2];
372        }
373        foreach (var s in strategyOperators) {
374          var c = s as IIntegerVectorStdDevStrategyParameterCreator;
375          if (c != null) {
376            c.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
377            c.LengthParameter.ActualName = intCreator.LengthParameter.ActualName;
378            c.StrategyParameterParameter.ActualName = paramName + "Strategy";
379          }
380          var m = s as IIntegerVectorStdDevStrategyParameterManipulator;
381          if (m != null) {
382            m.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
383            m.StrategyParameterParameter.ActualName = paramName + "Strategy";
384          }
385          var mm = s as Encodings.IntegerVectorEncoding.StdDevStrategyVectorManipulator;
386          if (mm != null) {
387            mm.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * problemSize));
388            mm.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(problemSize)));
389          }
390          var x = s as IIntegerVectorStdDevStrategyParameterCrossover;
391          if (x != null) {
392            x.ParentsParameter.ActualName = paramName + "Strategy";
393            x.StrategyParameterParameter.ActualName = paramName + "Strategy";
394          }
395        }
396        Operators.AddRange(strategyOperators.Except(Operators.OfType<IIntegerVectorStdDevStrategyParameterOperator>()));
397        #endregion
398        #endregion
399        #region Wire IntegerVector ShakingOperators
400        var shakingOperators = Operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>()
401          .Union(ApplicationManager.Manager.GetInstances<IIntegerVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IIntegerVectorMultiNeighborhoodShakingOperator>())
402          .ToList();
403        foreach (var so in shakingOperators) {
404          so.IntegerVectorParameter.ActualName = paramName;
405          so.IntegerVectorParameter.Hidden = true;
406        }
407        Operators.AddRange(shakingOperators.Except(Operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>()));
408        #endregion
409      } else {
410        Operators.RemoveAll(x => x is IIntegerVectorCrossover
411          || x is IIntegerVectorManipulator
412          || x is IIntegerVectorStdDevStrategyParameterOperator
413          || x is IIntegerVectorMultiNeighborhoodShakingOperator);
414      }
415      #endregion
416      #region Configure Operators for RealVectorEncoding
417      var realCreator = newCreator as IRealVectorCreator;
418      if (realCreator != null) {
419        var paramName = realCreator.RealVectorParameter.ActualName;
420        // do not replace a real vector creator that was manually set
421        if (!(SolutionCreator is IRealVectorCreator)
422            || ((IRealVectorCreator)SolutionCreator).RealVectorParameter.ActualName != realCreator.RealVectorParameter.ActualName) {
423          Operators.Remove(SolutionCreator);
424          SolutionCreator = newCreator;
425          Operators.Add(SolutionCreator);
426        }
427
428        #region Wire RealVector Crossovers
429        var crossovers = Operators.OfType<IRealVectorCrossover>()
430          .Union(ApplicationManager.Manager.GetInstances<IRealVectorCrossover>(), new TypeEqualityComparer<IRealVectorCrossover>())
431          .ToList();
432        foreach (var xo in crossovers) {
433          xo.ChildParameter.ActualName = paramName;
434          xo.ChildParameter.Hidden = true;
435          xo.ParentsParameter.ActualName = paramName;
436          xo.ParentsParameter.Hidden = true;
437          xo.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
438          xo.BoundsParameter.Hidden = true;
439        }
440        Operators.AddRange(crossovers.Except(Operators.OfType<IRealVectorCrossover>()));
441        #endregion
442        #region Wire RealVector Manipulators
443        var manipulators = Operators.OfType<IRealVectorManipulator>()
444          .Union(ApplicationManager.Manager.GetInstances<IRealVectorManipulator>(), new TypeEqualityComparer<IRealVectorManipulator>())
445          .ToList();
446        foreach (var m in manipulators) {
447          m.RealVectorParameter.ActualName = paramName;
448          m.RealVectorParameter.Hidden = true;
449          m.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
450          m.BoundsParameter.Hidden = true;
451          var sm = m as ISelfAdaptiveManipulator;
452          if (sm != null) {
453            var p = sm.StrategyParameterParameter as ILookupParameter;
454            if (p != null) {
455              p.ActualName = paramName + "Strategy";
456              p.Hidden = true;
457            }
458          }
459        }
460        Operators.AddRange(manipulators.Except(Operators.OfType<IRealVectorManipulator>()));
461        #region Wire RealVector Strategy Parameters for SelfAdaptiveManipulators
462        var strategyOperators = Operators.OfType<IRealVectorStdDevStrategyParameterOperator>()
463          .Union(ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>(), new TypeEqualityComparer<IRealVectorStdDevStrategyParameterOperator>())
464          .ToList();
465        var problemSize = ((RealEncoding)encoding).Length.Value;
466        var bounds = (DoubleMatrix)((RealEncoding)encoding).Bounds.Clone();
467        for (var i = 0; i < bounds.Rows; i++) {
468          bounds[i, 1] = 0.1 * (bounds[i, 1] - bounds[i, 0]);
469          bounds[i, 0] = 0;
470        }
471        foreach (var s in strategyOperators) {
472          var c = s as IRealVectorStdDevStrategyParameterCreator;
473          if (c != null) {
474            c.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
475            c.LengthParameter.ActualName = realCreator.LengthParameter.ActualName;
476            c.StrategyParameterParameter.ActualName = paramName + "Strategy";
477          }
478          var m = s as IRealVectorStdDevStrategyParameterManipulator;
479          if (m != null) {
480            m.BoundsParameter.Value = (DoubleMatrix)bounds.Clone();
481            m.StrategyParameterParameter.ActualName = paramName + "Strategy";
482          }
483          var mm = s as Encodings.RealVectorEncoding.StdDevStrategyVectorManipulator;
484          if (mm != null) {
485            mm.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * problemSize));
486            mm.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(problemSize)));
487          }
488          var x = s as IRealVectorStdDevStrategyParameterCrossover;
489          if (x != null) {
490            x.ParentsParameter.ActualName = paramName + "Strategy";
491            x.StrategyParameterParameter.ActualName = paramName + "Strategy";
492          }
493        }
494        Operators.AddRange(strategyOperators.Except(Operators.OfType<IRealVectorStdDevStrategyParameterOperator>()));
495        #endregion
496        #endregion
497        #region Wire RealVector ParticleCreators
498        var particleCreators = Operators.OfType<IRealVectorParticleCreator>()
499          .Union(ApplicationManager.Manager.GetInstances<IRealVectorParticleCreator>(), new TypeEqualityComparer<IRealVectorParticleCreator>())
500          .ToList();
501        foreach (var pc in particleCreators) {
502          pc.RealVectorParameter.ActualName = paramName;
503          pc.RealVectorParameter.Hidden = true;
504          pc.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
505          pc.BoundsParameter.Hidden = true;
506          pc.ProblemSizeParameter.ActualName = realCreator.LengthParameter.ActualName;
507          pc.ProblemSizeParameter.Hidden = true;
508        }
509        Operators.AddRange(particleCreators.Except(Operators.OfType<IRealVectorParticleCreator>()));
510        #endregion
511        #region Wire RealVector ParticleUpdaters
512        var particleUpdaters = Operators.OfType<IRealVectorParticleUpdater>()
513          .Union(ApplicationManager.Manager.GetInstances<IRealVectorParticleUpdater>(), new TypeEqualityComparer<IRealVectorParticleUpdater>())
514          .ToList();
515        foreach (var pu in particleUpdaters) {
516          pu.RealVectorParameter.ActualName = paramName;
517          pu.RealVectorParameter.Hidden = true;
518          pu.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
519          pu.BoundsParameter.Hidden = true;
520        }
521        Operators.AddRange(particleUpdaters.Except(Operators.OfType<IRealVectorParticleUpdater>()));
522        #endregion
523        #region Wire RealVector SwarmUpdaters
524        var swarmUpdaters = Operators.OfType<IRealVectorSwarmUpdater>()
525          .Union(ApplicationManager.Manager.GetInstances<IRealVectorSwarmUpdater>(), new TypeEqualityComparer<IRealVectorSwarmUpdater>())
526          .ToList();
527        foreach (var su in swarmUpdaters) {
528          su.RealVectorParameter.ActualName = paramName;
529          su.RealVectorParameter.Hidden = true;
530          su.MaximizationParameter.ActualName = MaximizationParameter.Name;
531          su.MaximizationParameter.Hidden = true;
532        }
533        Operators.AddRange(swarmUpdaters.Except(Operators.OfType<IRealVectorSwarmUpdater>()));
534        #endregion
535        #region Wire RealVector ShakingOperators
536        var shakingOperators = Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()
537          .Union(ApplicationManager.Manager.GetInstances<IRealVectorMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IRealVectorMultiNeighborhoodShakingOperator>())
538          .ToList();
539        foreach (var so in shakingOperators) {
540          so.RealVectorParameter.ActualName = paramName;
541          so.RealVectorParameter.Hidden = true;
542        }
543        Operators.AddRange(shakingOperators.Except(Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()));
544        #endregion
545      } else {
546        Operators.RemoveAll(x => x is IRealVectorCrossover
547          || x is IRealVectorManipulator
548          || x is IRealVectorStdDevStrategyParameterOperator
549          || x is IRealVectorParticleCreator
550          || x is IRealVectorParticleUpdater
551          || x is IRealVectorSwarmUpdater
552          || x is IRealVectorMultiNeighborhoodShakingOperator);
553      }
554      #endregion
555      #region Configure Operators for PermutationEncoding
556      var permCreator = newCreator as IPermutationCreator;
557      if (permCreator != null) {
558        var paramName = permCreator.PermutationParameter.ActualName;
559        // do not replace a permutation creator that was manually set
560        if (!(SolutionCreator is IPermutationCreator)
561            || ((IPermutationCreator)SolutionCreator).PermutationParameter.ActualName != permCreator.PermutationParameter.ActualName) {
562          Operators.Remove(SolutionCreator);
563          SolutionCreator = newCreator;
564          Operators.Add(SolutionCreator);
565        }
566
567        #region Wire Permutation Crossovers
568        var crossovers = Operators.OfType<IPermutationCrossover>()
569          .Union(ApplicationManager.Manager.GetInstances<IPermutationCrossover>(), new TypeEqualityComparer<IPermutationCrossover>())
570          .ToList();
571        foreach (var xo in crossovers) {
572          xo.ChildParameter.ActualName = permCreator.PermutationParameter.ActualName;
573          xo.ChildParameter.Hidden = true;
574          xo.ParentsParameter.ActualName = permCreator.PermutationParameter.ActualName;
575          xo.ParentsParameter.Hidden = true;
576        }
577        Operators.AddRange(crossovers.Except(Operators.OfType<IPermutationCrossover>()));
578        #endregion
579        #region Wire Permutation Manipulators
580        var manipulators = Operators.OfType<IPermutationManipulator>()
581          .Union(ApplicationManager.Manager.GetInstances<IPermutationManipulator>(), new TypeEqualityComparer<IPermutationManipulator>())
582          .ToList();
583        foreach (var m in manipulators) {
584          m.PermutationParameter.ActualName = permCreator.PermutationParameter.ActualName;
585          m.PermutationParameter.Hidden = true;
586        }
587        Operators.AddRange(manipulators.Except(Operators.OfType<IPermutationManipulator>()));
588        #endregion
589        #region Wire Permutation ShakingOperators
590        var shakingOperators = Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()
591          .Union(ApplicationManager.Manager.GetInstances<IPermutationMultiNeighborhoodShakingOperator>(), new TypeEqualityComparer<IPermutationMultiNeighborhoodShakingOperator>())
592          .ToList();
593        foreach (var op in shakingOperators) {
594          op.PermutationParameter.ActualName = paramName;
595          op.PermutationParameter.Hidden = true;
596        }
597        Operators.AddRange(shakingOperators.Except(Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()));
598        #endregion
599      } else {
600        Operators.RemoveAll(x => x is IPermutationCrossover
601          || x is IPermutationManipulator
602          || x is IPermutationMultiNeighborhoodShakingOperator);
603      }
604      #endregion
605    }
606
607    protected virtual void ConfigureMultiVectorEncodingOperators(MultiEncodingCreator newCreator, MultiEncoding encoding) {
608      var newBinParams = new HashSet<string>(newCreator.Operators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName));
609      var newIntParams = new HashSet<string>(newCreator.Operators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName));
610      var newRealParams = new HashSet<string>(newCreator.Operators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName));
611      var newPermParams = new HashSet<string>(newCreator.Operators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName));
612
613      var oldCreator = SolutionCreator as MultiEncodingCreator;
614      if (oldCreator == null) SolutionCreator = newCreator;
615      else {
616        #region Configure BinaryVector Creator
617        var oldBinParams = new HashSet<string>(oldCreator.Operators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName));
618        foreach (var toAdd in newBinParams.Except(oldBinParams)) {
619          oldCreator.Operators.Add(newCreator.Operators.OfType<IBinaryVectorCreator>().Single(x => x.BinaryVectorParameter.ActualName == toAdd));
620        }
621        foreach (var toRemove in oldBinParams.Except(newBinParams)) {
622          var op = oldCreator.Operators.OfType<IBinaryVectorCreator>().SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove);
623          if (op != null) oldCreator.Operators.Remove(op);
624        }
625        #endregion
626
627        #region Configure IntegerVector Creator
628        var oldIntParams = new HashSet<string>(oldCreator.Operators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName));
629        foreach (var toAdd in newIntParams.Except(oldIntParams)) {
630          oldCreator.Operators.Add(newCreator.Operators.OfType<IIntegerVectorCreator>().Single(x => x.IntegerVectorParameter.ActualName == toAdd));
631        }
632        foreach (var toRemove in oldIntParams.Except(newIntParams)) {
633          var op = oldCreator.Operators.OfType<IIntegerVectorCreator>().SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove);
634          if (op != null) oldCreator.Operators.Remove(op);
635        }
636        #endregion
637
638        #region Configure RealVector Creator
639        var oldRealParams = new HashSet<string>(oldCreator.Operators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName));
640        foreach (var toAdd in newRealParams.Except(oldRealParams)) {
641          oldCreator.Operators.Add(newCreator.Operators.OfType<IRealVectorCreator>().Single(x => x.RealVectorParameter.ActualName == toAdd));
642        }
643        foreach (var toRemove in oldRealParams.Except(newRealParams)) {
644          var op = oldCreator.Operators.OfType<IRealVectorCreator>().SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove);
645          if (op != null) oldCreator.Operators.Remove(op);
646        }
647        #endregion
648
649        #region Configure Permutation Creator
650        var oldPermParams = new HashSet<string>(oldCreator.Operators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName));
651        foreach (var toAdd in newPermParams.Except(oldPermParams)) {
652          oldCreator.Operators.Add(newCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == toAdd));
653        }
654        foreach (var toRemove in oldPermParams.Except(newPermParams)) {
655          var op = oldCreator.Operators.OfType<IPermutationCreator>().SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove);
656          if (op != null) oldCreator.Operators.Remove(op);
657        }
658        // we also have to sync the permutation type (in case this changes, as it is a value parameter)
659        foreach (var intersect in newPermParams.Intersect(oldPermParams)) {
660          var oldPermCreator = oldCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == intersect);
661          var newPermCreator = newCreator.Operators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == intersect);
662          oldPermCreator.PermutationTypeParameter.Value = newPermCreator.PermutationTypeParameter.Value;
663        }
664        #endregion
665
666      }
667
668      // crossover and manipulator for multi-vector encoding
669      // the condition checks if a multi-vector encoding is to be updated (there already exists ParameterVectorCrossover and ParameterVectorManipulator)
670      if (Operators.OfType<MultiEncodingCrossover>().Any() && Operators.OfType<MultiEncodingManipulator>().Any()) {
671        #region Update existing multi-vector encoding
672        #region Update ParameterVector Crossover ...
673        foreach (var oldXo in Operators.OfType<MultiEncodingCrossover>()) {
674          #region ... for binary parameters
675          var oldBinParams = new HashSet<string>(oldXo.Operators.OfType<IBinaryVectorCrossover>().Select(x => x.ChildParameter.ActualName));
676          foreach (var toAdd in newBinParams.Except(oldBinParams))
677            oldXo.Operators.Add(GetDefaultBinaryCrossover(toAdd, encoding));
678          foreach (var toRemove in oldBinParams.Except(newBinParams)) {
679            var op = oldXo.Operators.OfType<IBinaryVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
680            if (op != null) oldXo.Operators.Remove(op);
681          }
682          #endregion
683          #region ... for integer parameters
684          var oldIntParams = new HashSet<string>(oldXo.Operators.OfType<IIntegerVectorCrossover>().Select(x => x.ChildParameter.ActualName));
685          foreach (var toAdd in newIntParams.Except(oldIntParams))
686            oldXo.Operators.Add(GetDefaultIntegerCrossover(toAdd, encoding));
687          foreach (var toRemove in oldIntParams.Except(newIntParams)) {
688            var op = oldXo.Operators.OfType<IIntegerVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
689            if (op != null) oldXo.Operators.Remove(op);
690          }
691          #endregion
692          #region ... for real parameters
693          var oldRealParams = new HashSet<string>(oldXo.Operators.OfType<IRealVectorCrossover>().Select(x => x.ChildParameter.ActualName));
694          foreach (var toAdd in newRealParams.Except(oldRealParams))
695            oldXo.Operators.Add(GetDefaultRealCrossover(toAdd, encoding));
696          foreach (var toRemove in oldRealParams.Except(newRealParams)) {
697            var op = oldXo.Operators.OfType<IRealVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
698            if (op != null) oldXo.Operators.Remove(op);
699          }
700          #endregion
701          #region ... for permutation parameters
702          var oldPermParams = new HashSet<string>(oldXo.Operators.OfType<IPermutationCrossover>().Select(x => x.ChildParameter.ActualName));
703          foreach (var toAdd in newPermParams.Except(oldPermParams))
704            oldXo.Operators.Add(GetDefaultPermutationCrossover(toAdd, encoding));
705          foreach (var toRemove in oldPermParams.Except(newPermParams)) {
706            var op = oldXo.Operators.OfType<IPermutationCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
707            if (op != null) oldXo.Operators.Remove(op);
708          }
709          #endregion
710        }
711        #endregion
712        #region Update ParameterVector Manipulator ...
713        foreach (var oldM in Operators.OfType<MultiEncodingManipulator>()) {
714          #region ... for binary parameters
715          var oldBinParams = new HashSet<string>(oldM.Operators.OfType<IBinaryVectorManipulator>().Select(x => x.BinaryVectorParameter.ActualName));
716          foreach (var toAdd in newBinParams.Except(oldBinParams))
717            oldM.Operators.Add(GetDefaultBinaryManipulator(toAdd, encoding));
718          foreach (var toRemove in oldBinParams.Except(newBinParams)) {
719            var op = oldM.Operators.OfType<IBinaryVectorManipulator>().SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove);
720            if (op != null) oldM.Operators.Remove(op);
721          }
722          #endregion
723          #region ... for integer parameters
724          var oldIntParams = new HashSet<string>(oldM.Operators.OfType<IIntegerVectorManipulator>().Select(x => x.IntegerVectorParameter.ActualName));
725          foreach (var toAdd in newIntParams.Except(oldIntParams))
726            oldM.Operators.Add(GetDefaultIntegerManipulator(toAdd, encoding));
727          foreach (var toRemove in oldIntParams.Except(newIntParams)) {
728            var op = oldM.Operators.OfType<IIntegerVectorManipulator>().SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove);
729            if (op != null) oldM.Operators.Remove(op);
730          }
731          #endregion
732          #region ... for real parameters
733          var oldRealParams = new HashSet<string>(oldM.Operators.OfType<IRealVectorManipulator>().Select(x => x.RealVectorParameter.ActualName));
734          foreach (var toAdd in newRealParams.Except(oldRealParams))
735            oldM.Operators.Add(GetDefaultRealManipulator(toAdd, encoding));
736          foreach (var toRemove in oldRealParams.Except(newRealParams)) {
737            var op = oldM.Operators.OfType<IRealVectorManipulator>().SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove);
738            if (op != null) oldM.Operators.Remove(op);
739          }
740          #endregion
741          #region ... for permutation parameters
742          var oldPermParams = new HashSet<string>(oldM.Operators.OfType<IPermutationManipulator>().Select(x => x.PermutationParameter.ActualName));
743          foreach (var toAdd in newPermParams.Except(oldPermParams))
744            oldM.Operators.Add(GetDefaultPermutationManipulator(toAdd, encoding));
745          foreach (var toRemove in oldPermParams.Except(newPermParams)) {
746            var op = oldM.Operators.OfType<IPermutationManipulator>().SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove);
747            if (op != null) oldM.Operators.Remove(op);
748          }
749          #endregion
750        }
751        #endregion
752        #endregion
753      } else {
754        #region Handle transition from single-vector to multi-vector encoding
755        Operators.RemoveAll(x => x is ICrossover);
756        Operators.RemoveAll(x => x is IManipulator);
757        Operators.RemoveAll(x => x is IStrategyParameterCreator || x is IStrategyParameterManipulator || x is IStrategyParameterCrossover);
758        Operators.RemoveAll(x => x is IParticleCreator);
759        Operators.RemoveAll(x => x is IParticleUpdater);
760        Operators.RemoveAll(x => x is ISwarmUpdater);
761        Operators.RemoveAll(x => x is IMultiNeighborhoodShakingOperator);
762
763        var crossover = new MultiEncodingCrossover();
764        var manipulator = new MultiEncodingManipulator();
765        foreach (var enc in encoding.Encodings) {
766          if (enc is BinaryEncoding) {
767            crossover.Operators.Add(GetDefaultBinaryCrossover(enc.Name, encoding));
768            manipulator.Operators.Add(GetDefaultBinaryManipulator(enc.Name, encoding));
769            continue;
770          }
771          var intConfig = enc as IntegerEncoding;
772          if (intConfig != null) {
773            crossover.Operators.Add(GetDefaultIntegerCrossover(enc.Name, encoding));
774            manipulator.Operators.Add(GetDefaultIntegerManipulator(enc.Name, encoding));
775            continue;
776          }
777          var realConfig = enc as RealEncoding;
778          if (realConfig != null) {
779            crossover.Operators.Add(GetDefaultRealCrossover(enc.Name, encoding));
780            manipulator.Operators.Add(GetDefaultRealManipulator(enc.Name, encoding));
781            continue;
782          }
783          var permConfig = enc as PermutationEncoding;
784          if (permConfig != null) {
785            crossover.Operators.Add(GetDefaultPermutationCrossover(enc.Name, encoding));
786            manipulator.Operators.Add(GetDefaultPermutationManipulator(enc.Name, encoding));
787            continue;
788          }
789          throw new InvalidOperationException("Unknown type for parameter " + enc.Name);
790        }
791        Operators.Add(crossover);
792        Operators.Add(manipulator);
793        #endregion
794      }
795    }
796
797    protected virtual void UpdateImprovementOperators() {
798      if (!Operators.Any(x => x is SingleObjectiveImprover))
799        Operators.Add(new SingleObjectiveImprover());
800      foreach (var improver in Operators.OfType<SingleObjectiveImprover>()) {
801        improver.EncodingParameter.ActualName = EncodingParameter.Name;
802        improver.MaximizationParameter.ActualName = MaximizationParameter.Name;
803        improver.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
804        improver.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
805      }
806    }
807
808    protected virtual void UpdateMoveOperators() {
809      if (!Operators.Any(x => x is SingleObjectiveMoveGenerator))
810        Operators.Add(new SingleObjectiveMoveGenerator());
811      if (!Operators.Any(x => x is SingleObjectiveMoveEvaluator))
812        Operators.Add(new SingleObjectiveMoveEvaluator());
813      if (!Operators.Any(x => x is SingleObjectiveMoveMaker))
814        Operators.Add(new SingleObjectiveMoveMaker());
815
816      foreach (var generator in Operators.OfType<SingleObjectiveMoveGenerator>()) {
817        generator.EncodingParameter.ActualName = EncodingParameter.Name;
818        generator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
819      }
820      foreach (var evaluator in Operators.OfType<SingleObjectiveMoveEvaluator>()) {
821        evaluator.EncodingParameter.ActualName = EncodingParameter.Name;
822        evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
823        evaluator.ProblemDefinitionParameter.ActualName = ProblemDefinitionParameter.Name;
824      }
825      foreach (var maker in Operators.OfType<SingleObjectiveMoveMaker>()) {
826        maker.EncodingParameter.ActualName = EncodingParameter.Name;
827        maker.MoveQualityParameter.ActualName = Operators.OfType<SingleObjectiveMoveEvaluator>().First().MoveQualityParameter.ActualName;
828        maker.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
829      }
830    }
831
832    #region GetDefaultOperators for Crossovers and Manipulators
833    // ReSharper disable RedundantNameQualifier
834    protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, MultiEncoding config) {
835      var binConfig = (BinaryEncoding)config.Encodings[paramName];
836      IBinaryVectorCrossover binXo;
837      if (binConfig.Length.Value > 3) binXo = new Encodings.BinaryVectorEncoding.SinglePointCrossover();
838      else binXo = new Encodings.BinaryVectorEncoding.UniformCrossover();
839      binXo.ChildParameter.ActualName = paramName;
840      binXo.ParentsParameter.ActualName = paramName;
841      return binXo;
842    }
843
844    protected virtual IBinaryVectorManipulator GetDefaultBinaryManipulator(string paramName, MultiEncoding config) {
845      var binM = new Encodings.BinaryVectorEncoding.SomePositionsBitflipManipulator();
846      binM.BinaryVectorParameter.ActualName = paramName;
847      binM.MutationProbabilityParameter.Value = new DoubleValue(0.1);
848      return binM;
849    }
850
851    protected virtual IIntegerVectorCrossover GetDefaultIntegerCrossover(string paramName, MultiEncoding config) {
852      var intXo = new Encodings.IntegerVectorEncoding.RoundedBlendAlphaBetaCrossover();
853      intXo.ChildParameter.ActualName = paramName;
854      intXo.ParentsParameter.ActualName = paramName;
855      intXo.BoundsParameter.ActualName = paramName + "Bounds";
856      intXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
857      intXo.MaximizationParameter.ActualName = MaximizationParameter.Name;
858      return intXo;
859    }
860
861    protected virtual IIntegerVectorManipulator GetDefaultIntegerManipulator(string paramName, MultiEncoding configuration) {
862      var intM = new Encodings.IntegerVectorEncoding.UniformSomePositionsManipulator();
863      intM.IntegerVectorParameter.ActualName = paramName;
864      intM.BoundsParameter.ActualName = paramName + "Bounds";
865      intM.ProbabilityParameter.Value = new DoubleValue(0.1);
866      return intM;
867    }
868
869    protected virtual IRealVectorCrossover GetDefaultRealCrossover(string paramName, MultiEncoding configuration) {
870      var realXo = new Encodings.RealVectorEncoding.BlendAlphaBetaCrossover();
871      realXo.ChildParameter.ActualName = paramName;
872      realXo.ParentsParameter.ActualName = paramName;
873      realXo.BoundsParameter.ActualName = paramName + "Bounds";
874      realXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
875      realXo.MaximizationParameter.ActualName = MaximizationParameter.Name;
876      return realXo;
877    }
878
879    protected virtual IRealVectorManipulator GetDefaultRealManipulator(string paramName, MultiEncoding configuration) {
880      var realM = new Encodings.RealVectorEncoding.BreederGeneticAlgorithmManipulator();
881      realM.RealVectorParameter.ActualName = paramName;
882      realM.BoundsParameter.ActualName = paramName + "Bounds";
883      return realM;
884    }
885
886    protected virtual IPermutationCrossover GetDefaultPermutationCrossover(string paramName, MultiEncoding configuration) {
887      var permXo = new Encodings.PermutationEncoding.PartiallyMatchedCrossover();
888      permXo.ChildParameter.ActualName = paramName;
889      permXo.ParentsParameter.ActualName = paramName;
890      return permXo;
891    }
892
893    protected virtual IPermutationManipulator GetDefaultPermutationManipulator(string paramName, MultiEncoding configuration) {
894      var permM = new Encodings.PermutationEncoding.Swap2Manipulator();
895      permM.PermutationParameter.ActualName = paramName;
896      return permM;
897    }
898    // ReSharper restore RedundantNameQualifier
899    #endregion
900  }
901}
Note: See TracBrowser for help on using the repository browser.