- Timestamp:
- 10/25/14 02:54:42 (10 years ago)
- Location:
- branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj
r11500 r11501 108 108 <Compile Include="### obsolete\ServiceParameter.cs" /> 109 109 <Compile Include="### obsolete\ServiceParameterCollection.cs" /> 110 <Compile Include="Nodes\GenericNode.cs" /> 111 <Compile Include="Nodes\IGenericNode.cs" /> 112 <Compile Include="Ports\MessageCollection.cs" /> 110 113 <Compile Include="### obsolete\ServiceParameterCollectionCollection.cs" /> 111 114 <Compile Include="### obsolete\ServiceParameterType.cs" /> -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Nodes/AlgorithmServiceNode.cs
r11500 r11501 82 82 } 83 83 84 private void UpdateParameter(IInputPort port) { 85 if (template != null) { 86 IParameter param = null; 87 if (template.Parameters.TryGetValue(port.Name, out param)) { 88 IValueParameter p = param as IValueParameter; 89 if ((p != null) && (port.Value != null)) { 90 p.Value = (IItem)port.Value; 84 protected virtual void UpdateParameters(IMessage message, CancellationToken token) { 85 // set template parameters 86 lock (locker) { 87 if (template != null) { 88 foreach (var v in message.Values) { 89 IParameter param = null; 90 if (Template.Parameters.TryGetValue(v.Name, out param)) { 91 var vp = param as IValueParameter; 92 if (vp != null) vp.Value = v.Value; 93 } 94 if (Template.Problem.Parameters.TryGetValue(v.Name, out param)) { 95 var vp = param as IValueParameter; 96 if (vp != null) vp.Value = v.Value; 97 } 91 98 } 92 99 } … … 94 101 } 95 102 96 protected virtual void Execute( ServiceParameterCollection parameters, CancellationToken token) {103 protected virtual void Execute(IMessage message, CancellationToken token) { 97 104 if (Template == null) throw new InvalidOperationException("Template is null"); 98 105 … … 104 111 105 112 // set parameters 106 foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Input)) {113 foreach (var v in message.Values) { 107 114 IParameter param = null; 108 if (algorithm.Parameters.TryGetValue( p.Name, out param)) {109 var v = param as IValueParameter;110 if (v != null) v.Value = p.Value;111 } 112 if (algorithm.Problem.Parameters.TryGetValue( p.Name, out param)) {113 var v = param as IValueParameter;114 if (v != null) v.Value = p.Value;115 if (algorithm.Parameters.TryGetValue(v.Name, out param)) { 116 var vp = param as IValueParameter; 117 if (vp != null) vp.Value = v.Value; 118 } 119 if (algorithm.Problem.Parameters.TryGetValue(v.Name, out param)) { 120 var vp = param as IValueParameter; 121 if (vp != null) vp.Value = v.Value; 115 122 } 116 123 } … … 140 147 // retrieve results 141 148 var run = algorithm.Runs.First(); 142 foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) {149 foreach (var v in message.Values) { 143 150 IItem result = null; 144 if (run.Results.TryGetValue( p.Name, out result)) {145 p.Value = result;151 if (run.Results.TryGetValue(v.Name, out result)) { 152 v.Value = result; 146 153 } 147 154 } … … 205 212 #region Port Events 206 213 private void RegisterPortEvents(IPort port) { 207 IInputPort i = port as IInputPort; 208 if (i != null) { 209 i.NameChanged += InputPort_NameChanged; 210 i.ValueChanged += InputPort_ValueChanged; 211 UpdateParameter(i); 212 } 213 IServicePort s = port as IServicePort; 214 if (s != null) { 215 s.ProcessParameters += ServicePort_ProcessParameters; 216 } 217 } 218 214 IGenericPort g = port as IGenericPort; 215 if (g != null) { 216 g.MessageReceived += GenericPort_MessageReceived; 217 } 218 } 219 219 private void DeregisterPortEvents(IPort port) { 220 IInputPort i = port as IInputPort; 221 if (i != null) { 222 i.NameChanged -= InputPort_NameChanged; 223 i.ValueChanged -= InputPort_ValueChanged; 224 } 225 IServicePort s = port as IServicePort; 226 if (s != null) { 227 s.ProcessParameters -= ServicePort_ProcessParameters; 228 } 229 } 230 private void InputPort_NameChanged(object sender, EventArgs e) { 231 UpdateParameter((IInputPort)sender); 232 } 233 private void InputPort_ValueChanged(object sender, EventArgs e) { 234 UpdateParameter((IInputPort)sender); 235 } 236 private void ServicePort_ProcessParameters(object sender, EventArgs<ServiceParameterCollection, CancellationToken> e) { 237 Execute(e.Value, e.Value2); 220 IGenericPort g = port as IGenericPort; 221 if (g != null) { 222 g.MessageReceived -= GenericPort_MessageReceived; 223 } 224 } 225 private void GenericPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 226 var port = (IGenericPort)sender; 227 if (port.Parameters.Any(p => p.Type.HasFlag(PortParameterType.Output))) 228 Execute(e.Value, e.Value2); // execute algorithm to compute output 229 else 230 UpdateParameters(e.Value, e.Value2); // update template parameters 238 231 } 239 232 #endregion -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/GenericPort.cs
r11500 r11501 65 65 } 66 66 } 67 [Storable] 68 protected MessageCollection messages; 69 public MessageCollection Messages { 70 get { return messages; } 71 } 67 72 68 73 [StorableConstructor] 69 74 protected GenericPort(bool deserializing) : base(deserializing) { } 70 protected GenericPort(GenericPort original, Cloner cloner) : base(original, cloner) { 75 protected GenericPort(GenericPort original, Cloner cloner) 76 : base(original, cloner) { 71 77 connectedPort = cloner.Clone(original.connectedPort); 72 78 portConnectionValid = original.portConnectionValid; 79 messages = cloner.Clone(original.messages); 73 80 RegisterConnectedPortEvents(); 74 81 } 75 public GenericPort() : base("GenericPort") { } 76 public GenericPort(string name) : base(name) { } 77 public GenericPort(string name, string description) : base(name, description) { } 82 public GenericPort() 83 : base("GenericPort") { 84 portConnectionValid = true; 85 messages = new MessageCollection(); 86 } 87 public GenericPort(string name) 88 : base(name) { 89 portConnectionValid = true; 90 messages = new MessageCollection(); 91 } 92 public GenericPort(string name, string description) 93 : base(name, description) { 94 portConnectionValid = true; 95 messages = new MessageCollection(); 96 } 78 97 79 98 [StorableHook(HookType.AfterDeserialization)] … … 164 183 public void SendMessage(IMessage message, CancellationToken token) { 165 184 if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid"); 185 Messages.Add(message); 166 186 if (ConnectedPort != null) ConnectedPort.ReceiveMessage(message, token); 167 187 OnMessageSent(message, token); … … 180 200 181 201 public void ReceiveMessage(IMessage message, CancellationToken token) { 202 if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid"); 203 Messages.Add(message); 182 204 OnMessageReceived(message, token); 183 205 } … … 195 217 196 218 protected override void OnInterfaceChanged() { 197 PortConnectionValid = (connectedPort != null) &&CanConnectToPort(connectedPort);219 PortConnectionValid = CanConnectToPort(connectedPort); 198 220 base.OnInterfaceChanged(); 199 221 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/IGenericPort.cs
r11500 r11501 29 29 IConnectedPort ConnectedPort { get; set; } 30 30 bool PortConnectionValid { get; } 31 MessageCollection Messages { get; } 31 32 32 33 event EventHandler ConnectedPortChanged; -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/PortParameter.cs
r11500 r11501 35 35 public override Image ItemImage { 36 36 get { 37 if (Type == PortParameterType.Input) return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown; 38 else if (Type == PortParameterType.Output) return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp; 39 else return base.ItemImage; 37 if (Type.HasFlag(PortParameterType.Input) && Type.HasFlag(PortParameterType.Output)) 38 return HeuristicLab.Common.Resources.VSImageLibrary.Field; 39 else if (Type.HasFlag(PortParameterType.Input)) 40 return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown; 41 else if (Type.HasFlag(PortParameterType.Output)) 42 return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp; 43 else 44 return base.ItemImage; 40 45 } 41 46 } … … 96 101 RegisterDefaultValueEvents(); 97 102 } 98 public PortParameter() : base("PortParameter") { } 99 public PortParameter(string name) : base(name) { } 100 public PortParameter(string name, string description) : base(name, description) { } 103 public PortParameter() 104 : base("PortParameter") { 105 type = PortParameterType.Input; 106 } 107 public PortParameter(string name) 108 : base(name) { 109 type = PortParameterType.Input; 110 } 111 public PortParameter(string name, string description) 112 : base(name, description) { 113 type = PortParameterType.Input; 114 } 101 115 102 116 [StorableHook(HookType.AfterDeserialization)] -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/PortParameterType.cs
r11500 r11501 25 25 [Flags] 26 26 public enum PortParameterType { 27 None = 0, 27 28 Input = 1, 28 29 Output = 2
Note: See TracChangeset
for help on using the changeset viewer.