Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5080


Ignore:
Timestamp:
12/10/10 17:38:49 (14 years ago)
Author:
mkommend
Message:

Implemented wiring of problem specific analyzers in UserDefinedAlgorithms (ticket #1327)

Location:
trunk/sources
Files:
1 added
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis/3.3/MultiAnalyzer.cs

    r4722 r5080  
    3535  [Item("MultiAnalyzer", "An analyzer which applies arbitrary many other analyzers.")]
    3636  [StorableClass]
    37   public class MultiAnalyzer : CheckedMultiOperator<IAnalyzer>, IAnalyzer {
     37  public class MultiAnalyzer : CheckedMultiOperator<IAnalyzer>, IMultiAnalyzer {
    3838    public override bool CanChangeName {
    3939      get { return false; }
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r4477 r5080  
    143143    <Compile Include="Constraints\IConstraint.cs" />
    144144    <Compile Include="Constraints\TypeCompatibilityConstraint.cs" />
     145    <Compile Include="Interfaces\IMultiOperator.cs" />
    145146    <Compile Include="OperatorExecutionException.cs" />
    146147    <Compile Include="Interfaces\IScopeTreeLookupParameter.cs" />
  • trunk/sources/HeuristicLab.Operators/3.3/MultiOperator.cs

    r4722 r5080  
    3434  [Item("MultiOperator", "A base class for operators which apply arbitrary many other operators of a specific type.")]
    3535  [StorableClass]
    36   public abstract class MultiOperator<T> : SingleSuccessorOperator where T : class, IOperator {
     36  public abstract class MultiOperator<T> : SingleSuccessorOperator, IMultiOperator<T> where T : class, IOperator {
    3737    private List<IValueParameter<T>> operatorParameters;
    3838
     
    6868      Initialize();
    6969    }
    70    
     70
    7171    private void Initialize() {
    7272      if (operators != null) RegisterOperatorsEvents();
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r4564 r5080  
    112112    <Compile Include="Algorithm.cs" />
    113113    <Compile Include="BatchRun.cs" />
     114    <Compile Include="Interfaces\IMultiAnalyzer.cs" />
    114115    <Compile Include="Interfaces\IIterationBasedOperator.cs" />
    115116    <Compile Include="Interfaces\IRealVectorDecoder.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IMultiAnalyzer.cs

    r5078 r5080  
    2020#endregion
    2121
     22
    2223using HeuristicLab.Core;
    23 
    2424namespace HeuristicLab.Optimization {
    2525  /// <summary>
    26   /// An interface which represents an analysis operator.
     26  /// An interface which represents an multi analysis operator.
    2727  /// </summary>
    28   public interface IAnalyzer : IOperator { }
     28  public interface IMultiAnalyzer : IMultiOperator<IAnalyzer>, IAnalyzer { }
    2929}
  • trunk/sources/HeuristicLab.Optimization/3.3/UserDefinedAlgorithm.cs

    r4722 r5080  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    5051    }
    5152
     53    private IValueParameter AnalyzerParameter {
     54      get { return (IValueParameter)Parameters["Analyzer"]; }
     55    }
     56    private IMultiAnalyzer Analyzer {
     57      get {
     58        if (AnalyzerParameter != null)
     59          return AnalyzerParameter.Value as IMultiAnalyzer;
     60        return null;
     61      }
     62    }
     63
    5264    public UserDefinedAlgorithm() : base() { }
    5365    public UserDefinedAlgorithm(string name) : base(name) { }
     
    6476      return new UserDefinedAlgorithm(this, cloner);
    6577    }
     78
     79    #region update of problem specific analyzers
     80    protected override void OnProblemChanged() {
     81      AddProblemAnalyzer();
     82      base.OnProblemChanged();
     83    }
     84    protected override void Problem_OperatorsChanged(object sender, System.EventArgs e) {
     85      RemoveProblemAnalyzers();
     86      AddProblemAnalyzer();
     87      base.Problem_OperatorsChanged(sender, e);
     88    }
     89
     90    protected override void DeregisterProblemEvents() {
     91      RemoveProblemAnalyzers();
     92      base.DeregisterProblemEvents();
     93    }
     94
     95    private void RemoveProblemAnalyzers() {
     96      if (Analyzer != null) {
     97        foreach (var analyzer in Problem.Operators.OfType<IAnalyzer>())
     98          Analyzer.Operators.Remove(analyzer);
     99      }
     100    }
     101    private void AddProblemAnalyzer() {
     102      if (Analyzer != null && Problem != null) {
     103        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
     104          Analyzer.Operators.Add(analyzer);
     105        }
     106      }
     107    }
     108    #endregion
    66109  }
    67110}
Note: See TracChangeset for help on using the changeset viewer.