Changeset 14624 for branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratedAlgorithmNode.cs
- Timestamp:
- 01/31/17 13:58:50 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratedAlgorithmNode.cs
r14611 r14624 65 65 [StorableConstructor] 66 66 protected OrchestratedAlgorithmNode(bool deserializing) : base(deserializing) { } 67 protected OrchestratedAlgorithmNode(OrchestratedAlgorithmNode original, Cloner cloner) : base(original, cloner) { 67 protected OrchestratedAlgorithmNode(OrchestratedAlgorithmNode original, Cloner cloner) 68 : base(original, cloner) { 68 69 EvalHook = cloner.Clone(original.EvalHook); 69 70 RegisterEvents(); 70 71 } 71 72 public OrchestratedAlgorithmNode() : this("OrchestratedAlgorithmNode") { } 72 public OrchestratedAlgorithmNode(string name) : base(name) { 73 public OrchestratedAlgorithmNode(string name) 74 : base(name) { 73 75 var orchestrationPort = new MessagePort(OrchestrationPortName); 74 76 Ports.Add(orchestrationPort); … … 95 97 #region Port Events 96 98 private void OrchestrationPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 97 var message = ((EnumValue<OrchestrationMessage>)e.Value["OrchestrationMessage"]).Value; 99 var message = e.Value; 100 var orchestrationMessage = ((EnumValue<OrchestrationMessage>)message["OrchestrationMessage"]).Value; 98 101 99 102 #region Prepare 100 if ( message.HasFlag(OrchestrationMessage.Prepare)) {103 if (orchestrationMessage.HasFlag(OrchestrationMessage.Prepare)) { 101 104 switch (Algorithm.ExecutionState) { 102 105 case ExecutionState.Prepared: … … 107 110 var prob = (IHeuristicOptimizationProblem)problemMsgVal.Value.Clone(); 108 111 109 if ( message.HasFlag(OrchestrationMessage.SetEvalHook)) {112 if (orchestrationMessage.HasFlag(OrchestrationMessage.SetEvalHook)) { 110 113 var instEval = prob.Evaluator as InstrumentedOperator; 111 114 if (instEval != null && EvalHook != null) instEval.AfterExecutionOperators.Add(EvalHook); … … 137 140 } 138 141 139 Algorithm.Prepare( message.HasFlag(OrchestrationMessage.ClearRuns));142 Algorithm.Prepare(orchestrationMessage.HasFlag(OrchestrationMessage.ClearRuns)); 140 143 } 141 144 break; … … 145 148 146 149 #region Start 147 if ( message.HasFlag(OrchestrationMessage.Start)) {150 if (orchestrationMessage.HasFlag(OrchestrationMessage.Start)) { 148 151 switch (Algorithm.ExecutionState) { 149 152 case ExecutionState.Prepared: … … 172 175 173 176 if (sendResultMessage) { 177 message["Results"] = (ResultCollection)Algorithm.Results.Clone(); 174 178 var msg = OrchestrationPort.PrepareMessage(); 175 179 msg["Results"] = (ResultCollection)Algorithm.Results.Clone(); … … 182 186 183 187 #region Pause 184 if ( message.HasFlag(OrchestrationMessage.Pause)) {188 if (orchestrationMessage.HasFlag(OrchestrationMessage.Pause)) { 185 189 if (Algorithm.ExecutionState == ExecutionState.Started) { 186 190 sendResultMessage = false; 187 191 try { 188 192 Algorithm.Pause(); 189 } catch (InvalidOperationException) { 193 } 194 catch (InvalidOperationException) { 190 195 // ExecutionState might have changed since we accepted the message 191 196 } … … 195 200 196 201 #region Stop 197 if ( message.HasFlag(OrchestrationMessage.Stop)) {202 if (orchestrationMessage.HasFlag(OrchestrationMessage.Stop)) { 198 203 switch (Algorithm.ExecutionState) { 199 204 case ExecutionState.Started: … … 201 206 try { 202 207 Algorithm.Stop(); 203 } catch (InvalidOperationException) { 208 } 209 catch (InvalidOperationException) { 204 210 // ExecutionState might have changed since we accepted the message 205 } catch (NullReferenceException) { 211 } 212 catch (NullReferenceException) { 206 213 // BasicAlgorithm might have stopped since we accepted the message 207 214 // CancellationTokenSource is null in this case
Note: See TracChangeset
for help on using the changeset viewer.