Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14624


Ignore:
Timestamp:
01/31/17 13:58:50 (7 years ago)
Author:
mkommend
Message:

#2205: Refactored messages in orchestrated algorithm node.

Location:
branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratedAlgorithmNode.cs

    r14611 r14624  
    6565    [StorableConstructor]
    6666    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) {
    6869      EvalHook = cloner.Clone(original.EvalHook);
    6970      RegisterEvents();
    7071    }
    7172    public OrchestratedAlgorithmNode() : this("OrchestratedAlgorithmNode") { }
    72     public OrchestratedAlgorithmNode(string name) : base(name) {
     73    public OrchestratedAlgorithmNode(string name)
     74      : base(name) {
    7375      var orchestrationPort = new MessagePort(OrchestrationPortName);
    7476      Ports.Add(orchestrationPort);
     
    9597    #region Port Events
    9698    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;
    98101
    99102      #region Prepare
    100       if (message.HasFlag(OrchestrationMessage.Prepare)) {
     103      if (orchestrationMessage.HasFlag(OrchestrationMessage.Prepare)) {
    101104        switch (Algorithm.ExecutionState) {
    102105          case ExecutionState.Prepared:
     
    107110              var prob = (IHeuristicOptimizationProblem)problemMsgVal.Value.Clone();
    108111
    109               if (message.HasFlag(OrchestrationMessage.SetEvalHook)) {
     112              if (orchestrationMessage.HasFlag(OrchestrationMessage.SetEvalHook)) {
    110113                var instEval = prob.Evaluator as InstrumentedOperator;
    111114                if (instEval != null && EvalHook != null) instEval.AfterExecutionOperators.Add(EvalHook);
     
    137140              }
    138141
    139               Algorithm.Prepare(message.HasFlag(OrchestrationMessage.ClearRuns));
     142              Algorithm.Prepare(orchestrationMessage.HasFlag(OrchestrationMessage.ClearRuns));
    140143            }
    141144            break;
     
    145148
    146149      #region Start
    147       if (message.HasFlag(OrchestrationMessage.Start)) {
     150      if (orchestrationMessage.HasFlag(OrchestrationMessage.Start)) {
    148151        switch (Algorithm.ExecutionState) {
    149152          case ExecutionState.Prepared:
     
    172175
    173176            if (sendResultMessage) {
     177              message["Results"] = (ResultCollection)Algorithm.Results.Clone();
    174178              var msg = OrchestrationPort.PrepareMessage();
    175179              msg["Results"] = (ResultCollection)Algorithm.Results.Clone();
     
    182186
    183187      #region Pause
    184       if (message.HasFlag(OrchestrationMessage.Pause)) {
     188      if (orchestrationMessage.HasFlag(OrchestrationMessage.Pause)) {
    185189        if (Algorithm.ExecutionState == ExecutionState.Started) {
    186190          sendResultMessage = false;
    187191          try {
    188192            Algorithm.Pause();
    189           } catch (InvalidOperationException) {
     193          }
     194          catch (InvalidOperationException) {
    190195            // ExecutionState might have changed since we accepted the message
    191196          }
     
    195200
    196201      #region Stop
    197       if (message.HasFlag(OrchestrationMessage.Stop)) {
     202      if (orchestrationMessage.HasFlag(OrchestrationMessage.Stop)) {
    198203        switch (Algorithm.ExecutionState) {
    199204          case ExecutionState.Started:
     
    201206            try {
    202207              Algorithm.Stop();
    203             } catch (InvalidOperationException) {
     208            }
     209            catch (InvalidOperationException) {
    204210              // ExecutionState might have changed since we accepted the message
    205             } catch (NullReferenceException) {
     211            }
     212            catch (NullReferenceException) {
    206213              // BasicAlgorithm might have stopped since we accepted the message
    207214              // CancellationTokenSource is null in this case
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization/3.3/OrchestratorNode.cs

    r14616 r14624  
    3535  [StorableClass]
    3636  public abstract class OrchestratorNode : Node, IOrchestratorNode {
     37    //TODO remove suffixes
    3738    #region Constants
    3839    protected const string OrchestrationMessageParameterName = "OrchestrationMessage";
    39     protected const string OrchestrationPortNameSuffix = "OrchestrationPort";
    40     protected const string EvaluationPortNameSuffix = "EvaluationPort";
     40    protected const string OrchestrationPortNameSuffix = "";
     41    protected const string EvaluationPortNameSuffix = "";
    4142    #endregion
    4243
     
    6263    [StorableConstructor]
    6364    protected OrchestratorNode(bool deserializing) : base(deserializing) { }
    64     protected OrchestratorNode(OrchestratorNode original, Cloner cloner) : base(original, cloner) {
     65    protected OrchestratorNode(OrchestratorNode original, Cloner cloner)
     66      : base(original, cloner) {
    6567      results = cloner.Clone(original.results);
    6668      parameters = cloner.Clone(original.parameters);
     
    6971    }
    7072
    71     protected OrchestratorNode() : base("OrchestratorNode") {
     73    protected OrchestratorNode()
     74      : base("OrchestratorNode") {
    7275      results = new ResultCollection();
    7376      parameters = new ParameterCollection();
     
    7578      readOnlyParameters = null;
    7679    }
    77     protected OrchestratorNode(string name) : base(name) {
     80    protected OrchestratorNode(string name)
     81      : base(name) {
    7882      results = new ResultCollection();
    7983      parameters = new ParameterCollection();
     
    8185      readOnlyParameters = null;
    8286    }
    83     protected OrchestratorNode(string name, string description) : base(name, description) {
     87    protected OrchestratorNode(string name, string description)
     88      : base(name, description) {
    8489      results = new ResultCollection();
    8590      parameters = new ParameterCollection();
Note: See TracChangeset for help on using the changeset viewer.