Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/15/14 15:06:57 (11 years ago)
Author:
abeham
Message:

#2174: Worked on programmable problem

  • Changed ProblemBase to IProblemDefinition and SingleObjectiveProblemBase to ISingleObjectiveProblemDefinition
  • Derived ParameterVectorCreater, -Crossover, and -Manipulator from MultiOperator<> instead of InstrumentedOperator
  • Split the megamoth ScriptOnInstanceChanged to multiple methods dealing with single-vector and multi-vector encodings separately, it's still a lot of tedious code
  • Removed maximization from Configuration again (would not be consistent with multi-objective problems)
Location:
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3
Files:
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/BinaryParameterConfiguration.cs

    r10850 r10856  
    4646      length = cloner.Clone(original.length);
    4747    }
    48     public BinaryParameterConfiguration(int length)
    49       : base() {
     48    public BinaryParameterConfiguration(int length) {
    5049      this.length = new IntValue(length);
    5150    }
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/Configuration.cs

    r10855 r10856  
    3434    public Dictionary<string, ParameterConfiguration> Parameters { get; protected set; }
    3535
    36     [Storable]
    37     public bool Maximization { get; protected set; }
    38 
    3936    [StorableConstructor]
    4037    protected Configuration(bool deserializing) : base(deserializing) { }
     
    4744        }
    4845      }
    49       Maximization = original.Maximization;
    5046    }
    5147    public Configuration() {
     
    8884    }
    8985
    90     public Configuration AddPermutation(string name, PermutationTypes type, int length) {
     86    public Configuration AddPermutation(string name, int length, PermutationTypes type) {
    9187      if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name");
    9288      Parameters.Add(name, new PermutationParameterConfiguration(length, type));
    9389      return this;
    9490    }
    95 
    96     public Configuration SetMaximization(bool maximization) {
    97       Maximization = maximization;
    98       return this;
    99     }
    10091  }
    10192}
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/IntegerParameterConfiguration.cs

    r10850 r10856  
    6161      bounds = cloner.Clone(original.bounds);
    6262    }
    63     public IntegerParameterConfiguration(int length, int min, int max, int? step = null)
    64       : base() {
     63    public IntegerParameterConfiguration(int length, int min, int max, int? step = null) {
    6564      if (min >= max) throw new ArgumentException("min must be less than max", "min");
    6665      if (step.HasValue && step.Value <= 0) throw new ArgumentException("step must be greater than zero or null", "step");
     
    7170      if (step.HasValue) bounds[0, 2] = step.Value;
    7271    }
    73     public IntegerParameterConfiguration(int length, IList<int> min, IList<int> max, IList<int> step = null)
    74       : base() {
     72    public IntegerParameterConfiguration(int length, IList<int> min, IList<int> max, IList<int> step = null) {
    7573      if (min.Count == 0) throw new ArgumentException("Bounds must be given for the integer parameters.");
    7674      if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min");
    7775      if (step != null && min.Count != step.Count) throw new ArgumentException("step must be of the same length as min or null", "step");
    78       if (min.Zip(max, (m, M) => m >= M).Any()) throw new ArgumentException("min must be less than max in each dimension", "min");
     76      if (min.Zip(max, (mi, ma) => mi >= ma).Any()) throw new ArgumentException("min must be less than max in each dimension", "min");
    7977      this.length = new IntValue(length);
    8078      bounds = new IntMatrix(min.Count, step != null ? 3 : 2);
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/PermutationParameterConfiguration.cs

    r10850 r10856  
    5959      type = cloner.Clone(original.type);
    6060    }
    61     public PermutationParameterConfiguration(int length, PermutationTypes type)
    62       : base() {
     61    public PermutationParameterConfiguration(int length, PermutationTypes type) {
    6362      this.length = new IntValue(length);
    6463      this.type = new PermutationType(type);
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/RealParameterConfiguration.cs

    r10850 r10856  
    6161      bounds = cloner.Clone(original.bounds);
    6262    }
    63     public RealParameterConfiguration(int length, double min, double max)
    64       : base() {
     63    public RealParameterConfiguration(int length, double min, double max) {
    6564      if (min >= max) throw new ArgumentException("min must be less than max", "min");
    6665      this.length = new IntValue(length);
     
    6968      bounds[0, 1] = max;
    7069    }
    71     public RealParameterConfiguration(int length, IList<double> min, IList<double> max)
    72       : base() {
     70    public RealParameterConfiguration(int length, IList<double> min, IList<double> max) {
    7371      if (min.Count == 0) throw new ArgumentException("Bounds must be given for the real parameters.");
    7472      if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min");
    75       if (min.Zip(max, (m, M) => m >= M).Any()) throw new ArgumentException("min must be less than max in each dimension", "min");
     73      if (min.Zip(max, (mi, ma) => mi >= ma).Any()) throw new ArgumentException("min must be less than max in each dimension", "min");
    7674      this.length = new IntValue(length);
    7775      bounds = new DoubleMatrix(min.Count, 2);
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj

    r10850 r10856  
    148148    <Compile Include="Operators\SingleObjectiveEvaluator.cs" />
    149149    <Compile Include="Operators\ParameterVectorCreater.cs" />
    150     <Compile Include="ProblemBase.cs" />
    151     <Compile Include="SingleObjectiveProblemBase.cs" />
     150    <Compile Include="Interfaces\IProblemDefinition.cs" />
     151    <Compile Include="Interfaces\ISingleObjectiveProblemDefinition.cs" />
    152152    <Compile Include="ProgrammableProblemScript.cs" />
    153153    <Compile Include="SingleObjectiveScript.cs" />
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Interfaces/IProblemDefinition.cs

    r10855 r10856  
    2121
    2222namespace HeuristicLab.Problems.Programmable {
    23   public abstract class ProblemBase {
    24     public abstract Configuration GetConfiguration();
     23  public interface IProblemDefinition {
     24    Configuration GetConfiguration();
    2525  }
    2626}
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProblemDefinition.cs

    r10855 r10856  
    2323
    2424namespace HeuristicLab.Problems.Programmable {
    25   public abstract class SingleObjectiveProblemBase : ProblemBase {
    26     public abstract double Evaluate(IRandom random, ParameterVector vector);
     25  public interface ISingleObjectiveProblemDefinition : IProblemDefinition {
     26    bool IsMaximizationProblem { get; }
     27    double Evaluate(IRandom random, ParameterVector vector);
    2728  }
    2829}
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorCreater.cs

    r10850 r10856  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2930  [Item("ParameterVectorCreater", "Contains solution creators that together create a multi-vector encoding.")]
    3031  [StorableClass]
    31   public class ParameterVectorCreater : InstrumentedOperator, ISolutionCreator {
     32  public class ParameterVectorCreater : MultiOperator<ISolutionCreator>, ISolutionCreator {
    3233
    3334    [StorableConstructor]
     
    3940      return new ParameterVectorCreater(this, cloner);
    4041    }
     42
     43    public override IOperation InstrumentedApply() {
     44      var baseOperations = base.InstrumentedApply();
     45      return new OperationCollection(new[] { baseOperations }.Concat(Operators.Select(x => ExecutionContext.CreateOperation(x))));
     46    }
    4147  }
    4248}
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorCrossover.cs

    r10850 r10856  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2930  [Item("ParameterVector Crossover", "Applies different crossovers to cross a multi vector encoding.")]
    3031  [StorableClass]
    31   public class ParameterVectorCrossover : InstrumentedOperator, ICrossover {
     32  public class ParameterVectorCrossover : MultiOperator<ICrossover>, ICrossover {
    3233
    3334    [StorableConstructor]
     
    4142      return new ParameterVectorCrossover(this, cloner);
    4243    }
     44
     45    public override IOperation InstrumentedApply() {
     46      var baseOperations = base.InstrumentedApply();
     47      return new OperationCollection(new[] { baseOperations }.Concat(Operators.Select(x => ExecutionContext.CreateOperation(x))));
     48    }
    4349  }
    4450}
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorManipulator.cs

    r10850 r10856  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2930  [Item("ParameterVector Manipulator", "Applies different manipulators to change a multi vector encoding.")]
    3031  [StorableClass]
    31   public class ParameterVectorManipulator : InstrumentedOperator, IManipulator {
     32  public class ParameterVectorManipulator : MultiOperator<IManipulator>, IManipulator {
    3233
    3334    [StorableConstructor]
     
    4142      return new ParameterVectorManipulator(this, cloner);
    4243    }
     44
     45    public override IOperation InstrumentedApply() {
     46      var baseOperations = base.InstrumentedApply();
     47      return new OperationCollection(new[] { baseOperations }.Concat(Operators.Select(x => ExecutionContext.CreateOperation(x))));
     48    }
    4349  }
    4450}
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/ProgrammableProblemScript.cs

    r10754 r10856  
    4040    public ProgrammableProblemScript() { }
    4141
    42     private volatile ProblemBase instance;
     42    private volatile IProblemDefinition instance;
    4343    private object locker = new object();
    44     public ProblemBase Instance {
     44    public IProblemDefinition Instance {
    4545      get {
    4646        SuppressEvents = true;
     
    7373      var types = assembly.GetTypes();
    7474      try {
    75         Instance = (ProblemBase)Activator.CreateInstance(types.First(x => typeof(ProblemBase).IsAssignableFrom(x)));
     75        Instance = (IProblemDefinition)Activator.CreateInstance(types.First(x => typeof(IProblemDefinition).IsAssignableFrom(x)));
    7676      } catch {
    7777        Instance = null;
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r10855 r10856  
    4545
    4646    public static new Image StaticItemImage {
    47       get { return HeuristicLab.Common.Resources.VSImageLibrary.Script; }
     47      get { return Common.Resources.VSImageLibrary.Script; }
    4848    }
    4949
     
    7676    public SingleObjectiveProgrammableProblem()
    7777      : base(new SingleObjectiveEvaluator(), new ParameterVectorCreater()) {
    78       Parameters.Add(new ValueParameter<SingleObjectiveScript>("Script", "Defines the problem.", new SingleObjectiveScript() { Name = ItemName }));
     78      Parameters.Add(new ValueParameter<SingleObjectiveScript>("Script", "Defines the problem.", new SingleObjectiveScript() { Name = Name }));
    7979      Parameters.Add(new ValueParameter<Configuration>("Configuration", "Describes which parameters exist, what they're called, what type they are and their bounds if any."));
    8080
     
    9393
    9494    [StorableHook(HookType.AfterDeserialization)]
     95    // ReSharper disable UnusedMember.Local
    9596    private void AfterDeserialization() {
    9697      RegisterEventHandlers();
    9798    }
     99    // ReSharper restore UnusedMember.Local
    98100
    99101    private void RegisterEventHandlers() {
     
    113115    private void ScriptOnNameChanged(object sender, EventArgs eventArgs) {
    114116      if (sender != ScriptParameter.Value) return;
    115       if (Name != ScriptParameter.Value.Name)
    116         Name = ScriptParameter.Value.Name;
     117      Name = ScriptParameter.Value.Name;
    117118    }
    118119
    119120    protected override void OnNameChanged() {
    120121      base.OnNameChanged();
    121       if (ScriptParameter.Value.Name != Name)
    122         ScriptParameter.Value.Name = Name;
     122      ScriptParameter.Value.Name = Name;
    123123    }
    124124
    125125    protected virtual void ScriptOnInstanceChanged(object sender, EventArgs eventArgs) {
    126 
    127126      var instance = ScriptParameter.Value.Instance;
    128127      if (instance == null) return;
     
    130129      var configuration = instance.GetConfiguration();
    131130      ConfigurationParameter.Value = configuration;
    132       Maximization.Value = configuration.Maximization;
    133 
     131      Maximization.Value = instance.IsMaximizationProblem;
     132
     133      var solutionCreators = UpdateDynamicConfigurationParameters(configuration);
     134
     135      if (solutionCreators.Count == 1) {
     136        UpdateSingleVectorEncodingOperators(solutionCreators);
     137      } else {
     138        UpdateMultiVectorEncodingOperators(solutionCreators, configuration);
     139      }
     140    }
     141
     142    protected virtual List<ISolutionCreator> UpdateDynamicConfigurationParameters(Configuration configuration) {
    134143      foreach (var param in DynamicConfigurationParameters)
    135144        if (Parameters.Contains(param)) Parameters.Remove(param);
     
    138147      var solutionCreators = new List<ISolutionCreator>();
    139148      foreach (var param in configuration.Parameters) {
     149        /*
     150         * Binary Vectors
     151         */
    140152        var binConfig = param.Value as BinaryParameterConfiguration;
    141153        if (binConfig != null) {
     
    148160          solutionCreators.Add(creator);
    149161        }
     162        /*
     163         * Integer Vectors
     164         */
    150165        var intConfig = param.Value as IntegerParameterConfiguration;
    151166        if (intConfig != null) {
     
    161176          solutionCreators.Add(creator);
    162177        }
     178        /*
     179         * Real Vectors
     180         */
    163181        var realConfig = param.Value as RealParameterConfiguration;
    164182        if (realConfig != null) {
     
    174192          solutionCreators.Add(creator);
    175193        }
     194        /*
     195         * Permutations
     196         */
    176197        var permConfig = param.Value as PermutationParameterConfiguration;
    177198        if (permConfig != null) {
     
    191212        Parameters.Add(param);
    192213      }
    193 
    194       // use specialized creators if the configuration consists only of a single parameter type
    195       // this allows to use specialized algorithms such as CMA-ES
    196       if (solutionCreators.Count == 1) { // single-vector encoding
     214      return solutionCreators;
     215    }
     216
     217    protected virtual void UpdateSingleVectorEncodingOperators(List<ISolutionCreator> solutionCreators) {
     218      var newCreator = solutionCreators.Single();
     219      var binCreator = newCreator as IBinaryVectorCreator;
     220      if (binCreator != null) {
     221        var paramName = binCreator.BinaryVectorParameter.ActualName;
     222        // do not replace a binary vector creator that was manually set
     223        if (!(SolutionCreator is IBinaryVectorCreator) || ((IBinaryVectorCreator)SolutionCreator).BinaryVectorParameter.ActualName != paramName) {
     224          Operators.Remove(SolutionCreator);
     225          SolutionCreator = newCreator;
     226          Operators.Add(SolutionCreator);
     227        }
     228        Operators.RemoveAll(x => x is ICrossover && !(x is IBinaryVectorCrossover) || x is IBinaryVectorCrossover && ((IBinaryVectorCrossover)x).ChildParameter.ActualName != paramName);
     229        Operators.RemoveAll(x => x is IManipulator && !(x is IBinaryVectorManipulator) || x is IBinaryVectorManipulator && ((IBinaryVectorManipulator)x).BinaryVectorParameter.ActualName != paramName);
     230        var crossovers = ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>().ToList();
     231        var manipulators = ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>().ToList();
     232        foreach (var xo in crossovers) {
     233          xo.ChildParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
     234          xo.ParentsParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
     235        }
     236        foreach (var m in manipulators)
     237          m.BinaryVectorParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
     238        Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));
     239        Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
     240      }
     241      var intCreator = newCreator as IIntegerVectorCreator;
     242      if (intCreator != null) {
     243        var paramName = intCreator.IntegerVectorParameter.ActualName;
     244        // do not replace an integer vector creator that was manually set
     245        if (!(SolutionCreator is IIntegerVectorCreator)
     246          || ((IIntegerVectorCreator)SolutionCreator).IntegerVectorParameter.ActualName != intCreator.IntegerVectorParameter.ActualName) {
     247          Operators.Remove(SolutionCreator);
     248          SolutionCreator = newCreator;
     249          Operators.Add(SolutionCreator);
     250        }
     251        Operators.RemoveAll(x => x is ICrossover && !(x is IIntegerVectorCrossover) || x is IIntegerVectorCrossover && ((IIntegerVectorCrossover)x).ChildParameter.ActualName != paramName);
     252        Operators.RemoveAll(x => x is IManipulator && !(x is IIntegerVectorManipulator) || x is IIntegerVectorManipulator && ((IIntegerVectorManipulator)x).IntegerVectorParameter.ActualName != paramName);
     253        var crossovers = ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>().ToList();
     254        var manipulators = ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>().ToList();
     255        foreach (var xo in crossovers) {
     256          xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
     257          xo.ParentsParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
     258        }
     259        foreach (var m in manipulators)
     260          m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
     261        foreach (var bo in crossovers.OfType<IBoundedIntegerVectorOperator>()
     262              .Concat(manipulators.OfType<IBoundedIntegerVectorOperator>())
     263              .ToList()) {
     264          bo.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName;
     265        }
     266        Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));
     267        Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
     268      }
     269      var realCreator = newCreator as IRealVectorCreator;
     270      if (realCreator != null) {
     271        var paramName = realCreator.RealVectorParameter.ActualName;
     272        // do not replace a real vector creator that was manually set
     273        if (!(SolutionCreator is IRealVectorCreator)
     274            || ((IRealVectorCreator)SolutionCreator).RealVectorParameter.ActualName != realCreator.RealVectorParameter.ActualName) {
     275          Operators.Remove(SolutionCreator);
     276          SolutionCreator = newCreator;
     277          Operators.Add(SolutionCreator);
     278        }
     279        Operators.RemoveAll(x => x is ICrossover && !(x is IRealVectorCrossover) || x is IRealVectorCrossover && ((IRealVectorCrossover)x).ChildParameter.ActualName != paramName);
     280        Operators.RemoveAll(x => x is IManipulator && !(x is IRealVectorManipulator) || x is IRealVectorManipulator && ((IRealVectorManipulator)x).RealVectorParameter.ActualName != paramName);
     281        var crossovers = ApplicationManager.Manager.GetInstances<IRealVectorCrossover>().ToList();
     282        var manipulators = ApplicationManager.Manager.GetInstances<IRealVectorManipulator>().ToList();
     283        foreach (var xo in crossovers) {
     284          xo.ChildParameter.ActualName = realCreator.RealVectorParameter.ActualName;
     285          xo.ParentsParameter.ActualName = realCreator.RealVectorParameter.ActualName;
     286          xo.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
     287        }
     288        foreach (var m in manipulators) {
     289          m.RealVectorParameter.ActualName = realCreator.RealVectorParameter.ActualName;
     290          m.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
     291        }
     292        Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));
     293        Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
     294      }
     295      var permCreator = newCreator as IPermutationCreator;
     296      if (permCreator != null) {
     297        var paramName = permCreator.PermutationParameter.ActualName;
     298        // do not replace a permutation creator that was manually set
     299        if (!(SolutionCreator is IPermutationCreator)
     300            || ((IPermutationCreator)SolutionCreator).PermutationParameter.ActualName != permCreator.PermutationParameter.ActualName) {
     301          Operators.Remove(SolutionCreator);
     302          SolutionCreator = newCreator;
     303          Operators.Add(SolutionCreator);
     304        }
     305        Operators.RemoveAll(x => x is ICrossover && !(x is IPermutationCrossover) || x is IPermutationCrossover && ((IPermutationCrossover)x).ChildParameter.ActualName != paramName);
     306        Operators.RemoveAll(x => x is IManipulator && !(x is IPermutationManipulator) || x is IPermutationManipulator && ((IPermutationManipulator)x).PermutationParameter.ActualName != paramName);
     307        var crossovers = ApplicationManager.Manager.GetInstances<IPermutationCrossover>().ToList();
     308        var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList();
     309        foreach (var xo in crossovers) {
     310          xo.ChildParameter.ActualName = permCreator.PermutationParameter.ActualName;
     311          xo.ParentsParameter.ActualName = permCreator.PermutationParameter.ActualName;
     312        }
     313        foreach (var m in manipulators)
     314          m.PermutationParameter.ActualName = permCreator.PermutationParameter.ActualName;
     315        Operators.AddRange(crossovers.Where(x => Operators.All(y => x.GetType() != y.GetType())));
     316        Operators.AddRange(manipulators.Where(x => Operators.All(y => x.GetType() != y.GetType())));
     317      }
     318    }
     319
     320    protected virtual void UpdateMultiVectorEncodingOperators(List<ISolutionCreator> solutionCreators, Configuration configuration) {
     321      var oldCreator = SolutionCreator as ParameterVectorCreater;
     322      var newCreator = new ParameterVectorCreater();
     323
     324      /*
     325       * Binary Vectors
     326       */
     327      var newBinParams = new HashSet<string>(solutionCreators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName));
     328      if (oldCreator != null) {
     329        // we want to reuse the old creator
     330        var oldParams = new HashSet<string>(oldCreator.Operators.OfType<IBinaryVectorCreator>()
     331          .Select(x => x.BinaryVectorParameter.ActualName));
     332        foreach (var toAdd in newBinParams.Except(oldParams)) {
     333          var paramName = toAdd;
     334          oldCreator.Operators.Add(
     335            solutionCreators.OfType<IBinaryVectorCreator>().Single(x => x.BinaryVectorParameter.ActualName == paramName));
     336        }
     337        foreach (var toRemove in oldParams.Except(newBinParams)) {
     338          var paramName = toRemove;
     339          var op =
     340            oldCreator.Operators.OfType<IBinaryVectorCreator>()
     341              .SingleOrDefault(x => x.BinaryVectorParameter.ActualName == paramName);
     342          if (op != null) oldCreator.Operators.Remove(op);
     343        }
     344      } else {
     345        // we will use the new creator
     346        foreach (var binCreator in solutionCreators.OfType<IBinaryVectorCreator>()) {
     347          newCreator.Operators.Add(binCreator);
     348        }
     349      }
     350
     351      /*
     352       * Integer Vectors
     353       */
     354      var newIntParams = new HashSet<string>(solutionCreators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName));
     355      if (oldCreator != null) {
     356        // we want to reuse the old creator
     357        var oldParams = new HashSet<string>(oldCreator
     358          .Operators.OfType<IIntegerVectorCreator>()
     359          .Select(x => x.IntegerVectorParameter.ActualName));
     360        foreach (var toAdd in newIntParams.Except(oldParams)) {
     361          var paramName = toAdd;
     362          oldCreator.Operators.Add(
     363            solutionCreators.OfType<IIntegerVectorCreator>().Single(x => x.IntegerVectorParameter.ActualName == paramName));
     364        }
     365        foreach (var toRemove in oldParams.Except(newIntParams)) {
     366          var paramName = toRemove;
     367          var op =
     368            oldCreator.Operators.OfType<IIntegerVectorCreator>()
     369              .SingleOrDefault(x => x.IntegerVectorParameter.ActualName == paramName);
     370          if (op != null) oldCreator.Operators.Remove(op);
     371        }
     372      } else {
     373        // we will use the new creator
     374        foreach (var intCreator in solutionCreators.OfType<IIntegerVectorCreator>()) {
     375          newCreator.Operators.Add(intCreator);
     376        }
     377      }
     378
     379      /*
     380       * Real Vectors
     381       */
     382      var newRealParams = new HashSet<string>(solutionCreators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName));
     383      if (oldCreator != null) {
     384        // we want to reuse the old creator
     385        var oldParams = new HashSet<string>(oldCreator
     386          .Operators.OfType<IRealVectorCreator>()
     387          .Select(x => x.RealVectorParameter.ActualName));
     388        foreach (var toAdd in newRealParams.Except(oldParams)) {
     389          var paramName = toAdd;
     390          oldCreator.Operators.Add(
     391            solutionCreators.OfType<IRealVectorCreator>().Single(x => x.RealVectorParameter.ActualName == paramName));
     392        }
     393        foreach (var toRemove in oldParams.Except(newRealParams)) {
     394          var paramName = toRemove;
     395          var op =
     396            oldCreator.Operators.OfType<IRealVectorCreator>()
     397              .SingleOrDefault(x => x.RealVectorParameter.ActualName == paramName);
     398          if (op != null) oldCreator.Operators.Remove(op);
     399        }
     400      } else {
     401        // we will use the new creator
     402        foreach (var realCreator in solutionCreators.OfType<IRealVectorCreator>()) {
     403          newCreator.Operators.Add(realCreator);
     404        }
     405      }
     406
     407      /*
     408       * Permutations
     409       */
     410      var newPermParams = new HashSet<string>(solutionCreators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName));
     411      if (oldCreator != null) {
     412        // we want to reuse the old creator
     413        var oldParams = new HashSet<string>(oldCreator
     414          .Operators.OfType<IPermutationCreator>()
     415          .Select(x => x.PermutationParameter.ActualName));
     416        foreach (var toAdd in newPermParams.Except(oldParams)) {
     417          var paramName = toAdd;
     418          oldCreator.Operators.Add(
     419            solutionCreators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == paramName));
     420        }
     421        foreach (var toRemove in oldParams.Except(newPermParams)) {
     422          var paramName = toRemove;
     423          var op =
     424            oldCreator.Operators.OfType<IPermutationCreator>()
     425              .SingleOrDefault(x => x.PermutationParameter.ActualName == paramName);
     426          if (op != null) oldCreator.Operators.Remove(op);
     427        }
     428        // we also have to sync the permutation type (in case this changes, as it is a value parameter)
     429        foreach (var intersect in newPermParams.Intersect(oldParams)) {
     430          var paramName = intersect;
     431          var oldPermCreator = oldCreator.Operators.OfType<IPermutationCreator>()
     432            .Single(x => x.PermutationParameter.ActualName == paramName);
     433          var newPermCreator = solutionCreators.OfType<IPermutationCreator>()
     434            .Single(x => x.PermutationParameter.ActualName == paramName);
     435          oldPermCreator.PermutationTypeParameter.Value = newPermCreator.PermutationTypeParameter.Value;
     436        }
     437      } else {
     438        // we will use the new creator
     439        foreach (var permCreator in solutionCreators.OfType<IPermutationCreator>()) {
     440          newCreator.Operators.Add(permCreator);
     441        }
     442      }
     443
     444      if (oldCreator == null) SolutionCreator = newCreator;
     445
     446      // crossover and manipulator for multi-vector encoding
     447      // the condition checks if a multi-vector encoding is to be updated (there already exists ParameterVectorCrossover and ParameterVectorManipulator)
     448      if (Operators.OfType<ParameterVectorCrossover>().Any() && Operators.OfType<ParameterVectorManipulator>().Any()) {
     449        // Update the crossovers
     450        foreach (var oldXo in Operators.OfType<ParameterVectorCrossover>()) {
     451          /*
     452           * Binary Vectors
     453           */
     454          var oldBinParams = new HashSet<string>(oldXo.Operators.OfType<IBinaryVectorCrossover>()
     455            .Select(x => x.ChildParameter.ActualName));
     456          foreach (var toAdd in newBinParams.Except(oldBinParams))
     457            oldXo.Operators.Add(GetDefaultBinaryCrossover(toAdd, configuration));
     458          foreach (var toRemove in oldBinParams.Except(newBinParams)) {
     459            var op =
     460              oldXo.Operators.OfType<IBinaryVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
     461            if (op != null) oldXo.Operators.Remove(op);
     462          }
     463
     464          /*
     465           * Integer Vectors
     466           */
     467          var oldIntParams = new HashSet<string>(oldXo.Operators.OfType<IIntegerVectorCrossover>()
     468            .Select(x => x.ChildParameter.ActualName));
     469          foreach (var toAdd in newIntParams.Except(oldIntParams))
     470            oldXo.Operators.Add(GetDefaultIntegerCrossover(toAdd, configuration));
     471          foreach (var toRemove in oldIntParams.Except(newIntParams)) {
     472            var op =
     473              oldXo.Operators.OfType<IIntegerVectorCrossover>()
     474                .SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
     475            if (op != null) oldXo.Operators.Remove(op);
     476          }
     477
     478          /*
     479           * Real Vectors
     480           */
     481          var oldRealParams = new HashSet<string>(oldXo.Operators.OfType<IRealVectorCrossover>()
     482            .Select(x => x.ChildParameter.ActualName));
     483          foreach (var toAdd in newRealParams.Except(oldRealParams))
     484            oldXo.Operators.Add(GetDefaultRealCrossover(toAdd, configuration));
     485          foreach (var toRemove in oldRealParams.Except(newRealParams)) {
     486            var op =
     487              oldXo.Operators.OfType<IRealVectorCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
     488            if (op != null) oldXo.Operators.Remove(op);
     489          }
     490
     491          /*
     492           * Permutations
     493           */
     494          var oldPermParams = new HashSet<string>(oldXo.Operators.OfType<IPermutationCrossover>()
     495            .Select(x => x.ChildParameter.ActualName));
     496          foreach (var toAdd in newPermParams.Except(oldPermParams))
     497            oldXo.Operators.Add(GetDefaultPermutationCrossover(toAdd, configuration));
     498          foreach (var toRemove in oldPermParams.Except(newPermParams)) {
     499            var op =
     500              oldXo.Operators.OfType<IPermutationCrossover>().SingleOrDefault(x => x.ChildParameter.ActualName == toRemove);
     501            if (op != null) oldXo.Operators.Remove(op);
     502          }
     503        }
     504        // Update the manipulators
     505        foreach (var oldM in Operators.OfType<ParameterVectorManipulator>()) {
     506          /*
     507           * Binary Vectors
     508           */
     509          var oldBinParams = new HashSet<string>(oldM.Operators.OfType<IBinaryVectorManipulator>()
     510            .Select(x => x.BinaryVectorParameter.ActualName));
     511          foreach (var toAdd in newBinParams.Except(oldBinParams))
     512            oldM.Operators.Add(GetDefaultBinaryManipulator(toAdd, configuration));
     513          foreach (var toRemove in oldBinParams.Except(newBinParams)) {
     514            var op =
     515              oldM.Operators.OfType<IBinaryVectorManipulator>()
     516                .SingleOrDefault(x => x.BinaryVectorParameter.ActualName == toRemove);
     517            if (op != null) oldM.Operators.Remove(op);
     518          }
     519
     520          /*
     521           * Integer Vectors
     522           */
     523          var oldIntParams = new HashSet<string>(oldM.Operators.OfType<IIntegerVectorManipulator>()
     524            .Select(x => x.IntegerVectorParameter.ActualName));
     525          foreach (var toAdd in newIntParams.Except(oldIntParams))
     526            oldM.Operators.Add(GetDefaultIntegerManipulator(toAdd, configuration));
     527          foreach (var toRemove in oldIntParams.Except(newIntParams)) {
     528            var op =
     529              oldM.Operators.OfType<IIntegerVectorManipulator>()
     530                .SingleOrDefault(x => x.IntegerVectorParameter.ActualName == toRemove);
     531            if (op != null) oldM.Operators.Remove(op);
     532          }
     533
     534          /*
     535           * Real Vectors
     536           */
     537          var oldRealParams = new HashSet<string>(oldM.Operators.OfType<IRealVectorManipulator>()
     538            .Select(x => x.RealVectorParameter.ActualName));
     539          foreach (var toAdd in newRealParams.Except(oldRealParams))
     540            oldM.Operators.Add(GetDefaultRealManipulator(toAdd, configuration));
     541          foreach (var toRemove in oldRealParams.Except(newRealParams)) {
     542            var op =
     543              oldM.Operators.OfType<IRealVectorManipulator>()
     544                .SingleOrDefault(x => x.RealVectorParameter.ActualName == toRemove);
     545            if (op != null) oldM.Operators.Remove(op);
     546          }
     547
     548          /*
     549           * Permutations
     550           */
     551          var oldPermParams = new HashSet<string>(oldM.Operators.OfType<IPermutationManipulator>()
     552            .Select(x => x.PermutationParameter.ActualName));
     553          foreach (var toAdd in newPermParams.Except(oldPermParams))
     554            oldM.Operators.Add(GetDefaultPermutationManipulator(toAdd, configuration));
     555          foreach (var toRemove in oldPermParams.Except(newPermParams)) {
     556            var op =
     557              oldM.Operators.OfType<IPermutationManipulator>()
     558                .SingleOrDefault(x => x.PermutationParameter.ActualName == toRemove);
     559            if (op != null) oldM.Operators.Remove(op);
     560          }
     561        }
     562      } else {
     563        // change from single-vector encoding to multi-vector encoding
    197564        Operators.RemoveAll(x => x is ICrossover);
    198565        Operators.RemoveAll(x => x is IManipulator);
    199         var newCreator = solutionCreators.Single();
    200         var binCreator = newCreator as IBinaryVectorCreator;
    201         if (binCreator != null) {
    202           // do not replace a binary vector creator that was manually set
    203           if (!(SolutionCreator is IBinaryVectorCreator)
    204               || ((IBinaryVectorCreator)SolutionCreator).BinaryVectorParameter.ActualName != binCreator.BinaryVectorParameter.ActualName) {
    205             Operators.Remove(SolutionCreator);
    206             SolutionCreator = newCreator;
    207             Operators.Add(SolutionCreator);
    208           }
    209           var crossovers = ApplicationManager.Manager.GetInstances<IBinaryVectorCrossover>().ToList();
    210           var manipulators = ApplicationManager.Manager.GetInstances<IBinaryVectorManipulator>().ToList();
    211           foreach (var xo in crossovers) {
    212             xo.ChildParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
    213             xo.ParentsParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
    214           }
    215           foreach (var m in manipulators)
    216             m.BinaryVectorParameter.ActualName = binCreator.BinaryVectorParameter.ActualName;
    217           Operators.AddRange(crossovers);
    218           Operators.AddRange(manipulators);
    219         }
    220         var intCreator = newCreator as IIntegerVectorCreator;
    221         if (intCreator != null) {
    222           // do not replace an integer vector creator that was manually set
    223           if (!(SolutionCreator is IIntegerVectorCreator)
    224               || ((IIntegerVectorCreator)SolutionCreator).IntegerVectorParameter.ActualName != intCreator.IntegerVectorParameter.ActualName) {
    225             Operators.Remove(SolutionCreator);
    226             SolutionCreator = newCreator;
    227             Operators.Add(SolutionCreator);
    228           }
    229           var crossovers = ApplicationManager.Manager.GetInstances<IIntegerVectorCrossover>().ToList();
    230           var manipulators = ApplicationManager.Manager.GetInstances<IIntegerVectorManipulator>().ToList();
    231           foreach (var xo in crossovers) {
    232             xo.ChildParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
    233             xo.ParentsParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
    234           }
    235           foreach (var m in manipulators)
    236             m.IntegerVectorParameter.ActualName = intCreator.IntegerVectorParameter.ActualName;
    237           foreach (var bo in crossovers.OfType<IBoundedIntegerVectorOperator>().Concat(manipulators.OfType<IBoundedIntegerVectorOperator>()).ToList()) {
    238             bo.BoundsParameter.ActualName = intCreator.BoundsParameter.ActualName;
    239           }
    240           Operators.AddRange(crossovers);
    241           Operators.AddRange(manipulators);
    242         }
    243         var realCreator = newCreator as IRealVectorCreator;
    244         if (realCreator != null) {
    245           // do not replace a real vector creator that was manually set
    246           if (!(SolutionCreator is IRealVectorCreator)
    247               || ((IRealVectorCreator)SolutionCreator).RealVectorParameter.ActualName != realCreator.RealVectorParameter.ActualName) {
    248             Operators.Remove(SolutionCreator);
    249             SolutionCreator = newCreator;
    250             Operators.Add(SolutionCreator);
    251           }
    252           var crossovers = ApplicationManager.Manager.GetInstances<IRealVectorCrossover>().ToList();
    253           var manipulators = ApplicationManager.Manager.GetInstances<IRealVectorManipulator>().ToList();
    254           foreach (var xo in crossovers) {
    255             xo.ChildParameter.ActualName = realCreator.RealVectorParameter.ActualName;
    256             xo.ParentsParameter.ActualName = realCreator.RealVectorParameter.ActualName;
    257             xo.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
    258           }
    259           foreach (var m in manipulators) {
    260             m.RealVectorParameter.ActualName = realCreator.RealVectorParameter.ActualName;
    261             m.BoundsParameter.ActualName = realCreator.BoundsParameter.ActualName;
    262           }
    263           Operators.AddRange(crossovers);
    264           Operators.AddRange(manipulators);
    265         }
    266         var permCreator = newCreator as IPermutationCreator;
    267         if (permCreator != null) {
    268           // do not replace a permutation creator that was manually set
    269           if (!(SolutionCreator is IPermutationCreator)
    270               || ((IPermutationCreator)SolutionCreator).PermutationParameter.ActualName != permCreator.PermutationParameter.ActualName) {
    271             Operators.Remove(SolutionCreator);
    272             SolutionCreator = newCreator;
    273             Operators.Add(SolutionCreator);
    274           }
    275           var crossovers = ApplicationManager.Manager.GetInstances<IPermutationCrossover>().ToList();
    276           var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList();
    277           foreach (var xo in crossovers) {
    278             xo.ChildParameter.ActualName = permCreator.PermutationParameter.ActualName;
    279             xo.ParentsParameter.ActualName = permCreator.PermutationParameter.ActualName;
    280           }
    281           foreach (var m in manipulators)
    282             m.PermutationParameter.ActualName = permCreator.PermutationParameter.ActualName;
    283           Operators.AddRange(crossovers);
    284           Operators.AddRange(manipulators);
    285         }
    286       } else { // multi-vector encoding
    287         var oldCreator = SolutionCreator as ParameterVectorCreater;
    288         var newCreator = new ParameterVectorCreater();
    289         var newBinParams = new HashSet<string>(solutionCreators.OfType<IBinaryVectorCreator>().Select(x => x.BinaryVectorParameter.ActualName));
    290         if (oldCreator != null) { // we want to reuse the old creator
    291           var oldParams = new HashSet<string>(oldCreator
    292             .BeforeExecutionOperators.OfType<IBinaryVectorCreator>()
    293             .Select(x => x.BinaryVectorParameter.ActualName));
    294           foreach (var toAdd in newBinParams.Except(oldParams)) {
    295             var paramName = toAdd;
    296             oldCreator.BeforeExecutionOperators.Add(solutionCreators.OfType<IBinaryVectorCreator>().Single(x => x.BinaryVectorParameter.ActualName == paramName));
    297           }
    298           foreach (var toRemove in oldParams.Except(newBinParams)) {
    299             var paramName = toRemove;
    300             oldCreator.BeforeExecutionOperators.RemoveAll(
    301               op => op is IBinaryVectorCreator && ((IBinaryVectorCreator)op).BinaryVectorParameter.ActualName == paramName);
    302           }
    303         } else { // we will use the new creator
    304           foreach (var binCreator in solutionCreators.OfType<IBinaryVectorCreator>()) {
    305             newCreator.BeforeExecutionOperators.Add(binCreator);
    306           }
    307         }
    308 
    309         var newIntParams = new HashSet<string>(solutionCreators.OfType<IIntegerVectorCreator>().Select(x => x.IntegerVectorParameter.ActualName));
    310         if (oldCreator != null) { // we want to reuse the old creator
    311           var oldParams = new HashSet<string>(oldCreator
    312             .BeforeExecutionOperators.OfType<IIntegerVectorCreator>()
    313             .Select(x => x.IntegerVectorParameter.ActualName));
    314           foreach (var toAdd in newIntParams.Except(oldParams)) {
    315             var paramName = toAdd;
    316             oldCreator.BeforeExecutionOperators.Add(solutionCreators.OfType<IIntegerVectorCreator>().Single(x => x.IntegerVectorParameter.ActualName == paramName));
    317           }
    318           foreach (var toRemove in oldParams.Except(newIntParams)) {
    319             var paramName = toRemove;
    320             oldCreator.BeforeExecutionOperators.RemoveAll(
    321               op => op is IIntegerVectorCreator && ((IIntegerVectorCreator)op).IntegerVectorParameter.ActualName == paramName);
    322           }
    323         } else { // we will use the new creator
    324           foreach (var intCreator in solutionCreators.OfType<IIntegerVectorCreator>()) {
    325             newCreator.BeforeExecutionOperators.Add(intCreator);
    326           }
    327         }
    328 
    329         var newRealParams = new HashSet<string>(solutionCreators.OfType<IRealVectorCreator>().Select(x => x.RealVectorParameter.ActualName));
    330         if (oldCreator != null) { // we want to reuse the old creator
    331           var oldParams = new HashSet<string>(oldCreator
    332             .BeforeExecutionOperators.OfType<IRealVectorCreator>()
    333             .Select(x => x.RealVectorParameter.ActualName));
    334           foreach (var toAdd in newRealParams.Except(oldParams)) {
    335             var paramName = toAdd;
    336             oldCreator.BeforeExecutionOperators.Add(solutionCreators.OfType<IRealVectorCreator>().Single(x => x.RealVectorParameter.ActualName == paramName));
    337           }
    338           foreach (var toRemove in oldParams.Except(newRealParams)) {
    339             var paramName = toRemove;
    340             oldCreator.BeforeExecutionOperators.RemoveAll(
    341               op => op is IRealVectorCreator && ((IRealVectorCreator)op).RealVectorParameter.ActualName == paramName);
    342           }
    343         } else { // we will use the new creator
    344           foreach (var realCreator in solutionCreators.OfType<IRealVectorCreator>()) {
    345             newCreator.BeforeExecutionOperators.Add(realCreator);
    346           }
    347         }
    348 
    349         var newPermParams = new HashSet<string>(solutionCreators.OfType<IPermutationCreator>().Select(x => x.PermutationParameter.ActualName));
    350         if (oldCreator != null) { // we want to reuse the old creator
    351           var oldParams = new HashSet<string>(oldCreator
    352             .BeforeExecutionOperators.OfType<IPermutationCreator>()
    353             .Select(x => x.PermutationParameter.ActualName));
    354           foreach (var toAdd in newPermParams.Except(oldParams)) {
    355             var paramName = toAdd;
    356             oldCreator.BeforeExecutionOperators.Add(solutionCreators.OfType<IPermutationCreator>().Single(x => x.PermutationParameter.ActualName == paramName));
    357           }
    358           foreach (var toRemove in oldParams.Except(newPermParams)) {
    359             var paramName = toRemove;
    360             oldCreator.BeforeExecutionOperators.RemoveAll(
    361               op => op is IPermutationCreator && ((IPermutationCreator)op).PermutationParameter.ActualName == paramName);
    362           }
    363           // we also have to sync the permutation type (in case this changes, as it is a value parameter)
    364           foreach (var intersect in newPermParams.Intersect(oldParams)) {
    365             var paramName = intersect;
    366             var oldPermCreator = oldCreator.BeforeExecutionOperators.OfType<IPermutationCreator>()
    367               .Single(x => x.PermutationParameter.ActualName == paramName);
    368             var newPermCreator = solutionCreators.OfType<IPermutationCreator>()
    369                 .Single(x => x.PermutationParameter.ActualName == paramName);
    370             oldPermCreator.PermutationTypeParameter.Value = newPermCreator.PermutationTypeParameter.Value;
    371           }
    372         } else { // we will use the new creator
    373           foreach (var permCreator in solutionCreators.OfType<IPermutationCreator>()) {
    374             newCreator.BeforeExecutionOperators.Add(permCreator);
    375           }
    376         }
    377 
    378         // crossover and manipulator for multi-vector encoding
    379         if (Operators.OfType<ParameterVectorCrossover>().Any()) {
    380           foreach (var oldXo in Operators.OfType<ParameterVectorCrossover>()) {
    381             // TODO: compare crossovers for old configuration with new configuration
    382           }
    383           foreach (var oldM in Operators.OfType<ParameterVectorManipulator>()) {
    384             // TODO: compare manipulators for old configuration with new configuration
    385           }
    386         } else {
    387           Operators.RemoveAll(x => x is ICrossover);
    388           Operators.RemoveAll(x => x is IManipulator);
    389           var crossover = new ParameterVectorCrossover();
    390           var manipulator = new ParameterVectorManipulator();
    391           foreach (var param in configuration.Parameters) {
    392             var binConfig = param.Value as BinaryParameterConfiguration;
    393             if (binConfig != null) {
    394               IBinaryVectorCrossover binXo;
    395               if (binConfig.Length.Value > 3) binXo = new Encodings.BinaryVectorEncoding.SinglePointCrossover();
    396               else binXo = new Encodings.BinaryVectorEncoding.UniformCrossover();
    397               binXo.ChildParameter.ActualName = param.Key;
    398               binXo.ParentsParameter.ActualName = param.Key;
    399               var binM = new Encodings.BinaryVectorEncoding.SomePositionsBitflipManipulator();
    400               binM.BinaryVectorParameter.ActualName = param.Key;
    401               binM.MutationProbabilityParameter.Value = new DoubleValue(0.1);
    402               crossover.BeforeExecutionOperators.Add(binXo);
    403               manipulator.BeforeExecutionOperators.Add(binM);
    404               continue;
    405             }
    406             var intConfig = param.Value as IntegerParameterConfiguration;
    407             if (intConfig != null) {
    408               var intXo = new Encodings.IntegerVectorEncoding.RoundedBlendAlphaBetaCrossover();
    409               intXo.ChildParameter.ActualName = param.Key;
    410               intXo.ParentsParameter.ActualName = param.Key;
    411               intXo.BoundsParameter.ActualName = param.Key + "Bounds";
    412               intXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    413               intXo.MaximizationParameter.ActualName = MaximizationParameter.Name;
    414               var intM = new Encodings.IntegerVectorEncoding.UniformSomePositionsManipulator();
    415               intM.IntegerVectorParameter.ActualName = param.Key;
    416               intM.BoundsParameter.ActualName = param.Key + "Bounds";
    417               intM.ProbabilityParameter.Value = new DoubleValue(0.1);
    418               crossover.BeforeExecutionOperators.Add(intXo);
    419               manipulator.BeforeExecutionOperators.Add(intM);
    420               continue;
    421             }
    422             var realConfig = param.Value as RealParameterConfiguration;
    423             if (realConfig != null) {
    424               var realXo = new Encodings.RealVectorEncoding.BlendAlphaBetaCrossover();
    425               realXo.ChildParameter.ActualName = param.Key;
    426               realXo.ParentsParameter.ActualName = param.Key;
    427               realXo.BoundsParameter.ActualName = param.Key + "Bounds";
    428               realXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    429               realXo.MaximizationParameter.ActualName = MaximizationParameter.Name;
    430               var realM = new Encodings.RealVectorEncoding.BreederGeneticAlgorithmManipulator();
    431               realM.RealVectorParameter.ActualName = param.Key;
    432               realM.BoundsParameter.ActualName = param.Key + "Bounds";
    433               crossover.BeforeExecutionOperators.Add(realXo);
    434               manipulator.BeforeExecutionOperators.Add(realM);
    435               continue;
    436             }
    437             var permConfig = param.Value as PermutationParameterConfiguration;
    438             if (permConfig != null) {
    439               var permXo = new Encodings.PermutationEncoding.PartiallyMatchedCrossover();
    440               permXo.ChildParameter.ActualName = param.Key;
    441               permXo.ParentsParameter.ActualName = param.Key;
    442               var permM = new Encodings.PermutationEncoding.Swap2Manipulator();
    443               permM.PermutationParameter.ActualName = param.Key;
    444               crossover.BeforeExecutionOperators.Add(permXo);
    445               manipulator.BeforeExecutionOperators.Add(permM);
    446               continue;
    447             }
    448             throw new InvalidOperationException("Unknown type for parameter " + param.Key);
    449           }
    450           Operators.Add(crossover);
    451           Operators.Add(manipulator);
    452         }
    453       }
    454     }
     566        var crossover = new ParameterVectorCrossover();
     567        var manipulator = new ParameterVectorManipulator();
     568        foreach (var param in configuration.Parameters) {
     569          if (param.Value is BinaryParameterConfiguration) {
     570            crossover.Operators.Add(GetDefaultBinaryCrossover(param.Key, configuration));
     571            manipulator.Operators.Add(GetDefaultBinaryManipulator(param.Key, configuration));
     572            continue;
     573          }
     574          var intConfig = param.Value as IntegerParameterConfiguration;
     575          if (intConfig != null) {
     576            crossover.Operators.Add(GetDefaultIntegerCrossover(param.Key, configuration));
     577            manipulator.Operators.Add(GetDefaultIntegerManipulator(param.Key, configuration));
     578            continue;
     579          }
     580          var realConfig = param.Value as RealParameterConfiguration;
     581          if (realConfig != null) {
     582            crossover.Operators.Add(GetDefaultRealCrossover(param.Key, configuration));
     583            manipulator.Operators.Add(GetDefaultRealManipulator(param.Key, configuration));
     584            continue;
     585          }
     586          var permConfig = param.Value as PermutationParameterConfiguration;
     587          if (permConfig != null) {
     588            crossover.Operators.Add(GetDefaultPermutationCrossover(param.Key, configuration));
     589            manipulator.Operators.Add(GetDefaultPermutationManipulator(param.Key, configuration));
     590            continue;
     591          }
     592          throw new InvalidOperationException("Unknown type for parameter " + param.Key);
     593        }
     594        Operators.Add(crossover);
     595        Operators.Add(manipulator);
     596      }
     597    }
     598
     599    // ReSharper disable RedundantNameQualifier
     600    protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, Configuration config) {
     601      var binConfig = (BinaryParameterConfiguration)config.Parameters[paramName];
     602      IBinaryVectorCrossover binXo;
     603      if (binConfig.Length.Value > 3) binXo = new Encodings.BinaryVectorEncoding.SinglePointCrossover();
     604      else binXo = new Encodings.BinaryVectorEncoding.UniformCrossover();
     605      binXo.ChildParameter.ActualName = paramName;
     606      binXo.ParentsParameter.ActualName = paramName;
     607      return binXo;
     608    }
     609
     610    protected virtual IBinaryVectorManipulator GetDefaultBinaryManipulator(string paramName, Configuration config) {
     611      var binM = new Encodings.BinaryVectorEncoding.SomePositionsBitflipManipulator();
     612      binM.BinaryVectorParameter.ActualName = paramName;
     613      binM.MutationProbabilityParameter.Value = new DoubleValue(0.1);
     614      return binM;
     615    }
     616
     617    protected virtual IIntegerVectorCrossover GetDefaultIntegerCrossover(string paramName, Configuration config) {
     618      var intXo = new Encodings.IntegerVectorEncoding.RoundedBlendAlphaBetaCrossover();
     619      intXo.ChildParameter.ActualName = paramName;
     620      intXo.ParentsParameter.ActualName = paramName;
     621      intXo.BoundsParameter.ActualName = paramName + "Bounds";
     622      intXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     623      intXo.MaximizationParameter.ActualName = MaximizationParameter.Name;
     624      return intXo;
     625    }
     626
     627    protected virtual IIntegerVectorManipulator GetDefaultIntegerManipulator(string paramName, Configuration configuration) {
     628      var intM = new Encodings.IntegerVectorEncoding.UniformSomePositionsManipulator();
     629      intM.IntegerVectorParameter.ActualName = paramName;
     630      intM.BoundsParameter.ActualName = paramName + "Bounds";
     631      intM.ProbabilityParameter.Value = new DoubleValue(0.1);
     632      return intM;
     633    }
     634
     635    protected virtual IRealVectorCrossover GetDefaultRealCrossover(string paramName, Configuration configuration) {
     636      var realXo = new Encodings.RealVectorEncoding.BlendAlphaBetaCrossover();
     637      realXo.ChildParameter.ActualName = paramName;
     638      realXo.ParentsParameter.ActualName = paramName;
     639      realXo.BoundsParameter.ActualName = paramName + "Bounds";
     640      realXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     641      realXo.MaximizationParameter.ActualName = MaximizationParameter.Name;
     642      return realXo;
     643    }
     644
     645    protected virtual IRealVectorManipulator GetDefaultRealManipulator(string paramName, Configuration configuration) {
     646      var realM = new Encodings.RealVectorEncoding.BreederGeneticAlgorithmManipulator();
     647      realM.RealVectorParameter.ActualName = paramName;
     648      realM.BoundsParameter.ActualName = paramName + "Bounds";
     649      return realM;
     650    }
     651
     652    protected virtual IPermutationCrossover GetDefaultPermutationCrossover(string paramName, Configuration configuration) {
     653      var permXo = new Encodings.PermutationEncoding.PartiallyMatchedCrossover();
     654      permXo.ChildParameter.ActualName = paramName;
     655      permXo.ParentsParameter.ActualName = paramName;
     656      return permXo;
     657    }
     658
     659    protected virtual IPermutationManipulator GetDefaultPermutationManipulator(string paramName, Configuration configuration) {
     660      var permM = new Encodings.PermutationEncoding.Swap2Manipulator();
     661      permM.PermutationParameter.ActualName = paramName;
     662      return permM;
     663    }
     664    // ReSharper restore RedundantNameQualifier
    455665  }
    456666}
  • branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveScript.cs

    r10850 r10856  
    4040    }
    4141
    42     public new SingleObjectiveProblemBase Instance {
    43       get { return (SingleObjectiveProblemBase)base.Instance; }
     42    public new ISingleObjectiveProblemDefinition Instance {
     43      get { return (ISingleObjectiveProblemDefinition)base.Instance; }
    4444      protected set { base.Instance = value; }
    4545    }
     
    5656using HeuristicLab.Problems.Programmable;
    5757
    58 public class MyProblem : HeuristicLab.Problems.Programmable.SingleObjectiveProblemBase {
    59   public MyProblem() {
     58public class ProblemDefinition : ISingleObjectiveProblemDefinition {
     59  public ProblemDefinition() {
    6060    // initialize private fields
    6161  }
    6262
    63   public override Configuration GetConfiguration() {
     63  public bool IsMaximizationProblem { get { return false; } }
     64
     65  public Configuration GetConfiguration() {
    6466    return new Configuration()
    65       // .SetMaximization(true)
    66       // add an arbitrary number of uniquely named parameter vectors
    67       // .AddBinary(""p"", length: 5)
     67      // .AddBinary(""b"", length: 5)
    6868      // .AddInteger(""i"", length: 5, min: 2, max: 14, step: 4)
    6969      // .AddReal(""r"", length: 5, min: -1.0, max: 1.0)
    70       // .AddPermutation(""P"", type: PermutationTypes.Absolute, length: 5)
     70      // .AddPermutation(""P"", length: 5, type: PermutationTypes.Absolute)
    7171    ;
    7272  }
    7373
    74   public override double Evaluate(IRandom random, ParameterVector vector) {
     74  public double Evaluate(IRandom random, ParameterVector vector) {
    7575    var quality = 0.0;
    7676    // quality = vector.Real(""r"").Select(x => x * x).Sum();
Note: See TracChangeset for help on using the changeset viewer.