Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2757


Ignore:
Timestamp:
02/08/10 03:43:36 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on parameters and operators
Location:
trunk/sources
Files:
8 added
15 deleted
38 edited

Legend:

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

    r2687 r2757  
    9393    /// </summary>
    9494    [Storable]
    95     private Stack<ExecutionContext> executionStack;
     95    private Stack<IExecutionContext> executionStack;
    9696    /// <summary>
    9797    /// Gets the current execution stack.
    9898    /// </summary>
    99     protected Stack<ExecutionContext> ExecutionStack {
     99    protected Stack<IExecutionContext> ExecutionStack {
    100100      get { return executionStack; }
    101101    }
     
    135135    protected Engine() {
    136136      globalScope = new Scope("Global");
    137       executionStack = new Stack<ExecutionContext>();
     137      executionStack = new Stack<IExecutionContext>();
    138138      OperatorGraph = new OperatorGraph();
    139139    }
     
    151151      clone.globalScope = (Scope)cloner.Clone(globalScope);
    152152      clone.executionTime = executionTime;
    153       ExecutionContext[] contexts = executionStack.ToArray();
     153      IExecutionContext[] contexts = executionStack.ToArray();
    154154      for (int i = contexts.Length - 1; i >= 0; i--)
    155         clone.executionStack.Push((ExecutionContext)cloner.Clone(contexts[i]));
     155        clone.executionStack.Push((IExecutionContext)cloner.Clone(contexts[i]));
    156156      clone.running = running;
    157157      clone.canceled = canceled;
  • trunk/sources/HeuristicLab.Core/3.3/ExecutionContext.cs

    r2687 r2757  
    2626
    2727namespace HeuristicLab.Core {
    28   public class ExecutionContext : DeepCloneable {
     28  public class ExecutionContext : DeepCloneable, IExecutionContext {
    2929    [Storable]
    3030    private ExecutionContext parent;
  • trunk/sources/HeuristicLab.Core/3.3/ExecutionContextCollection.cs

    r2664 r2757  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using System.Text;
    2526using System.Xml;
     
    2728
    2829namespace HeuristicLab.Core {
    29   public class ExecutionContextCollection : DeepCloneable, IList<ExecutionContext> {
     30  public class ExecutionContextCollection : DeepCloneable, IList<IExecutionContext>, IExecutionContext {
    3031    [Storable]
    31     private IList<ExecutionContext> contexts;
     32    private IList<IExecutionContext> contexts;
    3233
    3334    [Storable]
     
    3940
    4041    public ExecutionContextCollection() {
    41       contexts = new List<ExecutionContext>();
     42      contexts = new List<IExecutionContext>();
    4243      parallel = false;
    4344    }
    44     public ExecutionContextCollection(IEnumerable<ExecutionContext> collection) {
    45       contexts = new List<ExecutionContext>(collection);
     45    public ExecutionContextCollection(IEnumerable<IExecutionContext> collection) {
     46      contexts = new List<IExecutionContext>(collection.Where(e => e != null));
    4647      parallel = false;
    4748    }
    48     public ExecutionContextCollection(params ExecutionContext[] list) {
    49       contexts = new List<ExecutionContext>(list);
     49    public ExecutionContextCollection(params IExecutionContext[] list) {
     50      contexts = new List<IExecutionContext>(list.Where(e => e != null));
    5051      parallel = false;
    5152    }
     
    5657      clone.parallel = parallel;
    5758      for (int i = 0; i < contexts.Count; i++)
    58         clone.contexts.Add((ExecutionContext)cloner.Clone(contexts[i]));
     59        clone.contexts.Add((IExecutionContext)cloner.Clone(contexts[i]));
    5960      return clone;
    6061    }
    6162
    62     #region IList<ExecutionContext> Members
    63     public int IndexOf(ExecutionContext item) {
     63    #region IList<IExecutionContext> Members
     64    public int IndexOf(IExecutionContext item) {
    6465      return contexts.IndexOf(item);
    6566    }
    66     public void Insert(int index, ExecutionContext item) {
    67       contexts.Insert(index, item);
     67    public void Insert(int index, IExecutionContext item) {
     68      if (item != null) contexts.Insert(index, item);
    6869    }
    6970    public void RemoveAt(int index) {
    7071      contexts.RemoveAt(index);
    7172    }
    72     public ExecutionContext this[int index] {
     73    public IExecutionContext this[int index] {
    7374      get { return contexts[index]; }
    74       set { contexts[index] = value; }
     75      set { if (value != null) contexts[index] = value; }
    7576    }
    7677    #endregion
    7778
    78     #region ICollection<ExecutionContext> Members
    79     public void Add(ExecutionContext item) {
    80       contexts.Add(item);
     79    #region ICollection<IExecutionContext> Members
     80    public void Add(IExecutionContext item) {
     81      if (item != null) contexts.Add(item);
    8182    }
    8283    public void Clear() {
    8384      contexts.Clear();
    8485    }
    85     public bool Contains(ExecutionContext item) {
     86    public bool Contains(IExecutionContext item) {
    8687      return contexts.Contains(item);
    8788    }
    88     public void CopyTo(ExecutionContext[] array, int arrayIndex) {
     89    public void CopyTo(IExecutionContext[] array, int arrayIndex) {
    8990      contexts.CopyTo(array, arrayIndex);
    9091    }
     
    9596      get { return contexts.IsReadOnly; }
    9697    }
    97     public bool Remove(ExecutionContext item) {
     98    public bool Remove(IExecutionContext item) {
    9899      return contexts.Remove(item);
    99100    }
    100101    #endregion
    101102
    102     #region IEnumerable<ExecutionContext> Members
    103     public IEnumerator<ExecutionContext> GetEnumerator() {
     103    #region IEnumerable<IExecutionContext> Members
     104    public IEnumerator<IExecutionContext> GetEnumerator() {
    104105      return contexts.GetEnumerator();
    105106    }
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r2756 r2757  
    104104    <Compile Include="ChangedEventArgs.cs" />
    105105    <None Include="HeuristicLabCorePlugin.cs.frame" />
     106    <Compile Include="Interfaces\IExecutionContext.cs" />
    106107    <Compile Include="Interfaces\IValueLookupParameter.cs" />
    107108    <Compile Include="Interfaces\IValueParameter.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IOperator.cs

    r2653 r2757  
    4444    /// <param name="scope">The scope where to execute the current instance.</param>
    4545    /// <returns>The next operation.</returns>
    46     ExecutionContextCollection Execute(ExecutionContext context);
     46    IExecutionContext Execute(ExecutionContext context);
    4747    /// <summary>
    4848    /// Aborts the current operator.
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IParameter.cs

    r2740 r2757  
    2929  public interface IParameter : INamedItem {
    3030    Type DataType { get; }
     31    IItem ActualValue { get; set; }
    3132    ExecutionContext ExecutionContext { get; set; }
    3233  }
  • trunk/sources/HeuristicLab.Core/3.3/ItemArray.cs

    r2746 r2757  
    2929using HeuristicLab.Common.Resources;
    3030using HeuristicLab.Collections;
    31 
    3231
    3332namespace HeuristicLab.Core {
  • trunk/sources/HeuristicLab.Data.Views/3.3/HeuristicLab.Data.Views-3.3.csproj

    r2754 r2757  
    5858    </Compile>
    5959    <None Include="HeuristicLabDataViewsPlugin.cs.frame" />
     60    <Compile Include="ComparisonDataView.cs">
     61      <SubType>UserControl</SubType>
     62    </Compile>
     63    <Compile Include="ComparisonDataView.Designer.cs">
     64      <DependentUpon>ComparisonDataView.cs</DependentUpon>
     65    </Compile>
    6066    <Compile Include="StringConvertibleDataView.cs">
    6167      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Data/3.3/BoolData.cs

    r2694 r2757  
    3131  [Item("BoolData", "Represents a boolean value.")]
    3232  [Creatable("Test")]
    33   public sealed class BoolData : ValueTypeData<bool>, IStringConvertibleData {
     33  public sealed class BoolData : ValueTypeData<bool>, IComparable, IStringConvertibleData {
    3434    public BoolData() : base() { }
    3535    public BoolData(bool value) : base(value) { }
     
    3939      cloner.RegisterClonedObject(this, clone);
    4040      return clone;
     41    }
     42
     43    public int CompareTo(object obj) {
     44      BoolData other = obj as BoolData;
     45      if (other != null)
     46        return Value.CompareTo(other.Value);
     47      else
     48        return Value.CompareTo(obj);
    4149    }
    4250
  • trunk/sources/HeuristicLab.Data/3.3/DateTimeData.cs

    r2694 r2757  
    3232  [Item("DateTimeData", "Represents a date and time value.")]
    3333  [Creatable("Test")]
    34   public sealed class DateTimeData : ValueTypeData<DateTime>, IStringConvertibleData {
     34  public sealed class DateTimeData : ValueTypeData<DateTime>, IComparable, IStringConvertibleData {
    3535    public DateTimeData() : base() { }
    3636    public DateTimeData(DateTime value) : base(value) { }
     
    4444    public override string ToString() {
    4545      return Value.ToString("o");  // round-trip format
     46    }
     47
     48    public int CompareTo(object obj) {
     49      DateTimeData other = obj as DateTimeData;
     50      if (other != null)
     51        return Value.CompareTo(other.Value);
     52      else
     53        return Value.CompareTo(obj);
    4654    }
    4755
  • trunk/sources/HeuristicLab.Data/3.3/DoubleData.cs

    r2694 r2757  
    3131  [Item("DoubleData", "Represents a double value.")]
    3232  [Creatable("Test")]
    33   public sealed class DoubleData : ValueTypeData<double>, IStringConvertibleData {
     33  public sealed class DoubleData : ValueTypeData<double>, IComparable, IStringConvertibleData {
    3434    public DoubleData() : base() { }
    3535    public DoubleData(double value) : base(value) { }
     
    4343    public override string ToString() {
    4444      return Value.ToString("r");  // round-trip format
     45    }
     46
     47    public int CompareTo(object obj) {
     48      DoubleData other = obj as DoubleData;
     49      if (other != null)
     50        return Value.CompareTo(other.Value);
     51      else
     52        return Value.CompareTo(obj);
    4553    }
    4654
  • trunk/sources/HeuristicLab.Data/3.3/HeuristicLab.Data-3.3.csproj

    r2754 r2757  
    106106    <Compile Include="BoolMatrixData.cs" />
    107107    <None Include="HeuristicLabDataPlugin.cs.frame" />
     108    <Compile Include="Comparison.cs" />
     109    <Compile Include="ComparisonData.cs" />
    108110    <Compile Include="StringMatrixData.cs" />
    109111    <Compile Include="StringArrayData.cs" />
  • trunk/sources/HeuristicLab.Data/3.3/IntData.cs

    r2694 r2757  
    3131  [Item("IntData", "Represents an integer value.")]
    3232  [Creatable("Test")]
    33   public sealed class IntData : ValueTypeData<int>, IStringConvertibleData {
     33  public sealed class IntData : ValueTypeData<int>, IComparable, IStringConvertibleData {
    3434    public IntData() : base() { }
    3535    public IntData(int value) : base(value) { }
     
    3939      cloner.RegisterClonedObject(this, clone);
    4040      return clone;
     41    }
     42
     43    public int CompareTo(object obj) {
     44      IntData other = obj as IntData;
     45      if (other != null)
     46        return Value.CompareTo(other.Value);
     47      else
     48        return Value.CompareTo(obj);
    4149    }
    4250
  • trunk/sources/HeuristicLab.Data/3.3/StringData.cs

    r2694 r2757  
    3131  [Item("StringData", "Represents a string.")]
    3232  [Creatable("Test")]
    33   public sealed class StringData : Item, IStringConvertibleData {
     33  public sealed class StringData : Item, IComparable, IStringConvertibleData {
    3434    [Storable]
    3535    private string value;
     
    6363    }
    6464
     65    public int CompareTo(object obj) {
     66      StringData other = obj as StringData;
     67      if (other != null)
     68        return Value.CompareTo(other.Value);
     69      else
     70        return Value.CompareTo(obj);
     71    }
     72
    6573    #region IStringConvertibleData Members
    6674    bool IStringConvertibleData.Validate(string value, out string errorMessage) {
  • trunk/sources/HeuristicLab.Data/3.3/TimeSpanData.cs

    r2694 r2757  
    3131  [Item("TimeSpanData", "Represents a duration of time.")]
    3232  [Creatable("Test")]
    33   public sealed class TimeSpanData : ValueTypeData<TimeSpan>, IStringConvertibleData {
     33  public sealed class TimeSpanData : ValueTypeData<TimeSpan>, IComparable, IStringConvertibleData {
    3434    public TimeSpanData() : base() { }
    3535    public TimeSpanData(TimeSpan value) : base(value) { }
     
    3939      cloner.RegisterClonedObject(this, clone);
    4040      return clone;
     41    }
     42
     43    public int CompareTo(object obj) {
     44      TimeSpanData other = obj as TimeSpanData;
     45      if (other != null)
     46        return Value.CompareTo(other.Value);
     47      else
     48        return Value.CompareTo(obj);
    4149    }
    4250
  • trunk/sources/HeuristicLab.Data/3.3/ValueTypeData.cs

    r2694 r2757  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
  • trunk/sources/HeuristicLab.Operators/3.3/CombinedOperator.cs

    r2740 r2757  
    6868    }
    6969
    70     public override ExecutionContextCollection Apply() {
    71       ExecutionContextCollection next = base.Apply();
     70    public override IExecutionContext Apply() {
     71      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
    7272      if (operatorGraph.InitialOperator != null)
    7373        next.Insert(0, new ExecutionContext(ExecutionContext, operatorGraph.InitialOperator, ExecutionContext.Scope));
  • trunk/sources/HeuristicLab.Operators/3.3/ConditionalBranch.cs

    r1530 r2757  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using System.Xml;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
     28using HeuristicLab.Parameters;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2730
    2831namespace HeuristicLab.Operators {
    2932  /// <summary>
    30   /// Branch of (one or)two operators whose executions depend on a specific condition.
     33  /// A branch of two operators whose executions depend on a condition.
    3134  /// </summary>
    32   public class ConditionalBranch : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"ConditionalBranch expects to have 1 or 2 sub-operators.
    36 It will return the 1st sub-operator if ""Condition"" is true and the 2nd sub-operator if ""Condition"" equals to false.
    37 
    38 In case a 2nd sub-operator does not exist and ""Condition"" would equal to false, Conditional Branch will not return a new operation."; }
     35  [Item("ConditionalBranch", "A branch of two operators whose executions depend on a boolean condition.")]
     36  [Creatable("Test")]
     37  [EmptyStorableClass]
     38  public class ConditionalBranch : SingleSuccessorOperator {
     39    public LookupParameter<BoolData> ConditionParameter {
     40      get { return (LookupParameter<BoolData>)Parameters["Condition"]; }
     41    }
     42    protected OperatorParameter TrueBranchParameter {
     43      get { return (OperatorParameter)Parameters["TrueBranch"]; }
     44    }
     45    protected OperatorParameter FalseBranchParameter {
     46      get { return (OperatorParameter)Parameters["FalseBranch"]; }
     47    }
     48    public IOperator TrueBranch {
     49      get { return TrueBranchParameter.Value; }
     50      set { TrueBranchParameter.Value = value; }
     51    }
     52    public IOperator FalseBranch {
     53      get { return FalseBranchParameter.Value; }
     54      set { FalseBranchParameter.Value = value; }
    3955    }
    4056
    41     /// <summary>
    42     /// Initializes a new instance of <see cref="ConditionalBranch"/> with one variable info
    43     /// (<c>Condition</c>).
    44     /// </summary>
    4557    public ConditionalBranch()
    4658      : base() {
    47       AddVariableInfo(new VariableInfo("Condition", "A boolean variable that decides the branch", typeof(BoolData), VariableKind.In));
     59      Parameters.Add(new LookupParameter<BoolData>("Condition", "A boolean variable which defines which branch is executed."));
     60      Parameters.Add(new OperatorParameter("TrueBranch", "The operator which is executed if the condition is true."));
     61      Parameters.Add(new OperatorParameter("FalseBranch", "The operator which is executed if the condition is false."));
    4862    }
    4963
    50     /// <summary>
    51     /// Applies the operator of branch one under a specific condition on the given
    52     /// <paramref name="scope"/>, or - if existent - operator of branch two if the condition could not
    53     /// be fulfilled.
    54     /// </summary>
    55     /// <param name="scope">The scope to apply the operators on.</param>
    56     /// <returns>A new <see cref="AtomicOperation"/> with either operator 1 or operator 2 applied
    57     /// to the given <paramref name="scope"/> or <c>null</c>.</returns>
    58     public override IOperation Apply(IScope scope) {
    59       BoolData resultData = GetVariableValue<BoolData>("Condition", scope, true);
    60       bool result = resultData.Data;
    61 
    62       if ((result) && (SubOperators.Count > 0) && (SubOperators[0] != null))
    63         return new AtomicOperation(SubOperators[0], scope);
    64       else if ((!result) && (SubOperators.Count > 1) && (SubOperators[1] != null))
    65         return new AtomicOperation(SubOperators[1], scope);
    66       return null;
     64    public override IExecutionContext Apply() {
     65      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
     66      if (ConditionParameter.ActualValue.Value) {
     67        if (TrueBranch != null) next.Insert(0, new ExecutionContext(ExecutionContext.Parent, TrueBranch, ExecutionContext.Scope));
     68      } else {
     69        if (FalseBranch != null) next.Insert(0, new ExecutionContext(ExecutionContext.Parent, FalseBranch, ExecutionContext.Scope));
     70      }
     71      return next;
    6772    }
    6873  }
  • trunk/sources/HeuristicLab.Operators/3.3/Counter.cs

    r2756 r2757  
    3939      get { return (LookupParameter<IntData>)Parameters["Value"]; }
    4040    }
    41     public ValueLookupParameter<IntData> IncrementParaneter {
     41    public ValueLookupParameter<IntData> IncrementParameter {
    4242      get { return (ValueLookupParameter<IntData>)Parameters["Increment"]; }
    4343    }
    4444    public IntData Increment {
    45       get { return IncrementParaneter.Value; }
    46       set { IncrementParaneter.Value = value; }
     45      get { return IncrementParameter.Value; }
     46      set { IncrementParameter.Value = value; }
    4747    }
    4848
     
    5353    }
    5454
    55     public override ExecutionContextCollection Apply() {
     55    public override IExecutionContext Apply() {
    5656      if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new IntData();
    57       ValueParameter.ActualValue.Value += IncrementParaneter.ActualValue.Value;
     57      ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value;
    5858      return base.Apply();
    5959    }
  • trunk/sources/HeuristicLab.Operators/3.3/DoubleCounter.cs

    r1530 r2757  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
    2830namespace HeuristicLab.Operators {
    2931  /// <summary>
    30   /// Class to add a specified interval to a double value.
     32  /// Operator which increments a double variable.
    3133  /// </summary>
    32   public class DoubleCounter : OperatorBase {
    33     /// <summary>
    34     /// Gets the description of the current instance.
    35     /// </summary>
    36     public override string Description {
    37       get { return @"Adds a given interval to a double value"; }
     34  [Item("DoubleCounter", "An operator which increments a double variable.")]
     35  [EmptyStorableClass]
     36  [Creatable("Test")]
     37  public sealed class DoubleCounter : SingleSuccessorOperator {
     38    public LookupParameter<DoubleData> ValueParameter {
     39      get { return (LookupParameter<DoubleData>)Parameters["Value"]; }
     40    }
     41    public ValueLookupParameter<DoubleData> IncrementParameter {
     42      get { return (ValueLookupParameter<DoubleData>)Parameters["Increment"]; }
     43    }
     44    public DoubleData Increment {
     45      get { return IncrementParameter.Value; }
     46      set { IncrementParameter.Value = value; }
    3847    }
    3948
    40     /// <summary>
    41     /// Initializes a new instance of <see cref="DoubleCounter"/>, including two variable infos
    42     /// (<c>Value</c> and <c>Interval</c>).
    43     /// </summary>
    4449    public DoubleCounter()
    4550      : base() {
    46       AddVariableInfo(new VariableInfo("Value", "Counter value", typeof(DoubleData), VariableKind.In | VariableKind.Out));
    47       AddVariableInfo(new VariableInfo("Interval", "Interval value", typeof(DoubleData), VariableKind.In));
     51      Parameters.Add(new LookupParameter<DoubleData>("Value", "The value which should be incremented."));
     52      Parameters.Add(new ValueLookupParameter<DoubleData>("Increment", "The increment which is added to the value.", new DoubleData(1)));
    4853    }
    4954
    50     /// <summary>
    51     /// Adds to a double value of the given <paramref name="scope"/> a specified interval.
    52     /// </summary>
    53     /// <param name="scope">The scope whose variable should be incremented.</param>
    54     /// <returns><c>null</c>.</returns>
    55     public override IOperation Apply(IScope scope) {
    56       DoubleData value = GetVariableValue<DoubleData>("Value", scope, true);
    57       double interval = GetVariableValue<DoubleData>("Interval", scope, true).Data;
    58       value.Data += interval;
    59       return null;
     55    public override IExecutionContext Apply() {
     56      if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new DoubleData();
     57      ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value;
     58      return base.Apply();
    6059    }
    6160  }
  • trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r2754 r2757  
    8787    <Compile Include="CombinedOperator.cs" />
    8888    <None Include="HeuristicLabOperatorsPlugin.cs.frame" />
     89    <Compile Include="ConditionalBranch.cs" />
     90    <Compile Include="Comparator.cs" />
     91    <Compile Include="ScopeCleaner.cs" />
     92    <Compile Include="SubScopesRemover.cs" />
     93    <Compile Include="SubScopesSorter.cs" />
     94    <Compile Include="DoubleCounter.cs" />
     95    <Compile Include="ParallelProcessor.cs" />
     96    <Compile Include="UniformParallelSubScopesProcessor.cs" />
     97    <Compile Include="UniformSequentialSubScopesProcessor.cs" />
     98    <Compile Include="ValueCollector.cs" />
    8999    <Compile Include="MultipleSuccessorsOperator.cs" />
    90100    <Compile Include="Counter.cs" />
     
    97107    <Compile Include="SequentialProcessor.cs" />
    98108    <Compile Include="SingleSuccessorOperator.cs" />
     109    <Compile Include="SubScopesCreater.cs" />
     110    <Compile Include="VariableInjector.cs">
     111      <SubType>Code</SubType>
     112    </Compile>
    99113  </ItemGroup>
    100114  <ItemGroup>
  • trunk/sources/HeuristicLab.Operators/3.3/Operator.cs

    r2740 r2757  
    6161    }
    6262
     63    [Storable]
     64    private ExecutionContext executionContext;
     65    protected ExecutionContext ExecutionContext {
     66      get { return executionContext; }
     67      private set {
     68        if (value != executionContext) {
     69          executionContext = value;
     70          OnExecutionContextChanged();
     71        }
     72      }
     73    }
     74
    6375    /// <summary>
    6476    /// Flag whether the current instance has been canceled.
     
    6880    protected bool Canceled {
    6981      get { return canceled; }
     82      private set {
     83        if (value != canceled) {
     84          canceled = value;
     85          OnCanceledChanged();
     86        }
     87      }
    7088    }
    7189
     
    82100        }
    83101      }
    84     }
    85 
    86     [Storable]
    87     private ExecutionContext executionContext;
    88     protected ExecutionContext ExecutionContext {
    89       get { return executionContext; }
    90102    }
    91103
     
    118130
    119131    /// <inheritdoc/>
    120     public virtual ExecutionContextCollection Execute(ExecutionContext context) {
     132    public virtual IExecutionContext Execute(ExecutionContext context) {
    121133      try {
    122         canceled = false;
    123         executionContext = context;
     134        Canceled = false;
     135        ExecutionContext = context;
    124136        foreach (IParameter param in Parameters)
    125137          param.ExecutionContext = context;
    126         ExecutionContextCollection next = Apply();
     138        IExecutionContext next = Apply();
    127139        OnExecuted();
    128140        return next;
     
    131143        foreach (IParameter param in Parameters)
    132144          param.ExecutionContext = null;
    133         context = null;
     145        ExecutionContext = null;
    134146      }
    135147    }
    136148    /// <inheritdoc/>
    137149    /// <remarks>Sets property <see cref="Canceled"/> to <c>true</c>.</remarks>
    138     public virtual void Abort() {
    139       canceled = true;
     150    public void Abort() {
     151      Canceled = true;
    140152    }
    141153    /// <summary>
     
    144156    /// <param name="scope">The scope where to execute the operator</param>
    145157    /// <returns><c>null</c>.</returns>
    146     public virtual ExecutionContextCollection Apply() {
    147       return new ExecutionContextCollection();
    148     }
     158    public abstract IExecutionContext Apply();
    149159
     160    protected virtual void OnExecutionContextChanged() { }
     161    protected virtual void OnCanceledChanged() { }
    150162    /// <inheritdoc/>
    151163    public event EventHandler BreakpointChanged;
  • trunk/sources/HeuristicLab.Operators/3.3/ParallelProcessor.cs

    r1530 r2757  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using System.Xml;
     26using HeuristicLab.Collections;
    2527using HeuristicLab.Core;
    2628using HeuristicLab.Data;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2730
    2831namespace HeuristicLab.Operators {
    2932  /// <summary>
    30   /// Performs <c>n</c> operators on the given scope; operations can be executed in parallel.
     33  /// Operator which executes multiple operators in parallel.
    3134  /// </summary>
    32   public class ParallelProcessor : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
     35  [Item("ParallelProcessor", "An operator which executes multiple operators in parallel.")]
     36  [Creatable("Test")]
     37  [EmptyStorableClass]
     38  public sealed class ParallelProcessor : MultipleSuccessorsOperator {
     39    public ParallelProcessor()
     40      : base() {
    3641    }
    3742
    38     /// <summary>
    39     /// Applies <c>n</c> operators on the given <paramref name="scope"/>.
    40     /// </summary>
    41     /// <param name="scope">The scope to apply the operators on.</param>
    42     /// <returns>A new <see cref="CompositeOperation"/> with the <c>n</c> operators applied
    43     /// to the given <paramref name="scope"/> with the <c>ExecuteInParallel</c> set to <c>true</c>.</returns>
    44     public override IOperation Apply(IScope scope) {
    45       CompositeOperation next = new CompositeOperation();
    46       next.ExecuteInParallel = true;
    47       for (int i = 0; i < SubOperators.Count; i++)
    48         next.AddOperation(new AtomicOperation(SubOperators[i], scope));
     43    public override IExecutionContext Apply() {
     44      ExecutionContextCollection next = new ExecutionContextCollection();
     45      for (int i = 0; i < Successors.Count; i++) {
     46        if (Successors[i] != null)
     47          next.Add(new ExecutionContext(ExecutionContext.Parent, Successors[i], ExecutionContext.Scope));
     48      }
     49      next.Parallel = true;
    4950      return next;
    5051    }
  • trunk/sources/HeuristicLab.Operators/3.3/ScopeCleaner.cs

    r1530 r2757  
    2424using System.Text;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
     26using HeuristicLab.Parameters;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    2829namespace HeuristicLab.Operators {
    2930  /// <summary>
    30   /// Operator that removes all variables in the given scope and deletes also all subscopes.
     31  /// An operator which removes all variables and sub-scopes from the current scope.
    3132  /// </summary>
    32   public class ScopeCleaner : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"Removes all variables in the current scope and deletes all subscopes"; }
     33  [Item("ScopeCleaner", "An operator which removes all variables and sub-scopes from the current scope.")]
     34  [EmptyStorableClass]
     35  [Creatable("Test")]
     36  public sealed class ScopeCleaner : SingleSuccessorOperator {
     37    private ScopeParameter CurrentScopeParameter {
     38      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     39    }
     40    public IScope CurrentScope {
     41      get { return CurrentScopeParameter.ActualValue; }
    3642    }
    3743
    38     /// <summary>
    39     /// Deletes all variable and sub scopes from the given <paramref name="scope"/>.
    40     /// </summary>
    41     /// <remarks>Calls <see cref="IScope.Clear"/> of interface <see cref="IScope"/>.</remarks>
    42     /// <param name="scope">The scope to clear.</param>
    43     /// <returns><c>null</c>.</returns>
    44     public override IOperation Apply(IScope scope) {
    45       scope.Clear();
    46       return null;
     44    public ScopeCleaner()
     45      : base() {
     46      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose variables and sub-scopes should be removed."));
     47    }
     48
     49    public override IExecutionContext Apply() {
     50      CurrentScope.Variables.Clear();
     51      CurrentScope.SubScopes.Clear();
     52      return base.Apply();
    4753    }
    4854  }
  • trunk/sources/HeuristicLab.Operators/3.3/SequentialProcessor.cs

    r2740 r2757  
    4141    }
    4242
    43     public override ExecutionContextCollection Apply() {
     43    public override IExecutionContext Apply() {
    4444      ExecutionContextCollection next = new ExecutionContextCollection();
    45       for (int i = 0; i < Successors.Count; i++)
    46         next.Add(new ExecutionContext(ExecutionContext.Parent, Successors[i], ExecutionContext.Scope));
     45      for (int i = 0; i < Successors.Count; i++) {
     46        if (Successors[i] != null)
     47          next.Add(new ExecutionContext(ExecutionContext.Parent, Successors[i], ExecutionContext.Scope));
     48      }
    4749      return next;
    4850    }
  • trunk/sources/HeuristicLab.Operators/3.3/SingleSuccessorOperator.cs

    r2740 r2757  
    4949    }
    5050
    51     public override ExecutionContextCollection Apply() {
     51    public override IExecutionContext Apply() {
    5252      if (Successor != null)
    53         return new ExecutionContextCollection(new ExecutionContext(ExecutionContext.Parent, Successor, ExecutionContext.Scope));
     53        return new ExecutionContext(ExecutionContext.Parent, Successor, ExecutionContext.Scope);
    5454      else
    55         return new ExecutionContextCollection();
     55        return null;
    5656    }
    5757  }
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesCreater.cs

    r1530 r2757  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
    2830namespace HeuristicLab.Operators {
    2931  /// <summary>
    30   /// Operator to create sub scopes in a given scope.
     32  /// An operator which adds new and empty sub-scopes to the current scope.
    3133  /// </summary>
    32   public class SubScopesCreater : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get { return @"TODO\r\nOperator description still missing ..."; }
     34  [Item("SubScopesCreater", "An operator which adds new and empty sub-scopes to the current scope.")]
     35  [EmptyStorableClass]
     36  [Creatable("Test")]
     37  public class SubScopesCreater : SingleSuccessorOperator {
     38    public ValueLookupParameter<IntData> NumberOfSubScopesParameter {
     39      get { return (ValueLookupParameter<IntData>)Parameters["NumberOfSubScopes"]; }
     40    }
     41    protected ScopeParameter CurrentScopeParameter {
     42      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     43    }
     44    public IScope CurrentScope {
     45      get { return CurrentScopeParameter.ActualValue; }
    3646    }
    3747
    38     /// <summary>
    39     /// Initializes a new instance of <see cref="SubScopesCreater"/> with one variable info (<c>SubScopes</c>).
    40     /// </summary>
    4148    public SubScopesCreater()
    4249      : base() {
    43       AddVariableInfo(new VariableInfo("SubScopes", "Number of sub-scopes", typeof(IntData), VariableKind.In));
     50      Parameters.Add(new ValueLookupParameter<IntData>("NumberOfSubScopes", "The number of new and empty sub-scopes which should be added to the current scope."));
     51      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new and empty sub-scopes are added."));
    4452    }
    4553
    46     /// <summary>
    47     /// Creates a specified number of sub scopes in the given <paramref name="scope"/>.
    48     /// </summary>
    49     /// <param name="scope">The scope where to create the sub scopes.</param>
    50     /// <returns><c>null</c>.</returns>
    51     public override IOperation Apply(IScope scope) {
    52       IntData count = GetVariableValue<IntData>("SubScopes", scope, true);
    53 
    54       for (int i = 0; i < count.Data; i++)
    55         scope.AddSubScope(new Scope(i.ToString()));
    56 
    57       return null;
     54    public override IExecutionContext Apply() {
     55      int n = NumberOfSubScopesParameter.ActualValue.Value;
     56      for (int i = 0; i < n; i++)
     57        CurrentScope.SubScopes.Add(new Scope(i.ToString()));
     58      return base.Apply();
    5859    }
    5960  }
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesRemover.cs

    r1530 r2757  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
    2830namespace HeuristicLab.Operators {
    2931  /// <summary>
    30   /// Removes one specified or - if nothing specified - all operators from the given scope.
     32  /// An operator which removes one specified or (if not specified) all sub-scopes from the current scope.
    3133  /// </summary>
    32   public class SubScopesRemover : OperatorBase {
    33     /// <inheritdoc select="summary"/>
    34     public override string Description {
    35       get {
    36         return @"This operator either removes the subscope specified in the variable SubScopeIndex or if this variable is absent, removes all subscopes.";
    37       }
     34  [Item("SubScopesRemover", "An operator which removes one specified or (if not specified) all sub-scopes from the current scope.")]
     35  [EmptyStorableClass]
     36  [Creatable("Test")]
     37  public class SubScopesRemover : SingleSuccessorOperator {
     38    public ValueLookupParameter<IntData> SubScopeIndexParameter {
     39      get { return (ValueLookupParameter<IntData>)Parameters["SubScopeIndex"]; }
     40    }
     41    protected ScopeParameter CurrentScopeParameter {
     42      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     43    }
     44    public IScope CurrentScope {
     45      get { return CurrentScopeParameter.ActualValue; }
    3846    }
    3947
    40     /// <summary>
    41     /// Initializes a new instance of <see cref="SubScopesRemover"/> with one variable info
    42     /// (<c>SubScopeIndex</c>).
    43     /// </summary>
    4448    public SubScopesRemover()
    4549      : base() {
    46       AddVariableInfo(new VariableInfo("SubScopeIndex", "(Optional) the index of the subscope to remove", typeof(IntData), VariableKind.In));
     50      Parameters.Add(new ValueLookupParameter<IntData>("SubScopeIndex", "The index of the sub-scope which should be removed. If this parameter has no value, all sub-scopes of the current scope are removed."));
     51      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which one or all sub-scopes should be removed."));
    4752    }
    4853
    49     /// <summary>
    50     /// Removes one sub scope with a specified index from the given <paramref name="scope"/>, or if no
    51     /// index has been specified, all sub scopes are removed.
    52     /// </summary>
    53     /// <exception cref="InvalidOperationException">Thrown when no sub scope with the specified index
    54     /// exists.</exception>
    55     /// <param name="scope">The scope whose sub scope(s) to remove.</param>
    56     /// <returns><c>null</c>.</returns>
    57     public override IOperation Apply(IScope scope) {
    58       IntData index = GetVariableValue<IntData>("SubScopeIndex", scope, true, false);
    59       if (index == null) { // remove all scopes
    60         while (scope.SubScopes.Count > 0) {
    61           scope.RemoveSubScope(scope.SubScopes[0]);
    62         }
    63       } else {
    64         if (index.Data < 0 && index.Data >= scope.SubScopes.Count) throw new InvalidOperationException("ERROR: no scope with index " + index.Data + " exists");
    65         scope.RemoveSubScope(scope.SubScopes[index.Data]);
    66       }
    67       return null;
     54    public override IExecutionContext Apply() {
     55      IntData index = SubScopeIndexParameter.ActualValue;
     56      if (index != null)
     57        CurrentScope.SubScopes.RemoveAt(index.Value);
     58      else
     59        CurrentScope.SubScopes.Clear();
     60      return base.Apply();
    6861    }
    6962  }
  • trunk/sources/HeuristicLab.Operators/3.3/UniformParallelSubScopesProcessor.cs

    r1530 r2757  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using System.Xml;
    2526using HeuristicLab.Core;
    26 using HeuristicLab.Data;
     27using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
    2830namespace HeuristicLab.Operators {
    2931  /// <summary>
    30   /// Performs the same operator on all <c>n</c> existing sub scopes of a given scope;
    31   /// operations can be executed in parallel.
     32  /// An operator which applies a specified operator on all sub-scopes of the current scope in parallel.
    3233  /// </summary>
    33   public class UniformParallelSubScopesProcessor : OperatorBase {
    34     /// <inheritdoc select="summary"/>
    35     public override string Description {
    36       get { return @"TODO\r\nOperator description still missing ..."; }
     34  [Item("UniformParallelSubScopesProcessor", "An operator which applies a specified operator on all sub-scopes of the current scope in parallel.")]
     35  [Creatable("Test")]
     36  [EmptyStorableClass]
     37  public sealed class UniformParallelSubScopesProcessor : SingleSuccessorOperator {
     38    private OperatorParameter OperatorParameter {
     39      get { return (OperatorParameter)Parameters["Operator"]; }
     40    }
     41    public IOperator Operator {
     42      get { return OperatorParameter.Value; }
     43      set { OperatorParameter.Value = value; }
    3744    }
    3845
    39     /// <summary>
    40     /// Applies one operator on all the sub scopes of the given <paramref name="scope"/>.
    41     /// </summary>
    42     /// <param name="scope">The scope on whose sub scopes the operator is applied.</param>
    43     /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes and
    44     /// the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns>
    45     public override IOperation Apply(IScope scope) {
    46       CompositeOperation next = new CompositeOperation();
    47       next.ExecuteInParallel = true;
    48       for (int i = 0; i < scope.SubScopes.Count; i++)
    49         next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i]));
     46    public UniformParallelSubScopesProcessor()
     47      : base() {
     48      Parameters.Add(new OperatorParameter("Operator", "The operator which should be applied on all sub-scopes of the current scope in parallel."));
     49    }
     50
     51    public override IExecutionContext Apply() {
     52      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
     53      if (Operator != null) {
     54        ExecutionContextCollection inner = new ExecutionContextCollection();
     55        inner.Parallel = true;
     56        for (int i = 0; i < ExecutionContext.Scope.SubScopes.Count; i++)
     57          inner.Add(new ExecutionContext(ExecutionContext.Parent, Operator, ExecutionContext.Scope.SubScopes[i]));
     58        next.Insert(0, inner);
     59      }
    5060      return next;
    5161    }
  • trunk/sources/HeuristicLab.Operators/3.3/UniformSequentialSubScopesProcessor.cs

    r1530 r2757  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using System.Xml;
    2526using HeuristicLab.Core;
    26 using HeuristicLab.Data;
     27using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
    2830namespace HeuristicLab.Operators {
    2931  /// <summary>
    30   /// Performs the same operator on all existing sub scopes of a given scope,
    31   /// must be executed sequentially.
     32  /// An operator which applies a specified operator sequentially on all sub-scopes of the current scope.
    3233  /// </summary>
    33   public class UniformSequentialSubScopesProcessor : OperatorBase {
    34     /// <inheritdoc select="summary"/>
    35     public override string Description {
    36       get { return @"TODO\r\nOperator description still missing ..."; }
     34  [Item("UniformSequentialSubScopesProcessor", "An operator which applies a specified operator sequentially on all sub-scopes of the current scope.")]
     35  [Creatable("Test")]
     36  [EmptyStorableClass]
     37  public sealed class UniformSequentialSubScopesProcessor : SingleSuccessorOperator {
     38    private OperatorParameter OperatorParameter {
     39      get { return (OperatorParameter)Parameters["Operator"]; }
     40    }
     41    public IOperator Operator {
     42      get { return OperatorParameter.Value; }
     43      set { OperatorParameter.Value = value; }
    3744    }
    3845
    39     /// <summary>
    40     /// Applies one operator on all the sub scopes of the given <paramref name="scope"/>.
    41     /// </summary>
    42     /// <param name="scope">The scope on whose sub scopes the operator is applied.</param>
    43     /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes.</returns>
    44     public override IOperation Apply(IScope scope) {
    45       CompositeOperation next = new CompositeOperation();
    46       for (int i = 0; i < scope.SubScopes.Count; i++)
    47         next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i]));
     46    public UniformSequentialSubScopesProcessor()
     47      : base() {
     48      Parameters.Add(new OperatorParameter("Operator", "The operator which should be applied sequentially on all sub-scopes of the current scope."));
     49    }
     50
     51    public override IExecutionContext Apply() {
     52      ExecutionContextCollection next = new ExecutionContextCollection(base.Apply());
     53      if (Operator != null) {
     54        ExecutionContextCollection inner = new ExecutionContextCollection();
     55        for (int i = 0; i < ExecutionContext.Scope.SubScopes.Count; i++)
     56          inner.Add(new ExecutionContext(ExecutionContext.Parent, Operator, ExecutionContext.Scope.SubScopes[i]));
     57        next.Insert(0, inner);
     58      }
    4859      return next;
    4960    }
  • trunk/sources/HeuristicLab.Operators/3.3/VariableInjector.cs

    r2526 r2757  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using System.Text;
    2526using System.Xml;
     27using HeuristicLab.Collections;
    2628using HeuristicLab.Core;
     29using HeuristicLab.Parameters;
    2730using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2831
    2932namespace HeuristicLab.Operators {
    3033  /// <summary>
    31   /// Class to inject local variables into the scope.
     34  /// An operator which collects the actual values of parameters and clones them into the current scope.
    3235  /// </summary>
    33   public class VariableInjector : OperatorBase {
    34 
    35     private Dictionary<IVariable, IVariableInfo> variableVariableInfoTable;   
    36     private Dictionary<IVariableInfo, IVariable> variableInfoVariableTable;
    37 
    38     /// <inheritdoc select="summary"/>
    39     public override string Description {
    40       get { return @"TODO\r\nOperator description still missing ..."; }
     36  [Item("VariableInjector", "An operator which collects the actual values of parameters and clones them into the current scope.")]
     37  [Creatable("Test")]
     38  [EmptyStorableClass]
     39  public class VariableInjector : ValueCollector {
     40    protected ScopeParameter CurrentScopeParameter {
     41      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     42    }
     43    public IScope CurrentScope {
     44      get { return CurrentScopeParameter.ActualValue; }
    4145    }
    4246
    43     /// <summary>
    44     /// Initializes a new instance of <see cref="VariableInjector"/>.
    45     /// </summary>
    4647    public VariableInjector()
    4748      : base() {
    48       variableVariableInfoTable = new Dictionary<IVariable, IVariableInfo>();
    49       variableInfoVariableTable = new Dictionary<IVariableInfo, IVariable>();
     49      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope into which the parameter values are cloned."));
    5050    }
    5151
    52     /// <summary>
    53     /// Clones the current instance (deep clone).
    54     /// </summary>
    55     /// <remarks>Deep clone performed with <see cref="cloner.Clone"/> of helper class
    56     /// <see cref="Auxiliary"/>.</remarks>
    57     /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    58     /// <returns>The cloned object as <see cref="VariableInjector"/>.</returns>
    59     public override IItem Clone(ICloner cloner) {
    60       VariableInjector clone = new VariableInjector();
    61       cloner.RegisterClonedObject(this, clone);
    62       clone.Name = Name;
    63       foreach (IVariable variable in Variables)
    64         clone.AddVariable((IVariable)cloner.Clone(variable));
    65       return clone;
     52    public override IExecutionContext Apply() {
     53      IVariable var;
     54      foreach (IParameter param in CollectedValues) {
     55        CurrentScope.Variables.TryGetValue(param.Name, out var);
     56        if (var != null)
     57          var.Value = (IItem)param.ActualValue.Clone();
     58        else
     59          CurrentScope.Variables.Add(new Variable(param.Name, (IItem)param.ActualValue.Clone()));
     60      }
     61      return base.Apply();
    6662    }
    67 
    68     /// <summary>
    69     /// Adds the specified <paramref name="variable"/> to the current instance to get injected.
    70     /// </summary>
    71     /// <param name="variable">The variable to add.</param>
    72     /// <remarks>Calls private method <see cref="CreateVariableInfo"/> and <see cref="OperatorBase.AddVariable"/>
    73     /// of base class <see cref="OperatorBase"/>.</remarks>
    74     public override void AddVariable(IVariable variable) {
    75       base.AddVariable(variable);
    76       CreateVariableInfo(variable);
    77     }
    78 
    79     /// <summary>
    80     /// Removes a variable with the specified <paramref name="name"/> from the current injector.
    81     /// </summary>
    82     /// <remarks>Calls private method <see cref="DeleteVariableInfo"/> and <see cref="OperatorBase.RemoveVariable"/>
    83     /// of base class <see cref="OperatorBase"/>.</remarks>
    84     /// <param name="name">The name of the </param>
    85     public override void RemoveVariable(string name) {
    86       DeleteVariableInfo(name);
    87       base.RemoveVariable(name);
    88     }
    89 
    90     /// <summary>
    91     /// Adds the specified variables to the given <paramref name="scope"/> (and removes them first,
    92     /// if they already exist in the current scope).
    93     /// </summary>
    94     /// <param name="scope">The scope where to inject the variables.</param>
    95     /// <returns><c>null</c>.</returns>
    96     public override IOperation Apply(IScope scope) {
    97       foreach (IVariable variable in Variables) {
    98         if (scope.GetVariable(variable.Name) != null)
    99           scope.RemoveVariable(variable.Name);
    100         scope.AddVariable((IVariable)variable.Clone());
    101       }
    102       return null;
    103     }
    104 
    105     [Storable]
    106     private KeyValuePair<Dictionary<IVariableInfo, IVariable>, Dictionary<IVariable, IVariableInfo>> VariableMappingPersistence {
    107       get {
    108         return new KeyValuePair<Dictionary<IVariableInfo, IVariable>, Dictionary<IVariable, IVariableInfo>>(
    109           variableInfoVariableTable, variableVariableInfoTable);
    110       }
    111       set {
    112         variableInfoVariableTable = value.Key;
    113         variableVariableInfoTable = value.Value;
    114         foreach (var pair in variableInfoVariableTable) {
    115           pair.Key.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);
    116           pair.Value.NameChanged += new EventHandler(Variable_NameChanged);         
    117         }
    118       }
    119     }
    120 
    121     private void CreateVariableInfo(IVariable variable) {
    122       IVariableInfo info = new VariableInfo(Guid.NewGuid().ToString(), "Injected variable", variable.Value.GetType(), VariableKind.New);
    123       info.ActualName = variable.Name;
    124       AddVariableInfo(info);
    125       variableVariableInfoTable.Add(variable, info);
    126       variableInfoVariableTable.Add(info, variable);
    127       info.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);
    128       variable.NameChanged += new EventHandler(Variable_NameChanged);
    129     }
    130     private void DeleteVariableInfo(string name) {
    131       IVariable variable = GetVariable(name);
    132       if (variable != null) {
    133         IVariableInfo info = variableVariableInfoTable[variable];
    134         RemoveVariableInfo(info.FormalName);
    135         variableVariableInfoTable.Remove(variable);
    136         variableInfoVariableTable.Remove(info);
    137         info.ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged);
    138         variable.NameChanged -= new EventHandler(Variable_NameChanged);
    139       }
    140     }
    141 
    142     #region VariableInfo and Variable Events
    143     private void VariableInfo_ActualNameChanged(object sender, EventArgs e) {
    144       IVariableInfo info = (IVariableInfo)sender;
    145       IVariable variable = variableInfoVariableTable[info];
    146       variable.Name = info.ActualName;
    147     }
    148     private void Variable_NameChanged(object sender, EventArgs e) {
    149       IVariable variable = (IVariable)sender;
    150       IVariableInfo info = variableVariableInfoTable[variable];
    151       info.ActualName = variable.Name;
    152     }
    153     #endregion
    15463  }
    15564}
  • trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs

    r2756 r2757  
    3232  /// A parameter whose value is retrieved from the scope.
    3333  /// </summary>
    34   [Item("LookupParameter<T>", "A parameter whose value is retrieved from the scope.")]
     34  [Item("LookupParameter<T>", "A parameter whose value is retrieved from or written to a scope.")]
    3535  public class LookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem {
    3636    [Storable]
     
    4646      }
    4747    }
    48     public T ActualValue {
    49       get { return GetActualValue(); }
     48    public new T ActualValue {
     49      get { return (T)GetActualValue(); }
    5050      set { SetActualValue(value); }
    5151    }
     
    8080      return scope != null ? scope.Variables[actualName] : null;
    8181    }
    82     protected virtual T GetActualValue() {
     82    protected override IItem GetActualValue() {
    8383      string name = TranslateName(Name, ExecutionContext);
    8484      IVariable var = LookupVariable(name);
     
    9595      return null;
    9696    }
    97     protected virtual void SetActualValue(T value) {
     97    protected override void SetActualValue(IItem value) {
     98      T val = value as T;
     99      if (val == null)
     100        throw new InvalidOperationException(
     101          string.Format("Type mismatch. Value is not a \"{0}\".",
     102                        typeof(T).GetPrettyName())
     103        );
    98104      string name = TranslateName(Name, ExecutionContext);
    99105      IVariable var = LookupVariable(name);
    100       if (var != null) var.Value = value;
    101       else ExecutionContext.Scope.Variables.Add(new Variable(name, value));
     106      if (var != null) var.Value = val;
     107      else ExecutionContext.Scope.Variables.Add(new Variable(name, val));
    102108    }
    103109
  • trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs

    r2756 r2757  
    4545      get { return dataType; }
    4646    }
     47    public IItem ActualValue {
     48      get { return GetActualValue(); }
     49      set { SetActualValue(value); }
     50    }
    4751    [Storable]
    4852    private ExecutionContext executionContext;
    4953    public ExecutionContext ExecutionContext {
    5054      get { return executionContext; }
    51       set { executionContext = value; }
     55      set {
     56        if (value != executionContext) {
     57          executionContext = value;
     58          OnExecutionContextChanged();
     59        }
     60      }
    5261    }
    5362
     
    7786      return string.Format("{0} ({1})", Name, DataType.Name);
    7887    }
     88
     89    protected abstract IItem GetActualValue();
     90    protected abstract void SetActualValue(IItem value);
     91
     92    protected virtual void OnExecutionContextChanged() { }
    7993  }
    8094}
  • trunk/sources/HeuristicLab.Parameters/3.3/ScopeParameter.cs

    r2756 r2757  
    3535  [Creatable("Test")]
    3636  public class ScopeParameter : Parameter {
    37     public IScope Value {
     37    public new IScope ActualValue {
    3838      get { return ExecutionContext.Scope; }
    3939    }
     
    5252      return string.Format("{0} ({1})", Name, DataType.Name);
    5353    }
     54
     55    protected override IItem GetActualValue() {
     56      return ExecutionContext.Scope;
     57    }
     58    protected override void SetActualValue(IItem value) {
     59      throw new NotSupportedException("The actual value of a ScopeParameter cannot be set. It is always the current scope.");
     60    }
    5461  }
    5562}
  • trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs

    r2756 r2757  
    3232  /// A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.
    3333  /// </summary>
    34   [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")]
     34  [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from or written to the sub-scopes of the current scope.")]
    3535  public class SubScopesLookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem {
    3636    [Storable]
     
    4747    }
    4848
    49     public T[] ActualValues {
    50       get { return GetActualValues(); }
    51       set { SetActualValues(value); }
     49    public new ItemArray<T> ActualValue {
     50      get { return (ItemArray<T>)GetActualValue(); }
     51      set { SetActualValue(value); }
    5252    }
    5353
    5454    public SubScopesLookupParameter()
    55       : base("Anonymous", typeof(T)) {
     55      : base("Anonymous", typeof(ItemArray<T>)) {
    5656      actualName = Name;
    5757    }
    5858    public SubScopesLookupParameter(string name)
    59       : base(name, typeof(T)) {
     59      : base(name, typeof(ItemArray<T>)) {
    6060      actualName = Name;
    6161    }
    6262    public SubScopesLookupParameter(string name, string description)
    63       : base(name, description, typeof(T)) {
     63      : base(name, description, typeof(ItemArray<T>)) {
    6464      actualName = Name;
    6565    }
     
    7575    }
    7676
    77     protected virtual T[] GetActualValues() {
     77    protected override IItem GetActualValue() {
    7878      string name = LookupParameter<T>.TranslateName(Name, ExecutionContext);
    7979      IScope scope = ExecutionContext.Scope;
    80       T[] values = new T[scope.SubScopes.Count];
     80      ItemArray<T> values = new ItemArray<T>(scope.SubScopes.Count);
    8181      IVariable var;
    8282      T value;
     
    9797      return values;
    9898    }
    99     protected virtual void SetActualValues(T[] values) {
     99    protected override void SetActualValue(IItem value) {
     100      ItemArray<T> values = value as ItemArray<T>;
     101      if (values == null)
     102        throw new InvalidOperationException(
     103          string.Format("Type mismatch. Value is not a \"{0}\".",
     104                        typeof(ItemArray<T>).GetPrettyName())
     105        );
     106
    100107      string name = LookupParameter<T>.TranslateName(Name, ExecutionContext);
    101108      IScope scope = ExecutionContext.Scope;
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs

    r2756 r2757  
    3232  /// A parameter whose value is either defined it the parameter itself or is retrieved from the scope.
    3333  /// </summary>
    34   [Item("ValueLookupParameter<T>", "A parameter whose value is either defined it the parameter itself or is retrieved from the scope.")]
     34  [Item("ValueLookupParameter<T>", "A parameter whose value is either defined it the parameter itself or is retrieved from or written to a scope.")]
    3535  public class ValueLookupParameter<T> : Parameter, IValueLookupParameter<T> where T : class, IItem {
    3636    [Storable]
     
    6161    }
    6262
    63     public T ActualValue {
    64       get { return GetActualValue(); }
     63    public new T ActualValue {
     64      get { return (T)GetActualValue(); }
    6565      set { SetActualValue(value); }
    6666    }
     
    137137      return scope != null ? scope.Variables[actualName] : null;
    138138    }
    139     protected virtual T GetActualValue() {
     139    protected override IItem GetActualValue() {
    140140      string name;
    141141      // try to get local value from context stack
     
    157157      return null;
    158158    }
    159     protected virtual void SetActualValue(T value) {
     159    protected override void SetActualValue(IItem value) {
     160      T val = value as T;
     161      if (val == null)
     162        throw new InvalidOperationException(
     163          string.Format("Type mismatch. Value is not a \"{0}\".",
     164                        typeof(T).GetPrettyName())
     165        );
     166      // try to get local value from context stack
    160167      string name;
    161       // try to get local value from context stack
    162168      IValueParameter<T> param = GetParameter(out name);
    163       if (param != null) param.Value = value;
     169      if (param != null) param.Value = val;
    164170      else {  // try to get variable from scope
    165171        IVariable var = LookupVariable(name);
    166         if (var != null) var.Value = value;
     172        if (var != null) var.Value = val;
    167173        else ExecutionContext.Scope.Variables.Add(new Variable(name, value));
    168174      }
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueParameter.cs

    r2756 r2757  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4546        }
    4647      }
     48    }
     49    public new T ActualValue {
     50      get { return Value; }
     51      set { Value = value; }
    4752    }
    4853
     
    7580    }
    7681
     82    protected override IItem GetActualValue() {
     83      return Value;
     84    }
     85    protected override void SetActualValue(IItem value) {
     86      T val = value as T;
     87      if (val == null)
     88        throw new InvalidOperationException(
     89          string.Format("Type mismatch. Value is not a \"{0}\".",
     90                        typeof(T).GetPrettyName())
     91        );
     92      Value = val;
     93    }
     94
    7795    public event EventHandler ValueChanged;
    7896    private void OnValueChanged() {
  • trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs

    r2664 r2757  
    5757    protected override void ProcessNextOperator() {
    5858      currentOperator = null;
    59       ExecutionContext context = ExecutionStack.Pop();
    60       ExecutionContextCollection next = null;
     59      IExecutionContext next = ExecutionStack.Pop();
     60      ExecutionContextCollection coll = next as ExecutionContextCollection;
     61      while (coll != null) {
     62        for (int i = coll.Count - 1; i >= 0; i--)
     63          ExecutionStack.Push(coll[i]);
     64        next = ExecutionStack.Pop();
     65        coll = next as ExecutionContextCollection;
     66      }
     67      ExecutionContext context = next as ExecutionContext;
    6168      try {
    6269        currentOperator = context.Operator;
    63         next = context.Operator.Execute(context);
     70        ExecutionStack.Push(context.Operator.Execute(context));
    6471        currentOperator = null;
    6572      }
     
    6976        OnExceptionOccurred(ex);
    7077      }
    71       if (next != null) {
    72         for (int i = next.Count - 1; i >= 0; i--)
    73           ExecutionStack.Push(next[i]);
    74       }
    7578      if (context.Operator.Breakpoint)
    7679        Stop();
Note: See TracChangeset for help on using the changeset viewer.