Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14635


Ignore:
Timestamp:
02/01/17 18:25:28 (8 years ago)
Author:
jkarder
Message:

#2205: worked on optimization networks

  • created default parameters for orchestration and evaluation ports
  • adapted FeatureSelectionNetwork
Location:
branches/OptimizationNetworks
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.MachineLearning/FeatureSelectionNetwork.cs

    r14625 r14635  
    6060
    6161      var featureSelectionAlgorithm = CreateFeatureSelectionAlgorithm();
    62       //TOO configure FeatureSelectionProblem
     62      //TODO configure FeatureSelectionProblem
    6363
    6464      FeatureSelectionAlgorithmNode = new OrchestratedAlgorithmNode("Feature Selection");
     
    6969
    7070      var regressionAlgorithm = CreateRegressionAlgorithm();
    71       //TODO set empty regresion problem
     71      //TODO set empty regression problem
    7272
    7373      RegressionAlgorithmNode = new OrchestratedAlgorithmNode("Regression");
    7474      RegressionAlgorithmNode.Algorithm = regressionAlgorithm;
    75       RegressionAlgorithmNode.OrchestrationPort.ConnectedPort = Orchestrator.RegressionOrchestrationPort;
     75      Orchestrator.RegressionOrchestrationPort.ConnectedPort = RegressionAlgorithmNode.OrchestrationPort;
    7676      RegressionAlgorithmNode.OrchestrationPort.CloneParametersFromPort(Orchestrator.RegressionOrchestrationPort);
    7777      Nodes.Add(RegressionAlgorithmNode);
     
    103103    public void Prepare(bool clearRuns) {
    104104      var msg = FeatureSelectionAlgorithmNode.OrchestrationPort.PrepareMessage();
    105       msg.Values.Add(new MessageValue<EnumValue<OrchestrationMessage>>("OrchestrationMessage"));
    106105      if (clearRuns)
    107106        msg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Prepare | OrchestrationMessage.ClearRuns);
     
    116115
    117116      var msg = FeatureSelectionAlgorithmNode.OrchestrationPort.PrepareMessage();
    118       msg.Values.Add(new MessageValue<EnumValue<OrchestrationMessage>>("OrchestrationMessage"));
    119117      msg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Start);
    120118      FeatureSelectionAlgorithmNode.OrchestrationPort.ReceiveMessage(msg, new CancellationToken());
     
    122120    public void Pause() {
    123121      var msg = FeatureSelectionAlgorithmNode.OrchestrationPort.PrepareMessage();
    124       msg.Values.Add(new MessageValue<EnumValue<OrchestrationMessage>>("OrchestrationMessage"));
    125122      msg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Pause);
    126123      FeatureSelectionAlgorithmNode.OrchestrationPort.ReceiveMessage(msg, new CancellationToken());
     
    128125    public void Stop() {
    129126      var msg = FeatureSelectionAlgorithmNode.OrchestrationPort.PrepareMessage();
    130       msg.Values.Add(new MessageValue<EnumValue<OrchestrationMessage>>("OrchestrationMessage"));
    131127      msg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Stop);
    132128      FeatureSelectionAlgorithmNode.OrchestrationPort.ReceiveMessage(msg, new CancellationToken()); ;
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratedAlgorithmNode.cs

    r14631 r14635  
    7373    public OrchestratedAlgorithmNode(string name)
    7474      : 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"));
    8077
    8178      RegisterEvents();
     
    9390    private void RegisterEvents() {
    9491      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;
    95117    }
    96118
     
    106128          case ExecutionState.Paused:
    107129          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();
    111133
    112134              var heuristicOptimizationProblem = problem as IHeuristicOptimizationProblem;
     
    140162                }
    141163              }
    142 
    143               Algorithm.Prepare(messageFlags.HasFlag(OrchestrationMessage.ClearRuns));
    144164            }
     165
     166
     167            Algorithm.Prepare(messageFlags.HasFlag(OrchestrationMessage.ClearRuns));
    145168            break;
    146169        }
     
    192215          try {
    193216            Algorithm.Pause();
    194           }
    195           catch (InvalidOperationException) {
     217          } catch (InvalidOperationException) {
    196218            // ExecutionState might have changed since we accepted the message
    197219          }
     
    207229            try {
    208230              Algorithm.Stop();
    209             }
    210             catch (InvalidOperationException) {
     231            } catch (InvalidOperationException) {
    211232              // ExecutionState might have changed since we accepted the message
    212             }
    213             catch (NullReferenceException) {
     233            } catch (NullReferenceException) {
    214234              // BasicAlgorithm might have stopped since we accepted the message
    215235              // CancellationTokenSource is null in this case
Note: See TracChangeset for help on using the changeset viewer.