Changeset 2042


Ignore:
Timestamp:
06/15/09 02:18:42 (12 years ago)
Author:
swagner
Message:

Refactoring of the operator architecture (#95)

Location:
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/AtomicOperation.cs

    r2033 r2042  
    7272    /// <param name="clonedObjects">All already cloned objects. (Needed to avoid cycles.)</param>
    7373    /// <returns>The cloned object as <see cref="AtomicOperation"/>.</returns>
    74     public override object Clone(IDictionary<long, object> clonedObjects) {
     74    public override ICloneable Clone(ICloner cloner) {
    7575      AtomicOperation clone = new AtomicOperation();
    76       clonedObjects.Add(clone.Id, clone);
    77       clone.myOperator = (IOperator)Auxiliary.Clone(Operator, clonedObjects);
    78       clone.myScope = (IScope)Auxiliary.Clone(Scope, clonedObjects);
     76      cloner.AddClonedObject(this, clone);
     77      clone.myOperator = (IOperator)cloner.Clone(Operator);
     78      clone.myScope = (IScope)cloner.Clone(Scope);
    7979      return clone;
    8080    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Auxiliary.cs

    r2033 r2042  
    3030  /// </summary>
    3131  public static class Auxiliary {
    32     #region Cloning
    33     /// <summary>
    34     /// Clones the given <paramref name="obj"/> (deep clone).
    35     /// </summary>
    36     /// <remarks>Checks before clone if object has not already been cloned.</remarks>
    37     /// <param name="obj">The object to clone.</param>
    38     /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    39     /// <returns>The cloned object.</returns>
    40     public static object Clone(ICloneable obj, IDictionary<long, object> clonedObjects) {
    41       object clone;
    42       if (clonedObjects.TryGetValue(obj.Id, out clone))
    43         return clone;
    44       else
    45         return obj.Clone(clonedObjects);
    46     }
    47     #endregion
    48 
    4932    #region Error Messages
    5033    /// <summary>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/CloneableBase.cs

    r2033 r2042  
    3131  /// </summary>
    3232  public abstract class CloneableBase : ICloneable {
    33     /// <summary>
    34     /// Gets a unique id (memory address) of the current instance. The id is used to
    35     /// detect, if an object has already been cloned or not.
    36     /// </summary>
    37     public long Id {
    38       get {
    39         GCHandle handle = new GCHandle();
    40         handle.Target = this;
    41         return GCHandle.ToIntPtr(handle).ToInt64();
    42       }
    43     }
    44 
    45     /// <summary>
    46     /// Clones the current instance (deep clone).
    47     /// </summary>
    48     /// <remarks>Uses the <see cref="Auxiliary.Clone"/> method of the class <see cref="Auxiliary"/>.</remarks>
    49     /// <returns>The clone.</returns>
    5033    public object Clone() {
    51       return Auxiliary.Clone(this, new Dictionary<long, object>());
     34      return Clone(new Cloner());
    5235    }
    5336    /// <summary>
     
    5740    /// <param name="clonedObjects">All already cloned objects.</param>
    5841    /// <returns>The clone.</returns>
    59     public virtual object Clone(IDictionary<long, object> clonedObjects) {
     42    public virtual ICloneable Clone(ICloner cloner) {
    6043      CloneableBase clone = (CloneableBase)Activator.CreateInstance(this.GetType());
    61       clonedObjects.Add(clone.Id, clone);
     44      cloner.AddClonedObject(this, clone);
    6245      return clone;
    6346    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/CompositeOperation.cs

    r2033 r2042  
    8484    /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    8585    /// <returns>The cloned operation as <see cref="CompositeOperation"/>.</returns>
    86     public override object Clone(IDictionary<long, object> clonedObjects) {
     86    public override ICloneable Clone(ICloner cloner) {
    8787      CompositeOperation clone = new CompositeOperation();
    88       clonedObjects.Add(clone.Id, clone);
     88      cloner.AddClonedObject(this, clone);
    8989      clone.myExecuteInParallel = ExecuteInParallel;
    9090      for (int i = 0; i < Operations.Count; i++)
    91         clone.AddOperation((IOperation)Auxiliary.Clone(Operations[i], clonedObjects));
     91        clone.AddOperation((IOperation)cloner.Clone(Operations[i]));
    9292      return clone;
    9393    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/EngineBase.cs

    r2033 r2042  
    130130    /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param>
    131131    /// <returns>The cloned object as <see cref="EngineBase"/>.</returns>
    132     public override object Clone(IDictionary<long, object> clonedObjects) {
    133       EngineBase clone = (EngineBase)base.Clone(clonedObjects);
    134       clone.myOperatorGraph = (IOperatorGraph)Auxiliary.Clone(OperatorGraph, clonedObjects);
    135       clone.myGlobalScope = (IScope)Auxiliary.Clone(GlobalScope, clonedObjects);
     132    public override ICloneable Clone(ICloner cloner) {
     133      EngineBase clone = (EngineBase)base.Clone(cloner);
     134      clone.myOperatorGraph = (IOperatorGraph)cloner.Clone(OperatorGraph);
     135      clone.myGlobalScope = (IScope)cloner.Clone(GlobalScope);
    136136      clone.myExecutionTime = ExecutionTime;
    137137      IOperation[] operations = new IOperation[ExecutionStack.Count];
    138138      ExecutionStack.CopyTo(operations, 0);
    139139      for (int i = operations.Length - 1; i >= 0; i--)
    140         clone.myExecutionStack.Push((IOperation)Auxiliary.Clone(operations[i], clonedObjects));
     140        clone.myExecutionStack.Push((IOperation)cloner.Clone(operations[i]));
    141141      clone.myRunning = Running;
    142142      clone.myCanceled = Canceled;
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r2033 r2042  
    125125    <Compile Include="CallGraph.cs" />
    126126    <Compile Include="CallNode.cs" />
     127    <Compile Include="Cloner.cs" />
     128    <Compile Include="ParameterEventArgs.cs" />
     129    <Compile Include="Interfaces\ICloner.cs" />
     130    <Compile Include="Interfaces\ICloneable.cs" />
    127131    <Compile Include="ParameterView.cs">
    128132      <SubType>UserControl</SubType>
     
    136140    <Compile Include="Interfaces\ICallNode.cs" />
    137141    <Compile Include="Interfaces\ICallGraph.cs" />
    138     <Compile Include="Interfaces\ICloneable.cs" />
    139142    <Compile Include="KeyValueEventArgs.cs" />
    140143    <Compile Include="OperatorBaseDescriptionView.cs">
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/ICloneable.cs

    r2033 r2042  
    3030  /// </summary>
    3131  public interface ICloneable : System.ICloneable {
    32     /// <summary>
    33     /// Gets a unique id representing the current object. This id is used to check, if an object has
    34     /// already been cloned (to avoid cycles).
    35     /// </summary>
    36     long Id { get; }
    37     /// <summary>
    38     /// Clones the current instance, considering already cloned objects.
    39     /// </summary>
    40     /// <param name="clonedObjects">All already cloned objects. (Needed to avoid cycles.)</param>
    41     /// <returns>The cloned object.</returns>
    42     object Clone(IDictionary<long, object> clonedObjects);
     32    ICloneable Clone(ICloner cloner);
    4333  }
    4434}
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IOperator.cs

    r2033 r2042  
    4949
    5050    /// <summary>
    51     /// Gets a list of all sub operators.
    52     /// </summary>
    53     IList<IOperator> SubOperators { get; }
    54     /// <summary>
    5551    /// Gets a collection of all variable (parameter) infos.
    5652    /// </summary>
    57     ICollection<IVariableInfo> VariableInfos { get; }
    58     /// <summary>
    59     /// Gets a collection of all variables of the current operator.
    60     /// </summary>
    61     ICollection<IVariable> Variables { get; }
    62 
    63     /// <summary>
    64     /// Adds the given sub operator to the current instance.
    65     /// </summary>
    66     /// <param name="op">The operator to add.</param>
    67     void AddSubOperator(IOperator op);
    68     /// <summary>
    69     /// Adds the given sub operator at a the specified <paramref name="index"/>.
    70     /// </summary>
    71     /// <param name="op">The operator to add.</param>
    72     /// <param name="index">The position where to add the operator.</param>
    73     void AddSubOperator(IOperator op, int index);
    74     /// <summary>
    75     /// Removes a sub operator at the specified <paramref name="index"/>.
    76     /// </summary>
    77     /// <param name="index">The position where to delete the operator.</param>
    78     void RemoveSubOperator(int index);
     53    ICollection<IParameter> Parameters { get; }
    7954
    8055    /// <summary>
     
    8358    /// <param name="formalName">The formal name of the variable info.</param>
    8459    /// <returns>The variable info with the specified formal name.</returns>
    85     IVariableInfo GetVariableInfo(string formalName);
     60    IParameter GetParameter(string name);
    8661    /// <summary>
    8762    /// Adds the specified variable info to the current instance.
    8863    /// </summary>
    8964    /// <param name="variableInfo">The variable info to add.</param>
    90     void AddVariableInfo(IVariableInfo variableInfo);
     65    void AddParameter(IParameter parameter);
    9166    /// <summary>
    9267    /// Removes the variable info with the given formal name.
    9368    /// </summary>
    9469    /// <param name="formalName">The formal name of the variable info to remove.</param>
    95     void RemoveVariableInfo(string formalName);
    96 
    97     /// <summary>
    98     /// Gets a variable with the given <paramref name="name"/>.
    99     /// </summary>
    100     /// <param name="name">The name of the variable.</param>
    101     /// <returns>The variable with the specified name.</returns>
    102     IVariable GetVariable(string name);
    103     /// <summary>
    104     /// Adds the specified <paramref name="variable"/> to the current instance.
    105     /// </summary>
    106     /// <param name="variable">The variable to add.</param>
    107     void AddVariable(IVariable variable);
    108     /// <summary>
    109     /// Deletes the variable with the specified <paramref name="name"/>.
    110     /// </summary>
    111     /// <param name="name">The name of the variable to delete.</param>
    112     void RemoveVariable(string name);
    113 
    114     /// <inheritdoc cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/>
    115     /// <typeparam name="T">The type of the value that is searched.</typeparam>       
    116     T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem;
    117     /// <inheritdoc cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>
    118     /// <typeparam name="T">The type of the value that is searched.</typeparam>
    119     T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem;
    120     /// <inheritdoc cref="GetVariableValue(System.String, IScope, bool, bool)"
    121     /// select="summary"/>
    122     /// <param name="formalName">The formal name of the variable info whose variable value is searched.</param>
    123     /// <param name="scope">The scope where to look for the variable.</param>
    124     /// <param name="recursiveLookup">Boolean value, whether also the parent scopes shall be searched if
    125     /// the variable is not found in the specified <paramref name="scope"/>.</param>
    126     /// <returns>The value of the searched variable or null if it is not found.</returns>
    127     IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup);
    128     /// <summary>
    129     /// Gets the value of the variable in the specified <paramref name="scope"/>
    130     /// whose variable(parameter) info has the specified <paramref name="formalName"/>.
    131     /// </summary>
    132     /// <param name="formalName">The formal name of the variable info whose variable value is searched.</param>
    133     /// <param name="scope">The scope where to look for the variable.</param>
    134     /// <param name="recursiveLookup">Boolean value, whether also the parent scopes shall be searched if
    135     /// the variable is not found in the specified <paramref name="scope"/>.</param>
    136     /// <param name="throwOnError">Boolean value, whether an exception shall be thrown, if the variable
    137     /// cannot be found or just <c>null</c> shall be returned.</param>
    138     /// <returns>The value of the searched variable (or null if the variable is not
    139     /// found and <paramref name="throwOnError"/> is set to false).</returns>
    140     IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError);
     70    void RemoveParameter(string name);
    14171
    14272    /// <summary>
     
    16090    event EventHandler BreakpointChanged;
    16191    /// <summary>
    162     /// Occurs when a sub operator has been added.
    163     /// </summary>
    164     event EventHandler<OperatorIndexEventArgs> SubOperatorAdded;
    165     /// <summary>
    166     /// Occurs when a sub operator has been deleted.
    167     /// </summary>
    168     event EventHandler<OperatorIndexEventArgs> SubOperatorRemoved;
    169     /// <summary>
    17092    /// Occurs when a variable info has been added.
    17193    /// </summary>
    172     event EventHandler<VariableInfoEventArgs> VariableInfoAdded;
     94    event EventHandler<ParameterEventArgs> ParameterAdded;
    17395    /// <summary>
    17496    /// Occurs when a variable info has been deleted.
    17597    /// </summary>
    176     event EventHandler<VariableInfoEventArgs> VariableInfoRemoved;
    177     /// <summary>
    178     /// Occurs when a variable has been added.
    179     /// </summary>
    180     event EventHandler<VariableEventArgs> VariableAdded;
    181     /// <summary>
    182     /// Occurs when a variable has been deleted.
    183     /// </summary>
    184     event EventHandler<VariableEventArgs> VariableRemoved;
     98    event EventHandler<ParameterEventArgs> ParameterRemoved;
    18599    /// <summary>
    186100    /// Occurs when the current instance is executed.
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IScope.cs

    r2033 r2042  
    3939    /// </summary>
    4040    ICollection<IVariable> Variables { get; }
    41     /// <summary>
    42     /// Gets all aliases of the current scope.
    43     /// </summary>
    44     IEnumerable<KeyValuePair<string, string>> Aliases { get; }
    4541    /// <summary>
    4642    /// Gets all subscopes in the current scope.
     
    9692
    9793    /// <summary>
    98     /// Gets the actual name of the given alias.
    99     /// </summary>
    100     /// <param name="name">The alias whose actual name is searched.</param>
    101     /// <returns>The actual name.</returns>
    102     string TranslateName(string name);
    103     /// <summary>
    104     /// Adds an alias to the current instance.
    105     /// </summary>
    106     /// <param name="alias">The alias to add.</param>
    107     /// <param name="name">The actual name of the alias.</param>
    108     void AddAlias(string alias, string name);
    109     /// <summary>
    110     /// Deletes the specified <paramref name="alias"/> from the current instance.
    111     /// </summary>
    112     /// <param name="alias">The alias to delete.</param>
    113     void RemoveAlias(string alias);
    114 
    115     /// <summary>
    11694    /// Adds the specified sub scope to the current instance.
    11795    /// </summary>
     
    149127    event EventHandler<VariableEventArgs> VariableRemoved;
    150128    /// <summary>
    151     /// Occurs when an alias has been added to the current instance.
    152     /// </summary>
    153     event EventHandler<AliasEventArgs> AliasAdded;
    154     /// <summary>
    155     /// Occurs when an alias has been removed from the current instance.
    156     /// </summary>
    157     event EventHandler<AliasEventArgs> AliasRemoved;
    158     /// <summary>
    159129    /// Occurs when a sub scope has been added to the current instance.
    160130    /// </summary>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorBase.cs

    r2033 r2042  
    7878
    7979    [Storable]
    80     private List<IOperator> mySubOperators;
    81     /// <summary>
    82     /// Gets a list of all suboperators.
    83     /// <note type="caution"> Returns the suboperators read-only!</note>
    84     /// </summary>
    85     public virtual IList<IOperator> SubOperators {
    86       get { return mySubOperators.AsReadOnly(); }
    87     }
    88 
    89     [Storable]
    90     private Dictionary<string, IVariableInfo> myVariableInfos;
    91     /// <inheritdoc/>
    92     public virtual ICollection<IVariableInfo> VariableInfos {
    93       get { return myVariableInfos.Values; }
    94     }
    95    
    96     private Dictionary<string, IVariable> myVariables;
    97     /// <inheritdoc/>   
    98     public virtual ICollection<IVariable> Variables {
    99       get { return myVariables.Values; }
    100     }
    101 
    102     [Storable(Name="Variables")]
    103     private List<IVariable> VariablePersistence {
    104       get { return new List<IVariable>(myVariables.Values); }
    105       set {
    106         myVariables.Clear();
    107         foreach (IVariable var in value) {
    108           AddVariable(var);
    109         }
    110       }
     80    private Dictionary<string, IParameter> myParameters;
     81    /// <inheritdoc/>
     82    public virtual ICollection<IParameter> Parameters {
     83      get { return myParameters.Values; }
    11184    }
    11285
     
    11992      myCanceled = false;
    12093      myBreakpoint = false;
    121       mySubOperators = new List<IOperator>();
    122       myVariableInfos = new Dictionary<string, IVariableInfo>();
    123       myVariables = new Dictionary<string, IVariable>();
     94      myParameters = new Dictionary<string, IParameter>();
    12495    }
    12596
     
    130101    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    131102    /// <returns>The cloned object as <see cref="OperatorBase"/>.</returns>
    132     public override object Clone(IDictionary<long, object> clonedObjects) {
    133       OperatorBase clone = (OperatorBase)base.Clone(clonedObjects);
     103    public override ICloneable Clone(ICloner cloner) {
     104      OperatorBase clone = (OperatorBase)base.Clone(cloner);
    134105      clone.myName = Name;
    135       clone.mySubOperators.Clear();
    136       for (int i = 0; i < SubOperators.Count; i++)
    137         clone.AddSubOperator((IOperator)Auxiliary.Clone(SubOperators[i], clonedObjects));
    138       clone.myVariableInfos.Clear();
    139       foreach (IVariableInfo variableInfo in myVariableInfos.Values)
    140         clone.AddVariableInfo((IVariableInfo)Auxiliary.Clone(variableInfo, clonedObjects));
    141       clone.myVariables.Clear();
    142       foreach (IVariable variable in myVariables.Values)
    143         clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects));
     106      clone.myParameters.Clear();
     107      foreach (IParameter parameter in myParameters.Values)
     108        clone.AddParameter((IParameter)cloner.Clone(parameter));
    144109      return clone;
    145110    }
     
    154119    }
    155120
    156     #region SubOperator Methods
    157     /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator)"/>
    158     /// <param name="subOperator">The sub operator to add.</param>
    159     /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
    160     public virtual void AddSubOperator(IOperator subOperator) {
    161       mySubOperators.Add(subOperator);
    162       OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);
    163     }
    164     /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator, int)"/>
    165     /// <param name="subOperator">The sub operator to add.</param>
    166     /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
    167     public virtual void AddSubOperator(IOperator subOperator, int index) {
    168       mySubOperators.Insert(index, subOperator);
    169       OnSubOperatorAdded(subOperator, index);
    170     }
    171     /// <inheritdoc/>
    172     /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>
    173     public virtual void RemoveSubOperator(int index) {
    174       IOperator op = mySubOperators[index];
    175       mySubOperators.RemoveAt(index);
    176       OnSubOperatorRemoved(op, index);
    177     }
    178     #endregion
    179 
    180     #region VariableInfo Methods
    181     /// <inheritdoc/>
    182     public virtual IVariableInfo GetVariableInfo(string formalName) {
    183       IVariableInfo info;
    184       if (myVariableInfos.TryGetValue(formalName, out info))
    185         return info;
     121    #region Parameter Methods
     122    /// <inheritdoc/>
     123    public virtual IParameter GetParameter(string name) {
     124      IParameter parameter;
     125      if (myParameters.TryGetValue(name, out parameter))
     126        return parameter;
    186127      else
    187128        return null;
     
    189130    /// <inheritdoc/>
    190131    /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>
    191     public virtual void AddVariableInfo(IVariableInfo variableInfo) {
    192       myVariableInfos.Add(variableInfo.FormalName, variableInfo);
    193       OnVariableInfoAdded(variableInfo);
     132    public virtual void AddParameter(IParameter parameter) {
     133      myParameters.Add(parameter.Name, parameter);
     134      OnParameterAdded(parameter);
    194135    }
    195136    /// <inheritdoc/>
    196137    /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>
    197     public virtual void RemoveVariableInfo(string formalName) {
    198       IVariableInfo variableInfo;
    199       if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {
    200         myVariableInfos.Remove(formalName);
    201         OnVariableInfoRemoved(variableInfo);
    202       }
    203     }
    204     #endregion
    205 
    206     #region Variable Methods
    207     /// <inheritdoc/>
    208     public virtual IVariable GetVariable(string name) {
    209       IVariable variable;
    210       if (myVariables.TryGetValue(name, out variable))
    211         return variable;
    212       else
    213         return null;
    214     }
    215     /// <inheritdoc/>
    216     /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>
    217     /// event handlers.</remarks>
    218     public virtual void AddVariable(IVariable variable) {
    219       myVariables.Add(variable.Name, variable);
    220       variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    221       variable.NameChanged += new EventHandler(Variable_NameChanged);
    222       OnVariableAdded(variable);
    223     }
    224     /// <inheritdoc/>
    225     /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>
    226     /// event handlers.</remarks>
    227     public virtual void RemoveVariable(string name) {
    228       IVariable variable;
    229       if (myVariables.TryGetValue(name, out variable)) {
    230         variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    231         variable.NameChanged -= new EventHandler(Variable_NameChanged);
    232         myVariables.Remove(name);
    233         OnVariableRemoved(variable);
    234       }
    235     }
    236     private void Variable_NameChanging(object sender, NameChangingEventArgs e) {
    237       e.Cancel = myVariables.ContainsKey(e.Name);
    238     }
    239     private void Variable_NameChanged(object sender, EventArgs e) {
    240       IVariable variable = (IVariable)sender;
    241       string oldName = null;
    242       foreach (KeyValuePair<string, IVariable> element in myVariables) {
    243         if (element.Value == variable)
    244           oldName = element.Key;
    245       }
    246       myVariables.Remove(oldName);
    247       myVariables.Add(variable.Name, variable);
    248     }
    249     /// <inheritdoc cref="IOperator.GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool)"/>
    250     ///  <remarks>Calls <see cref="GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool, bool)"/>
    251     /// with <c>throwOnError</c> set to <c>false</c>.</remarks>
    252     public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem {
    253       return GetVariableValue<T>(formalName, scope, recursiveLookup, true);
    254     }
    255     /// <inheritdoc cref="IOperator.GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool, bool)"/>
    256     /// <remarks>Calls
    257     /// <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>.</remarks>
    258     public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem {
    259       return (T)GetVariableValue(formalName, scope, recursiveLookup, throwOnError);
    260     }
    261     /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/>
    262     /// <remarks>Calls <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>
    263     /// with <c>throwOnError</c> set to <c>false</c>.</remarks>
    264     public IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup) {
    265       return GetVariableValue(formalName, scope, recursiveLookup, true);
    266     }
    267     /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>
    268     public virtual IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) {
    269       IVariableInfo info = GetVariableInfo(formalName);
    270       if (info.Local) {
    271         IVariable variable;
    272         if (myVariables.TryGetValue(info.ActualName, out variable))
    273           return variable.Value;
    274         else {
    275           if (throwOnError)
    276             throw new ArgumentException("Variable " + info.ActualName + " not found");
    277           else
    278             return null;
    279         }
    280       } else {
    281         return scope.GetVariableValue(formalName, recursiveLookup, throwOnError);
     138    public virtual void RemoveParameter(string name) {
     139      IParameter parameter;
     140      if (myParameters.TryGetValue(name, out parameter)) {
     141        myParameters.Remove(name);
     142        OnParameterRemoved(parameter);
    282143      }
    283144    }
     
    287148    public virtual IOperation Execute(IScope scope) {
    288149      myCanceled = false;
    289 
    290       foreach (IVariableInfo variableInfo in VariableInfos)
    291         scope.AddAlias(variableInfo.FormalName, variableInfo.ActualName);
    292 
    293150      IOperation next = Apply(scope);
    294 
    295       foreach (IVariableInfo variableInfo in VariableInfos)
    296         scope.RemoveAlias(variableInfo.FormalName);
    297 
    298151      OnExecuted();
    299152      return next;
     
    333186    }
    334187    /// <inheritdoc/>
    335     public event EventHandler<OperatorIndexEventArgs> SubOperatorAdded;
    336     /// <summary>
    337     /// Fires a new <c>SubOperatorAdded</c> event.
    338     /// </summary>
    339     /// <param name="subOperator">The sub operator that has been added.</param>
    340     /// <param name="index">The position where the operator has been added.</param>
    341     protected virtual void OnSubOperatorAdded(IOperator subOperator, int index) {
    342       if (SubOperatorAdded != null)
    343         SubOperatorAdded(this, new OperatorIndexEventArgs(subOperator, index));
    344     }
    345     /// <inheritdoc/>
    346     public event EventHandler<OperatorIndexEventArgs> SubOperatorRemoved;
    347     /// <summary>
    348     /// Fires a new <c>SubOperatorRemoved</c> event.
    349     /// </summary>
    350     /// <param name="subOperator">The sub operator that has been removed.</param>
    351     /// <param name="index">The position where the operator has been removed.</param>
    352     protected virtual void OnSubOperatorRemoved(IOperator subOperator, int index) {
    353       if (SubOperatorRemoved != null)
    354         SubOperatorRemoved(this, new OperatorIndexEventArgs(subOperator, index));
    355     }
    356     /// <inheritdoc/>
    357     public event EventHandler<VariableInfoEventArgs> VariableInfoAdded;
     188    public event EventHandler<ParameterEventArgs> ParameterAdded;
    358189    /// <summary>
    359190    /// Fires a new <c>VariableInfoAdded</c> event.
    360191    /// </summary>
    361192    /// <param name="variableInfo">The variable info that has been added.</param>
    362     protected virtual void OnVariableInfoAdded(IVariableInfo variableInfo) {
    363       if (VariableInfoAdded != null)
    364         VariableInfoAdded(this, new VariableInfoEventArgs(variableInfo));
    365     }
    366     /// <inheritdoc/>
    367     public event EventHandler<VariableInfoEventArgs> VariableInfoRemoved;
     193    protected virtual void OnParameterAdded(IParameter parameter) {
     194      if (ParameterAdded != null)
     195        ParameterAdded(this, new ParameterEventArgs(parameter));
     196    }
     197    /// <inheritdoc/>
     198    public event EventHandler<ParameterEventArgs> ParameterRemoved;
    368199    /// <summary>
    369200    /// Fires a new <c>VariableInfoRemoved</c> event.
    370201    /// </summary>
    371202    /// <param name="variableInfo">The variable info that has been removed.</param>
    372     protected virtual void OnVariableInfoRemoved(IVariableInfo variableInfo) {
    373       if (VariableInfoRemoved != null)
    374         VariableInfoRemoved(this, new VariableInfoEventArgs(variableInfo));
    375     }
    376     /// <inheritdoc/>
    377     public event EventHandler<VariableEventArgs> VariableAdded;
    378     /// <summary>
    379     /// Fires a new <c>VariableAdded</c> event.
    380     /// </summary>
    381     /// <param name="variable">The variable that has been added.</param>
    382     protected virtual void OnVariableAdded(IVariable variable) {
    383       if (VariableAdded != null)
    384         VariableAdded(this, new VariableEventArgs(variable));
    385     }
    386     /// <inheritdoc/>
    387     public event EventHandler<VariableEventArgs> VariableRemoved;
    388     /// <summary>
    389     /// Fires a new <c>VariableRemoved</c> event.
    390     /// </summary>
    391     /// <param name="variable">The variable that has been removed</param>
    392     protected virtual void OnVariableRemoved(IVariable variable) {
    393       if (VariableRemoved != null)
    394         VariableRemoved(this, new VariableEventArgs(variable));
     203    protected virtual void OnParameterRemoved(IParameter parameter) {
     204      if (ParameterRemoved != null)
     205        ParameterRemoved(this, new ParameterEventArgs(parameter));
    395206    }
    396207    /// <inheritdoc/>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorGraph.cs

    r2033 r2042  
    8080    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    8181    /// <returns>The cloned object as <see cref="OperatorGraph"/>.</returns>
    82     public override object Clone(IDictionary<long, object> clonedObjects) {
     82    public override ICloneable Clone(ICloner cloner) {
    8383      OperatorGraph clone = new OperatorGraph();
    84       clonedObjects.Add(clone.Id, clone);
     84      cloner.AddClonedObject(this, clone);
    8585      foreach (IOperator op in Operators)
    86         clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
     86        clone.AddOperator((IOperator)cloner.Clone(op));
    8787      if (InitialOperator != null)
    88         clone.myInitialOperator = (IOperator)Auxiliary.Clone(InitialOperator, clonedObjects);
     88        clone.myInitialOperator = (IOperator)cloner.Clone(InitialOperator);
    8989      return clone;
    9090    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorGroup.cs

    r2033 r2042  
    8484    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    8585    /// <returns>The cloned object as <see cref="OperatorGroup"/>.</returns>
    86     public override object Clone(IDictionary<long, object> clonedObjects) {
    87       OperatorGroup clone = (OperatorGroup)base.Clone(clonedObjects);
     86    public override ICloneable Clone(ICloner cloner) {
     87      OperatorGroup clone = (OperatorGroup)base.Clone(cloner);
    8888      clone.myName = Name;
    8989      foreach (IOperatorGroup group in SubGroups)
    90         clone.AddSubGroup((IOperatorGroup)Auxiliary.Clone(group, clonedObjects));
     90        clone.AddSubGroup((IOperatorGroup)cloner.Clone(group));
    9191      foreach (IOperator op in Operators)
    92         clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
     92        clone.AddOperator((IOperator)cloner.Clone(op));
    9393      return clone;
    9494    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorLibrary.cs

    r2033 r2042  
    7070    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    7171    /// <returns>The cloned object as <see cref="OperatorLibrary"/>.</returns>
    72     public override object Clone(IDictionary<long, object> clonedObjects) {
     72    public override ICloneable Clone(ICloner cloner) {
    7373      OperatorLibrary clone = new OperatorLibrary();
    74       clonedObjects.Add(clone.Id, clone);
    75       clone.myGroup = (IOperatorGroup)Auxiliary.Clone(Group, clonedObjects);
     74      cloner.AddClonedObject(this, clone);
     75      clone.myGroup = (IOperatorGroup)cloner.Clone(Group);
    7676      return clone;
    7777    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Parameter.cs

    r2033 r2042  
    6969    }
    7070
    71     public override object Clone(IDictionary<long, object> clonedObjects) {
     71    public override ICloneable Clone(ICloner cloner) {
    7272      Parameter clone = new Parameter();
    73       clonedObjects.Add(clone.Id, clone);
     73      cloner.AddClonedObject(this, clone);
    7474      clone.myName = Name;
    7575      clone.myDescription = Description;
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Scope.cs

    r2033 r2042  
    6060      }
    6161    }
    62    
    63     [Storable]
    64     private IDictionary<string, string> myAliases;
    65     /// <inheritdoc/>
    66     public IEnumerable<KeyValuePair<string, string>> Aliases {
    67       get { return myAliases; }
    68     }
    6962
    7063    [Storable]
     
    8477      myName = "Anonymous";
    8578      myVariables = new Dictionary<string, IVariable>();
    86       myAliases = new Dictionary<string, string>();
    8779      mySubScopes = new List<IScope>();
    8880    }
     
    177169      }
    178170    }
    179     /// <inheritdoc/>
    180     public string TranslateName(string name) {
    181       while (myAliases.ContainsKey(name))
    182         name = myAliases[name];
    183       if (parent != null)
    184         name = parent.TranslateName(name);
    185       return name;
    186     }
    187     /// <inheritdoc/>
    188     public void AddAlias(string alias, string name) {
    189       RemoveAlias(alias);
    190       if (alias != name) {
    191         myAliases.Add(alias, name);
    192         OnAliasAdded(alias);
    193       }
    194     }
    195     /// <inheritdoc/>
    196     public void RemoveAlias(string alias) {
    197       if (myAliases.ContainsKey(alias)) {
    198         myAliases.Remove(alias);
    199         OnAliasRemoved(alias);
    200       }
    201     }
    202171
    203172    /// <inheritdoc/>
     
    256225
    257226    /// <inheritdoc/>
    258     public override object Clone(IDictionary<long, object> clonedObjects) {
    259       Scope clone = (Scope)base.Clone(clonedObjects);
     227    public override ICloneable Clone(ICloner cloner) {
     228      Scope clone = (Scope)base.Clone(cloner);
    260229      clone.myName = Name;
    261230
    262231      foreach (IVariable variable in myVariables.Values)
    263         clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects));
    264       foreach (KeyValuePair<string, string> alias in myAliases)
    265         clone.AddAlias(alias.Key, alias.Value);
     232        clone.AddVariable((IVariable)cloner.Clone(variable));
    266233      for (int i = 0; i < SubScopes.Count; i++)
    267         clone.AddSubScope((IScope)Auxiliary.Clone(SubScopes[i], clonedObjects));
     234        clone.AddSubScope((IScope)cloner.Clone(SubScopes[i]));
    268235
    269236      return clone;
     
    289256      if (VariableRemoved != null)
    290257        VariableRemoved(this, new VariableEventArgs(variable));
    291     }
    292     /// <inheritdoc />
    293     public event EventHandler<AliasEventArgs> AliasAdded;
    294     /// <summary>
    295     /// Fires a new <c>AliasAdded</c> event.
    296     /// </summary>
    297     /// <param name="alias">The alias that has been added.</param>
    298     protected virtual void OnAliasAdded(string alias) {
    299       if (AliasAdded != null)
    300         AliasAdded(this, new AliasEventArgs(alias));
    301     }
    302     /// <inheritdoc/>
    303     public event EventHandler<AliasEventArgs> AliasRemoved;
    304     /// <summary>
    305     /// Fires a new <c>AliasRemoved</c> event.
    306     /// </summary>
    307     /// <param name="alias">The alias that has been deleted.</param>
    308     protected virtual void OnAliasRemoved(string alias) {
    309       if (AliasRemoved != null)
    310         AliasRemoved(this, new AliasEventArgs(alias));
    311258    }
    312259    /// <inheritdoc/>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Variable.cs

    r2033 r2042  
    102102    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    103103    /// <returns>The cloned object as <see cref="Variable"/>.</returns>
    104     public override object Clone(IDictionary<long, object> clonedObjects) {
     104    public override ICloneable Clone(ICloner cloner) {
    105105      Variable clone = new Variable();
    106       clonedObjects.Add(clone.Id, clone);
     106      cloner.AddClonedObject(this, clone);
    107107      clone.myName = Name;
    108108      if (Value != null)
    109         clone.myValue = (IItem)Auxiliary.Clone(Value, clonedObjects);
     109        clone.myValue = (IItem)cloner.Clone(Value);
    110110      return clone;
    111111    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/VariableInfo.cs

    r2033 r2042  
    145145    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    146146    /// <returns>The cloned object as <see cref="VariableInfo"/>.</returns>
    147     public override object Clone(IDictionary<long, object> clonedObjects) {
     147    public override ICloneable Clone(ICloner cloner) {
    148148      VariableInfo clone = new VariableInfo();
    149       clonedObjects.Add(clone.Id, clone);
     149      cloner.AddClonedObject(this, clone);
    150150      clone.myActualName = ActualName;
    151151      clone.myFormalName = FormalName;
Note: See TracChangeset for help on using the changeset viewer.