Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/03/11 11:04:02 (13 years ago)
Author:
cneumuel
Message:

#1424

  • created extension method GetObjectGraphObjects for objects
  • created IStatefulItem interface, which means an object has a state which can be initialized and cleared
  • after an algorithm stopped, all objects of the algorithm-objectgraph with the type IStatefulItem are cleared
  • on prepare, all IStatefulItem objects are initialized
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators/3.3/Operator.cs

    r5445 r6103  
    3333  [Item("Operator", "Base class for operators.")]
    3434  [StorableClass]
    35   public abstract class Operator : ParameterizedNamedItem, IOperator {
     35  public abstract class Operator : ParameterizedNamedItem, IOperator, IStatefulItem {
    3636    public override Image ItemImage {
    3737      get {
     
    7474    protected Operator(bool deserializing)
    7575      : base(deserializing) {
    76       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     76      InitializeState();
    7777    }
    7878    protected Operator(Operator original, Cloner cloner)
    7979      : base(original, cloner) {
    80       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     80      InitializeState();
    8181      this.breakpoint = original.breakpoint;
    8282    }
    8383    protected Operator()
    8484      : base() {
    85       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     85      InitializeState();
    8686      breakpoint = false;
    8787    }
    8888    protected Operator(string name)
    8989      : base(name) {
    90       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     90      InitializeState();
    9191      breakpoint = false;
    9292    }
    9393    protected Operator(string name, ParameterCollection parameters)
    9494      : base(name, parameters) {
    95       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     95      InitializeState();
    9696      breakpoint = false;
    9797    }
    9898    protected Operator(string name, string description)
    9999      : base(name, description) {
    100       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     100      InitializeState();
    101101      breakpoint = false;
    102102    }
    103103    protected Operator(string name, string description, ParameterCollection parameters)
    104104      : base(name, description, parameters) {
     105      InitializeState();
     106      breakpoint = false;
     107    }
     108
     109    public virtual void InitializeState() {
    105110      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    106       breakpoint = false;
     111    }
     112    public virtual void ClearState() {
     113      executionContexts = null;
    107114    }
    108115
Note: See TracChangeset for help on using the changeset viewer.