Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/07/14 08:32:58 (10 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

Location:
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj

    r11412 r11421  
    4848  </ItemGroup>
    4949  <ItemGroup>
     50    <Compile Include="IPort.cs" />
    5051    <Compile Include="IVariablesNode.cs" />
     52    <Compile Include="Port.cs" />
    5153    <Compile Include="VariablesNode.cs" />
    5254    <Compile Include="EventArgs.cs" />
     
    6163    <Compile Include="INetwork.cs" />
    6264    <Compile Include="IInputPort.cs" />
    63     <Compile Include="IPort.cs" />
     65    <Compile Include="IValuePort.cs" />
    6466    <Compile Include="INode.cs" />
    6567    <Compile Include="Network.cs" />
     
    6769    <Compile Include="NodeCollection.cs" />
    6870    <Compile Include="PortCollection.cs" />
    69     <Compile Include="Port.cs" />
     71    <Compile Include="ValuePort.cs" />
    7072    <Compile Include="Plugin.cs" />
    7173    <Compile Include="Properties\AssemblyInfo.cs" />
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputOutputPort.cs

    r11412 r11421  
    2424
    2525namespace HeuristicLab.Optimization.Networks {
    26   public interface IInputOutputPort : IPort {
     26  public interface IInputOutputPort : IValuePort {
    2727    IOutputInputPort OutputInputPort { get; }
    2828
     
    3030  }
    3131
    32   public interface IInputOutputPort<TIn, TOut> : IInputOutputPort, IPort<TIn>
     32  public interface IInputOutputPort<TIn, TOut> : IInputOutputPort, IValuePort<TIn>
    3333    where TIn : class, IItem
    3434    where TOut : class, IItem {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputPort.cs

    r11412 r11421  
    2424
    2525namespace HeuristicLab.Optimization.Networks {
    26   public interface IInputPort : IPort {
     26  public interface IInputPort : IValuePort {
    2727    IOutputPort OutputPort { get; set; }
    2828
     
    3030  }
    3131
    32   public interface IInputPort<T> : IInputPort, IPort<T> where T : class, IItem {
     32  public interface IInputPort<T> : IInputPort, IValuePort<T> where T : class, IItem {
    3333    new IOutputPort<T> OutputPort { get; set; }
    3434  }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputInputPort.cs

    r11406 r11421  
    2424
    2525namespace HeuristicLab.Optimization.Networks {
    26   public interface IOutputInputPort : IPort {
     26  public interface IOutputInputPort : IValuePort {
    2727    object SendValue(object value);
    2828  }
    2929
    30   public interface IOutputInputPort<TOut, TIn> : IOutputInputPort, IPort<TOut>
     30  public interface IOutputInputPort<TOut, TIn> : IOutputInputPort, IValuePort<TOut>
    3131    where TOut : class, IItem
    3232    where TIn : class, IItem {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputPort.cs

    r11401 r11421  
    2323
    2424namespace HeuristicLab.Optimization.Networks {
    25   public interface IOutputPort : IPort {
     25  public interface IOutputPort : IValuePort {
    2626    new object Value { get; set; }
    2727  }
    2828
    29   public interface IOutputPort<T> : IOutputPort, IPort<T> where T : class, IItem {
     29  public interface IOutputPort<T> : IOutputPort, IValuePort<T> where T : class, IItem {
    3030    new T Value { get; set; }
    3131  }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IPort.cs

    r11409 r11421  
    2121
    2222using HeuristicLab.Core;
    23 using System;
    2423
    2524namespace HeuristicLab.Optimization.Networks {
    2625  public interface IPort : INamedItem {
    27     //DISCUSS: Should there be a reference to the node of this port?
    28 
    29     object Value { get; }
    30 
    31     event EventHandler ValueChanged;
    32   }
    33 
    34   public interface IPort<T> : IPort where T : class, IItem {
    35     new T Value { get; }
     26    INode Node { get; set; }
    3627  }
    3728}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputOutputPort.cs

    r11412 r11421  
    2828  [Item("InputOutputPort", "A synchronous input/output port of an optimization network node.")]
    2929  [StorableClass]
    30   public class InputOutputPort<TIn, TOut> : Port<TIn>, IInputOutputPort<TIn, TOut>
     30  public class InputOutputPort<TIn, TOut> : ValuePort<TIn>, IInputOutputPort<TIn, TOut>
    3131    where TIn : class, IItem
    3232    where TOut : class, IItem {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs

    r11412 r11421  
    2929  [Item("InputPort", "An asynchronous input port of an optimization network node.")]
    3030  [StorableClass]
    31   public class InputPort<T> : Port<T>, IInputPort<T> where T : class, IItem {
     31  public class InputPort<T> : ValuePort<T>, IInputPort<T> where T : class, IItem {
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown; }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Node.cs

    r11401 r11421  
    5656    public Node()
    5757      : base("Node") {
    58       ports = new PortCollection();
     58      ports = new PortCollection(this);
    5959      readOnlyPorts = null;
    6060    }
    6161    public Node(string name)
    6262      : base(name) {
    63       ports = new PortCollection();
     63      ports = new PortCollection(this);
    6464      readOnlyPorts = null;
    6565    }
    6666    public Node(string name, string description)
    6767      : base(name, description) {
    68       ports = new PortCollection();
     68      ports = new PortCollection(this);
    6969      readOnlyPorts = null;
    7070    }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputInputPort.cs

    r11406 r11421  
    2828  [Item("OutputInputPort", "A synchronous output/input port of an optimization network node.")]
    2929  [StorableClass]
    30   public class OutputInputPort<TOut, TIn> : Port<TOut>, IOutputInputPort<TOut, TIn>
     30  public class OutputInputPort<TOut, TIn> : ValuePort<TOut>, IOutputInputPort<TOut, TIn>
    3131    where TOut : class, IItem
    3232    where TIn : class, IItem {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputPort.cs

    r11409 r11421  
    2929  [Item("OutputPort", "An asynchronous output port of an optimization network node.")]
    3030  [StorableClass]
    31   public class OutputPort<T> : Port<T>, IOutputPort<T> where T : class, IItem {
     31  public class OutputPort<T> : ValuePort<T>, IOutputPort<T> where T : class, IItem {
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp; }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs

    r11406 r11421  
    2929  [Item("Port", "Abstract base class for ports of an optimization network node.")]
    3030  [StorableClass]
    31   public abstract class Port<T> : NamedItem, IPort<T> where T : class, IItem {
     31  public abstract class Port : NamedItem, IPort {
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; }
     
    3535
    3636    [Storable]
    37     protected T value;
    38     public virtual T Value {
    39       get { return value; }
    40       protected set {
    41         DeregisterValueEvents();
    42         this.value = value;
    43         RegisterValueEvents();
    44         OnValueChanged();
     37    private INode node;
     38    public INode Node {
     39      get { return node; }
     40      set {
     41        if ((value != null) && !value.Ports.Contains(this))
     42          throw new InvalidOperationException("Port is not contained in port collection of node.");
     43        if ((value == null) && node.Ports.Contains(this))
     44          throw new InvalidOperationException("Port is still contained in port collection of node.");
     45        node = value;
    4546      }
    46     }
    47     object IPort.Value {
    48       get { return Value; }
    4947    }
    5048
    5149    [StorableConstructor]
    5250    protected Port(bool deserializing) : base(deserializing) { }
    53     protected Port(Port<T> original, Cloner cloner)
     51    protected Port(Port original, Cloner cloner)
    5452      : base(original, cloner) {
    55       value = cloner.Clone(original.value);
    56       RegisterValueEvents();
     53      node = (INode)cloner.GetClone(original.node);  // NOTE: original node is NOT automatically cloned
    5754    }
    5855    protected Port() : base("Port") { }
    5956    protected Port(string name) : base(name) { }
    6057    protected Port(string name, string description) : base(name, description) { }
    61 
    62     [StorableHook(HookType.AfterDeserialization)]
    63     private void AfterDeserialization() {
    64       RegisterValueEvents();
    65     }
    66 
    67     public override string ToString() {
    68       return Name + ": " + (Value != null ? Value.ToString() : "null");
    69     }
    70 
    71     public event EventHandler ValueChanged;
    72     protected virtual void OnValueChanged() {
    73       var handler = ValueChanged;
    74       if (handler != null) handler(this, EventArgs.Empty);
    75       OnToStringChanged();
    76     }
    77 
    78     protected virtual void RegisterValueEvents() {
    79       if (value != null) {
    80         value.ToStringChanged += new EventHandler(Value_ToStringChanged);
    81       }
    82     }
    83     protected virtual void DeregisterValueEvents() {
    84       if (value != null) {
    85         value.ToStringChanged -= new EventHandler(Value_ToStringChanged);
    86       }
    87     }
    88     private void Value_ToStringChanged(object sender, EventArgs e) {
    89       OnToStringChanged();
    90     }
    9158  }
    9259}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/PortCollection.cs

    r11401 r11421  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using System;
     26using System.Collections.Generic;
    2627
    2728namespace HeuristicLab.Optimization.Networks {
    2829  [StorableClass]
    29   [Item("PortCollection", "Represents a collection of ports.")]
     30  [Item("PortCollection", "Represents a collection of ports in an optimization network node.")]
    3031  public class PortCollection : NamedItemCollection<IPort> {
     32    [Storable]
     33    private INode node;
     34    public INode Node {
     35      get { return node; }
     36    }
     37
    3138    [StorableConstructor]
    3239    protected PortCollection(bool deserializing) : base(deserializing) { }
    33     protected PortCollection(PortCollection original, Cloner cloner) : base(original, cloner) { }
    34     public PortCollection() : base() { }
    35     public PortCollection(int capacity) : base(capacity) { }
    36     public PortCollection(IEnumerable<IPort> collection) : base(collection) { }
     40    protected PortCollection(PortCollection original, Cloner cloner)
     41      : base(original, cloner) {
     42      if (!cloner.ClonedObjectRegistered(original.node))
     43        // NOTE: cannot clone port collection alone if referenced node is not cloned
     44        throw new InvalidOperationException("Node of port collection is not cloned.");
     45      node = cloner.Clone(original.node);
     46    }
     47    public PortCollection(INode node)
     48      : base() {
     49      this.node = node;
     50    }
     51    public PortCollection(INode node, int capacity)
     52      : base(capacity) {
     53      this.node = node;
     54    }
     55    public PortCollection(INode node, IEnumerable<IPort> collection)
     56      : base(collection) {
     57      this.node = node;
     58    }
    3759
    3860    public override IDeepCloneable Clone(Cloner cloner) { return new PortCollection(this, cloner); }
     61
     62    protected override void OnItemsAdded(IEnumerable<IPort> items) {
     63      foreach (var p in items)
     64        p.Node = node;
     65      base.OnItemsAdded(items);
     66    }
     67    protected override void OnItemsRemoved(IEnumerable<IPort> items) {
     68      foreach (var p in items)
     69        p.Node = null;
     70      base.OnItemsRemoved(items);
     71    }
     72    protected override void OnItemsReplaced(IEnumerable<IPort> items, IEnumerable<IPort> oldItems) {
     73      foreach (var p in oldItems)
     74        p.Node = null;
     75      foreach (var p in items)
     76        p.Node = node;
     77      base.OnItemsReplaced(items, oldItems);
     78    }
     79    protected override void OnCollectionReset(IEnumerable<IPort> items, IEnumerable<IPort> oldItems) {
     80      foreach (var p in oldItems)
     81        p.Node = null;
     82      foreach (var p in items)
     83        p.Node = node;
     84      base.OnCollectionReset(items, oldItems);
     85    }
    3986  }
    4087}
Note: See TracChangeset for help on using the changeset viewer.