Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/09 03:36:48 (15 years ago)
Author:
swagner
Message:

Refactoring of the operator architecture (#95)

Location:
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3
Files:
7 added
15 deleted
16 edited

Legend:

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

    r2033 r2046  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
    2627namespace HeuristicLab.Core {
    27   public class CallGraph : ItemBase, ICallGraph {
     28  public class CallGraph : CallNodeBase, ICallGraph {
     29    [Storable]
     30    private Dictionary<ICallNode, List<ICallNode>> transitions;
     31
     32    [Storable]
     33    private List<ICallNode> myCallNodes;
     34    public ICollection<ICallNode> CallNodes {
     35      get { return myCallNodes.AsReadOnly(); }
     36    }
     37    [Storable]
     38    private ICallNode myInitialCallNode;
     39    public ICallNode InitialCallNode {
     40      get { return myInitialCallNode; }
     41      internal set {
     42        if (myInitialCallNode != value) {
     43          myInitialCallNode = value;
     44          OnInitialCallNodeChanged();
     45        }
     46      }
     47    }
     48
     49    public CallGraph()
     50      : base() {
     51      transitions = new Dictionary<ICallNode, List<ICallNode>>();
     52      myCallNodes = new List<ICallNode>();
     53      myInitialCallNode = null;
     54    }
     55    public CallGraph(CallGraph parentGraph)
     56      : base(parentGraph) {
     57      transitions = new Dictionary<ICallNode, List<ICallNode>>();
     58      myCallNodes = new List<ICallNode>();
     59      myInitialCallNode = null;
     60    }
     61
     62    public override ICloneable Clone(ICloner cloner) {
     63      CallGraph clone = (CallGraph)base.Clone(cloner);
     64      foreach (ICallNode callNode in CallNodes)
     65        clone.AddCallNode((ICallNode)cloner.Clone(callNode));
     66      foreach (ICallNode source in CallNodes)
     67        foreach (ICallNode target in transitions[source])
     68          clone.AddTransition((ICallNode)cloner.Clone(source), (ICallNode)cloner.Clone(target));
     69      clone.InitialCallNode = (ICallNode)cloner.Clone(InitialCallNode);
     70
     71      return base.Clone(cloner);
     72    }
     73
     74    public override IView CreateView() {
     75      return new CallGraphView(this);
     76    }
     77
     78    internal void AddCallNode(ICallNode callNode) {
     79      myCallNodes.Add(callNode);
     80      transitions.Add(callNode, new List<ICallNode>());
     81      OnCallNodeAdded(callNode);
     82    }
     83    public void RemoveCallNode(ICallNode callNode) {
     84      if (myCallNodes.Remove(callNode)) {
     85        foreach (ICallNode node in CallNodes) {  // remove incoming transitions
     86          while (transitions[node].Contains(callNode))
     87            RemoveTransition(node, callNode);
     88        }
     89        while (transitions[callNode].Count > 0)  // remove outgoing transitions
     90          RemoveTransition(callNode, transitions[callNode][0]);
     91        transitions.Remove(callNode);
     92        OnCallNodeRemoved(callNode);
     93      }
     94    }
     95
     96    public void AddTransition(ICallNode source, ICallNode target) {
     97      transitions[source].Add(target);
     98      OnTransitionAdded(source, target);
     99    }
     100    public void RemoveTransition(ICallNode source, ICallNode target) {
     101      if (transitions[source].Remove(target))
     102        OnTransitionRemoved(source, target);
     103    }
     104
     105    internal IList<ICallNode> GetSuccessorNodes(ICallNode callNode) {
     106      return transitions[callNode].AsReadOnly();
     107    }
     108
     109    public event EventHandler<EventArgs<ICallNode>> CallNodeAdded;
     110    protected virtual void OnCallNodeAdded(ICallNode callNode) {
     111      if (CallNodeAdded != null)
     112        CallNodeAdded(this, new EventArgs<ICallNode>(callNode));
     113    }
     114    public event EventHandler<EventArgs<ICallNode>> CallNodeRemoved;
     115    protected virtual void OnCallNodeRemoved(ICallNode callNode) {
     116      if (CallNodeRemoved != null)
     117        CallNodeRemoved(this, new EventArgs<ICallNode>(callNode));
     118    }
     119    public event EventHandler InitialCallNodeChanged;
     120    protected virtual void OnInitialCallNodeChanged() {
     121      if (InitialCallNodeChanged != null)
     122        InitialCallNodeChanged(this, new EventArgs());
     123    }
     124    public event EventHandler<EventArgs<ICallNode, ICallNode>> TransistionAdded;
     125    protected virtual void OnTransitionAdded(ICallNode source, ICallNode target) {
     126      if (TransistionAdded != null)
     127        TransistionAdded(this, new EventArgs<ICallNode,ICallNode>(source, target));
     128    }
     129    public event EventHandler<EventArgs<ICallNode, ICallNode>> TransistionRemoved;
     130    protected virtual void OnTransitionRemoved(ICallNode source, ICallNode target) {
     131      if (TransistionRemoved != null)
     132        TransistionRemoved(this, new EventArgs<ICallNode, ICallNode>(source, target));
     133    }
    28134  }
    29135}
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Cloner.cs

    r2042 r2046  
    4646
    4747    public ICloneable Clone(ICloneable obj) {
     48      if (obj == null) return null;
    4849      ICloneable clone;
    4950      if (mapping.TryGetValue(obj, out clone))
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/EngineBase.cs

    r2042 r2046  
    237237    /// Occurs when an operation is executed.
    238238    /// </summary>
    239     public event EventHandler<OperationEventArgs> OperationExecuted;
     239    public event EventHandler<EventArgs<IOperation>> OperationExecuted;
    240240    /// <summary>
    241241    /// Fires a new <c>OperationExecuted</c> event.
     
    244244    protected virtual void OnOperationExecuted(IOperation operation) {
    245245      if (OperationExecuted != null)
    246         OperationExecuted(this, new OperationEventArgs(operation));
     246        OperationExecuted(this, new EventArgs<IOperation>(operation));
    247247    }
    248248    /// <summary>
    249249    /// Occurs when an exception occured during the execution.
    250250    /// </summary>
    251     public event EventHandler<ExceptionEventArgs> ExceptionOccurred;
     251    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    252252    /// <summary>
    253253    /// Aborts the execution and fires a new <c>ExceptionOccurred</c> event.
     
    257257      Abort();
    258258      if (ExceptionOccurred != null)
    259         ExceptionOccurred(this, new ExceptionEventArgs(exception));
     259        ExceptionOccurred(this, new EventArgs<Exception>(exception));
    260260    }
    261261    /// <summary>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r2042 r2046  
    122122      <DependentUpon>ChooseTypeDialog.cs</DependentUpon>
    123123    </Compile>
    124     <Compile Include="AliasEventArgs.cs" />
    125124    <Compile Include="CallGraph.cs" />
    126     <Compile Include="CallNode.cs" />
     125    <Compile Include="OperatorCallNode.cs" />
    127126    <Compile Include="Cloner.cs" />
    128     <Compile Include="ParameterEventArgs.cs" />
     127    <Compile Include="CallGraphView.cs">
     128      <SubType>UserControl</SubType>
     129    </Compile>
     130    <Compile Include="CallGraphView.Designer.cs">
     131      <DependentUpon>CallGraphView.cs</DependentUpon>
     132    </Compile>
     133    <Compile Include="CancelEventArgs.cs" />
     134    <Compile Include="CallNodeBase.cs" />
     135    <Compile Include="EventArgs.cs" />
    129136    <Compile Include="Interfaces\ICloner.cs" />
    130137    <Compile Include="Interfaces\ICloneable.cs" />
     
    140147    <Compile Include="Interfaces\ICallNode.cs" />
    141148    <Compile Include="Interfaces\ICallGraph.cs" />
    142     <Compile Include="KeyValueEventArgs.cs" />
    143149    <Compile Include="OperatorBaseDescriptionView.cs">
    144150      <SubType>UserControl</SubType>
     
    150156    <Compile Include="Interfaces\IOperatorLibrary.cs" />
    151157    <Compile Include="Interfaces\IVisualizationItem.cs" />
    152     <Compile Include="NameChangingEventArgs.cs" />
    153     <Compile Include="OperationEventArgs.cs" />
    154158    <Compile Include="OperatorBaseVariablesView.cs">
    155159      <SubType>UserControl</SubType>
     
    164168      <DependentUpon>OperatorBaseVariableInfosView.cs</DependentUpon>
    165169    </Compile>
    166     <Compile Include="ExceptionEventArgs.cs" />
    167170    <Compile Include="Interfaces\IItem.cs" />
    168171    <Compile Include="ItemBase.cs" />
     
    173176      <DependentUpon>ItemBaseView.cs</DependentUpon>
    174177    </Compile>
    175     <Compile Include="ItemEventArgs.cs" />
    176     <Compile Include="ItemIndexEventArgs.cs" />
    177178    <Compile Include="OperatorLibrary.cs" />
    178179    <Compile Include="OperatorLibraryEditor.cs">
     
    187188      <DependentUpon>Resources.resx</DependentUpon>
    188189    </Compile>
    189     <Compile Include="ScopeIndexEventArgs.cs" />
    190190    <Compile Include="EngineBaseEditor.cs">
    191191      <SubType>UserControl</SubType>
     
    194194      <DependentUpon>EngineBaseEditor.cs</DependentUpon>
    195195    </Compile>
    196     <Compile Include="VariableInfoEventArgs.cs" />
    197     <Compile Include="VariableEventArgs.cs" />
    198196    <Compile Include="Interfaces\IOperatorGroup.cs" />
    199197    <Compile Include="Interfaces\IOperatorGraph.cs" />
     
    201199    <Compile Include="Interfaces\IVariable.cs" />
    202200    <Compile Include="Interfaces\IVariableInfo.cs" />
    203     <Compile Include="OperatorEventArgs.cs" />
    204201    <Compile Include="OperatorGroup.cs">
    205202      <SubType>Code</SubType>
    206203    </Compile>
    207     <Compile Include="OperatorIndexEventArgs.cs" />
    208     <Compile Include="ScopeEventArgs.cs" />
    209204    <Compile Include="OperatorBaseView.cs">
    210205      <SubType>UserControl</SubType>
     
    300295      <SubType>Designer</SubType>
    301296    </EmbeddedResource>
     297    <EmbeddedResource Include="CallGraphView.resx">
     298      <DependentUpon>CallGraphView.cs</DependentUpon>
     299      <SubType>Designer</SubType>
     300    </EmbeddedResource>
    302301    <EmbeddedResource Include="ParameterView.resx">
    303302      <DependentUpon>ParameterView.cs</DependentUpon>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/ICallGraph.cs

    r2033 r2046  
    2525
    2626namespace HeuristicLab.Core {
    27   public interface ICallGraph : IItem {
     27  public interface ICallGraph : ICallNode {
     28    ICollection<ICallNode> CallNodes { get; }
     29    ICallNode InitialCallNode { get; }
     30
     31    void RemoveCallNode(ICallNode callNode);
     32
     33    event EventHandler<EventArgs<ICallNode>> CallNodeAdded;
     34    event EventHandler<EventArgs<ICallNode>> CallNodeRemoved;
     35    event EventHandler InitialCallNodeChanged;
     36
    2837  }
    2938}
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/ICallNode.cs

    r2033 r2046  
    2626namespace HeuristicLab.Core {
    2727  public interface ICallNode : IItem {
     28    IEnumerable<KeyValuePair<string, string>> NameMappings { get; }
     29    IList<ICallNode> SuccessorNodes { get; }
     30    bool InitialCallNode { get; set; }
     31
     32    void AddNameMapping(string name, string alias);
     33    void RemoveNameMapping(string name);
     34    string MapName(string name);
     35
     36    event EventHandler<EventArgs<string, string>> NameMappingAdded;
     37    event EventHandler<EventArgs<string, string>> NameMappingRemoved;
    2838  }
    2939}
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IEngine.cs

    r776 r2046  
    8787    /// Occurs when an operation is executed.
    8888    /// </summary>
    89     event EventHandler<OperationEventArgs> OperationExecuted;
     89    event EventHandler<EventArgs<IOperation>> OperationExecuted;
    9090    /// <summary>
    9191    /// Occurs when an exception was thrown.
    9292    /// </summary>
    93     event EventHandler<ExceptionEventArgs> ExceptionOccurred;
     93    event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    9494    /// <summary>
    9595    /// Occurs when the execution time was changed.
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IOperator.cs

    r2042 r2046  
    9292    /// Occurs when a variable info has been added.
    9393    /// </summary>
    94     event EventHandler<ParameterEventArgs> ParameterAdded;
     94    event EventHandler<EventArgs<IParameter>> ParameterAdded;
    9595    /// <summary>
    9696    /// Occurs when a variable info has been deleted.
    9797    /// </summary>
    98     event EventHandler<ParameterEventArgs> ParameterRemoved;
     98    event EventHandler<EventArgs<IParameter>> ParameterRemoved;
    9999    /// <summary>
    100100    /// Occurs when the current instance is executed.
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IOperatorGraph.cs

    r2033 r2046  
    5757    /// Occurs when a new operator has been added to the current instance.
    5858    /// </summary>
    59     event EventHandler<OperatorEventArgs> OperatorAdded;
     59    event EventHandler<EventArgs<IOperator>> OperatorAdded;
    6060    /// <summary>
    6161    /// Occurs when an operator has been deleted from the current instance.
    6262    /// </summary>
    63     event EventHandler<OperatorEventArgs> OperatorRemoved;
     63    event EventHandler<EventArgs<IOperator>> OperatorRemoved;
    6464    /// <summary>
    6565    /// Occurs when the initial operator (the starting one) has been changed.
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IParameter.cs

    r2033 r2046  
    3030    Type DataType { get; }
    3131    ParamterType Type { get; }
     32    IItem Value { get; set; }
    3233  }
    3334}
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IScope.cs

    r2042 r2046  
    121121    /// Occurs when a variable has been added to the current instance.
    122122    /// </summary>
    123     event EventHandler<VariableEventArgs> VariableAdded;
     123    event EventHandler<EventArgs<IVariable>> VariableAdded;
    124124    /// <summary>
    125125    /// Occurs when a variable has been deleted from the current instance.
    126126    /// </summary>
    127     event EventHandler<VariableEventArgs> VariableRemoved;
     127    event EventHandler<EventArgs<IVariable>> VariableRemoved;
    128128    /// <summary>
    129129    /// Occurs when a sub scope has been added to the current instance.
    130130    /// </summary>
    131     event EventHandler<ScopeIndexEventArgs> SubScopeAdded;
     131    event EventHandler<EventArgs<IScope, int>> SubScopeAdded;
    132132    /// <summary>
    133133    /// Occurs when a sub scope has been deleted from the current instance.
    134134    /// </summary>
    135     event EventHandler<ScopeIndexEventArgs> SubScopeRemoved;
     135    event EventHandler<EventArgs<IScope, int>> SubScopeRemoved;
    136136    /// <summary>
    137137    /// Occurs when the sub scopes have been reordered.
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Interfaces/IVariable.cs

    r776 r2046  
    4949    /// Occurs when the name of the variable is currently changing.
    5050    /// </summary>
    51     event EventHandler<NameChangingEventArgs> NameChanging;
     51    event EventHandler<CancelEventArgs<string>> NameChanging;
    5252    /// <summary>
    5353    /// Occurs when the name of the current instance has been changed.
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorBase.cs

    r2042 r2046  
    186186    }
    187187    /// <inheritdoc/>
    188     public event EventHandler<ParameterEventArgs> ParameterAdded;
     188    public event EventHandler<EventArgs<IParameter>> ParameterAdded;
    189189    /// <summary>
    190190    /// Fires a new <c>VariableInfoAdded</c> event.
     
    193193    protected virtual void OnParameterAdded(IParameter parameter) {
    194194      if (ParameterAdded != null)
    195         ParameterAdded(this, new ParameterEventArgs(parameter));
    196     }
    197     /// <inheritdoc/>
    198     public event EventHandler<ParameterEventArgs> ParameterRemoved;
     195        ParameterAdded(this, new EventArgs<IParameter>(parameter));
     196    }
     197    /// <inheritdoc/>
     198    public event EventHandler<EventArgs<IParameter>> ParameterRemoved;
    199199    /// <summary>
    200200    /// Fires a new <c>VariableInfoRemoved</c> event.
     
    203203    protected virtual void OnParameterRemoved(IParameter parameter) {
    204204      if (ParameterRemoved != null)
    205         ParameterRemoved(this, new ParameterEventArgs(parameter));
     205        ParameterRemoved(this, new EventArgs<IParameter>(parameter));
    206206    }
    207207    /// <inheritdoc/>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorGraph.cs

    r2042 r2046  
    127127
    128128    /// <inheritdoc/>
    129     public event EventHandler<OperatorEventArgs> OperatorAdded;
     129    public event EventHandler<EventArgs<IOperator>> OperatorAdded;
    130130    /// <summary>
    131131    /// Fires a new <c>OperatorAdded</c> event.
     
    134134    protected virtual void OnOperatorAdded(IOperator op) {
    135135      if (OperatorAdded != null)
    136         OperatorAdded(this, new OperatorEventArgs(op));
     136        OperatorAdded(this, new EventArgs<IOperator>(op));
    137137    }
    138138    /// <inheritdoc/>
    139     public event EventHandler<OperatorEventArgs> OperatorRemoved;
     139    public event EventHandler<EventArgs<IOperator>> OperatorRemoved;
    140140    /// <summary>
    141141    /// Fires a new <c>OperatorRemoved</c> event.
     
    144144    protected virtual void OnOperatorRemoved(IOperator op) {
    145145      if (OperatorRemoved != null)
    146         OperatorRemoved(this, new OperatorEventArgs(op));
     146        OperatorRemoved(this, new EventArgs<IOperator>(op));
    147147    }
    148148    /// <inheritdoc/>
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Scope.cs

    r2042 r2046  
    238238
    239239    /// <inheritdoc />
    240     public event EventHandler<VariableEventArgs> VariableAdded;
     240    public event EventHandler<EventArgs<IVariable>> VariableAdded;
    241241    /// <summary>
    242242    /// Fires a new <c>VariableAdded</c> event.
     
    245245    protected virtual void OnVariableAdded(IVariable variable) {
    246246      if (VariableAdded != null)
    247         VariableAdded(this, new VariableEventArgs(variable));
     247        VariableAdded(this, new EventArgs<IVariable>(variable));
    248248    }
    249249    /// <inheritdoc />
    250     public event EventHandler<VariableEventArgs> VariableRemoved;
     250    public event EventHandler<EventArgs<IVariable>> VariableRemoved;
    251251    /// <summary>
    252252    /// Fires a new <c>VariableRemoved</c>.
     
    255255    protected virtual void OnVariableRemoved(IVariable variable) {
    256256      if (VariableRemoved != null)
    257         VariableRemoved(this, new VariableEventArgs(variable));
    258     }
    259     /// <inheritdoc/>
    260     public event EventHandler<ScopeIndexEventArgs> SubScopeAdded;
     257        VariableRemoved(this, new EventArgs<IVariable>(variable));
     258    }
     259    /// <inheritdoc/>
     260    public event EventHandler<EventArgs<IScope, int>> SubScopeAdded;
    261261    /// <summary>
    262262    /// Fires a new <c>SubScopeAdded</c> event.
     
    266266    protected virtual void OnSubScopeAdded(IScope scope, int index) {
    267267      if (SubScopeAdded != null)
    268         SubScopeAdded(this, new ScopeIndexEventArgs(scope, index));
    269     }
    270     /// <inheritdoc/>
    271     public event EventHandler<ScopeIndexEventArgs> SubScopeRemoved;
     268        SubScopeAdded(this, new EventArgs<IScope,int>(scope, index));
     269    }
     270    /// <inheritdoc/>
     271    public event EventHandler<EventArgs<IScope, int>> SubScopeRemoved;
    272272    /// <summary>
    273273    /// Fires a new <c>SubScopeRemoved</c> event.
     
    277277    protected virtual void OnSubScopeRemoved(IScope scope, int index) {
    278278      if (SubScopeRemoved != null)
    279         SubScopeRemoved(this, new ScopeIndexEventArgs(scope, index));
     279        SubScopeRemoved(this, new EventArgs<IScope,int>(scope, index));
    280280    }
    281281    /// <inheritdoc />
  • branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/Variable.cs

    r2042 r2046  
    4141      set {
    4242        if (!myName.Equals(value)) {
    43           NameChangingEventArgs e = new NameChangingEventArgs(value);
    44           OnNameChanging(e);
    45           if (!e.Cancel) {
     43          if (! OnNameChanging(value).Cancel) {
    4644            myName = value;
    4745            OnNameChanged();
     
    120118
    121119    /// <inheritdoc/>
    122     public event EventHandler<NameChangingEventArgs> NameChanging;
     120    public event EventHandler<CancelEventArgs<string>> NameChanging;
    123121    /// <summary>
    124122    /// Fires a new <c>NameChanging</c> event.
    125123    /// </summary>
    126124    /// <param name="e">The event arguments of the changing.</param>
    127     protected virtual void OnNameChanging(NameChangingEventArgs e) {
     125    protected virtual CancelEventArgs<string> OnNameChanging(string name) {
     126      CancelEventArgs<string> eventArgs = new CancelEventArgs<string>(name);
    128127      if (NameChanging != null)
    129         NameChanging(this, e);
     128        NameChanging(this, eventArgs);
     129      return eventArgs;
    130130    }
    131131    /// <inheritdoc/>
Note: See TracChangeset for help on using the changeset viewer.