- Timestamp:
- 01/31/17 16:54:03 (8 years ago)
- Location:
- branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3
- Files:
-
- 2 added
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/HeuristicLab.Networks.IntegratedOptimization-3.3.csproj
r14619 r14628 131 131 <ItemGroup> 132 132 <Compile Include="IOrchestratorNode.cs" /> 133 <Compile Include="MaximizationVariegationProblem.cs" /> 134 <Compile Include="MinimizationVariegationProblem.cs" /> 133 135 <Compile Include="OrchestratedAlgorithmNode.cs" /> 134 136 <Compile Include="OrchestrationMessage.cs" /> 135 137 <Compile Include="OrchestratorNode.cs" /> 136 <Compile Include="VariegationProblem.cs" />137 138 <None Include="Plugin.cs.frame" /> 138 139 <None Include="Properties\AssemblyInfo.cs.frame" /> -
branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratedAlgorithmNode.cs
r14624 r14628 65 65 [StorableConstructor] 66 66 protected OrchestratedAlgorithmNode(bool deserializing) : base(deserializing) { } 67 protected OrchestratedAlgorithmNode(OrchestratedAlgorithmNode original, Cloner cloner) 68 : base(original, cloner) { 67 protected OrchestratedAlgorithmNode(OrchestratedAlgorithmNode original, Cloner cloner) : base(original, cloner) { 69 68 EvalHook = cloner.Clone(original.EvalHook); 70 69 RegisterEvents(); 71 70 } 72 71 public OrchestratedAlgorithmNode() : this("OrchestratedAlgorithmNode") { } 73 public OrchestratedAlgorithmNode(string name) 74 : base(name) { 72 public OrchestratedAlgorithmNode(string name) : base(name) { 75 73 var orchestrationPort = new MessagePort(OrchestrationPortName); 76 74 Ports.Add(orchestrationPort); … … 97 95 #region Port Events 98 96 private void OrchestrationPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 99 var message = e.Value;100 var orchestrationMessage = ((EnumValue<OrchestrationMessage>)message["OrchestrationMessage"]).Value;97 var requestMessage = e.Value; 98 var messageFlags = ((EnumValue<OrchestrationMessage>)requestMessage["OrchestrationMessage"]).Value; 101 99 102 100 #region Prepare 103 if ( orchestrationMessage.HasFlag(OrchestrationMessage.Prepare)) {101 if (messageFlags.HasFlag(OrchestrationMessage.Prepare)) { 104 102 switch (Algorithm.ExecutionState) { 105 103 case ExecutionState.Prepared: … … 110 108 var prob = (IHeuristicOptimizationProblem)problemMsgVal.Value.Clone(); 111 109 112 if ( orchestrationMessage.HasFlag(OrchestrationMessage.SetEvalHook)) {110 if (messageFlags.HasFlag(OrchestrationMessage.SetEvalHook)) { 113 111 var instEval = prob.Evaluator as InstrumentedOperator; 114 112 if (instEval != null && EvalHook != null) instEval.AfterExecutionOperators.Add(EvalHook); … … 140 138 } 141 139 142 Algorithm.Prepare( orchestrationMessage.HasFlag(OrchestrationMessage.ClearRuns));140 Algorithm.Prepare(messageFlags.HasFlag(OrchestrationMessage.ClearRuns)); 143 141 } 144 142 break; … … 148 146 149 147 #region Start 150 if ( orchestrationMessage.HasFlag(OrchestrationMessage.Start)) {148 if (messageFlags.HasFlag(OrchestrationMessage.Start)) { 151 149 switch (Algorithm.ExecutionState) { 152 150 case ExecutionState.Prepared: … … 175 173 176 174 if (sendResultMessage) { 177 message["Results"] = (ResultCollection)Algorithm.Results.Clone();178 var msg= OrchestrationPort.PrepareMessage();179 msg["Results"] = (ResultCollection)Algorithm.Results.Clone();180 OrchestrationPort.SendMessage( msg);175 requestMessage["Results"] = (ResultCollection)Algorithm.Results.Clone(); 176 var responseMessage = OrchestrationPort.PrepareMessage(); 177 responseMessage["Results"] = (ResultCollection)Algorithm.Results.Clone(); 178 OrchestrationPort.SendMessage(responseMessage); 181 179 } else sendResultMessage = true; 182 180 break; … … 186 184 187 185 #region Pause 188 if ( orchestrationMessage.HasFlag(OrchestrationMessage.Pause)) {186 if (messageFlags.HasFlag(OrchestrationMessage.Pause)) { 189 187 if (Algorithm.ExecutionState == ExecutionState.Started) { 190 188 sendResultMessage = false; 191 189 try { 192 190 Algorithm.Pause(); 193 } 194 catch (InvalidOperationException) { 191 } catch (InvalidOperationException) { 195 192 // ExecutionState might have changed since we accepted the message 196 193 } … … 200 197 201 198 #region Stop 202 if ( orchestrationMessage.HasFlag(OrchestrationMessage.Stop)) {199 if (messageFlags.HasFlag(OrchestrationMessage.Stop)) { 203 200 switch (Algorithm.ExecutionState) { 204 201 case ExecutionState.Started: … … 206 203 try { 207 204 Algorithm.Stop(); 208 } 209 catch (InvalidOperationException) { 205 } catch (InvalidOperationException) { 210 206 // ExecutionState might have changed since we accepted the message 211 } 212 catch (NullReferenceException) { 207 } catch (NullReferenceException) { 213 208 // BasicAlgorithm might have stopped since we accepted the message 214 209 // CancellationTokenSource is null in this case -
branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratorNode.cs
r14624 r14628 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters;31 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 31 … … 35 34 [StorableClass] 36 35 public abstract class OrchestratorNode : Node, IOrchestratorNode { 37 //TODO remove suffixes38 #region Constants39 protected const string OrchestrationMessageParameterName = "OrchestrationMessage";40 protected const string OrchestrationPortNameSuffix = "";41 protected const string EvaluationPortNameSuffix = "";42 #endregion43 44 36 [Storable] 45 37 private ParameterCollection parameters; … … 63 55 [StorableConstructor] 64 56 protected OrchestratorNode(bool deserializing) : base(deserializing) { } 65 protected OrchestratorNode(OrchestratorNode original, Cloner cloner) 66 : base(original, cloner) { 57 protected OrchestratorNode(OrchestratorNode original, Cloner cloner) : base(original, cloner) { 67 58 results = cloner.Clone(original.results); 68 59 parameters = cloner.Clone(original.parameters); … … 71 62 } 72 63 73 protected OrchestratorNode() 74 : base("OrchestratorNode") { 64 protected OrchestratorNode() : base("OrchestratorNode") { 75 65 results = new ResultCollection(); 76 66 parameters = new ParameterCollection(); 77 Parameters.Add(new ValueParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage", new EnumValue<OrchestrationMessage>()));78 67 readOnlyParameters = null; 79 68 } 80 protected OrchestratorNode(string name) 81 : base(name) { 69 protected OrchestratorNode(string name) : base(name) { 82 70 results = new ResultCollection(); 83 71 parameters = new ParameterCollection(); 84 Parameters.Add(new ValueParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage", new EnumValue<OrchestrationMessage>()));85 72 readOnlyParameters = null; 86 73 } 87 protected OrchestratorNode(string name, string description) 88 : base(name, description) { 74 protected OrchestratorNode(string name, string description) : base(name, description) { 89 75 results = new ResultCollection(); 90 76 parameters = new ParameterCollection(); 91 Parameters.Add(new ValueParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage", new EnumValue<OrchestrationMessage>()));92 77 readOnlyParameters = null; 93 78 } … … 102 87 } 103 88 104 protected IMessagePort CreateOrchestrationPort<T>(string solverName) where T : class, IProblem {105 var orchestrationPort = new MessagePort( solverName + OrchestrationPortNameSuffix);89 protected IMessagePort CreateOrchestrationPort<T>(string portName) where T : class, IProblem { 90 var orchestrationPort = new MessagePort(portName); 106 91 orchestrationPort.Parameters.Add(new PortParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage") { 107 92 Type = PortParameterType.Output … … 116 101 } 117 102 118 protected IMessagePort CreateEvaluationPort<T>(string solverName, string solutionName, string qualityName) where T : class, IItem {119 var evaluationPort = new MessagePort( solverName + EvaluationPortNameSuffix);103 protected IMessagePort CreateEvaluationPort<T>(string portName, string solutionName, string qualityName) where T : class, IItem { 104 var evaluationPort = new MessagePort(portName); 120 105 evaluationPort.Parameters.Add(new PortParameter<T>(solutionName) { 121 106 Type = PortParameterType.Input
Note: See TracChangeset
for help on using the changeset viewer.