Changeset 11519
- Timestamp:
- 11/02/14 03:03:21 (10 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 9 added
- 4 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/### obsolete/ServiceParameterView.cs
r11500 r11519 112 112 typeSelectorDialog = new TypeSelectorDialog(); 113 113 typeSelectorDialog.Caption = "Select Value"; 114 typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);115 114 } 115 typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true); 116 116 if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) { 117 117 try { -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/AlgorithmNodeView.Designer.cs
r11409 r11519 34 34 /// </summary> 35 35 private void InitializeComponent() { 36 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AlgorithmNodeView)); 36 37 this.portCollectionView = new HeuristicLab.Optimization.Networks.Views.PortCollectionView(); 37 38 this.tabControl = new HeuristicLab.MainForm.WindowsForms.DragOverTabControl(); … … 42 43 this.clearAlgorithmButton = new System.Windows.Forms.Button(); 43 44 this.setAlgorithmButton = new System.Windows.Forms.Button(); 45 this.runsTabPage = new System.Windows.Forms.TabPage(); 46 this.runCollectionView = new HeuristicLab.Optimization.Views.RunCollectionView(); 44 47 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 45 48 this.tabControl.SuspendLayout(); … … 47 50 this.algorithmTabPage.SuspendLayout(); 48 51 this.algorithmPanel.SuspendLayout(); 52 this.runsTabPage.SuspendLayout(); 49 53 this.SuspendLayout(); 50 54 // … … 56 60 // portCollectionView 57 61 // 58 this.portCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 59 | System.Windows.Forms.AnchorStyles.Left) 62 this.portCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 63 | System.Windows.Forms.AnchorStyles.Left) 60 64 | System.Windows.Forms.AnchorStyles.Right))); 61 65 this.portCollectionView.Caption = "PortCollection View"; … … 70 74 // tabControl 71 75 // 72 this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 73 | System.Windows.Forms.AnchorStyles.Left) 76 this.tabControl.AllowDrop = true; 77 this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 78 | System.Windows.Forms.AnchorStyles.Left) 74 79 | System.Windows.Forms.AnchorStyles.Right))); 75 80 this.tabControl.Controls.Add(this.portsTabPage); 76 81 this.tabControl.Controls.Add(this.algorithmTabPage); 82 this.tabControl.Controls.Add(this.runsTabPage); 77 83 this.tabControl.Location = new System.Drawing.Point(0, 26); 78 84 this.tabControl.Name = "tabControl"; … … 108 114 // 109 115 this.algorithmPanel.AllowDrop = true; 110 this.algorithmPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 111 | System.Windows.Forms.AnchorStyles.Left) 116 this.algorithmPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 117 | System.Windows.Forms.AnchorStyles.Left) 112 118 | System.Windows.Forms.AnchorStyles.Right))); 113 119 this.algorithmPanel.Controls.Add(this.algorithmViewHost); … … 153 159 this.setAlgorithmButton.UseVisualStyleBackColor = true; 154 160 this.setAlgorithmButton.Click += new System.EventHandler(this.setAlgorithmButton_Click); 161 // 162 // runsTabPage 163 // 164 this.runsTabPage.Controls.Add(this.runCollectionView); 165 this.runsTabPage.Location = new System.Drawing.Point(4, 22); 166 this.runsTabPage.Name = "runsTabPage"; 167 this.runsTabPage.Size = new System.Drawing.Size(637, 465); 168 this.runsTabPage.TabIndex = 2; 169 this.runsTabPage.Text = "Runs"; 170 this.runsTabPage.UseVisualStyleBackColor = true; 171 // 172 // runCollectionView 173 // 174 this.runCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 175 | System.Windows.Forms.AnchorStyles.Left) 176 | System.Windows.Forms.AnchorStyles.Right))); 177 this.runCollectionView.Caption = "RunCollection View"; 178 this.runCollectionView.Content = null; 179 this.runCollectionView.Location = new System.Drawing.Point(3, 3); 180 this.runCollectionView.Name = "runCollectionView"; 181 this.runCollectionView.ReadOnly = false; 182 this.runCollectionView.Size = new System.Drawing.Size(631, 459); 183 this.runCollectionView.TabIndex = 0; 155 184 // 156 185 // AlgorithmNodeView … … 168 197 this.algorithmTabPage.ResumeLayout(false); 169 198 this.algorithmPanel.ResumeLayout(false); 199 this.runsTabPage.ResumeLayout(false); 170 200 this.ResumeLayout(false); 171 201 this.PerformLayout(); … … 183 213 protected System.Windows.Forms.TabPage algorithmTabPage; 184 214 protected MainForm.WindowsForms.ViewHost algorithmViewHost; 215 protected System.Windows.Forms.TabPage runsTabPage; 216 protected Optimization.Views.RunCollectionView runCollectionView; 185 217 186 218 -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/AlgorithmNodeView.cs
r11452 r11519 64 64 portCollectionView.Content = null; 65 65 algorithmViewHost.Content = null; 66 runCollectionView.Content = null; 66 67 } else { 67 68 portCollectionView.Content = Content.Ports; 68 69 algorithmViewHost.ViewType = null; 69 70 algorithmViewHost.Content = Content.Algorithm; 71 runCollectionView.Content = Content.Runs; 70 72 } 71 73 } … … 77 79 clearAlgorithmButton.Enabled = Content != null && Content.Algorithm != null && !ReadOnly; 78 80 algorithmPanel.Enabled = Content != null; 81 runCollectionView.Enabled = Content != null && !ReadOnly; 79 82 } 80 83 -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.Designer.cs
r11501 r11519 43 43 this.portParameterCollectionView = new HeuristicLab.Optimization.Networks.Views.PortParameterCollectionView(); 44 44 this.messageCollectionView = new HeuristicLab.Optimization.Networks.Views.MessageCollectionView(); 45 this.logMessagesCheckBox = new System.Windows.Forms.CheckBox(); 45 46 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 46 47 this.connectedPortGroupBox.SuspendLayout(); … … 79 80 this.setConnectedPortButton.Size = new System.Drawing.Size(24, 24); 80 81 this.setConnectedPortButton.TabIndex = 0; 82 this.toolTip.SetToolTip(this.setConnectedPortButton, "Set Connected Port"); 81 83 this.setConnectedPortButton.UseVisualStyleBackColor = true; 82 84 this.setConnectedPortButton.Click += new System.EventHandler(this.setConnectedPortButton_Click); … … 89 91 this.clearConnectedPortButton.Size = new System.Drawing.Size(24, 24); 90 92 this.clearConnectedPortButton.TabIndex = 1; 93 this.toolTip.SetToolTip(this.clearConnectedPortButton, "Remove Connected Port"); 91 94 this.clearConnectedPortButton.UseVisualStyleBackColor = true; 92 95 this.clearConnectedPortButton.Click += new System.EventHandler(this.clearConnectedPortButton_Click); … … 146 149 // splitContainer.Panel2 147 150 // 151 this.splitContainer.Panel2.Controls.Add(this.logMessagesCheckBox); 148 152 this.splitContainer.Panel2.Controls.Add(this.messageCollectionView); 149 153 this.splitContainer.Size = new System.Drawing.Size(645, 435); … … 174 178 this.messageCollectionView.Size = new System.Drawing.Size(645, 213); 175 179 this.messageCollectionView.TabIndex = 0; 180 // 181 // logMessagesCheckBox 182 // 183 this.logMessagesCheckBox.AutoSize = true; 184 this.logMessagesCheckBox.Location = new System.Drawing.Point(156, 24); 185 this.logMessagesCheckBox.Name = "logMessagesCheckBox"; 186 this.logMessagesCheckBox.Size = new System.Drawing.Size(95, 17); 187 this.logMessagesCheckBox.TabIndex = 1; 188 this.logMessagesCheckBox.Text = "&Log Messages"; 189 this.logMessagesCheckBox.UseVisualStyleBackColor = true; 190 this.logMessagesCheckBox.CheckedChanged += new System.EventHandler(this.logMessagesCheckBox_CheckedChanged); 176 191 // 177 192 // GenericPortView … … 194 209 this.splitContainer.Panel1.ResumeLayout(false); 195 210 this.splitContainer.Panel2.ResumeLayout(false); 211 this.splitContainer.Panel2.PerformLayout(); 196 212 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 197 213 this.splitContainer.ResumeLayout(false); … … 212 228 protected PortParameterCollectionView portParameterCollectionView; 213 229 protected MessageCollectionView messageCollectionView; 230 protected System.Windows.Forms.CheckBox logMessagesCheckBox; 214 231 215 232 -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.cs
r11501 r11519 52 52 53 53 protected override void DeregisterContentEvents() { 54 Content.InterfaceChanged -= Content_InterfaceChanged;55 54 Content.ConnectedPortChanged -= Content_ConnectedPortChanged; 55 Content.PortConnectionValidChanged -= Content_PortConnectionValidChanged; 56 Content.LogMessagesChanged -= Content_LogMessagesChanged; 56 57 base.DeregisterContentEvents(); 57 58 } 58 59 protected override void RegisterContentEvents() { 59 60 base.RegisterContentEvents(); 60 Content.InterfaceChanged += Content_InterfaceChanged;61 61 Content.ConnectedPortChanged += Content_ConnectedPortChanged; 62 Content.PortConnectionValidChanged += Content_PortConnectionValidChanged; 63 Content.LogMessagesChanged += Content_LogMessagesChanged; 62 64 } 63 65 … … 66 68 connectedPortView.Content = Content == null ? null : Content.ConnectedPort; 67 69 portParameterCollectionView.Content = Content == null ? null : Content.Parameters; 70 logMessagesCheckBox.Checked = Content == null ? false : Content.LogMessages; 68 71 messageCollectionView.Content = Content == null ? null : Content.Messages; 69 72 errorProvider.SetError(connectedPortView, ((Content == null) || Content.PortConnectionValid) ? string.Empty : "Port connection is not valid"); … … 78 81 portParameterCollectionView.Enabled = Content != null && !ReadOnly; 79 82 cloneConnectedPortParametersButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly; 83 logMessagesCheckBox.Enabled = Content != null && !ReadOnly; 80 84 messageCollectionView.Enabled = Content != null && !ReadOnly; 81 85 } … … 90 94 } 91 95 } 92 protected virtual void Content_ InterfaceChanged(object sender, EventArgs e) {96 protected virtual void Content_PortConnectionValidChanged(object sender, EventArgs e) { 93 97 if (InvokeRequired) 94 Invoke(new EventHandler(Content_ InterfaceChanged), sender, e);98 Invoke(new EventHandler(Content_PortConnectionValidChanged), sender, e); 95 99 else { 96 100 errorProvider.SetError(connectedPortView, Content.PortConnectionValid ? string.Empty : "Port connection is not valid"); 101 } 102 } 103 protected virtual void Content_LogMessagesChanged(object sender, EventArgs e) { 104 if (InvokeRequired) 105 Invoke(new EventHandler(Content_LogMessagesChanged), sender, e); 106 else { 107 logMessagesCheckBox.Checked = Content.LogMessages; 97 108 } 98 109 } … … 148 159 Content.CloneConnectedPortParameters(); 149 160 } 161 protected virtual void logMessagesCheckBox_CheckedChanged(object sender, EventArgs e) { 162 Content.LogMessages = logMessagesCheckBox.Checked; 163 } 150 164 } 151 165 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/HeuristicLab.Optimization.Networks.Views-3.3.csproj
r11501 r11519 151 151 <DependentUpon>ClientNodeView.cs</DependentUpon> 152 152 </Compile> 153 <Compile Include="AlgorithmServiceNodeView.cs">154 <SubType>UserControl</SubType>155 </Compile>156 <Compile Include="AlgorithmServiceNodeView.Designer.cs">157 <DependentUpon>AlgorithmServiceNodeView.cs</DependentUpon>158 </Compile>159 153 <Compile Include="GenericPortView.cs"> 160 154 <SubType>UserControl</SubType> … … 180 174 <Compile Include="GenericNodeView.Designer.cs"> 181 175 <DependentUpon>GenericNodeView.cs</DependentUpon> 176 </Compile> 177 <Compile Include="HookOperatorView.cs"> 178 <SubType>UserControl</SubType> 179 </Compile> 180 <Compile Include="HookOperatorView.Designer.cs"> 181 <DependentUpon>HookOperatorView.cs</DependentUpon> 182 182 </Compile> 183 183 <Compile Include="ParameterizedPortView.cs"> … … 306 306 <Name>HeuristicLab.MainForm-3.3</Name> 307 307 </ProjectReference> 308 <ProjectReference Include="..\..\HeuristicLab.Operators.Views\3.3\HeuristicLab.Operators.Views-3.3.csproj"> 309 <Project>{c49cb749-8b24-4628-8003-e86475749410}</Project> 310 <Name>HeuristicLab.Operators.Views-3.3</Name> 311 </ProjectReference> 312 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> 313 <Project>{23da7ff4-d5b8-41b6-aa96-f0561d24f3ee}</Project> 314 <Name>HeuristicLab.Operators-3.3</Name> 315 </ProjectReference> 308 316 <ProjectReference Include="..\..\HeuristicLab.Optimization.Networks\3.3\HeuristicLab.Optimization.Networks-3.3.csproj"> 309 317 <Project>{7cf51332-0e37-447c-8017-82a258c59ef2}</Project> -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/Plugin.cs.frame
r11463 r11519 36 36 [PluginDependency("HeuristicLab.MainForm", "3.3")] 37 37 [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")] 38 [PluginDependency("HeuristicLab.Operators", "3.3")] 39 [PluginDependency("HeuristicLab.Operators.Views", "3.3")] 38 40 [PluginDependency("HeuristicLab.Optimization", "3.3")] 39 41 [PluginDependency("HeuristicLab.Optimization.Views", "3.3")] -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/PortParameterView.cs
r11500 r11519 119 119 typeSelectorDialog = new TypeSelectorDialog(); 120 120 typeSelectorDialog.Caption = "Select Default Value"; 121 typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);122 121 } 122 typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true); 123 123 if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) { 124 124 try { -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj
r11501 r11519 108 108 <Compile Include="### obsolete\ServiceParameter.cs" /> 109 109 <Compile Include="### obsolete\ServiceParameterCollection.cs" /> 110 <Compile Include="IHookOperator.cs" /> 111 <Compile Include="Nodes\KSPTSPConnector.cs" /> 110 112 <Compile Include="Nodes\GenericNode.cs" /> 111 113 <Compile Include="Nodes\IGenericNode.cs" /> 114 <Compile Include="Ports\ConfigurationPort.cs" /> 115 <Compile Include="Ports\ExecutionPort.cs" /> 116 <Compile Include="Ports\IConfigurationPort.cs" /> 117 <Compile Include="Ports\IExecutionPort.cs" /> 112 118 <Compile Include="Ports\MessageCollection.cs" /> 113 119 <Compile Include="### obsolete\ServiceParameterCollectionCollection.cs" /> … … 116 122 <Compile Include="### obsolete\ValuePort.cs" /> 117 123 <Compile Include="Nodes\AlgorithmNode.cs" /> 118 <Compile Include="Nodes\AlgorithmServiceNode.cs" />119 124 <Compile Include="Nodes\ClientNode.cs" /> 120 125 <Compile Include="Nodes\IAlgorithmNode.cs" /> 121 <Compile Include="Nodes\IAlgorithmServiceNode.cs" />122 126 <Compile Include="Nodes\IClientNode.cs" /> 123 127 <Compile Include="Nodes\INetwork.cs" /> … … 150 154 <Compile Include="Plugin.cs" /> 151 155 <Compile Include="Properties\AssemblyInfo.cs" /> 156 <Compile Include="HookOperator.cs" /> 152 157 </ItemGroup> 153 158 <ItemGroup> … … 177 182 <Project>{bbab9df5-5ef3-4ba8-ade9-b36e82114937}</Project> 178 183 <Name>HeuristicLab.Data-3.3</Name> 184 </ProjectReference> 185 <ProjectReference Include="..\..\HeuristicLab.Encodings.BinaryVectorEncoding\3.3\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj"> 186 <Project>{66d249c3-a01d-42a8-82a2-919bc8ec3d83}</Project> 187 <Name>HeuristicLab.Encodings.BinaryVectorEncoding-3.3</Name> 188 </ProjectReference> 189 <ProjectReference Include="..\..\HeuristicLab.Encodings.PermutationEncoding\3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.csproj"> 190 <Project>{dbecb8b0-b166-4133-baf1-ed67c3fd7fca}</Project> 191 <Name>HeuristicLab.Encodings.PermutationEncoding-3.3</Name> 192 </ProjectReference> 193 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> 194 <Project>{23da7ff4-d5b8-41b6-aa96-f0561d24f3ee}</Project> 195 <Name>HeuristicLab.Operators-3.3</Name> 179 196 </ProjectReference> 180 197 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Nodes/AlgorithmNode.cs
r11500 r11519 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 25 using System; 26 using System.Collections.Generic; 27 using System.Linq; 28 using System.Threading; 26 29 27 30 namespace HeuristicLab.Optimization.Networks { … … 29 32 [StorableClass] 30 33 public class AlgorithmNode : Node, IAlgorithmNode { 34 private object locker = new object(); 35 private Dictionary<IAlgorithm, AutoResetEvent> waitHandles = new Dictionary<IAlgorithm, AutoResetEvent>(); 36 private Dictionary<IAlgorithm, Exception> exceptions = new Dictionary<IAlgorithm, Exception>(); 37 31 38 new public PortCollection Ports { 32 39 get { return base.Ports; } … … 39 46 set { 40 47 if (value != algorithm) { 41 DeregisterAlgorithmEvents();42 48 algorithm = value; 43 RegisterAlgorithmEvents();44 49 OnAlgorithmChanged(); 45 50 } 46 51 } 52 } 53 54 [Storable] 55 private RunCollection runs; 56 public RunCollection Runs { 57 get { return runs; } 47 58 } 48 59 … … 52 63 : base(original, cloner) { 53 64 algorithm = cloner.Clone(original.algorithm); 54 RegisterAlgorithmEvents(); 55 } 56 public AlgorithmNode() : base("AlgorithmNode") { } 57 public AlgorithmNode(string name) : base(name) { } 58 public AlgorithmNode(string name, string description) : base(name, description) { } 59 60 [StorableHook(HookType.AfterDeserialization)] 61 private void AfterDeserialization() { 62 RegisterAlgorithmEvents(); 65 runs = cloner.Clone(original.runs); 66 } 67 public AlgorithmNode() 68 : base("AlgorithmNode") { 69 runs = new RunCollection(); 70 } 71 public AlgorithmNode(string name) 72 : base(name) { 73 runs = new RunCollection(); 74 } 75 public AlgorithmNode(string name, string description) 76 : base(name, description) { 77 runs = new RunCollection(); 63 78 } 64 79 … … 67 82 } 68 83 69 private void UpdateParameter(IInputPort port) { 70 if (algorithm != null) { 84 protected virtual void Configure(IConfigurationPort port, IMessage message, CancellationToken token) { 85 // set algorithm and problem parameters 86 lock (locker) { 87 if (algorithm != null) { 88 foreach (var v in message.Values) { 89 IParameter param = null; 90 if (Algorithm.Parameters.TryGetValue(v.Name, out param)) { 91 var vp = param as IValueParameter; 92 if (vp != null) vp.Value = v.Value; 93 } 94 if (Algorithm.Problem.Parameters.TryGetValue(v.Name, out param)) { 95 var vp = param as IValueParameter; 96 if (vp != null) vp.Value = v.Value; 97 } 98 } 99 } 100 } 101 } 102 103 protected virtual void Execute(IExecutionPort port, IMessage message, CancellationToken token) { 104 if (Algorithm == null) throw new InvalidOperationException("Algorithm is null"); 105 106 IAlgorithm algorithm; 107 lock (locker) { 108 algorithm = (IAlgorithm)Algorithm.Clone(); 109 waitHandles.Add(algorithm, new AutoResetEvent(false)); 110 } 111 112 // set parameters 113 foreach (var v in message.Values) { 71 114 IParameter param = null; 72 if (algorithm.Parameters.TryGetValue(port.Name, out param)) { 73 IValueParameter p = param as IValueParameter; 74 if ((p != null) && (port.Value != null)) { 75 p.Value = (IItem)port.Value; 76 } 77 } 78 } 79 } 80 private void UpdateOutputPort(IResult result) { 81 IPort port = null; 82 if (Ports.TryGetValue(result.Name, out port)) { 83 IOutputPort p = port as IOutputPort; 84 if (p != null) { 85 p.Value = result.Value; 86 } 87 } 88 } 89 private void UpdateOutputPort(IOutputPort port) { 90 if ((algorithm != null) && (algorithm.Results != null)) { 91 IResult result = null; 92 if (algorithm.Results.TryGetValue(port.Name, out result)) { 93 port.Value = result != null ? result.Value : null; 94 } else { 95 port.Value = null; 96 } 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; 122 } 123 } 124 125 algorithm.StoreAlgorithmInEachRun = false; 126 algorithm.Runs.Clear(); 127 algorithm.Prepare(); 128 algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred; 129 algorithm.Stopped += Algorithm_Stopped; 130 131 using (token.Register(() => { algorithm.Stop(); })) { 132 algorithm.Start(); 133 waitHandles[algorithm].WaitOne(); 134 } 135 136 lock (locker) { 137 waitHandles[algorithm].Dispose(); 138 waitHandles.Remove(algorithm); 139 140 Exception ex = null; 141 if (exceptions.TryGetValue(algorithm, out ex)) { 142 exceptions.Remove(algorithm); 143 throw ex; 144 } 145 } 146 147 // retrieve results 148 var run = algorithm.Runs.First(); 149 foreach (var v in message.Values) { 150 IItem result = null; 151 if (run.Results.TryGetValue(v.Name, out result)) { 152 v.Value = result; 153 } 154 } 155 156 lock (locker) { 157 Runs.Add(run); 158 } 159 } 160 161 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 162 var algorithm = (IAlgorithm)sender; 163 lock (locker) { 164 exceptions.Add(algorithm, e.Value); 165 } 166 algorithm.Stop(); 167 } 168 private void Algorithm_Stopped(object sender, EventArgs e) { 169 lock (locker) { 170 waitHandles[(IAlgorithm)sender].Set(); 97 171 } 98 172 } … … 138 212 #region Port Events 139 213 private void RegisterPortEvents(IPort port) { 140 IInputPort i = port as IInputPort; 141 if (i != null) { 142 i.NameChanged += InputPort_NameChanged; 143 i.ValueChanged += InputPort_ValueChanged; 144 UpdateParameter(i); 145 } 146 IOutputPort o = port as IOutputPort; 147 if (o != null) { 148 o.NameChanged += OutputPort_NameChanged; 149 UpdateOutputPort(o); 214 IConfigurationPort c = port as IConfigurationPort; 215 if (c != null) { 216 c.MessageReceived += ConfigurationPort_MessageReceived; 217 } 218 IExecutionPort e = port as IExecutionPort; 219 if (e != null) { 220 e.MessageReceived += ExecutionPort_MessageReceived; 150 221 } 151 222 } 152 223 private void DeregisterPortEvents(IPort port) { 153 IInputPort i = port as IInputPort; 154 if (i != null) { 155 i.NameChanged -= InputPort_NameChanged; 156 i.ValueChanged -= InputPort_ValueChanged; 157 } 158 IOutputPort o = port as IOutputPort; 159 if (o != null) { 160 o.NameChanged -= OutputPort_NameChanged; 161 } 162 } 163 private void InputPort_NameChanged(object sender, EventArgs e) { 164 UpdateParameter((IInputPort)sender); 165 } 166 private void InputPort_ValueChanged(object sender, EventArgs e) { 167 UpdateParameter((IInputPort)sender); 168 } 169 private void OutputPort_NameChanged(object sender, EventArgs e) { 170 UpdateOutputPort((IOutputPort)sender); 171 } 172 #endregion 173 174 #region Algorithm Events 175 private void RegisterAlgorithmEvents() { 176 if (algorithm != null) { 177 algorithm.Prepared += Algorithm_Prepared; 178 RegisterResultsEvents(); 179 } 180 } 181 182 private void DeregisterAlgorithmEvents() { 183 if (algorithm != null) { 184 algorithm.Prepared -= Algorithm_Prepared; 185 DeregisterResultsEvents(); 186 } 187 } 188 private void Algorithm_Prepared(object sender, EventArgs e) { 189 RegisterResultsEvents(); 190 } 191 #endregion 192 193 #region Results Events 194 private void RegisterResultsEvents() { 195 if ((algorithm != null) && (algorithm.Results != null)) { 196 algorithm.Results.ItemsAdded += Results_ItemsAdded; 197 algorithm.Results.ItemsRemoved += Results_ItemsRemoved; 198 algorithm.Results.ItemsReplaced += Results_ItemsReplaced; 199 algorithm.Results.CollectionReset += Results_CollectionReset; 200 foreach (var r in algorithm.Results) 201 RegisterResultEvents(r); 202 } 203 } 204 private void DeregisterResultsEvents() { 205 if ((algorithm != null) && (algorithm.Results != null)) { 206 algorithm.Results.ItemsAdded -= Results_ItemsAdded; 207 algorithm.Results.ItemsRemoved -= Results_ItemsRemoved; 208 algorithm.Results.ItemsReplaced -= Results_ItemsReplaced; 209 algorithm.Results.CollectionReset -= Results_CollectionReset; 210 foreach (var r in algorithm.Results) 211 DeregisterResultEvents(r); 212 } 213 } 214 private void Results_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) { 215 foreach (var r in e.Items) 216 RegisterResultEvents(r); 217 } 218 private void Results_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) { 219 foreach (var r in e.Items) 220 DeregisterResultEvents(r); 221 } 222 private void Results_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) { 223 foreach (var r in e.OldItems) 224 DeregisterResultEvents(r); 225 foreach (var r in e.Items) 226 RegisterResultEvents(r); 227 } 228 private void Results_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) { 229 foreach (var r in e.OldItems) 230 DeregisterResultEvents(r); 231 foreach (var r in e.Items) 232 RegisterResultEvents(r); 233 } 234 #endregion 235 236 #region Result Events 237 private void RegisterResultEvents(IResult result) { 238 if (result != null) { 239 result.ValueChanged += Result_ValueChanged; 240 result.ToStringChanged += Result_ToStringChanged; 241 UpdateOutputPort(result); 242 } 243 } 244 private void DeregisterResultEvents(IResult result) { 245 if (result != null) { 246 result.ValueChanged -= Result_ValueChanged; 247 result.ToStringChanged += Result_ToStringChanged; 248 } 249 } 250 private void Result_ValueChanged(object sender, EventArgs e) { 251 UpdateOutputPort((IResult)sender); 252 } 253 private void Result_ToStringChanged(object sender, EventArgs e) { 254 UpdateOutputPort((IResult)sender); 224 IConfigurationPort c = port as IConfigurationPort; 225 if (c != null) { 226 c.MessageReceived -= ConfigurationPort_MessageReceived; 227 } 228 IExecutionPort e = port as IExecutionPort; 229 if (e != null) { 230 e.MessageReceived -= ExecutionPort_MessageReceived; 231 } 232 } 233 protected virtual void ConfigurationPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 234 Configure((IConfigurationPort)sender, e.Value, e.Value2); 235 } 236 protected virtual void ExecutionPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 237 Execute((IExecutionPort)sender, e.Value, e.Value2); 255 238 } 256 239 #endregion -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Nodes/IAlgorithmNode.cs
r11500 r11519 26 26 new PortCollection Ports { get; } 27 27 IAlgorithm Algorithm { get; set; } 28 RunCollection Runs { get; } 28 29 29 30 event EventHandler AlgorithmChanged; -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Plugin.cs.frame
r11452 r11519 33 33 [PluginDependency("HeuristicLab.Core", "3.3")] 34 34 [PluginDependency("HeuristicLab.Data", "3.3")] 35 [PluginDependency("HeuristicLab.Encodings.BinaryVectorEncoding", "3.3")] 36 [PluginDependency("HeuristicLab.Encodings.PermutationEncoding", "3.3")] 37 [PluginDependency("HeuristicLab.Operators", "3.3")] 35 38 [PluginDependency("HeuristicLab.Optimization", "3.3")] 36 39 [PluginDependency("HeuristicLab.Persistence", "3.3")] -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/GenericPort.cs
r11501 r11519 61 61 if (value != portConnectionValid) { 62 62 portConnectionValid = value; 63 OnPortConnectionValidChanged(); 63 64 OnItemImageChanged(); 65 } 66 } 67 } 68 [Storable] 69 protected bool logMessages; 70 public bool LogMessages { 71 get { return logMessages; } 72 set { 73 if (value != logMessages) { 74 logMessages = value; 75 OnLogMessagesChanged(); 64 76 } 65 77 } … … 77 89 connectedPort = cloner.Clone(original.connectedPort); 78 90 portConnectionValid = original.portConnectionValid; 91 logMessages = original.logMessages; 79 92 messages = cloner.Clone(original.messages); 80 93 RegisterConnectedPortEvents(); … … 83 96 : base("GenericPort") { 84 97 portConnectionValid = true; 98 logMessages = false; 85 99 messages = new MessageCollection(); 86 100 } … … 88 102 : base(name) { 89 103 portConnectionValid = true; 104 logMessages = false; 90 105 messages = new MessageCollection(); 91 106 } … … 93 108 : base(name, description) { 94 109 portConnectionValid = true; 110 logMessages = false; 95 111 messages = new MessageCollection(); 96 112 } … … 183 199 public void SendMessage(IMessage message, CancellationToken token) { 184 200 if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid"); 185 Messages.Add(message);201 if (LogMessages) Messages.Add(message); 186 202 if (ConnectedPort != null) ConnectedPort.ReceiveMessage(message, token); 187 203 OnMessageSent(message, token); … … 201 217 public void ReceiveMessage(IMessage message, CancellationToken token) { 202 218 if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid"); 203 Messages.Add(message);219 if (LogMessages) Messages.Add(message); 204 220 OnMessageReceived(message, token); 205 221 } … … 213 229 protected virtual void OnConnectedPortChanged() { 214 230 var handler = ConnectedPortChanged; 231 if (handler != null) handler(this, EventArgs.Empty); 232 } 233 public event EventHandler PortConnectionValidChanged; 234 protected virtual void OnPortConnectionValidChanged() { 235 var handler = PortConnectionValidChanged; 236 if (handler != null) handler(this, EventArgs.Empty); 237 } 238 public event EventHandler LogMessagesChanged; 239 protected virtual void OnLogMessagesChanged() { 240 var handler = LogMessagesChanged; 215 241 if (handler != null) handler(this, EventArgs.Empty); 216 242 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/IGenericPort.cs
r11501 r11519 29 29 IConnectedPort ConnectedPort { get; set; } 30 30 bool PortConnectionValid { get; } 31 bool LogMessages { get; set; } 31 32 MessageCollection Messages { get; } 32 33 33 34 event EventHandler ConnectedPortChanged; 35 event EventHandler PortConnectionValidChanged; 36 event EventHandler LogMessagesChanged; 34 37 35 38 bool CanConnectToPort(IPort port); -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/IMessage.cs
r11500 r11519 25 25 public interface IMessage : IItem { 26 26 MessageValueCollection Values { get; } 27 IItem this[string valueName] { get; }27 IItem this[string valueName] { get; set; } 28 28 } 29 29 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/Message.cs
r11500 r11519 40 40 public IItem this[string valueName] { 41 41 get { return Values[valueName].Value; } 42 set { Values[valueName].Value = value; } 42 43 } 43 44
Note: See TracChangeset
for help on using the changeset viewer.