Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/15/10 05:26:02 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on operators, parameters and problems
Location:
trunk/sources/HeuristicLab.Core/3.3
Files:
3 added
8 edited
1 moved

Legend:

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

    r2793 r2796  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
     24using System.Drawing;
    2625using System.Threading;
    27 using System.Drawing;
     26using HeuristicLab.Common;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 using HeuristicLab.Common;
    3028
    3129namespace HeuristicLab.Core {
     
    4139    }
    4240
    43     /// <summary>
    44     /// Field of the current instance that represent the operator graph.
    45     /// </summary>
    4641    private OperatorGraph operatorGraph;
    4742    /// <summary>
    48     /// Gets the current operator graph.
     43    /// Gets or sets the current operator graph.
    4944    /// </summary>
    5045    [Storable]
     
    7671
    7772    [Storable]
     73    private IProblem problem;
     74    /// <summary>
     75    /// Gets or sets the current problem.
     76    /// </summary>
     77    public IProblem Problem {
     78      get { return problem; }
     79      set {
     80        if (value == null) throw new ArgumentNullException();
     81        if (value != problem) {
     82          problem = value;
     83          OnProblemChanged();
     84          Prepare();
     85        }
     86      }
     87    }
     88
     89    [Storable]
    7890    private TimeSpan executionTime;
    7991    /// <summary>
     
    134146    protected Engine() {
    135147      globalScope = new Scope("Global");
     148      problem = null;
    136149      executionStack = new Stack<IExecutionSequence>();
    137150      OperatorGraph = new OperatorGraph();
     
    149162      clone.OperatorGraph = (OperatorGraph)cloner.Clone(operatorGraph);
    150163      clone.globalScope = (Scope)cloner.Clone(globalScope);
     164      clone.problem = (IProblem)cloner.Clone(problem);
    151165      clone.executionTime = executionTime;
    152166      IExecutionSequence[] contexts = executionStack.ToArray();
     
    169183      ExecutionTime = new TimeSpan();
    170184      executionStack.Clear();
    171       if (OperatorGraph.InitialOperator != null)
    172         executionStack.Push(new ExecutionContext(null, OperatorGraph.InitialOperator, GlobalScope));
     185      if ((OperatorGraph.InitialOperator != null) && (Problem != null))
     186        executionStack.Push(new ExecutionContext(null, OperatorGraph.InitialOperator, GlobalScope, Problem));
    173187      OnPrepared();
    174188    }
     
    228242    }
    229243
     244    /// <summary>
     245    /// Occurs when the operator graph was changed.
     246    /// </summary>
    230247    public event EventHandler OperatorGraphChanged;
     248    /// <summary>
     249    /// Fires a new <c>OperatorGraphChanged</c> event.
     250    /// </summary>
    231251    protected virtual void OnOperatorGraphChanged() {
    232252      if (OperatorGraphChanged != null)
    233253        OperatorGraphChanged(this, EventArgs.Empty);
     254    }
     255    /// <summary>
     256    /// Occurs when the problem was changed.
     257    /// </summary>
     258    public event EventHandler ProblemChanged;
     259    /// <summary>
     260    /// Fires a new <c>ProblemChanged</c> event.
     261    /// </summary>
     262    protected virtual void OnProblemChanged() {
     263      if (ProblemChanged != null)
     264        ProblemChanged(this, EventArgs.Empty);
    234265    }
    235266    /// <summary>
  • trunk/sources/HeuristicLab.Core/3.3/ExecutionContext.cs

    r2790 r2796  
    4545    }
    4646
     47    [Storable]
     48    private IProblem problem;
     49    public IProblem Problem {
     50      get { return problem; }
     51    }
     52
    4753    private ExecutionContext() {
    4854      parent = null;
    4955      op = null;
    5056      scope = null;
     57      problem = null;
    5158    }
    52     public ExecutionContext(ExecutionContext parent, IOperator op, IScope scope) {
    53       if ((op == null) || (scope == null)) throw new ArgumentNullException();
     59    public ExecutionContext(ExecutionContext parent, IOperator op, IScope scope, IProblem problem) {
     60      if ((op == null) || (scope == null) || (problem == null)) throw new ArgumentNullException();
    5461      this.parent = parent;
    5562      this.op = op;
    5663      this.scope = scope;
     64      this.problem = problem;
    5765    }
    5866
     
    6371      clone.op = (IOperator)cloner.Clone(op);
    6472      clone.scope = (IScope)cloner.Clone(scope);
     73      clone.problem = (IProblem)cloner.Clone(problem);
    6574      return clone;
     75    }
     76
     77    public ExecutionContext CreateContext(IOperator op) {
     78      return new ExecutionContext(parent, op, scope, problem);
     79    }
     80    public ExecutionContext CreateContext(IOperator op, IScope scope) {
     81      return new ExecutionContext(parent, op, scope, problem);
     82    }
     83    public ExecutionContext CreateChildContext(IOperator op) {
     84      return new ExecutionContext(this, op, scope, problem);
     85    }
     86    public ExecutionContext CreateChildContext(IOperator op, IScope scope) {
     87      return new ExecutionContext(this, op, scope, problem);
    6688    }
    6789  }
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r2773 r2796  
    104104    <Compile Include="ChangedEventArgs.cs" />
    105105    <None Include="HeuristicLabCorePlugin.cs.frame" />
     106    <Compile Include="ValueParameterCollection.cs" />
     107    <Compile Include="Interfaces\IProblem.cs" />
    106108    <Compile Include="Interfaces\IExecutionSequence.cs" />
    107109    <Compile Include="Interfaces\IValueLookupParameter.cs" />
     
    115117    <Compile Include="Item.cs" />
    116118    <Compile Include="NamedItem.cs" />
     119    <Compile Include="Operator.cs" />
     120    <Compile Include="Problem.cs" />
    117121    <Compile Include="OperatorGraph.cs" />
    118122    <Compile Include="Interfaces\IParameter.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IEngine.cs

    r2790 r2796  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Common;
    2624
     
    4038    /// </summary>
    4139    IScope GlobalScope { get; }
     40    /// <summary>
     41    /// Gets the problem of the current instance.
     42    /// </summary>
     43    IProblem Problem { get; set; }
    4244
    4345    /// <summary>
     
    7274    void Stop();
    7375
     76    /// <summary>
     77    /// Occurs when the operator graph was changed.
     78    /// </summary>
    7479    event EventHandler OperatorGraphChanged;
     80    /// <summary>
     81    /// Occurs when the problem was changed.
     82    /// </summary>
     83    event EventHandler ProblemChanged;
    7584    /// <summary>
    7685    /// Occurs when the execution time was changed.
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/ILookupParameter.cs

    r2790 r2796  
    2626
    2727namespace HeuristicLab.Core {
    28   public interface ILookupParameter<T> : IParameter where T : class, IItem {
     28  public interface ILookupParameter : IParameter {
    2929    string ActualName { get; set; }
    30 
    3130    event EventHandler ActualNameChanged;
    3231  }
     32
     33  public interface ILookupParameter<T> : ILookupParameter where T : class, IItem {
     34    new T ActualValue { get; set; }
     35  }
    3336}
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IValueLookupParameter.cs

    r2790 r2796  
    2626
    2727namespace HeuristicLab.Core {
    28   public interface IValueLookupParameter<T> : IValueParameter<T>, ILookupParameter<T> where T : class, IItem { }
     28  public interface IValueLookupParameter : IValueParameter, ILookupParameter { }
     29
     30  public interface IValueLookupParameter<T> : IValueLookupParameter, IValueParameter<T>, ILookupParameter<T> where T : class, IItem { }
    2931}
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IValueParameter.cs

    r2790 r2796  
    2626
    2727namespace HeuristicLab.Core {
    28   public interface IValueParameter<T> : IParameter where T : class, IItem {
    29     T Value { get; set; }
    30 
     28  public interface IValueParameter : IParameter {
     29    IItem Value { get; set; }
    3130    event EventHandler ValueChanged;
    3231  }
     32
     33  public interface IValueParameter<T> : IValueParameter where T : class, IItem {
     34    new T Value { get; set; }
     35  }
    3336}
  • trunk/sources/HeuristicLab.Core/3.3/Operator.cs

    r2795 r2796  
    2323using System.Drawing;
    2424using HeuristicLab.Collections;
    25 using HeuristicLab.Core;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2726
    28 namespace HeuristicLab.Operators {
     27namespace HeuristicLab.Core {
    2928  /// <summary>
    3029  /// The base class for all operators.
  • trunk/sources/HeuristicLab.Core/3.3/OperatorGraph.cs

    r2793 r2796  
    3434  /// </summary>
    3535  [Item("OperatorGraph", "Represents a graph of operators.")]
    36   [Creatable("Test")]
     36  [Creatable("Algorithms")]
    3737  public class OperatorGraph : Item {
    3838    private OperatorSet operators;
Note: See TracChangeset for help on using the changeset viewer.