Changeset 2027


Ignore:
Timestamp:
06/06/09 02:09:35 (12 years ago)
Author:
swagner
Message:

Refactoring of the operator architecture (#95)

Location:
branches/Operator Architecture Refactoring
Files:
12 added
3 deleted
29 edited

Legend:

Unmodified
Added
Removed
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/EngineBase.cs

    r1815 r2027  
    188188      myExecutionStack.Clear();
    189189      if (OperatorGraph.InitialOperator != null)
    190         myExecutionStack.Push(new AtomicOperation(OperatorGraph.InitialOperator, GlobalScope));
     190        myExecutionStack.Push(new AtomicOperation(OperatorGraph.InitialOperator, new Environment(), GlobalScope));
    191191      OnInitialized();
    192192    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Environment.cs

    r1994 r2027  
    2727namespace HeuristicLab.Core {
    2828  public class Environment : ItemBase, IEnvironment {
    29     private Environment parent;
     29    private IEnvironment parent;
     30    private Dictionary<string, string> aliases;
    3031
    3132    /// <summary>
    3233    /// Initializes a new instance of <see cref="Environment"/>.
    3334    /// </summary>
    34     public Environment() { }
     35    public Environment() {
     36      aliases = new Dictionary<string, string>();
     37    }
    3538    /// <summary>
    3639    /// Initializes a new instance of <see cref="Environment"/> with the given <paramref name="parent"/>.
    3740    /// </summary>
    3841    /// <param name="parnet">The parent environment.</param>
    39     public Environment(Environment parent) {
     42    public Environment(IEnvironment parent)
     43      : this() {
    4044      this.parent = parent;
    4145    }
     
    5155      Environment clone = new Environment();
    5256      clonedObjects.Add(Guid, clone);
    53       clone.parent = (Environment)Auxiliary.Clone(parent, clonedObjects);
     57      clone.parent = (IEnvironment)Auxiliary.Clone(parent, clonedObjects);
    5458      return clone;
     59    }
     60
     61    public void AddAlias(string oldName, string newName) {
     62      aliases.Add(oldName, newName);
     63    }
     64    public void RemoveAlias(string name) {
     65      aliases.Remove(name);
     66    }
     67
     68    public string TranslateName(string name) {
     69      string translatedName = name;
     70      if (aliases.ContainsKey(translatedName))
     71        translatedName = aliases[translatedName];
     72      if (parent != null)
     73        translatedName = parent.TranslateName(translatedName);
     74      return translatedName;
    5575    }
    5676
     
    83103    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    84104      base.Populate(node, restoredObjects);
    85       parent = (Environment)PersistenceManager.Restore(node.SelectSingleNode("ParentEnvironment"), restoredObjects);
     105      parent = (IEnvironment)PersistenceManager.Restore(node.SelectSingleNode("ParentEnvironment"), restoredObjects);
    86106    }
    87107    #endregion
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/HeuristicLab.Core-3.2.csproj

    r1994 r2027  
    126126    </Compile>
    127127    <Compile Include="AliasEventArgs.cs" />
     128    <Compile Include="Interfaces\IVariablesContainer.cs" />
     129    <Compile Include="VariablesContainerView.cs">
     130      <SubType>UserControl</SubType>
     131    </Compile>
     132    <Compile Include="VariablesContainerView.Designer.cs">
     133      <DependentUpon>VariablesContainerView.cs</DependentUpon>
     134    </Compile>
     135    <Compile Include="Parameter.cs" />
     136    <Compile Include="OperatorBaseParametersView.cs">
     137      <SubType>UserControl</SubType>
     138    </Compile>
     139    <Compile Include="OperatorBaseParametersView.Designer.cs">
     140      <DependentUpon>OperatorBaseParametersView.cs</DependentUpon>
     141    </Compile>
     142    <Compile Include="ParameterView.cs">
     143      <SubType>UserControl</SubType>
     144    </Compile>
     145    <Compile Include="ParameterView.Designer.cs">
     146      <DependentUpon>ParameterView.cs</DependentUpon>
     147    </Compile>
    128148    <Compile Include="Environment.cs" />
     149    <Compile Include="OperatorBaseView.cs">
     150      <SubType>UserControl</SubType>
     151    </Compile>
     152    <Compile Include="OperatorBaseView.Designer.cs">
     153      <DependentUpon>OperatorBaseView.cs</DependentUpon>
     154    </Compile>
    129155    <Compile Include="ParameterEventArgs.cs" />
    130156    <Compile Include="ParameterType.cs" />
     
    143169    <Compile Include="NameChangingEventArgs.cs" />
    144170    <Compile Include="OperationEventArgs.cs" />
    145     <Compile Include="OperatorBaseVariablesView.cs">
    146       <SubType>UserControl</SubType>
    147     </Compile>
    148     <Compile Include="OperatorBaseVariablesView.Designer.cs">
    149       <DependentUpon>OperatorBaseVariablesView.cs</DependentUpon>
    150     </Compile>
    151     <Compile Include="OperatorBaseVariableInfosView.cs">
    152       <SubType>UserControl</SubType>
    153     </Compile>
    154     <Compile Include="OperatorBaseVariableInfosView.Designer.cs">
    155       <DependentUpon>OperatorBaseVariableInfosView.cs</DependentUpon>
    156     </Compile>
    157171    <Compile Include="ExceptionEventArgs.cs" />
    158172    <Compile Include="Interfaces\IConstrainedItem.cs" />
     
    200214    <Compile Include="OperatorIndexEventArgs.cs" />
    201215    <Compile Include="ScopeEventArgs.cs" />
    202     <Compile Include="OperatorBaseView.cs">
    203       <SubType>UserControl</SubType>
    204     </Compile>
    205     <Compile Include="OperatorBaseView.Designer.cs">
    206       <DependentUpon>OperatorBaseView.cs</DependentUpon>
    207     </Compile>
    208216    <Compile Include="OperatorGraphView.cs">
    209217      <SubType>UserControl</SubType>
     
    295303      <SubType>Designer</SubType>
    296304    </EmbeddedResource>
     305    <EmbeddedResource Include="OperatorBaseParametersView.resx">
     306      <DependentUpon>OperatorBaseParametersView.cs</DependentUpon>
     307      <SubType>Designer</SubType>
     308    </EmbeddedResource>
     309    <EmbeddedResource Include="VariablesContainerView.resx">
     310      <DependentUpon>VariablesContainerView.cs</DependentUpon>
     311      <SubType>Designer</SubType>
     312    </EmbeddedResource>
     313    <EmbeddedResource Include="ParameterView.resx">
     314      <DependentUpon>ParameterView.cs</DependentUpon>
     315      <SubType>Designer</SubType>
     316    </EmbeddedResource>
    297317    <EmbeddedResource Include="OperatorBaseDescriptionView.resx">
    298318      <DependentUpon>OperatorBaseDescriptionView.cs</DependentUpon>
    299       <SubType>Designer</SubType>
    300     </EmbeddedResource>
    301     <EmbeddedResource Include="OperatorBaseVariablesView.resx">
    302       <DependentUpon>OperatorBaseVariablesView.cs</DependentUpon>
    303       <SubType>Designer</SubType>
    304     </EmbeddedResource>
    305     <EmbeddedResource Include="OperatorBaseVariableInfosView.resx">
    306       <DependentUpon>OperatorBaseVariableInfosView.cs</DependentUpon>
    307319      <SubType>Designer</SubType>
    308320    </EmbeddedResource>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Interfaces/IEnvironment.cs

    r1994 r2027  
    2727  public interface IEnvironment : IItem {
    2828    string TranslateName(string name);
     29
     30    void AddAlias(string oldName, string newName);
     31    void RemoveAlias(string name);
    2932  }
    3033}
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Interfaces/IOperator.cs

    r1994 r2027  
    4949
    5050    /// <summary>
     51    /// Gets a list of all sub operators.
     52    /// </summary>
     53    IList<IOperator> SubOperators { get; }
     54    /// <summary>
    5155    /// Gets a collection of all variable (parameter) infos.
    5256    /// </summary>
    5357    ICollection<IParameter> Parameters { get; }
     58
     59    /// <summary>
     60    /// Adds the given sub operator to the current instance.
     61    /// </summary>
     62    /// <param name="op">The operator to add.</param>
     63    void AddSubOperator(IOperator op);
     64    /// <summary>
     65    /// Adds the given sub operator at a the specified <paramref name="index"/>.
     66    /// </summary>
     67    /// <param name="op">The operator to add.</param>
     68    /// <param name="index">The position where to add the operator.</param>
     69    void AddSubOperator(IOperator op, int index);
     70    /// <summary>
     71    /// Removes a sub operator at the specified <paramref name="index"/>.
     72    /// </summary>
     73    /// <param name="index">The position where to delete the operator.</param>
     74    void RemoveSubOperator(int index);
    5475
    5576    /// <summary>
     
    7596    /// <param name="scope">The scope where to execute the current instance.</param>
    7697    /// <returns>The next operation.</returns>
    77     IOperation Execute(IEnvironment environment, IScope scope);
     98    IOperation Execute(IEnvironment env, IScope scope);
    7899    /// <summary>
    79100    /// Aborts the current operator.
     
    88109    /// Occurs when the breakpoint flag of the current instance was changed.
    89110    /// </summary>
    90     event EventHandler BreakpointChanged;
     111    event EventHandler BreakpointChanged;
     112    /// <summary>
     113    /// Occurs when a sub operator has been added.
     114    /// </summary>
     115    event EventHandler<OperatorIndexEventArgs> SubOperatorAdded;
     116    /// <summary>
     117    /// Occurs when a sub operator has been deleted.
     118    /// </summary>
     119    event EventHandler<OperatorIndexEventArgs> SubOperatorRemoved;
    91120    /// <summary>
    92121    /// Occurs when a variable info has been added.
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Interfaces/IScope.cs

    r1994 r2027  
    2929  /// Interface for a hierarchical container of variables (containing variables and subscopes).
    3030  /// </summary>
    31   public interface IScope : IItem {
     31  public interface IScope : IItem, IVariablesContainer {
    3232    /// <summary>
    3333    /// Gets the name of the current instance.
     
    3535    string Name { get; }
    3636
    37     /// <summary>
    38     /// Gets the varibles of the current scope.
    39     /// </summary>
    40     ICollection<IVariable> Variables { get; }
    4137    /// <summary>
    4238    /// Gets all subscopes in the current scope.
     
    5046    void SetParent(IScope scope);
    5147
    52     /// <summary>
    53     /// Gets a variable with the given <paramref name="name"/>.
    54     /// </summary>
    55     /// <param name="name">The name of the variable.</param>
    56     /// <returns>The variable with the specified name.</returns>
    57     IVariable GetVariable(string name);
    58     /// <summary>
    59     /// Adds the specified variable to the curent instance.
    60     /// </summary>
    61     /// <param name="variable">The variable to add.</param>
    62     void AddVariable(IVariable variable);
    63     /// <summary>
    64     /// Deletes a variable with the specified <paramref name="name"/> from the current instance.
    65     /// </summary>
    66     /// <param name="name">The name of the variable to delete.</param>
    67     void RemoveVariable(string name);
    68    
    6948    /// <inheritdoc cref="GetVariableValue(string, bool)"/>
    7049    /// <typeparam name="T">The type of the value that is searched.</typeparam>
     
    125104
    126105    /// <summary>
    127     /// Occurs when a variable has been added to the current instance.
    128     /// </summary>
    129     event EventHandler<VariableEventArgs> VariableAdded;
    130     /// <summary>
    131     /// Occurs when a variable has been deleted from the current instance.
    132     /// </summary>
    133     event EventHandler<VariableEventArgs> VariableRemoved;
    134     /// <summary>
    135106    /// Occurs when a sub scope has been added to the current instance.
    136107    /// </summary>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/OperatorBase.cs

    r1851 r2027  
    2929  /// The base class for all operators.
    3030  /// </summary>
    31   public abstract class OperatorBase : ConstrainedItemBase, IOperator {
     31  public abstract class OperatorBase : ItemBase, IOperator {
    3232    private string myName;
    3333    /// <summary>
     
    8080      get { return mySubOperators.AsReadOnly(); }
    8181    }
    82     private Dictionary<string, IVariableInfo> myVariableInfos;
    83     /// <inheritdoc/>
    84     public virtual ICollection<IVariableInfo> VariableInfos {
    85       get { return myVariableInfos.Values; }
    86     }
    87     private Dictionary<string, IVariable> myVariables;
    88     /// <inheritdoc/>
    89     public virtual ICollection<IVariable> Variables {
    90       get { return myVariables.Values; }
     82    private Dictionary<string, IParameter> myParameters;
     83    /// <inheritdoc/>
     84    public virtual ICollection<IParameter> Parameters {
     85      get { return myParameters.Values; }
    9186    }
    9287
     
    10095      myBreakpoint = false;
    10196      mySubOperators = new List<IOperator>();
    102       myVariableInfos = new Dictionary<string, IVariableInfo>();
    103       myVariables = new Dictionary<string, IVariable>();
     97      myParameters = new Dictionary<string, IParameter>();
    10498    }
    10599
     
    116110      for (int i = 0; i < SubOperators.Count; i++)
    117111        clone.AddSubOperator((IOperator)Auxiliary.Clone(SubOperators[i], clonedObjects));
    118       clone.myVariableInfos.Clear();
    119       foreach (IVariableInfo variableInfo in myVariableInfos.Values)
    120         clone.AddVariableInfo((IVariableInfo)Auxiliary.Clone(variableInfo, clonedObjects));
    121       clone.myVariables.Clear();
    122       foreach (IVariable variable in myVariables.Values)
    123         clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects));
     112      clone.myParameters.Clear();
     113      foreach (IParameter parameter in myParameters.Values)
     114        clone.AddParameter((IParameter)Auxiliary.Clone(parameter, clonedObjects));
    124115      return clone;
    125116    }
     
    142133      OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);
    143134    }
    144     /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator)"/>
    145     /// <param name="subOperator">The sub operator to add.</param>
    146     /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
    147     public virtual bool TryAddSubOperator(IOperator subOperator) {
    148       mySubOperators.Add(subOperator);
    149       if (IsValid()) {
    150         OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);
    151         return true;
    152       } else {
    153         mySubOperators.RemoveAt(mySubOperators.Count - 1);
    154         return false;
    155       }
    156     }
    157     /// <inheritdoc cref="HeuristicLab.Core.IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator,
    158     /// out System.Collections.Generic.ICollection&lt;HeuristicLab.Core.IConstraint&gt;)"/>
    159     /// <param name="subOperator">The sub operator to add.</param>
    160     /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
    161     public virtual bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {
    162       mySubOperators.Add(subOperator);
    163       if (IsValid(out violatedConstraints)) {
    164         OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);
    165         return true;
    166       } else {
    167         mySubOperators.RemoveAt(mySubOperators.Count - 1);
    168         return false;
    169       }
    170     }
    171135    /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator, int)"/>
    172136    /// <param name="subOperator">The sub operator to add.</param>
     
    176140      OnSubOperatorAdded(subOperator, index);
    177141    }
    178     /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int)"/>
    179     /// <param name="subOperator">The sub operator to add.</param>
    180     /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
    181     public virtual bool TryAddSubOperator(IOperator subOperator, int index) {
    182       mySubOperators.Insert(index, subOperator);
    183       if (IsValid()) {
    184         OnSubOperatorAdded(subOperator, index);
    185         return true;
    186       } else {
    187         mySubOperators.RemoveAt(index);
    188         return false;
    189       }
    190     }
    191     /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int, out
    192     /// System.Collections.Generic.ICollection&lt;HeuristicLab.Core.IConstraint&gt;)"/>
    193     /// <param name="subOperator">The sub operator to add.</param>
    194     /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
    195     public virtual bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {
    196       mySubOperators.Insert(index, subOperator);
    197       if (IsValid(out violatedConstraints)) {
    198         OnSubOperatorAdded(subOperator, index);
    199         return true;
    200       } else {
    201         mySubOperators.RemoveAt(index);
    202         return false;
    203       }
    204     }
    205142    /// <inheritdoc/>
    206143    /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>
     
    210147      OnSubOperatorRemoved(op, index);
    211148    }
    212     /// <inheritdoc/>
    213     /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>
    214     public virtual bool TryRemoveSubOperator(int index) {
    215       IOperator op = mySubOperators[index];
    216       mySubOperators.RemoveAt(index);
    217       if (IsValid()) {
    218         OnSubOperatorRemoved(op, index);
    219         return true;
    220       } else {
    221         mySubOperators.Insert(index, op);
    222         return false;
    223       }
    224     }
    225     /// <inheritdoc/>
    226     /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>
    227     public virtual bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {
    228       IOperator op = mySubOperators[index];
    229       mySubOperators.RemoveAt(index);
    230       if (IsValid(out violatedConstraints)) {
    231         OnSubOperatorRemoved(op, index);
    232         return true;
    233       } else {
    234         mySubOperators.Insert(index, op);
    235         return false;
    236       }
    237     }
    238149    #endregion
    239150
    240     #region VariableInfo Methods
    241     /// <inheritdoc/>
    242     public virtual IVariableInfo GetVariableInfo(string formalName) {
    243       IVariableInfo info;
    244       if (myVariableInfos.TryGetValue(formalName, out info))
     151    #region Parameter Methods
     152    /// <inheritdoc/>
     153    public virtual IParameter GetParameter(string name) {
     154      IParameter info;
     155      if (myParameters.TryGetValue(name, out info))
    245156        return info;
    246157      else
     
    249160    /// <inheritdoc/>
    250161    /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>
    251     public virtual void AddVariableInfo(IVariableInfo variableInfo) {
    252       myVariableInfos.Add(variableInfo.FormalName, variableInfo);
    253       OnVariableInfoAdded(variableInfo);
    254     }
    255     /// <inheritdoc/>
    256     /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>
    257     public virtual bool TryAddVariableInfo(IVariableInfo variableInfo) {
    258       myVariableInfos.Add(variableInfo.FormalName, variableInfo);
    259       if (IsValid()) {
    260         OnVariableInfoAdded(variableInfo);
    261         return true;
    262       } else {
    263         myVariableInfos.Remove(variableInfo.FormalName);
    264         return false;
    265       }
    266     }
    267     /// <inheritdoc/>
    268     /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>
    269     public virtual bool TryAddVariableInfo(IVariableInfo variableInfo, out ICollection<IConstraint> violatedConstraints) {
    270       myVariableInfos.Add(variableInfo.FormalName, variableInfo);
    271       if (IsValid(out violatedConstraints)) {
    272         OnVariableInfoAdded(variableInfo);
    273         return true;
    274       } else {
    275         myVariableInfos.Remove(variableInfo.FormalName);
    276         return false;
    277       }
     162    public virtual void AddParameter(IParameter parameter) {
     163      myParameters.Add(parameter.Name, parameter);
     164      OnParameterAdded(parameter);
    278165    }
    279166    /// <inheritdoc/>
    280167    /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>
    281     public virtual void RemoveVariableInfo(string formalName) {
    282       IVariableInfo variableInfo;
    283       if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {
    284         myVariableInfos.Remove(formalName);
    285         OnVariableInfoRemoved(variableInfo);
    286       }
    287     }
    288     /// <inheritdoc/>
    289     /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>
    290     public virtual bool TryRemoveVariableInfo(string formalName) {
    291       IVariableInfo variableInfo;
    292       if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {
    293         myVariableInfos.Remove(formalName);
    294         if (IsValid()) {
    295           OnVariableInfoRemoved(variableInfo);
    296           return true;
    297         } else {
    298           myVariableInfos.Add(formalName, variableInfo);
    299           return false;
    300         }
    301       }
    302       return true;
    303     }
    304     /// <inheritdoc/>
    305     /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>
    306     public virtual bool TryRemoveVariableInfo(string formalName, out ICollection<IConstraint> violatedConstraints) {
    307       IVariableInfo variableInfo;
    308       if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {
    309         myVariableInfos.Remove(formalName);
    310         if (IsValid(out violatedConstraints)) {
    311           OnVariableInfoRemoved(variableInfo);
    312           return true;
    313         } else {
    314           myVariableInfos.Add(formalName, variableInfo);
    315           return false;
    316         }
    317       }
    318       violatedConstraints = new List<IConstraint>();
    319       return true;
     168    public virtual void RemoveParameter(string name) {
     169      IParameter parameter;
     170      if (myParameters.TryGetValue(name, out parameter)) {
     171        myParameters.Remove(name);
     172        OnParameterRemoved(parameter);
     173      }
    320174    }
    321175    #endregion
    322176
    323     #region Variable Methods
    324     /// <inheritdoc/>
    325     public virtual IVariable GetVariable(string name) {
    326       IVariable variable;
    327       if (myVariables.TryGetValue(name, out variable))
    328         return variable;
    329       else
    330         return null;
    331     }
    332     /// <inheritdoc/>
    333     /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>
    334     /// event handlers.</remarks>
    335     public virtual void AddVariable(IVariable variable) {
    336       myVariables.Add(variable.Name, variable);
    337       variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    338       variable.NameChanged += new EventHandler(Variable_NameChanged);
    339       OnVariableAdded(variable);
    340     }
    341     /// <inheritdoc/>
    342     /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>
    343     /// event handlers.</remarks>
    344     public virtual bool TryAddVariable(IVariable variable) {
    345       myVariables.Add(variable.Name, variable);
    346       if (IsValid()) {
    347         variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    348         variable.NameChanged += new EventHandler(Variable_NameChanged);
    349         OnVariableAdded(variable);
    350         return true;
    351       } else {
    352         myVariableInfos.Remove(variable.Name);
    353         return false;
    354       }
    355     }
    356     /// <inheritdoc/>
    357     /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>
    358     /// event handlers.</remarks>
    359     public virtual bool TryAddVariable(IVariable variable, out ICollection<IConstraint> violatedConstraints) {
    360       myVariables.Add(variable.Name, variable);
    361       if (IsValid(out violatedConstraints)) {
    362         variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    363         variable.NameChanged += new EventHandler(Variable_NameChanged);
    364         OnVariableAdded(variable);
    365         return true;
    366       } else {
    367         myVariableInfos.Remove(variable.Name);
    368         return false;
    369       }
    370     }
    371     /// <inheritdoc/>
    372     /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>
    373     /// event handlers.</remarks>
    374     public virtual void RemoveVariable(string name) {
    375       IVariable variable;
    376       if (myVariables.TryGetValue(name, out variable)) {
    377         variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    378         variable.NameChanged -= new EventHandler(Variable_NameChanged);
    379         myVariables.Remove(name);
    380         OnVariableRemoved(variable);
    381       }
    382     }
    383     /// <inheritdoc/>
    384     /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>
    385     /// event handlers.</remarks>
    386     public virtual bool TryRemoveVariable(string name) {
    387       IVariable variable;
    388       if (myVariables.TryGetValue(name, out variable)) {
    389         myVariables.Remove(name);
    390         if (IsValid()) {
    391           variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    392           variable.NameChanged -= new EventHandler(Variable_NameChanged);
    393           OnVariableRemoved(variable);
    394           return true;
    395         } else {
    396           myVariables.Add(name, variable);
    397           return false;
    398         }
    399       }
    400       return true;
    401     }
    402     /// <inheritdoc/>
    403     /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>
    404     /// event handlers.</remarks>
    405     public virtual bool TryRemoveVariable(string name, out ICollection<IConstraint> violatedConstraints) {
    406       IVariable variable;
    407       if (myVariables.TryGetValue(name, out variable)) {
    408         myVariables.Remove(name);
    409         if (IsValid(out violatedConstraints)) {
    410           variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    411           variable.NameChanged -= new EventHandler(Variable_NameChanged);
    412           OnVariableRemoved(variable);
    413           return true;
    414         } else {
    415           myVariables.Add(name, variable);
    416           return false;
    417         }
    418       }
    419       violatedConstraints = new List<IConstraint>();
    420       return true;
    421     }
    422     private void Variable_NameChanging(object sender, NameChangingEventArgs e) {
    423       e.Cancel = myVariables.ContainsKey(e.Name);
    424     }
    425     private void Variable_NameChanged(object sender, EventArgs e) {
    426       IVariable variable = (IVariable)sender;
    427       string oldName = null;
    428       foreach (KeyValuePair<string, IVariable> element in myVariables) {
    429         if (element.Value == variable)
    430           oldName = element.Key;
    431       }
    432       myVariables.Remove(oldName);
    433       myVariables.Add(variable.Name, variable);
    434     }
    435     /// <inheritdoc cref="IOperator.GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool)"/>
    436     ///  <remarks>Calls <see cref="GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool, bool)"/>
    437     /// with <c>throwOnError</c> set to <c>false</c>.</remarks>
    438     public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem {
    439       return GetVariableValue<T>(formalName, scope, recursiveLookup, true);
    440     }
    441     /// <inheritdoc cref="IOperator.GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool, bool)"/>
    442     /// <remarks>Calls
    443     /// <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>.</remarks>
    444     public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem {
    445       return (T)GetVariableValue(formalName, scope, recursiveLookup, throwOnError);
    446     }
    447     /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/>
    448     /// <remarks>Calls <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>
    449     /// with <c>throwOnError</c> set to <c>false</c>.</remarks>
    450     public IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup) {
    451       return GetVariableValue(formalName, scope, recursiveLookup, true);
    452     }
    453     /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>
    454     public virtual IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) {
    455       IVariableInfo info = GetVariableInfo(formalName);
    456       if (info.Local) {
    457         IVariable variable;
    458         if (myVariables.TryGetValue(info.ActualName, out variable))
    459           return variable.Value;
    460         else {
    461           if (throwOnError)
    462             throw new ArgumentException("Variable " + info.ActualName + " not found");
    463           else
    464             return null;
    465         }
    466       } else {
    467         return scope.GetVariableValue(formalName, recursiveLookup, throwOnError);
    468       }
    469     }
    470     #endregion
    471     /// <inheritdoc/>
    472     public virtual IOperation Execute(IScope scope) {
     177    /// <inheritdoc/>
     178    public virtual IOperation Execute(IEnvironment env, IScope scope) {
    473179      myCanceled = false;
    474180
    475       foreach (IVariableInfo variableInfo in VariableInfos)
    476         scope.AddAlias(variableInfo.FormalName, variableInfo.ActualName);
    477 
    478       IOperation next = Apply(scope);
    479 
    480       foreach (IVariableInfo variableInfo in VariableInfos)
    481         scope.RemoveAlias(variableInfo.FormalName);
     181      IOperation next = Apply(env, scope);
    482182
    483183      OnExecuted();
     
    494194    /// <param name="scope">The scope where to execute the operator</param>
    495195    /// <returns><c>null</c>.</returns>
    496     public virtual IOperation Apply(IScope scope) {
     196    public virtual IOperation Apply(IEnvironment env, IScope scope) {
    497197      return null;
    498198    }
     
    540240    }
    541241    /// <inheritdoc/>
    542     public event EventHandler<VariableInfoEventArgs> VariableInfoAdded;
    543     /// <summary>
    544     /// Fires a new <c>VariableInfoAdded</c> event.
    545     /// </summary>
    546     /// <param name="variableInfo">The variable info that has been added.</param>
    547     protected virtual void OnVariableInfoAdded(IVariableInfo variableInfo) {
    548       if (VariableInfoAdded != null)
    549         VariableInfoAdded(this, new VariableInfoEventArgs(variableInfo));
    550     }
    551     /// <inheritdoc/>
    552     public event EventHandler<VariableInfoEventArgs> VariableInfoRemoved;
    553     /// <summary>
    554     /// Fires a new <c>VariableInfoRemoved</c> event.
    555     /// </summary>
    556     /// <param name="variableInfo">The variable info that has been removed.</param>
    557     protected virtual void OnVariableInfoRemoved(IVariableInfo variableInfo) {
    558       if (VariableInfoRemoved != null)
    559         VariableInfoRemoved(this, new VariableInfoEventArgs(variableInfo));
    560     }
    561     /// <inheritdoc/>
    562     public event EventHandler<VariableEventArgs> VariableAdded;
    563     /// <summary>
    564     /// Fires a new <c>VariableAdded</c> event.
    565     /// </summary>
    566     /// <param name="variable">The variable that has been added.</param>
    567     protected virtual void OnVariableAdded(IVariable variable) {
    568       if (VariableAdded != null)
    569         VariableAdded(this, new VariableEventArgs(variable));
    570     }
    571     /// <inheritdoc/>
    572     public event EventHandler<VariableEventArgs> VariableRemoved;
    573     /// <summary>
    574     /// Fires a new <c>VariableRemoved</c> event.
    575     /// </summary>
    576     /// <param name="variable">The variable that has been removed</param>
    577     protected virtual void OnVariableRemoved(IVariable variable) {
    578       if (VariableRemoved != null)
    579         VariableRemoved(this, new VariableEventArgs(variable));
     242    public event EventHandler<ParameterEventArgs> ParameterAdded;
     243    /// <summary>
     244    /// Fires a new <c>ParameterAdded</c> event.
     245    /// </summary>
     246    /// <param name="parameter">The parameter that has been added.</param>
     247    protected virtual void OnParameterAdded(IParameter parameter) {
     248      if (ParameterAdded != null)
     249        ParameterAdded(this, new ParameterEventArgs(parameter));
     250    }
     251    /// <inheritdoc/>
     252    public event EventHandler<ParameterEventArgs> ParameterRemoved;
     253    /// <summary>
     254    /// Fires a new <c>ParameterRemoved</c> event.
     255    /// </summary>
     256    /// <param name="parameter">The parameter that has been removed.</param>
     257    protected virtual void OnParameterRemoved(IParameter parameter) {
     258      if (ParameterRemoved != null)
     259        ParameterRemoved(this, new ParameterEventArgs(parameter));
    580260    }
    581261    /// <inheritdoc/>
     
    642322        subOperatorsNode.AppendChild(PersistenceManager.Persist(SubOperators[i], document, persistedObjects));
    643323      node.AppendChild(subOperatorsNode);
    644       XmlNode infosNode = document.CreateNode(XmlNodeType.Element, "VariableInfos", null);
    645       foreach (IVariableInfo info in myVariableInfos.Values)
    646         infosNode.AppendChild(PersistenceManager.Persist(info, document, persistedObjects));
    647       node.AppendChild(infosNode);
    648       XmlNode variablesNode = document.CreateNode(XmlNodeType.Element, "Variables", null);
    649       foreach (IVariable variable in myVariables.Values)
    650         variablesNode.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects));
    651       node.AppendChild(variablesNode);
     324      XmlNode parametersNode = document.CreateNode(XmlNodeType.Element, "Parameters", null);
     325      foreach (IParameter parameter in myParameters.Values)
     326        parametersNode.AppendChild(PersistenceManager.Persist(parameter, document, persistedObjects));
     327      node.AppendChild(parametersNode);
    652328      return node;
    653329    }
     
    668344      for (int i = 0; i < subOperatorsNode.ChildNodes.Count; i++)
    669345        AddSubOperator((IOperator)PersistenceManager.Restore(subOperatorsNode.ChildNodes[i], restoredObjects));
    670       XmlNode infosNode = node.SelectSingleNode("VariableInfos");
    671       myVariableInfos.Clear();
    672       foreach (XmlNode infoNode in infosNode.ChildNodes)
    673         AddVariableInfo((IVariableInfo)PersistenceManager.Restore(infoNode, restoredObjects));
    674       XmlNode variablesNode = node.SelectSingleNode("Variables");
    675       myVariables.Clear();
    676       foreach (XmlNode variableNode in variablesNode.ChildNodes)
    677         AddVariable((IVariable)PersistenceManager.Restore(variableNode, restoredObjects));
     346      XmlNode parametersNode = node.SelectSingleNode("Parameters");
     347      myParameters.Clear();
     348      foreach (XmlNode parameterNode in parametersNode.ChildNodes)
     349        AddParameter((IParameter)PersistenceManager.Restore(parameterNode, restoredObjects));
    678350    }
    679351    #endregion
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/OperatorBaseView.Designer.cs

    r1529 r2027  
    4949    private void InitializeComponent() {
    5050      this.tabControl = new System.Windows.Forms.TabControl();
    51       this.variableInfosTabPage = new System.Windows.Forms.TabPage();
    52       this.operatorBaseVariableInfosView = new HeuristicLab.Core.OperatorBaseVariableInfosView();
    53       this.variablesTabPage = new System.Windows.Forms.TabPage();
    54       this.operatorBaseVariablesView = new HeuristicLab.Core.OperatorBaseVariablesView();
    55       this.constraintsTabPage = new System.Windows.Forms.TabPage();
    56       this.constrainedItemBaseView = new HeuristicLab.Core.ConstrainedItemBaseView();
     51      this.parametersTabPage = new System.Windows.Forms.TabPage();
     52      this.operatorBaseParametersView = new HeuristicLab.Core.OperatorBaseParametersView();
    5753      this.descriptionTabPage = new System.Windows.Forms.TabPage();
    5854      this.operatorBaseDescriptionView = new HeuristicLab.Core.OperatorBaseDescriptionView();
    5955      this.tabControl.SuspendLayout();
    60       this.variableInfosTabPage.SuspendLayout();
    61       this.variablesTabPage.SuspendLayout();
    62       this.constraintsTabPage.SuspendLayout();
     56      this.parametersTabPage.SuspendLayout();
    6357      this.descriptionTabPage.SuspendLayout();
    6458      this.SuspendLayout();
     
    6660      // tabControl
    6761      //
    68       this.tabControl.Controls.Add(this.variableInfosTabPage);
    69       this.tabControl.Controls.Add(this.variablesTabPage);
    70       this.tabControl.Controls.Add(this.constraintsTabPage);
     62      this.tabControl.Controls.Add(this.parametersTabPage);
    7163      this.tabControl.Controls.Add(this.descriptionTabPage);
    7264      this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
     
    7769      this.tabControl.TabIndex = 0;
    7870      //
    79       // variableInfosTabPage
     71      // parametersTabPage
    8072      //
    81       this.variableInfosTabPage.Controls.Add(this.operatorBaseVariableInfosView);
    82       this.variableInfosTabPage.Location = new System.Drawing.Point(4, 22);
    83       this.variableInfosTabPage.Name = "variableInfosTabPage";
    84       this.variableInfosTabPage.Padding = new System.Windows.Forms.Padding(3);
    85       this.variableInfosTabPage.Size = new System.Drawing.Size(415, 307);
    86       this.variableInfosTabPage.TabIndex = 0;
    87       this.variableInfosTabPage.Text = "Variable Infos";
    88       this.variableInfosTabPage.UseVisualStyleBackColor = true;
     73      this.parametersTabPage.Controls.Add(this.operatorBaseParametersView);
     74      this.parametersTabPage.Location = new System.Drawing.Point(4, 22);
     75      this.parametersTabPage.Name = "parametersTabPage";
     76      this.parametersTabPage.Padding = new System.Windows.Forms.Padding(3);
     77      this.parametersTabPage.Size = new System.Drawing.Size(415, 307);
     78      this.parametersTabPage.TabIndex = 0;
     79      this.parametersTabPage.Text = "Parameters";
     80      this.parametersTabPage.UseVisualStyleBackColor = true;
    8981      //
    9082      // operatorBaseVariableInfosView
    9183      //
    92       this.operatorBaseVariableInfosView.Caption = "Operator";
    93       this.operatorBaseVariableInfosView.Dock = System.Windows.Forms.DockStyle.Fill;
    94       this.operatorBaseVariableInfosView.Location = new System.Drawing.Point(3, 3);
    95       this.operatorBaseVariableInfosView.Name = "operatorBaseVariableInfosView";
    96       this.operatorBaseVariableInfosView.Operator = null;
    97       this.operatorBaseVariableInfosView.Size = new System.Drawing.Size(409, 301);
    98       this.operatorBaseVariableInfosView.TabIndex = 0;
    99       //
    100       // variablesTabPage
    101       //
    102       this.variablesTabPage.Controls.Add(this.operatorBaseVariablesView);
    103       this.variablesTabPage.Location = new System.Drawing.Point(4, 22);
    104       this.variablesTabPage.Name = "variablesTabPage";
    105       this.variablesTabPage.Padding = new System.Windows.Forms.Padding(3);
    106       this.variablesTabPage.Size = new System.Drawing.Size(415, 307);
    107       this.variablesTabPage.TabIndex = 1;
    108       this.variablesTabPage.Text = "Local Variables";
    109       this.variablesTabPage.UseVisualStyleBackColor = true;
    110       //
    111       // operatorBaseVariablesView
    112       //
    113       this.operatorBaseVariablesView.Caption = "Operator";
    114       this.operatorBaseVariablesView.Dock = System.Windows.Forms.DockStyle.Fill;
    115       this.operatorBaseVariablesView.Location = new System.Drawing.Point(3, 3);
    116       this.operatorBaseVariablesView.Name = "operatorBaseVariablesView";
    117       this.operatorBaseVariablesView.Operator = null;
    118       this.operatorBaseVariablesView.Size = new System.Drawing.Size(409, 301);
    119       this.operatorBaseVariablesView.TabIndex = 0;
    120       //
    121       // constraintsTabPage
    122       //
    123       this.constraintsTabPage.Controls.Add(this.constrainedItemBaseView);
    124       this.constraintsTabPage.Location = new System.Drawing.Point(4, 22);
    125       this.constraintsTabPage.Name = "constraintsTabPage";
    126       this.constraintsTabPage.Padding = new System.Windows.Forms.Padding(3);
    127       this.constraintsTabPage.Size = new System.Drawing.Size(415, 307);
    128       this.constraintsTabPage.TabIndex = 2;
    129       this.constraintsTabPage.Text = "Constraints";
    130       this.constraintsTabPage.UseVisualStyleBackColor = true;
    131       //
    132       // constrainedItemBaseView
    133       //
    134       this.constrainedItemBaseView.Caption = "Constrained Data";
    135       this.constrainedItemBaseView.ConstrainedItem = null;
    136       this.constrainedItemBaseView.Dock = System.Windows.Forms.DockStyle.Fill;
    137       this.constrainedItemBaseView.Location = new System.Drawing.Point(3, 3);
    138       this.constrainedItemBaseView.Name = "constrainedItemBaseView";
    139       this.constrainedItemBaseView.Size = new System.Drawing.Size(409, 301);
    140       this.constrainedItemBaseView.TabIndex = 0;
     84      this.operatorBaseParametersView.Caption = "Operator";
     85      this.operatorBaseParametersView.Dock = System.Windows.Forms.DockStyle.Fill;
     86      this.operatorBaseParametersView.Location = new System.Drawing.Point(3, 3);
     87      this.operatorBaseParametersView.Name = "operatorBaseVariableInfosView";
     88      this.operatorBaseParametersView.Operator = null;
     89      this.operatorBaseParametersView.Size = new System.Drawing.Size(409, 301);
     90      this.operatorBaseParametersView.TabIndex = 0;
    14191      //
    14292      // descriptionTabPage
     
    170120      this.Size = new System.Drawing.Size(423, 333);
    171121      this.tabControl.ResumeLayout(false);
    172       this.variableInfosTabPage.ResumeLayout(false);
    173       this.variablesTabPage.ResumeLayout(false);
    174       this.constraintsTabPage.ResumeLayout(false);
     122      this.parametersTabPage.ResumeLayout(false);
    175123      this.descriptionTabPage.ResumeLayout(false);
    176124      this.ResumeLayout(false);
     
    181129
    182130    protected TabControl tabControl;
    183     protected TabPage variableInfosTabPage;
    184     protected TabPage variablesTabPage;
    185     private TabPage constraintsTabPage;
    186     protected ConstrainedItemBaseView constrainedItemBaseView;
    187     protected OperatorBaseVariableInfosView operatorBaseVariableInfosView;
    188     protected OperatorBaseVariablesView operatorBaseVariablesView;
     131    protected TabPage parametersTabPage;
     132    protected OperatorBaseParametersView operatorBaseParametersView;
    189133    private TabPage descriptionTabPage;
    190134    private OperatorBaseDescriptionView operatorBaseDescriptionView;
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/OperatorBaseView.cs

    r1529 r2027  
    6666    /// </summary>
    6767    protected override void RemoveItemEvents() {
    68       operatorBaseVariableInfosView.Operator = null;
    69       operatorBaseVariablesView.Operator = null;
    70       constrainedItemBaseView.ConstrainedItem = null;
     68      operatorBaseParametersView.Operator = null;
    7169      operatorBaseDescriptionView.Operator = null;
    7270      base.RemoveItemEvents();
     
    7775    protected override void AddItemEvents() {
    7876      base.AddItemEvents();
    79       operatorBaseVariableInfosView.Operator = Operator;
    80       operatorBaseVariablesView.Operator = Operator;
    81       constrainedItemBaseView.ConstrainedItem = Operator;
     77      operatorBaseParametersView.Operator = Operator;
    8278      operatorBaseDescriptionView.Operator = Operator;
    8379    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/OperatorGraphView.cs

    r1529 r2027  
    350350              IOperator newParent = (IOperator)node.Parent.Tag;
    351351              int newIndex = node.Index;
    352               ICollection<IConstraint> violatedConstraints;
    353               ICollection<IConstraint> violatedConstraints2;
    354               oldParent.TryRemoveSubOperator(oldIndex, out violatedConstraints);
    355               newParent.TryAddSubOperator(op, newIndex, out violatedConstraints2);
    356               if ((violatedConstraints.Count == 0) && (violatedConstraints2.Count == 0)) {
    357                 graphTreeView.SelectedNode = parentNode.Nodes[newIndex];
    358               } else {
    359                 List<IConstraint> allViolatedConstraints = new List<IConstraint>(violatedConstraints);
    360                 allViolatedConstraints.AddRange(violatedConstraints2);
    361                 if (Auxiliary.ShowIgnoreConstraintViolationMessageBox(allViolatedConstraints) == DialogResult.Yes) {
    362                   if (violatedConstraints.Count > 0)
    363                     oldParent.RemoveSubOperator(oldIndex);
    364                   if (violatedConstraints2.Count > 0)
    365                     newParent.AddSubOperator(op, newIndex);
    366                   graphTreeView.SelectedNode = parentNode.Nodes[newIndex];
    367                 } else {
    368                   if (violatedConstraints.Count == 0)
    369                     oldParent.AddSubOperator(op, oldIndex);
    370                   if (violatedConstraints2.Count == 0)
    371                     newParent.RemoveSubOperator(newIndex);
    372                 }
    373               }
     352              oldParent.RemoveSubOperator(oldIndex);
     353              newParent.AddSubOperator(op, newIndex);
     354              graphTreeView.SelectedNode = parentNode.Nodes[newIndex];
    374355            }
    375356          } else {
    376357            if (node != null) {
    377358              IOperator parent = (IOperator)node.Tag;
    378               ICollection<IConstraint> violatedConstraints;
    379               if (parent.TryAddSubOperator(op, out violatedConstraints)) {
    380                 graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1];
    381               } else if (Auxiliary.ShowIgnoreConstraintViolationMessageBox(violatedConstraints) == DialogResult.Yes) {
    382                 parent.AddSubOperator(op);
    383                 graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1];
    384               }
     359              parent.AddSubOperator(op);
     360              graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1];
    385361            }
    386362          }
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Scope.cs

    r1529 r2027  
    4545      get { return myVariables.Values; }
    4646    }
    47     private IDictionary<string, string> myAliases;
    48     /// <inheritdoc/>
    49     public IEnumerable<KeyValuePair<string, string>> Aliases {
    50       get { return myAliases; }
    51     }
    5247    private List<IScope> mySubScopes;
    5348    /// <summary>
     
    6560      myName = "Anonymous";
    6661      myVariables = new Dictionary<string, IVariable>();
    67       myAliases = new Dictionary<string, string>();
    6862      mySubScopes = new List<IScope>();
    6963    }
     
    144138    public IItem GetVariableValue(string name, bool recursiveLookup, bool throwOnError) {
    145139      IVariable variable;
    146       name = TranslateName(name);
    147140      if (myVariables.TryGetValue(name, out variable)) {
    148141        return variable.Value;
     
    158151      }
    159152    }
    160     /// <inheritdoc/>
    161     public string TranslateName(string name) {
    162       while (myAliases.ContainsKey(name))
    163         name = myAliases[name];
    164       if (parent != null)
    165         name = parent.TranslateName(name);
    166       return name;
    167     }
    168     /// <inheritdoc/>
    169     public void AddAlias(string alias, string name) {
    170       RemoveAlias(alias);
    171       if (alias != name) {
    172         myAliases.Add(alias, name);
    173         OnAliasAdded(alias);
    174       }
    175     }
    176     /// <inheritdoc/>
    177     public void RemoveAlias(string alias) {
    178       if (myAliases.ContainsKey(alias)) {
    179         myAliases.Remove(alias);
    180         OnAliasRemoved(alias);
    181       }
    182     }
    183153
    184154    /// <inheritdoc/>
     
    238208        RemoveVariable(variableNames[j]);
    239209
    240       KeyValuePair<string, string>[] aliases = new KeyValuePair<string,string>[myAliases.Count];
    241       myAliases.CopyTo(aliases, 0);
    242       for (int j = 0; j < aliases.Length; j++)
    243         RemoveAlias(aliases[j].Key);
    244 
    245210      while (SubScopes.Count > 0)
    246211        RemoveSubScope(SubScopes[0]);
     
    254219      foreach (IVariable variable in myVariables.Values)
    255220        clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects));
    256       foreach (KeyValuePair<string, string> alias in myAliases)
    257         clone.AddAlias(alias.Key, alias.Value);
    258221      for (int i = 0; i < SubScopes.Count; i++)
    259222        clone.AddSubScope((IScope)Auxiliary.Clone(SubScopes[i], clonedObjects));
     
    281244      if (VariableRemoved != null)
    282245        VariableRemoved(this, new VariableEventArgs(variable));
    283     }
    284     /// <inheritdoc />
    285     public event EventHandler<AliasEventArgs> AliasAdded;
    286     /// <summary>
    287     /// Fires a new <c>AliasAdded</c> event.
    288     /// </summary>
    289     /// <param name="alias">The alias that has been added.</param>
    290     protected virtual void OnAliasAdded(string alias) {
    291       if (AliasAdded != null)
    292         AliasAdded(this, new AliasEventArgs(alias));
    293     }
    294     /// <inheritdoc/>
    295     public event EventHandler<AliasEventArgs> AliasRemoved;
    296     /// <summary>
    297     /// Fires a new <c>AliasRemoved</c> event.
    298     /// </summary>
    299     /// <param name="alias">The alias that has been deleted.</param>
    300     protected virtual void OnAliasRemoved(string alias) {
    301       if (AliasRemoved != null)
    302         AliasRemoved(this, new AliasEventArgs(alias));
    303246    }
    304247    /// <inheritdoc/>
     
    380323      node.AppendChild(variables);
    381324
    382       XmlNode aliases = document.CreateNode(XmlNodeType.Element, "Aliases", null);
    383       foreach (KeyValuePair<string, string> alias in myAliases) {
    384         XmlNode aliasNode = document.CreateNode(XmlNodeType.Element, "Alias", null);
    385         XmlAttribute keyAttribute = document.CreateAttribute("Alias");
    386         keyAttribute.Value = alias.Key;
    387         aliasNode.Attributes.Append(keyAttribute);
    388         XmlAttribute valueAttribute = document.CreateAttribute("Name");
    389         valueAttribute.Value = alias.Value;
    390         aliasNode.Attributes.Append(valueAttribute);
    391         aliases.AppendChild(aliasNode);
    392       }
    393       node.AppendChild(aliases);
    394 
    395325      XmlNode subScopes = document.CreateNode(XmlNodeType.Element, "SubScopes", null);
    396326      for (int i = 0; i < SubScopes.Count; i++)
     
    419349      }
    420350
    421       XmlNode aliases = node.SelectSingleNode("Aliases");
    422       if (aliases != null) {
    423         foreach (XmlNode aliasNode in aliases.ChildNodes)
    424           AddAlias(aliasNode.Attributes["Alias"].Value, aliasNode.Attributes["Name"].Value);
    425       }
    426 
    427351      XmlNode subScopes = node.SelectSingleNode("SubScopes");
    428352      for (int i = 0; i < subScopes.ChildNodes.Count; i++) {
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ComparatorBase.cs

    r1530 r2027  
    3636    /// </summary>
    3737    protected ComparatorBase() {
    38       AddVariableInfo(new VariableInfo("LeftSide", "Variable on the left side of the comparison", typeof(IItem), VariableKind.In));
    39       AddVariableInfo(new VariableInfo("RightSide", "Variable on the right side of the comparison", typeof(IItem), VariableKind.In));
    40       AddVariableInfo(new VariableInfo("Result", "Result of the comparison", typeof(BoolData), VariableKind.Out | VariableKind.New));
     38      AddParameter(new Parameter("LeftSide", "Variable on the left side of the comparison", typeof(IItem), ParameterType.In));
     39      AddParameter(new Parameter("RightSide", "Variable on the right side of the comparison", typeof(IItem), ParameterType.In));
     40      AddParameter(new Parameter("Result", "Result of the comparison", typeof(BoolData), ParameterType.Out));
    4141    }
    4242
     
    5050    /// <param name="scope">The scope where to apply the compare operation.</param>
    5151    /// <returns><c>null</c>.</returns>
    52     public override IOperation Apply(IScope scope) {
    53       BoolData result = GetVariableValue<BoolData>("Result", scope, false, false);
     52    public override IOperation Apply(IEnvironment env, IScope scope) {
     53      string resultName = env.TranslateName("Result");
     54      BoolData result = scope.GetVariableValue<BoolData>(resultName, false, false);
    5455      if (result == null) {
    5556        result = new BoolData(true);
    56         IVariableInfo info = GetVariableInfo("Result");
    57         if (info.Local)
    58           AddVariable(new Variable(info.ActualName, result));
    59         else
    60           scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), result));
     57        scope.AddVariable(new Variable(resultName, result));
    6158      }
    62       IItem leftSide = GetVariableValue<IItem>("LeftSide", scope, true);
     59      IItem leftSide = scope.GetVariableValue<IItem>(env.TranslateName("LeftSide"), true);
    6360      if (!(leftSide is IComparable)) throw new InvalidOperationException("Comparator: Left side needs to be of type IComparable");
    6461      IComparable left = (IComparable)leftSide;
    65       IItem rightSide = GetVariableValue<IItem>("RightSide", scope, true);
     62      IItem rightSide = scope.GetVariableValue<IItem>(env.TranslateName("RightSide"), true);
    6663      result.Data = Compare(left, rightSide);
    6764      return null;
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ConditionalBranch.cs

    r1530 r2027  
    4545    public ConditionalBranch()
    4646      : base() {
    47       AddVariableInfo(new VariableInfo("Condition", "A boolean variable that decides the branch", typeof(BoolData), VariableKind.In));
     47      AddParameter(new Parameter("Condition", "A boolean variable that decides the branch", typeof(BoolData), ParameterType.In));
    4848    }
    4949
     
    5656    /// <returns>A new <see cref="AtomicOperation"/> with either operator 1 or operator 2 applied
    5757    /// 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;
     58    public override IOperation Apply(IEnvironment env, IScope scope) {
     59      bool result = scope.GetVariableValue<BoolData>(env.TranslateName("Condition"), true).Data;
    6160
    6261      if ((result) && (SubOperators.Count > 0) && (SubOperators[0] != null))
    63         return new AtomicOperation(SubOperators[0], scope);
     62        return new AtomicOperation(SubOperators[0], env, scope);
    6463      else if ((!result) && (SubOperators.Count > 1) && (SubOperators[1] != null))
    65         return new AtomicOperation(SubOperators[1], scope);
     64        return new AtomicOperation(SubOperators[1], env, scope);
    6665      return null;
    6766    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/Counter.cs

    r1530 r2027  
    4343    public Counter()
    4444      : base() {
    45       AddVariableInfo(new VariableInfo("Value", "Counter value", typeof(IntData), VariableKind.In | VariableKind.Out));
     45      AddParameter(new Parameter("Value", "Counter value", typeof(IntData), ParameterType.InOut));
    4646    }
    4747
     
    5151    /// <param name="scope">The scope whose variable should be incremented.</param>
    5252    /// <returns><c>null</c>.</returns>
    53     public override IOperation Apply(IScope scope) {
    54       IntData value = GetVariableValue<IntData>("Value", scope, true);
     53    public override IOperation Apply(IEnvironment env, IScope scope) {
     54      IntData value = scope.GetVariableValue<IntData>(env.TranslateName("Value"), true);
    5555      value.Data++;
    5656      return null;
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/DoubleCounter.cs

    r1530 r2027  
    4444    public DoubleCounter()
    4545      : 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));
     46      AddParameter(new Parameter("Value", "Counter value", typeof(DoubleData), ParameterType.InOut));
     47      AddParameter(new Parameter("Interval", "Interval value", typeof(DoubleData), ParameterType.In));
    4848    }
    4949
     
    5353    /// <param name="scope">The scope whose variable should be incremented.</param>
    5454    /// <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;
     55    public override IOperation Apply(IEnvironment env, IScope scope) {
     56      DoubleData value = scope.GetVariableValue<DoubleData>(env.TranslateName("Value"), true);
     57      double interval = scope.GetVariableValue<DoubleData>(env.TranslateName("Interval"), true).Data;
    5858      value.Data += interval;
    5959      return null;
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/EmptyOperator.cs

    r1530 r2027  
    4747    /// <param name="scope">The scope to apply the operator on.</param>
    4848    /// <returns><c>null</c>.</returns>
    49     public override IOperation Apply(IScope scope) {
     49    public override IOperation Apply(IEnvironment environment, IScope scope) {
    5050      return null;
    5151    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/HeuristicLab.Operators-3.2.csproj

    r1534 r2027  
    8181  </ItemGroup>
    8282  <ItemGroup>
    83     <Compile Include="AddVariableInfoDialog.cs">
    84       <SubType>Form</SubType>
     83    <Compile Include="ComparatorBase.cs">
     84      <SubType>Code</SubType>
    8585    </Compile>
    86     <Compile Include="AddVariableInfoDialog.Designer.cs">
    87       <DependentUpon>AddVariableInfoDialog.cs</DependentUpon>
    88     </Compile>
    89     <Compile Include="CombinedOperator.cs" />
    90     <Compile Include="CombinedOperatorView.cs">
    91       <SubType>UserControl</SubType>
    92     </Compile>
    93     <Compile Include="CombinedOperatorView.Designer.cs">
    94       <DependentUpon>CombinedOperatorView.cs</DependentUpon>
    95     </Compile>
    96     <Compile Include="ComparatorBase.cs" />
    9786    <Compile Include="ConditionalBranch.cs">
    9887      <SubType>Code</SubType>
    9988    </Compile>
    100     <Compile Include="DelegatingOperator.cs" />
    101     <Compile Include="DoubleCounter.cs" />
    102     <Compile Include="ScopeCleaner.cs" />
    103     <Compile Include="StochasticMultiBranch.cs" />
    104     <Compile Include="SubScopesMixer.cs" />
    105     <Compile Include="DataCollector.cs" />
    106     <Compile Include="EqualToComparator.cs" />
    107     <Compile Include="GreaterOrEqualThanComparator.cs" />
    108     <Compile Include="GreaterThanComparator.cs" />
    109     <Compile Include="LessOrEqualThanComparator.cs" />
    110     <Compile Include="LessThanComparator.cs" />
    111     <Compile Include="OperatorExtractor.cs" />
    112     <Compile Include="ParallelProcessor.cs" />
    113     <Compile Include="EmptyOperator.cs" />
    114     <Compile Include="SequentialProcessor.cs" />
    115     <Compile Include="SingleObjectiveEvaluatorBase.cs" />
    116     <Compile Include="Sorter.cs" />
    117     <Compile Include="StochasticBranch.cs" />
    118     <Compile Include="SubScopesRemover.cs" />
    119     <Compile Include="UnequalToComparator.cs" />
    120     <Compile Include="UniformSequentialSubScopesProcessor.cs" />
    121     <Compile Include="UniformParallelSubScopesProcessor.cs" />
    122     <Compile Include="ParallelSubScopesProcessor.cs" />
    123     <Compile Include="SequentialSubScopesProcessor.cs" />
    124     <Compile Include="SubScopesCreater.cs" />
    125     <Compile Include="Counter.cs" />
     89    <Compile Include="Counter.cs">
     90      <SubType>Code</SubType>
     91    </Compile>
     92    <Compile Include="DoubleCounter.cs">
     93      <SubType>Code</SubType>
     94    </Compile>
     95    <Compile Include="EmptyOperator.cs">
     96      <SubType>Code</SubType>
     97    </Compile>
     98    <Compile Include="EqualToComparator.cs">
     99      <SubType>Code</SubType>
     100    </Compile>
     101    <Compile Include="GreaterOrEqualThanComparator.cs">
     102      <SubType>Code</SubType>
     103    </Compile>
     104    <Compile Include="GreaterThanComparator.cs">
     105      <SubType>Code</SubType>
     106    </Compile>
    126107    <Compile Include="HeuristicLabOperatorsPlugin.cs" />
     108    <Compile Include="LessOrEqualThanComparator.cs">
     109      <SubType>Code</SubType>
     110    </Compile>
     111    <Compile Include="LessThanComparator.cs">
     112      <SubType>Code</SubType>
     113    </Compile>
     114    <Compile Include="ParallelProcessor.cs">
     115      <SubType>Code</SubType>
     116    </Compile>
     117    <Compile Include="ParallelSubScopesProcessor.cs">
     118      <SubType>Code</SubType>
     119    </Compile>
    127120    <Compile Include="Properties\AssemblyInfo.cs" />
    128     <Compile Include="VariableInjector.cs" />
     121    <Compile Include="SequentialProcessor.cs">
     122      <SubType>Code</SubType>
     123    </Compile>
     124    <Compile Include="SequentialSubScopesProcessor.cs">
     125      <SubType>Code</SubType>
     126    </Compile>
     127    <Compile Include="SubScopesCreater.cs">
     128      <SubType>Code</SubType>
     129    </Compile>
     130    <Compile Include="UnequalToComparator.cs">
     131      <SubType>Code</SubType>
     132    </Compile>
     133    <Compile Include="UniformParallelSubScopesProcessor.cs">
     134      <SubType>Code</SubType>
     135    </Compile>
     136    <Compile Include="UniformSequentialSubScopesProcessor.cs">
     137      <SubType>Code</SubType>
     138    </Compile>
     139    <Compile Include="VariableInjector.cs">
     140      <SubType>Code</SubType>
     141    </Compile>
    129142    <Compile Include="VariableInjectorView.cs">
    130143      <SubType>UserControl</SubType>
     
    135148  </ItemGroup>
    136149  <ItemGroup>
    137     <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">
    138       <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>
    139       <Name>HeuristicLab.Constraints-3.2</Name>
    140     </ProjectReference>
    141150    <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
    142151      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
     
    157166  </ItemGroup>
    158167  <ItemGroup>
    159     <EmbeddedResource Include="AddVariableInfoDialog.resx">
    160       <DependentUpon>AddVariableInfoDialog.cs</DependentUpon>
    161       <SubType>Designer</SubType>
    162     </EmbeddedResource>
    163     <EmbeddedResource Include="CombinedOperatorView.resx">
    164       <DependentUpon>CombinedOperatorView.cs</DependentUpon>
    165       <SubType>Designer</SubType>
     168    <EmbeddedResource Include="VariableInjectorView.resx">
     169      <DependentUpon>VariableInjectorView.cs</DependentUpon>
    166170    </EmbeddedResource>
    167171  </ItemGroup>
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/HeuristicLabOperatorsPlugin.cs

    r1927 r2027  
    3131  [ClassInfo(Name = "HeuristicLab.Operators-3.2")]
    3232  [PluginFile(Filename = "HeuristicLab.Operators-3.2.dll", Filetype = PluginFileType.Assembly)]
    33   [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]
    3433  [Dependency(Dependency = "HeuristicLab.Core-3.2")]
    3534  [Dependency(Dependency = "HeuristicLab.Data-3.2")]
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ParallelProcessor.cs

    r1530 r2027  
    4242    /// <returns>A new <see cref="CompositeOperation"/> with the <c>n</c> operators applied
    4343    /// to the given <paramref name="scope"/> with the <c>ExecuteInParallel</c> set to <c>true</c>.</returns>
    44     public override IOperation Apply(IScope scope) {
     44    public override IOperation Apply(IEnvironment env, IScope scope) {
    4545      CompositeOperation next = new CompositeOperation();
    4646      next.ExecuteInParallel = true;
    4747      for (int i = 0; i < SubOperators.Count; i++)
    48         next.AddOperation(new AtomicOperation(SubOperators[i], scope));
     48        next.AddOperation(new AtomicOperation(SubOperators[i], env, scope));
    4949      return next;
    5050    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ParallelSubScopesProcessor.cs

    r1530 r2027  
    4242    /// <returns>A new <see cref="CompositeOperation"/> with the <c>i</c>th operator applied
    4343    /// on the <c>i</c>th sub scope, the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns>
    44     public override IOperation Apply(IScope scope) {
     44    public override IOperation Apply(IEnvironment env, IScope scope) {
    4545      CompositeOperation next = new CompositeOperation();
    4646      next.ExecuteInParallel = true;
    4747      for (int i = 0; i < scope.SubScopes.Count; i++)
    48         next.AddOperation(new AtomicOperation(SubOperators[i], scope.SubScopes[i]));
     48        next.AddOperation(new AtomicOperation(SubOperators[i], env, scope.SubScopes[i]));
    4949      return next;
    5050    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SequentialProcessor.cs

    r1530 r2027  
    4242    /// <returns>A new <see cref="CompositeOperation"/> with the <c>n</c> operators applied
    4343    /// to the given <paramref name="scope"/>.</returns>
    44     public override IOperation Apply(IScope scope) {
     44    public override IOperation Apply(IEnvironment env, IScope scope) {
    4545      CompositeOperation next = new CompositeOperation();
    4646      for (int i = 0; i < SubOperators.Count; i++)
    47         next.AddOperation(new AtomicOperation(SubOperators[i], scope));
     47        next.AddOperation(new AtomicOperation(SubOperators[i], env, scope));
    4848      return next;
    4949    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SequentialSubScopesProcessor.cs

    r1530 r2027  
    4242    /// <returns>A new <see cref="CompositeOperation"/> with the <c>i</c>th operator applied
    4343    /// on the <c>i</c>th sub scope.</returns>
    44     public override IOperation Apply(IScope scope) {
     44    public override IOperation Apply(IEnvironment env, IScope scope) {
    4545      CompositeOperation next = new CompositeOperation();
    4646      for (int i = 0; i < scope.SubScopes.Count; i++)
    47         next.AddOperation(new AtomicOperation(SubOperators[i], scope.SubScopes[i]));
     47        next.AddOperation(new AtomicOperation(SubOperators[i], env, scope.SubScopes[i]));
    4848      return next;
    4949    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SubScopesCreater.cs

    r1530 r2027  
    4141    public SubScopesCreater()
    4242      : base() {
    43       AddVariableInfo(new VariableInfo("SubScopes", "Number of sub-scopes", typeof(IntData), VariableKind.In));
     43      AddParameter(new Parameter("SubScopes", "Number of sub-scopes", typeof(IntData), ParameterType.In));
    4444    }
    4545
     
    4949    /// <param name="scope">The scope where to create the sub scopes.</param>
    5050    /// <returns><c>null</c>.</returns>
    51     public override IOperation Apply(IScope scope) {
    52       IntData count = GetVariableValue<IntData>("SubScopes", scope, true);
     51    public override IOperation Apply(IEnvironment env, IScope scope) {
     52      IntData count = scope.GetVariableValue<IntData>(env.TranslateName("SubScopes"), true);
    5353
    5454      for (int i = 0; i < count.Data; i++)
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/UniformParallelSubScopesProcessor.cs

    r1530 r2027  
    4343    /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes and
    4444    /// the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns>
    45     public override IOperation Apply(IScope scope) {
     45    public override IOperation Apply(IEnvironment env, IScope scope) {
    4646      CompositeOperation next = new CompositeOperation();
    4747      next.ExecuteInParallel = true;
    4848      for (int i = 0; i < scope.SubScopes.Count; i++)
    49         next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i]));
     49        next.AddOperation(new AtomicOperation(SubOperators[0], env, scope.SubScopes[i]));
    5050      return next;
    5151    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/UniformSequentialSubScopesProcessor.cs

    r1530 r2027  
    4242    /// <param name="scope">The scope on whose sub scopes the operator is applied.</param>
    4343    /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes.</returns>
    44     public override IOperation Apply(IScope scope) {
     44    public override IOperation Apply(IEnvironment env, IScope scope) {
    4545      CompositeOperation next = new CompositeOperation();
    4646      for (int i = 0; i < scope.SubScopes.Count; i++)
    47         next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i]));
     47        next.AddOperation(new AtomicOperation(SubOperators[0], env, scope.SubScopes[i]));
    4848      return next;
    4949    }
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjector.cs

    r1530 r2027  
    3030  /// Class to inject local variables into the scope.
    3131  /// </summary>
    32   public class VariableInjector : OperatorBase {
    33     private Dictionary<IVariable, IVariableInfo> variableVariableInfoTable;
    34     private Dictionary<IVariableInfo, IVariable> variableInfoVariableTable;
     32  public class VariableInjector : OperatorBase, IVariablesContainer {
     33    private Dictionary<string, IVariable> myVariables;
     34    /// <summary>
     35    /// Gets a collection of all variables of the current operator.
     36    /// </summary>
     37    public virtual ICollection<IVariable> Variables {
     38      get { return myVariables.Values; }
     39    }
    3540
    3641    /// <inheritdoc select="summary"/>
    3742    public override string Description {
    38       get { return @"TODO\r\nOperator description still missing ..."; }
     43      get { return @"Injects new variable into a scope."; }
     44    }
     45
     46    /// <summary>
     47    /// Overrides the Parameters property so that a parameter is returned for each injected variable.
     48    /// </summary>
     49    public override ICollection<IParameter> Parameters {
     50      get {
     51        List<IParameter> parameters = new List<IParameter>();
     52        foreach (IVariable variable in Variables)
     53          parameters.Add(new Parameter(variable.Name, "Injected variable.", variable.Value.GetType(), ParameterType.Out));
     54        return parameters;
     55      }
    3956    }
    4057
     
    4461    public VariableInjector()
    4562      : base() {
    46       variableVariableInfoTable = new Dictionary<IVariable, IVariableInfo>();
    47       variableInfoVariableTable = new Dictionary<IVariableInfo, IVariable>();
     63      myVariables = new Dictionary<string, IVariable>();
    4864    }
    4965
     
    5672    /// <returns>The cloned object as <see cref="VariableInjector"/>.</returns>
    5773    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    58       VariableInjector clone = new VariableInjector();
    59       clonedObjects.Add(Guid, clone);
    60       clone.Name = Name;
     74      VariableInjector clone = (VariableInjector)base.Clone(clonedObjects);
    6175      foreach (IVariable variable in Variables)
    6276        clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects));
     
    6579
    6680    /// <summary>
    67     /// Adds the specified <paramref name="variable"/> to the current instance to get injected.
    68     /// </summary>
    69     /// <param name="variable">The variable to add.</param>
    70     /// <remarks>Calls private method <see cref="CreateVariableInfo"/> and <see cref="OperatorBase.AddVariable"/>
    71     /// of base class <see cref="OperatorBase"/>.</remarks>
    72     public override void AddVariable(IVariable variable) {
    73       base.AddVariable(variable);
    74       CreateVariableInfo(variable);
    75     }
    76 
    77     /// <summary>
    78     /// Removes a variable with the specified <paramref name="name"/> from the current injector.
    79     /// </summary>
    80     /// <remarks>Calls private method <see cref="DeleteVariableInfo"/> and <see cref="OperatorBase.RemoveVariable"/>
    81     /// of base class <see cref="OperatorBase"/>.</remarks>
    82     /// <param name="name">The name of the </param>
    83     public override void RemoveVariable(string name) {
    84       DeleteVariableInfo(name);
    85       base.RemoveVariable(name);
    86     }
    87 
    88     /// <summary>
    8981    /// Adds the specified variables to the given <paramref name="scope"/> (and removes them first,
    9082    /// if they already exist in the current scope).
     
    9284    /// <param name="scope">The scope where to inject the variables.</param>
    9385    /// <returns><c>null</c>.</returns>
    94     public override IOperation Apply(IScope scope) {
     86    public override IOperation Apply(IEnvironment env, IScope scope) {
    9587      foreach (IVariable variable in Variables) {
    9688        if (scope.GetVariable(variable.Name) != null)
     
    109101    }
    110102
    111     private void CreateVariableInfo(IVariable variable) {
    112       IVariableInfo info = new VariableInfo(Guid.NewGuid().ToString(), "Injected variable", variable.Value.GetType(), VariableKind.New);
    113       info.ActualName = variable.Name;
    114       AddVariableInfo(info);
    115       variableVariableInfoTable.Add(variable, info);
    116       variableInfoVariableTable.Add(info, variable);
    117       info.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);
     103    /// <summary>
     104    /// Gets a variable with the given <paramref name="name"/>.
     105    /// </summary>
     106    /// <param name="name">The name of the variable.</param>
     107    /// <returns>The variable with the specified name.</returns>
     108    public virtual IVariable GetVariable(string name) {
     109      IVariable variable;
     110      if (myVariables.TryGetValue(name, out variable))
     111        return variable;
     112      else
     113        return null;
     114    }
     115    /// <summary>
     116    /// Adds the specified <paramref name="variable"/> to the current instance.
     117    /// </summary>
     118    /// <param name="variable">The variable to add.</param>
     119    public virtual void AddVariable(IVariable variable) {
     120      myVariables.Add(variable.Name, variable);
     121      variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    118122      variable.NameChanged += new EventHandler(Variable_NameChanged);
    119     }
    120     private void DeleteVariableInfo(string name) {
    121       IVariable variable = GetVariable(name);
    122       if (variable != null) {
    123         IVariableInfo info = variableVariableInfoTable[variable];
    124         RemoveVariableInfo(info.FormalName);
    125         variableVariableInfoTable.Remove(variable);
    126         variableInfoVariableTable.Remove(info);
    127         info.ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged);
     123      OnVariableAdded(variable);
     124    }
     125    /// <summary>
     126    /// Deletes the variable with the specified <paramref name="name"/>.
     127    /// </summary>
     128    /// <param name="name">The name of the variable to delete.</param>
     129    public virtual void RemoveVariable(string name) {
     130      IVariable variable;
     131      if (myVariables.TryGetValue(name, out variable)) {
     132        variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging);
    128133        variable.NameChanged -= new EventHandler(Variable_NameChanged);
    129       }
    130     }
    131 
    132     #region VariableInfo and Variable Events
    133     private void VariableInfo_ActualNameChanged(object sender, EventArgs e) {
    134       IVariableInfo info = (IVariableInfo)sender;
    135       IVariable variable = variableInfoVariableTable[info];
    136       variable.Name = info.ActualName;
     134        myVariables.Remove(name);
     135        OnVariableRemoved(variable);
     136      }
     137    }
     138    private void Variable_NameChanging(object sender, NameChangingEventArgs e) {
     139      e.Cancel = myVariables.ContainsKey(e.Name);
    137140    }
    138141    private void Variable_NameChanged(object sender, EventArgs e) {
    139142      IVariable variable = (IVariable)sender;
    140       IVariableInfo info = variableVariableInfoTable[variable];
    141       info.ActualName = variable.Name;
    142     }
    143     #endregion
     143      string oldName = null;
     144      foreach (KeyValuePair<string, IVariable> element in myVariables) {
     145        if (element.Value == variable)
     146          oldName = element.Key;
     147      }
     148      myVariables.Remove(oldName);
     149      myVariables.Add(variable.Name, variable);
     150    }
     151
     152    /// <summary>
     153    /// Occurs when a variable has been added.
     154    /// </summary>
     155    public event EventHandler<VariableEventArgs> VariableAdded;
     156    /// <summary>
     157    /// Fires a new <c>VariableAdded</c> event.
     158    /// </summary>
     159    /// <param name="variable">The variable that has been added.</param>
     160    protected virtual void OnVariableAdded(IVariable variable) {
     161      if (VariableAdded != null)
     162        VariableAdded(this, new VariableEventArgs(variable));
     163    }
     164    /// <summary>
     165    /// Occurs when a variable has been deleted.
     166    /// </summary>
     167    public event EventHandler<VariableEventArgs> VariableRemoved;
     168    /// <summary>
     169    /// Fires a new <c>VariableRemoved</c> event.
     170    /// </summary>
     171    /// <param name="variable">The variable that has been removed</param>
     172    protected virtual void OnVariableRemoved(IVariable variable) {
     173      if (VariableRemoved != null)
     174        VariableRemoved(this, new VariableEventArgs(variable));
     175    }
    144176
    145177    #region Persistence Methods
    146178    /// <summary>
    147179    /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    148     /// <note type="caution"> Variable infos are not persisted!</note>
    149     /// </summary>
    150     /// <remarks>Calls <see cref="OperatorBase.GetXmlNode"/> of base class <see cref="OperatorBase"/>.</remarks>
     180    /// </summary>
     181    /// <remarks>
     182    /// Calls <see cref="OperatorBase.GetXmlNode"/> of base class <see cref="OperatorBase"/>.
     183    /// <br/>A quick overview how the single elements of the current instance are saved:
     184    /// <list type="bullet">
     185    /// <item>
     186    /// <term>Variables: </term>
     187    /// <description>Saved as child node with tag name <c>Variables</c>. All variables are themselves
     188    /// saved as child nodes.</description>
     189    /// </item>
     190    /// </list>
     191    /// </remarks>
    151192    /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    152193    /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    153194    /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    154195    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    155     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     196    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    156197      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    157       // variable infos should not be persisted
    158       XmlNode infosNode = node.SelectSingleNode("VariableInfos");
    159       infosNode.RemoveAll();
     198      XmlNode variablesNode = document.CreateNode(XmlNodeType.Element, "Variables", null);
     199      foreach (IVariable variable in myVariables.Values)
     200        variablesNode.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects));
     201      node.AppendChild(variablesNode);
    160202      return node;
     203    }
     204    /// <summary>
     205    /// Loads the persisted variable injector from the specified <paramref name="node"/>.
     206    /// </summary>
     207    /// <remarks>Calls <see cref="OperatorBase.Populate"/> of base class
     208    /// <see cref="OperatorBase"/>.
     209    /// For informations how the different elements must be saved please see <see cref="GetXmlNode"/>.</remarks>
     210    /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param>
     211    /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
     212    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     213      base.Populate(node, restoredObjects);
     214      XmlNode variablesNode = node.SelectSingleNode("Variables");
     215      foreach (XmlNode variableNode in variablesNode.ChildNodes)
     216        AddVariable((IVariable)PersistenceManager.Restore(variableNode, restoredObjects));
    161217    }
    162218    #endregion
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjectorView.Designer.cs

    r1530 r2027  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       components = new System.ComponentModel.Container();
     47      this.variablesTabPage = new System.Windows.Forms.TabPage();
     48      this.variablesContainerView = new HeuristicLab.Core.VariablesContainerView();
     49      this.tabControl.SuspendLayout();
     50      this.parametersTabPage.SuspendLayout();
     51      this.variablesTabPage.SuspendLayout();
     52      this.SuspendLayout();
     53      //
     54      // tabControl
     55      //
     56      this.tabControl.Controls.Add(this.variablesTabPage);
     57      this.tabControl.Controls.SetChildIndex(this.parametersTabPage, 0);
     58      this.tabControl.Controls.SetChildIndex(this.variablesTabPage, 0);
     59      //
     60      // variablesTabPage
     61      //
     62      this.variablesTabPage.Controls.Add(this.variablesContainerView);
     63      this.variablesTabPage.Location = new System.Drawing.Point(4, 22);
     64      this.variablesTabPage.Name = "variablesTabPage";
     65      this.variablesTabPage.Padding = new System.Windows.Forms.Padding(3);
     66      this.variablesTabPage.Size = new System.Drawing.Size(415, 307);
     67      this.variablesTabPage.TabIndex = 4;
     68      this.variablesTabPage.Text = "Variables";
     69      this.variablesTabPage.UseVisualStyleBackColor = true;
     70      //
     71      // variablesContainerView
     72      //
     73      this.variablesContainerView.Caption = "Variables Container";
     74      this.variablesContainerView.Dock = System.Windows.Forms.DockStyle.Fill;
     75      this.variablesContainerView.Location = new System.Drawing.Point(3, 3);
     76      this.variablesContainerView.Name = "variablesContainerView";
     77      this.variablesContainerView.Size = new System.Drawing.Size(409, 301);
     78      this.variablesContainerView.TabIndex = 0;
     79      this.variablesContainerView.VariablesContainer = null;
     80      //
     81      // VariableInjectorView
     82      //
     83      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    4884      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     85      this.Name = "VariableInjectorView";
     86      this.tabControl.ResumeLayout(false);
     87      this.parametersTabPage.ResumeLayout(false);
     88      this.variablesTabPage.ResumeLayout(false);
     89      this.ResumeLayout(false);
     90
    4991    }
    5092
    5193    #endregion
     94
     95    private System.Windows.Forms.TabPage variablesTabPage;
     96    private HeuristicLab.Core.VariablesContainerView variablesContainerView;
    5297  }
    5398}
  • branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjectorView.cs

    r1530 r2027  
    6060      VariableInjector = variableInjector;
    6161    }
     62
     63    /// <summary>
     64    /// Removes event handlers in all children.
     65    /// </summary>
     66    protected override void RemoveItemEvents() {
     67      variablesContainerView.VariablesContainer = null;
     68      base.RemoveItemEvents();
     69    }
     70    /// <summary>
     71    /// Adds event handlers in all children.
     72    /// </summary>
     73    protected override void AddItemEvents() {
     74      base.AddItemEvents();
     75      variablesContainerView.VariablesContainer = VariableInjector;
     76    }
     77
    6278  }
    6379}
  • branches/Operator Architecture Refactoring/HeuristicLab.SequentialEngine/3.2/SequentialEngine.cs

    r1851 r2027  
    7575        try {
    7676          currentOperator = atomicOperation.Operator;
    77           next = atomicOperation.Operator.Execute(atomicOperation.Scope);
     77          next = atomicOperation.Operator.Execute(atomicOperation.Environment, atomicOperation.Scope);
    7878        }
    7979        catch (Exception ex) {
Note: See TracChangeset for help on using the changeset viewer.