Changeset 14635
- Timestamp:
- 02/01/17 18:25:28 (8 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.MachineLearning/FeatureSelectionNetwork.cs
r14625 r14635 60 60 61 61 var featureSelectionAlgorithm = CreateFeatureSelectionAlgorithm(); 62 //TO O configure FeatureSelectionProblem62 //TODO configure FeatureSelectionProblem 63 63 64 64 FeatureSelectionAlgorithmNode = new OrchestratedAlgorithmNode("Feature Selection"); … … 69 69 70 70 var regressionAlgorithm = CreateRegressionAlgorithm(); 71 //TODO set empty regres ion problem71 //TODO set empty regression problem 72 72 73 73 RegressionAlgorithmNode = new OrchestratedAlgorithmNode("Regression"); 74 74 RegressionAlgorithmNode.Algorithm = regressionAlgorithm; 75 RegressionAlgorithmNode.OrchestrationPort.ConnectedPort = Orchestrator.RegressionOrchestrationPort;75 Orchestrator.RegressionOrchestrationPort.ConnectedPort = RegressionAlgorithmNode.OrchestrationPort; 76 76 RegressionAlgorithmNode.OrchestrationPort.CloneParametersFromPort(Orchestrator.RegressionOrchestrationPort); 77 77 Nodes.Add(RegressionAlgorithmNode); … … 103 103 public void Prepare(bool clearRuns) { 104 104 var msg = FeatureSelectionAlgorithmNode.OrchestrationPort.PrepareMessage(); 105 msg.Values.Add(new MessageValue<EnumValue<OrchestrationMessage>>("OrchestrationMessage"));106 105 if (clearRuns) 107 106 msg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Prepare | OrchestrationMessage.ClearRuns); … … 116 115 117 116 var msg = FeatureSelectionAlgorithmNode.OrchestrationPort.PrepareMessage(); 118 msg.Values.Add(new MessageValue<EnumValue<OrchestrationMessage>>("OrchestrationMessage"));119 117 msg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Start); 120 118 FeatureSelectionAlgorithmNode.OrchestrationPort.ReceiveMessage(msg, new CancellationToken()); … … 122 120 public void Pause() { 123 121 var msg = FeatureSelectionAlgorithmNode.OrchestrationPort.PrepareMessage(); 124 msg.Values.Add(new MessageValue<EnumValue<OrchestrationMessage>>("OrchestrationMessage"));125 122 msg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Pause); 126 123 FeatureSelectionAlgorithmNode.OrchestrationPort.ReceiveMessage(msg, new CancellationToken()); … … 128 125 public void Stop() { 129 126 var msg = FeatureSelectionAlgorithmNode.OrchestrationPort.PrepareMessage(); 130 msg.Values.Add(new MessageValue<EnumValue<OrchestrationMessage>>("OrchestrationMessage"));131 127 msg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Stop); 132 128 FeatureSelectionAlgorithmNode.OrchestrationPort.ReceiveMessage(msg, new CancellationToken()); ; -
branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratedAlgorithmNode.cs
r14631 r14635 73 73 public OrchestratedAlgorithmNode(string name) 74 74 : base(name) { 75 var orchestrationPort = new MessagePort(OrchestrationPortName); 76 Ports.Add(orchestrationPort); 77 78 var evaluationPort = new MessagePort(EvaluationPortName); 79 Ports.Add(evaluationPort); 75 Ports.Add(CreateOrchestrationPort<IProblem>(OrchestrationPortName)); 76 Ports.Add(CreateEvaluationPort<IItem>(EvaluationPortName, "Solution", "Quality")); 80 77 81 78 RegisterEvents(); … … 93 90 private void RegisterEvents() { 94 91 OrchestrationPort.MessageReceived += OrchestrationPort_MessageReceived; 92 } 93 94 protected IMessagePort CreateOrchestrationPort<T>(string portName) where T : class, IProblem { 95 var orchestrationPort = new MessagePort(portName); 96 orchestrationPort.Parameters.Add(new PortParameter<EnumValue<OrchestrationMessage>>("OrchestrationMessage") { 97 Type = PortParameterType.Input 98 }); 99 orchestrationPort.Parameters.Add(new PortParameter<T>("Problem") { 100 Type = PortParameterType.Input 101 }); 102 orchestrationPort.Parameters.Add(new PortParameter<ResultCollection>("Results") { 103 Type = PortParameterType.Output 104 }); 105 return orchestrationPort; 106 } 107 108 protected IMessagePort CreateEvaluationPort<T>(string portName, string solutionName, string qualityName) where T : class, IItem { 109 var evaluationPort = new MessagePort(portName); 110 evaluationPort.Parameters.Add(new PortParameter<T>(solutionName) { 111 Type = PortParameterType.Output 112 }); 113 evaluationPort.Parameters.Add(new PortParameter<DoubleValue>(qualityName) { 114 Type = PortParameterType.Input | PortParameterType.Output 115 }); 116 return evaluationPort; 95 117 } 96 118 … … 106 128 case ExecutionState.Paused: 107 129 case ExecutionState.Stopped: 108 IMessageValue problemMsgVal;109 if ( e.Value.Values.TryGetValue("Problem", out problemMsgVal)) {110 var problem = (IProblem)problemMsgVal.Value.Clone();130 var problem = (IProblem)requestMessage["Problem"]; 131 if (problem != null) { 132 problem = (IProblem)problem.Clone(); 111 133 112 134 var heuristicOptimizationProblem = problem as IHeuristicOptimizationProblem; … … 140 162 } 141 163 } 142 143 Algorithm.Prepare(messageFlags.HasFlag(OrchestrationMessage.ClearRuns));144 164 } 165 166 167 Algorithm.Prepare(messageFlags.HasFlag(OrchestrationMessage.ClearRuns)); 145 168 break; 146 169 } … … 192 215 try { 193 216 Algorithm.Pause(); 194 } 195 catch (InvalidOperationException) { 217 } catch (InvalidOperationException) { 196 218 // ExecutionState might have changed since we accepted the message 197 219 } … … 207 229 try { 208 230 Algorithm.Stop(); 209 } 210 catch (InvalidOperationException) { 231 } catch (InvalidOperationException) { 211 232 // ExecutionState might have changed since we accepted the message 212 } 213 catch (NullReferenceException) { 233 } catch (NullReferenceException) { 214 234 // BasicAlgorithm might have stopped since we accepted the message 215 235 // CancellationTokenSource is null in this case
Note: See TracChangeset
for help on using the changeset viewer.