Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15084


Ignore:
Timestamp:
06/28/17 22:55:27 (7 years ago)
Author:
abeham
Message:

#2775:

  • All single-objective operators inside IMultiOperators are now removed by the multi-objective problem
  • All multi-objective operators inside IMultiOperators are now removed by the single-objective problem
Location:
trunk/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IMultiOperator.cs

    r14185 r15084  
    2121
    2222
     23using System.Collections.Generic;
     24
    2325namespace HeuristicLab.Core {
    24   public interface IMultiOperator<T> : IOperator where T : class,IOperator {
    25     IItemList<T> Operators { get; }
     26  public interface IMultiOperator : IOperator {
     27    IEnumerable<IOperator> Operators { get; }
     28    bool AddOperator(IOperator op);
     29    bool RemoveOperator(IOperator op);
     30  }
     31  public interface IMultiOperator<T> : IMultiOperator where T : class,IOperator {
     32    new IItemList<T> Operators { get; }
    2633  }
    2734}
  • trunk/sources/HeuristicLab.Operators/3.3/MultiOperator.cs

    r14185 r15084  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Collections;
    2526using HeuristicLab.Common;
     
    5253      }
    5354    }
     55   
     56    IEnumerable<IOperator> IMultiOperator.Operators { get { return operators.AsEnumerable(); } }
    5457
    5558    [StorableConstructor]
     
    6972    private void AfterDeserialization() {
    7073      Initialize();
     74    }
     75
     76    public virtual bool AddOperator(IOperator op) {
     77      var tOp = op as T;
     78      if (tOp == null) return false;
     79      operators.Add(tOp);
     80      return true;
     81    }
     82
     83    public virtual bool RemoveOperator(IOperator op) {
     84      var tOp = op as T;
     85      if (tOp == null) return false;
     86      return operators.Remove(tOp);
    7187    }
    7288
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs

    r15080 r15084  
    7676      if (encoding != null && encoding.Operators.Any(x => x is ISingleObjectiveOperator && !(x is IMultiObjectiveOperator)))
    7777        encoding.Operators = encoding.Operators.Where(x => !(x is ISingleObjectiveOperator) || x is IMultiObjectiveOperator).ToList();
     78
     79      foreach (var multiOp in Encoding.Operators.OfType<IMultiOperator>()) {
     80        foreach (var soOp in multiOp.Operators.Where(x => x is ISingleObjectiveOperator).ToList()) {
     81          multiOp.RemoveOperator(soOp);
     82        }
     83      }
    7884    }
    7985
  • trunk/sources/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs

    r15051 r15084  
    110110      if (encoding.Operators.Any(x => x is IMultiObjectiveOperator && !(x is ISingleObjectiveOperator)))
    111111        encoding.Operators = encoding.Operators.Where(x => !(x is IMultiObjectiveOperator) || x is ISingleObjectiveOperator).ToList();
     112
     113      foreach (var multiOp in Encoding.Operators.OfType<IMultiOperator>()) {
     114        foreach (var moOp in multiOp.Operators.Where(x => x is IMultiObjectiveOperator).ToList()) {
     115          multiOp.RemoveOperator(moOp);
     116        }
     117      }
    112118    }
    113119
Note: See TracChangeset for help on using the changeset viewer.