- Timestamp:
- 10/08/14 03:27:24 (10 years ago)
- Location:
- branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmNode.cs
r11412 r11423 116 116 117 117 #region Ports Events 118 private void RegisterPortsEvents() { 119 Ports.ItemsAdded += Ports_ItemsAdded; 120 Ports.ItemsRemoved += Ports_ItemsRemoved; 121 Ports.ItemsReplaced += Ports_ItemsReplaced; 122 Ports.CollectionReset += Ports_CollectionReset; 118 protected override void RegisterPortsEvents() { 119 base.RegisterPortsEvents(); 123 120 foreach (var p in Ports) 124 121 RegisterPortEvents(p); 125 122 } 126 void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 127 foreach (var p in e.Items) 128 RegisterPortEvents(p); 129 } 130 void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 123 protected override void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 124 base.Ports_ItemsAdded(sender, e); 125 foreach (var p in e.Items) 126 RegisterPortEvents(p); 127 } 128 protected override void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 129 base.Ports_ItemsRemoved(sender, e); 131 130 foreach (var p in e.Items) 132 131 DeregisterPortEvents(p); 133 132 } 134 void Ports_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 133 protected override void Ports_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 134 base.Ports_ItemsReplaced(sender, e); 135 135 foreach (var p in e.OldItems) 136 136 DeregisterPortEvents(p); … … 138 138 RegisterPortEvents(p); 139 139 } 140 void Ports_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 140 protected override void Ports_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 141 base.Ports_CollectionReset(sender, e); 141 142 foreach (var p in e.OldItems) 142 143 DeregisterPortEvents(p); -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj
r11421 r11423 36 36 <PropertyGroup> 37 37 <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile> 38 </PropertyGroup> 39 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> 40 <DebugSymbols>true</DebugSymbols> 41 <OutputPath>bin\x64\Debug\</OutputPath> 42 <DefineConstants>DEBUG;TRACE</DefineConstants> 43 <DebugType>full</DebugType> 44 <PlatformTarget>x64</PlatformTarget> 45 <ErrorReport>prompt</ErrorReport> 46 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 47 </PropertyGroup> 48 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> 49 <OutputPath>bin\x64\Release\</OutputPath> 50 <DefineConstants>TRACE</DefineConstants> 51 <Optimize>true</Optimize> 52 <DebugType>pdbonly</DebugType> 53 <PlatformTarget>x64</PlatformTarget> 54 <ErrorReport>prompt</ErrorReport> 55 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 56 </PropertyGroup> 57 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 58 <DebugSymbols>true</DebugSymbols> 59 <OutputPath>bin\x86\Debug\</OutputPath> 60 <DefineConstants>DEBUG;TRACE</DefineConstants> 61 <DebugType>full</DebugType> 62 <PlatformTarget>x86</PlatformTarget> 63 <ErrorReport>prompt</ErrorReport> 64 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 65 </PropertyGroup> 66 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 67 <OutputPath>bin\x86\Release\</OutputPath> 68 <DefineConstants>TRACE</DefineConstants> 69 <Optimize>true</Optimize> 70 <DebugType>pdbonly</DebugType> 71 <PlatformTarget>x86</PlatformTarget> 72 <ErrorReport>prompt</ErrorReport> 73 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 38 74 </PropertyGroup> 39 75 <ItemGroup> -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IPort.cs
r11421 r11423 24 24 namespace HeuristicLab.Optimization.Networks { 25 25 public interface IPort : INamedItem { 26 INode Node{ get; set; }26 INode Parent { get; set; } 27 27 } 28 28 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs
r11421 r11423 88 88 if (outputPort != null) { 89 89 outputPort.ValueChanged += OutputPort_ValueChanged; 90 outputPort.ToStringChanged += OutputPort_ToStringChanged; 90 91 } 91 92 } … … 93 94 if (outputPort != null) { 94 95 outputPort.ValueChanged -= OutputPort_ValueChanged; 96 outputPort.ToStringChanged -= OutputPort_ToStringChanged; 95 97 } 96 98 } … … 100 102 //DISCUSS: switch threads to decouple value propagation and to make communication asynchronous -> should be done in Node? 101 103 } 104 protected void OutputPort_ToStringChanged(object sender, EventArgs e) { 105 OnOutputPortChanged(); 106 } 102 107 } 103 108 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Node.cs
r11421 r11423 52 52 : base(original, cloner) { 53 53 ports = cloner.Clone(original.ports); 54 foreach (var p in Ports) 55 p.Parent = this; 54 56 readOnlyPorts = null; 57 RegisterPortsEvents(); 55 58 } 56 59 public Node() 57 60 : base("Node") { 58 ports = new PortCollection( this);61 ports = new PortCollection(); 59 62 readOnlyPorts = null; 63 RegisterPortsEvents(); 60 64 } 61 65 public Node(string name) 62 66 : base(name) { 63 ports = new PortCollection( this);67 ports = new PortCollection(); 64 68 readOnlyPorts = null; 69 RegisterPortsEvents(); 65 70 } 66 71 public Node(string name, string description) 67 72 : base(name, description) { 68 ports = new PortCollection( this);73 ports = new PortCollection(); 69 74 readOnlyPorts = null; 75 RegisterPortsEvents(); 76 } 77 78 [StorableHook(HookType.AfterDeserialization)] 79 private void AfterDeserialization() { 80 foreach (var p in Ports) 81 p.Parent = this; 82 RegisterPortsEvents(); 70 83 } 71 84 … … 73 86 return new Node(this, cloner); 74 87 } 88 89 #region Ports Events 90 protected virtual void RegisterPortsEvents() { 91 ports.ItemsAdded += Ports_ItemsAdded; 92 ports.ItemsRemoved += Ports_ItemsRemoved; 93 ports.ItemsReplaced += Ports_ItemsReplaced; 94 ports.CollectionReset += Ports_CollectionReset; 95 } 96 protected virtual void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 97 foreach (var p in e.Items) 98 p.Parent = this; 99 } 100 protected virtual void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 101 foreach (var p in e.Items) 102 p.Parent = null; 103 } 104 protected virtual void Ports_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 105 foreach (var p in e.OldItems) 106 p.Parent = null; 107 foreach (var p in e.Items) 108 p.Parent = this; 109 } 110 protected virtual void Ports_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 111 foreach (var p in e.OldItems) 112 p.Parent = null; 113 foreach (var p in e.Items) 114 p.Parent = this; 115 } 116 #endregion 75 117 } 76 118 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs
r11421 r11423 34 34 } 35 35 36 [Storable] 37 private INode node; 38 public INode Node { 39 get { return node; } 36 private INode parent; 37 public INode Parent { 38 get { return parent; } 40 39 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; 40 if (value != parent) { 41 // NOTE: never call setter directly as the Parent property is set by the node which contains the port 42 if ((value != null) && !value.Ports.Contains(this)) 43 throw new InvalidOperationException("Port is not contained in port collection of node."); 44 if ((value == null) && parent.Ports.Contains(this)) 45 throw new InvalidOperationException("Port is still contained in port collection of node."); 46 DeregisterParentEvents(); 47 parent = value; 48 RegisterParentEvents(); 49 OnToStringChanged(); 50 } 46 51 } 47 52 } … … 49 54 [StorableConstructor] 50 55 protected Port(bool deserializing) : base(deserializing) { } 51 protected Port(Port original, Cloner cloner) 52 : base(original, cloner) { 53 node = (INode)cloner.GetClone(original.node); // NOTE: original node is NOT automatically cloned 54 } 56 protected Port(Port original, Cloner cloner) : base(original, cloner) { } 55 57 protected Port() : base("Port") { } 56 58 protected Port(string name) : base(name) { } 57 59 protected Port(string name, string description) : base(name, description) { } 60 61 public override string ToString() { 62 if (parent != null) { 63 return string.Concat(parent.ToString(), " -> ", base.ToString()); 64 } 65 return base.ToString(); 66 } 67 68 #region Parent Events 69 protected virtual void RegisterParentEvents() { 70 if (parent != null) { 71 parent.ToStringChanged += Parent_ToStringChanged; 72 } 73 } 74 protected virtual void DeregisterParentEvents() { 75 if (parent != null) { 76 parent.ToStringChanged -= Parent_ToStringChanged; 77 } 78 } 79 void Parent_ToStringChanged(object sender, EventArgs e) { 80 OnToStringChanged(); 81 } 82 #endregion 58 83 } 59 84 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/PortCollection.cs
r11421 r11423 30 30 [Item("PortCollection", "Represents a collection of ports in an optimization network node.")] 31 31 public class PortCollection : NamedItemCollection<IPort> { 32 [Storable]33 private INode node;34 public INode Node {35 get { return node; }36 }37 38 32 [StorableConstructor] 39 33 protected PortCollection(bool deserializing) : base(deserializing) { } 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 } 34 protected PortCollection(PortCollection original, Cloner cloner) : base(original, cloner) { } 35 public PortCollection() : base() { } 36 public PortCollection(INode node, int capacity) : base(capacity) { } 37 public PortCollection(INode node, IEnumerable<IPort> collection) : base(collection) { } 59 38 60 39 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 }86 40 } 87 41 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/VariablesNode.cs
r11412 r11423 101 101 102 102 #region Ports Events 103 private void RegisterPortsEvents() { 104 Ports.ItemsAdded += Ports_ItemsAdded; 105 Ports.ItemsRemoved += Ports_ItemsRemoved; 106 Ports.ItemsReplaced += Ports_ItemsReplaced; 107 Ports.CollectionReset += Ports_CollectionReset; 103 protected override void RegisterPortsEvents() { 104 base.RegisterPortsEvents(); 108 105 foreach (var p in Ports) 109 106 RegisterPortEvents(p); 110 107 } 111 void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 112 foreach (var p in e.Items) 113 RegisterPortEvents(p); 114 } 115 void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 108 protected override void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 109 base.Ports_ItemsAdded(sender, e); 110 foreach (var p in e.Items) 111 RegisterPortEvents(p); 112 } 113 protected override void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 114 base.Ports_ItemsRemoved(sender, e); 116 115 foreach (var p in e.Items) 117 116 DeregisterPortEvents(p); 118 117 } 119 void Ports_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 118 protected override void Ports_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 119 base.Ports_ItemsReplaced(sender, e); 120 120 foreach (var p in e.OldItems) 121 121 DeregisterPortEvents(p); … … 123 123 RegisterPortEvents(p); 124 124 } 125 void Ports_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 125 protected override void Ports_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) { 126 base.Ports_CollectionReset(sender, e); 126 127 foreach (var p in e.OldItems) 127 128 DeregisterPortEvents(p);
Note: See TracChangeset
for help on using the changeset viewer.