Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/07/15 13:52:48 (10 years ago)
Author:
abeham
Message:

#2174:

  • Added ISingleObjectiveOperator and IMultiObjectiveOperator interfaces
    • Added interface to all operators that would fall in either of these categories (excluding MainLoop operators)
  • Added some checks in BasicProblem on whether the MultiEncoding is being used
    • A new event handler is added that reacts on encodings being removed or added to the MultiEncoding
  • Added code to remove the non-fit operators in (Single|Multi)ObjectiveBasicProblem
Location:
trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/BasicProblem.cs

    r11949 r11970  
    8686    private void RegisterEvents() {
    8787      EncodingParameter.ValueChanged += (o, e) => OnEncodingChanged();
     88      var multiEncoding = Encoding as MultiEncoding;
     89      if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged;
    8890    }
    8991
    9092    protected virtual void OnEncodingChanged() {
    91       if (oldEncoding != null) AdaptEncodingOperators(oldEncoding, Encoding);
     93      if (oldEncoding != null) {
     94        AdaptEncodingOperators(oldEncoding, Encoding);
     95        var oldMultiEncoding = oldEncoding as MultiEncoding;
     96        if (oldMultiEncoding != null)
     97          oldMultiEncoding.EncodingsChanged -= MultiEncodingOnEncodingsChanged;
     98      }
    9299      oldEncoding = Encoding;
    93100
     
    104111      //TODO register solution creator changed event, change access modifier to private
    105112      //((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged;     
     113
     114      var multiEncoding = Encoding as MultiEncoding;
     115      if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged;
    106116
    107117      OnOperatorsChanged();
     
    141151    }
    142152
     153    protected virtual void MultiEncodingOnEncodingsChanged(object sender, EventArgs e) {
     154      OnOperatorsChanged();
     155    }
    143156  }
    144157}
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveMoveOperator.cs

    r11961 r11970  
    2121
    2222namespace HeuristicLab.Optimization {
    23   public interface ISingleObjectiveMoveOperator : IMoveOperator {
     23  public interface ISingleObjectiveMoveOperator : IMoveOperator, ISingleObjectiveOperator {
    2424  }
    2525}
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/internal/IMultiObjectiveAnalysisOperator.cs

    r11949 r11970  
    2424
    2525namespace HeuristicLab.Optimization {
    26   internal interface IMultiObjectiveAnalysisOperator : IEncodingOperator, IAnalyzer {
     26  internal interface IMultiObjectiveAnalysisOperator : IEncodingOperator, IAnalyzer, IMultiObjectiveOperator {
    2727    Action<Individual[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; }
    2828  }
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/internal/ISingleObjectiveAnalysisOperator.cs

    r11961 r11970  
    2424
    2525namespace HeuristicLab.Optimization {
    26   internal interface ISingleObjectiveAnalysisOperator : IEncodingOperator {
     26  internal interface ISingleObjectiveAnalysisOperator : IEncodingOperator, ISingleObjectiveOperator {
    2727    Action<Individual[], double[], ResultCollection, IRandom> AnalyzeAction { get; set; }
    2828  }
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs

    r11949 r11970  
    6363    }
    6464
     65    protected override void OnOperatorsChanged() {
     66      base.OnOperatorsChanged();
     67      if (Encoding != null) {
     68        PruneSingleObjectiveOperators(Encoding);
     69        var multiEncoding = Encoding as MultiEncoding;
     70        if (multiEncoding != null) {
     71          foreach (var encoding in multiEncoding.Encodings.ToList()) {
     72            PruneSingleObjectiveOperators(encoding);
     73          }
     74        }
     75      }
     76    }
     77
     78    private void PruneSingleObjectiveOperators(IEncoding encoding) {
     79      if (encoding != null && encoding.Operators.Any(x => x is ISingleObjectiveOperator && !(x is IMultiObjectiveOperator)))
     80        encoding.Operators = encoding.Operators.Where(x => !(x is ISingleObjectiveOperator) || x is IMultiObjectiveOperator).ToList();
     81    }
     82
    6583    protected override void OnEvaluatorChanged() {
    6684      base.OnEvaluatorChanged();
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs

    r11949 r11970  
    7575    }
    7676
     77    protected override void OnOperatorsChanged() {
     78      base.OnOperatorsChanged();
     79      if (Encoding != null) {
     80        PruneMultiObjectiveOperators(Encoding);
     81        var multiEncoding = Encoding as MultiEncoding;
     82        if (multiEncoding != null) {
     83          foreach (var encoding in multiEncoding.Encodings.ToList()) {
     84            PruneMultiObjectiveOperators(encoding);
     85          }
     86        }
     87      }
     88    }
     89
     90    private void PruneMultiObjectiveOperators(IEncoding encoding) {
     91      if (encoding.Operators.Any(x => x is IMultiObjectiveOperator && !(x is ISingleObjectiveOperator)))
     92        encoding.Operators = encoding.Operators.Where(x => !(x is IMultiObjectiveOperator) || x is ISingleObjectiveOperator).ToList();
     93    }
     94
    7795    protected override void OnEvaluatorChanged() {
    7896      base.OnEvaluatorChanged();
Note: See TracChangeset for help on using the changeset viewer.