Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/26/14 13:24:20 (10 years ago)
Author:
mkommend
Message:

#2174: Implemented multi-encoding operators and adapated wiring of operators in the programmable problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/MultiEncodingCreator.cs

    r11484 r11587  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    25 using HeuristicLab.Operators;
    2626using HeuristicLab.Optimization;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Problems.Programmable.Operators;
    2829
    2930namespace HeuristicLab.Problems.Programmable {
    30   [Item("MultiEncodingCreator", "Contains solution creators that together create a multiencoding.")]
     31  [Item("MultiEncodingCreator", "Contains solution creators that together create a multi-encoding.")]
    3132  [StorableClass]
    32   public class MultiEncodingCreator : MultiOperator<ISolutionCreator>, ISolutionCreator {
     33  public sealed class MultiEncodingCreator : MultiEncodingOperator<ISolutionCreator>, ISolutionCreator {
     34    [StorableConstructor]
     35    private MultiEncodingCreator(bool deserializing) : base(deserializing) { }
    3336
    34     [StorableConstructor]
    35     protected MultiEncodingCreator(bool deserializing) : base(deserializing) { }
    36     protected MultiEncodingCreator(MultiEncodingCreator original, Cloner cloner) : base(original, cloner) { }
     37    private MultiEncodingCreator(MultiEncodingCreator original, Cloner cloner) : base(original, cloner) { }
    3738    public MultiEncodingCreator() { }
    3839
     
    4142    }
    4243
    43     public override IOperation InstrumentedApply() {
    44       var baseOperations = base.InstrumentedApply();
    45       return new OperationCollection(new[] { baseOperations }.Concat(Operators.Select(x => ExecutionContext.CreateOperation(x))));
     44    public override void AddEncoding(IEncoding encoding) {
     45      base.AddEncoding(encoding);
     46      var parameter = GetParameter(encoding);
     47      parameter.Value = encoding.SolutionCreator;
     48      encoding.SolutionCreatorChanged += Encoding_SolutionCreatorChanged;
     49    }
     50
     51    public override bool RemoveEncoding(IEncoding encoding) {
     52      var success = base.RemoveEncoding(encoding);
     53      encoding.SolutionCreatorChanged -= Encoding_SolutionCreatorChanged;
     54      return success;
     55    }
     56
     57    private void Encoding_SolutionCreatorChanged(object sender, EventArgs e) {
     58      var encoding = (IEncoding)sender;
     59      var parameter = GetParameter(encoding);
     60
     61      var oldCreator = parameter.ValidValues.Single(creator => creator.GetType() == encoding.SolutionCreator.GetType());
     62      parameter.ValidValues.Remove(oldCreator);
     63      parameter.ValidValues.Add(encoding.SolutionCreator);
     64      parameter.Value = encoding.SolutionCreator;
    4665    }
    4766  }
Note: See TracChangeset for help on using the changeset viewer.