Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/25/14 02:54:42 (10 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

Location:
branches/OptimizationNetworks
Files:
8 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.Designer.cs

    r11500 r11501  
    3939      this.connectedPortView = new HeuristicLab.Optimization.Networks.Views.PortView();
    4040      this.cloneConnectedPortParametersButton = new System.Windows.Forms.Button();
     41      this.sendMessageButton = new System.Windows.Forms.Button();
     42      this.splitContainer = new System.Windows.Forms.SplitContainer();
     43      this.portParameterCollectionView = new HeuristicLab.Optimization.Networks.Views.PortParameterCollectionView();
     44      this.messageCollectionView = new HeuristicLab.Optimization.Networks.Views.MessageCollectionView();
    4145      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    4246      this.connectedPortGroupBox.SuspendLayout();
     47      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     48      this.splitContainer.Panel1.SuspendLayout();
     49      this.splitContainer.Panel2.SuspendLayout();
     50      this.splitContainer.SuspendLayout();
    4351      this.SuspendLayout();
    44       //
    45       // portParameterCollectionView
    46       //
    47       this.portParameterCollectionView.Location = new System.Drawing.Point(0, 82);
    48       this.portParameterCollectionView.Size = new System.Drawing.Size(645, 435);
    49       this.portParameterCollectionView.TabIndex = 4;
    5052      //
    5153      // nameTextBox
     
    5355      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    5456      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    55       this.nameTextBox.Location = new System.Drawing.Point(71, 0);
    56       this.nameTextBox.Size = new System.Drawing.Size(549, 20);
     57      this.nameTextBox.Location = new System.Drawing.Point(47, 0);
     58      this.nameTextBox.Size = new System.Drawing.Size(573, 20);
    5759      //
    5860      // connectedPortGroupBox
     
    6365      this.connectedPortGroupBox.Controls.Add(this.clearConnectedPortButton);
    6466      this.connectedPortGroupBox.Controls.Add(this.connectedPortView);
    65       this.connectedPortGroupBox.Location = new System.Drawing.Point(0, 26);
     67      this.connectedPortGroupBox.Location = new System.Drawing.Point(47, 26);
    6668      this.connectedPortGroupBox.Name = "connectedPortGroupBox";
    67       this.connectedPortGroupBox.Size = new System.Drawing.Size(645, 50);
    68       this.connectedPortGroupBox.TabIndex = 3;
     69      this.connectedPortGroupBox.Size = new System.Drawing.Size(598, 50);
     70      this.connectedPortGroupBox.TabIndex = 4;
    6971      this.connectedPortGroupBox.TabStop = false;
    7072      this.connectedPortGroupBox.Text = "&Connected Port";
     
    101103      this.connectedPortView.Name = "connectedPortView";
    102104      this.connectedPortView.ReadOnly = true;
    103       this.connectedPortView.Size = new System.Drawing.Size(554, 23);
     105      this.connectedPortView.Size = new System.Drawing.Size(507, 23);
    104106      this.connectedPortView.TabIndex = 2;
    105107      this.connectedPortView.DragDrop += new System.Windows.Forms.DragEventHandler(this.connectedPortView_DragDrop);
     
    118120      this.cloneConnectedPortParametersButton.Click += new System.EventHandler(this.cloneConnectedPortParametersButton_Click);
    119121      //
     122      // sendMessageButton
     123      //
     124      this.sendMessageButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Exception;
     125      this.sendMessageButton.Location = new System.Drawing.Point(6, 45);
     126      this.sendMessageButton.Name = "sendMessageButton";
     127      this.sendMessageButton.Size = new System.Drawing.Size(24, 24);
     128      this.sendMessageButton.TabIndex = 3;
     129      this.toolTip.SetToolTip(this.sendMessageButton, "Send Message");
     130      this.sendMessageButton.UseVisualStyleBackColor = true;
     131      this.sendMessageButton.Click += new System.EventHandler(this.sendMessageButton_Click);
     132      //
     133      // splitContainer
     134      //
     135      this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     136            | System.Windows.Forms.AnchorStyles.Left)
     137            | System.Windows.Forms.AnchorStyles.Right)));
     138      this.splitContainer.Location = new System.Drawing.Point(0, 82);
     139      this.splitContainer.Name = "splitContainer";
     140      this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
     141      //
     142      // splitContainer.Panel1
     143      //
     144      this.splitContainer.Panel1.Controls.Add(this.portParameterCollectionView);
     145      //
     146      // splitContainer.Panel2
     147      //
     148      this.splitContainer.Panel2.Controls.Add(this.messageCollectionView);
     149      this.splitContainer.Size = new System.Drawing.Size(645, 435);
     150      this.splitContainer.SplitterDistance = 218;
     151      this.splitContainer.TabIndex = 7;
     152      //
     153      // portParameterCollectionView
     154      //
     155      this.portParameterCollectionView.Caption = "PortParameterCollection View";
     156      this.portParameterCollectionView.Content = null;
     157      this.portParameterCollectionView.Dock = System.Windows.Forms.DockStyle.Fill;
     158      this.portParameterCollectionView.Location = new System.Drawing.Point(0, 0);
     159      this.portParameterCollectionView.Name = "portParameterCollectionView";
     160      this.portParameterCollectionView.ReadOnly = false;
     161      this.portParameterCollectionView.ShowDetails = true;
     162      this.portParameterCollectionView.Size = new System.Drawing.Size(645, 218);
     163      this.portParameterCollectionView.TabIndex = 0;
     164      //
     165      // messageCollectionView
     166      //
     167      this.messageCollectionView.Caption = "MessageCollection View";
     168      this.messageCollectionView.Content = null;
     169      this.messageCollectionView.Dock = System.Windows.Forms.DockStyle.Fill;
     170      this.messageCollectionView.Location = new System.Drawing.Point(0, 0);
     171      this.messageCollectionView.Name = "messageCollectionView";
     172      this.messageCollectionView.ReadOnly = false;
     173      this.messageCollectionView.ShowDetails = true;
     174      this.messageCollectionView.Size = new System.Drawing.Size(645, 213);
     175      this.messageCollectionView.TabIndex = 0;
     176      //
    120177      // GenericPortView
    121178      //
    122179      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     180      this.Controls.Add(this.sendMessageButton);
    123181      this.Controls.Add(this.cloneConnectedPortParametersButton);
    124182      this.Controls.Add(this.connectedPortGroupBox);
     183      this.Controls.Add(this.splitContainer);
    125184      this.Name = "GenericPortView";
    126       this.Controls.SetChildIndex(this.portParameterCollectionView, 0);
     185      this.Controls.SetChildIndex(this.splitContainer, 0);
    127186      this.Controls.SetChildIndex(this.nameLabel, 0);
    128187      this.Controls.SetChildIndex(this.nameTextBox, 0);
     
    130189      this.Controls.SetChildIndex(this.connectedPortGroupBox, 0);
    131190      this.Controls.SetChildIndex(this.cloneConnectedPortParametersButton, 0);
     191      this.Controls.SetChildIndex(this.sendMessageButton, 0);
    132192      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    133193      this.connectedPortGroupBox.ResumeLayout(false);
     194      this.splitContainer.Panel1.ResumeLayout(false);
     195      this.splitContainer.Panel2.ResumeLayout(false);
     196      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
     197      this.splitContainer.ResumeLayout(false);
    134198      this.ResumeLayout(false);
    135199      this.PerformLayout();
     
    144208    protected System.Windows.Forms.Button setConnectedPortButton;
    145209    protected System.Windows.Forms.Button cloneConnectedPortParametersButton;
     210    protected System.Windows.Forms.Button sendMessageButton;
     211    protected System.Windows.Forms.SplitContainer splitContainer;
     212    protected PortParameterCollectionView portParameterCollectionView;
     213    protected MessageCollectionView messageCollectionView;
    146214
    147215
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.cs

    r11500 r11501  
    2929  [Content(typeof(GenericPort), true)]
    3030  [Content(typeof(IGenericPort), false)]
    31   public partial class GenericPortView : ParameterizedPortView {
     31  public partial class GenericPortView : PortView {
    3232    protected EntitySelectorDialog entitySelectorDialog;
    3333
     
    5252
    5353    protected override void DeregisterContentEvents() {
     54      Content.InterfaceChanged -= Content_InterfaceChanged;
    5455      Content.ConnectedPortChanged -= Content_ConnectedPortChanged;
    5556      base.DeregisterContentEvents();
     
    5758    protected override void RegisterContentEvents() {
    5859      base.RegisterContentEvents();
     60      Content.InterfaceChanged += Content_InterfaceChanged;
    5961      Content.ConnectedPortChanged += Content_ConnectedPortChanged;
    6062    }
     
    6365      base.OnContentChanged();
    6466      connectedPortView.Content = Content == null ? null : Content.ConnectedPort;
     67      portParameterCollectionView.Content = Content == null ? null : Content.Parameters;
     68      messageCollectionView.Content = Content == null ? null : Content.Messages;
    6569      errorProvider.SetError(connectedPortView, ((Content == null) || Content.PortConnectionValid) ? string.Empty : "Port connection is not valid");
    6670    }
     
    6872    protected override void SetEnabledStateOfControls() {
    6973      base.SetEnabledStateOfControls();
     74      sendMessageButton.Enabled = Content != null;
    7075      connectedPortGroupBox.Enabled = Content != null && !ReadOnly;
    7176      setConnectedPortButton.Enabled = Content != null && !ReadOnly;
    7277      clearConnectedPortButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly;
     78      portParameterCollectionView.Enabled = Content != null && !ReadOnly;
    7379      cloneConnectedPortParametersButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly;
     80      messageCollectionView.Enabled = Content != null && !ReadOnly;
    7481    }
    7582
     
    8390      }
    8491    }
    85     protected override void Content_InterfaceChanged(object sender, EventArgs e) {
     92    protected virtual void Content_InterfaceChanged(object sender, EventArgs e) {
    8693      if (InvokeRequired)
    8794        Invoke(new EventHandler(Content_InterfaceChanged), sender, e);
    8895      else {
    89         base.Content_InterfaceChanged(sender, e);
    9096        errorProvider.SetError(connectedPortView, Content.PortConnectionValid ? string.Empty : "Port connection is not valid");
    9197      }
     98    }
     99
     100    protected virtual void sendMessageButton_Click(object sender, EventArgs e) {
     101      Content.SendMessageAsync(Content.PrepareMessage());
    92102    }
    93103
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/HeuristicLab.Optimization.Networks.Views-3.3.csproj

    r11500 r11501  
    115115      <DependentUpon>InputPortView.cs</DependentUpon>
    116116    </Compile>
     117    <Compile Include="MessageCollectionView.cs">
     118      <SubType>UserControl</SubType>
     119    </Compile>
     120    <Compile Include="MessageCollectionView.Designer.cs">
     121      <DependentUpon>MessageCollectionView.cs</DependentUpon>
     122    </Compile>
    117123    <Compile Include="### obsolete\ServiceParameterCollectionCollectionView.cs">
    118124      <SubType>UserControl</SubType>
     
    168174    <Compile Include="MessageView.Designer.cs">
    169175      <DependentUpon>MessageView.cs</DependentUpon>
     176    </Compile>
     177    <Compile Include="GenericNodeView.cs">
     178      <SubType>UserControl</SubType>
     179    </Compile>
     180    <Compile Include="GenericNodeView.Designer.cs">
     181      <DependentUpon>GenericNodeView.cs</DependentUpon>
    170182    </Compile>
    171183    <Compile Include="ParameterizedPortView.cs">
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj

    r11500 r11501  
    108108    <Compile Include="### obsolete\ServiceParameter.cs" />
    109109    <Compile Include="### obsolete\ServiceParameterCollection.cs" />
     110    <Compile Include="Nodes\GenericNode.cs" />
     111    <Compile Include="Nodes\IGenericNode.cs" />
     112    <Compile Include="Ports\MessageCollection.cs" />
    110113    <Compile Include="### obsolete\ServiceParameterCollectionCollection.cs" />
    111114    <Compile Include="### obsolete\ServiceParameterType.cs" />
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Nodes/AlgorithmServiceNode.cs

    r11500 r11501  
    8282    }
    8383
    84     private void UpdateParameter(IInputPort port) {
    85       if (template != null) {
    86         IParameter param = null;
    87         if (template.Parameters.TryGetValue(port.Name, out param)) {
    88           IValueParameter p = param as IValueParameter;
    89           if ((p != null) && (port.Value != null)) {
    90             p.Value = (IItem)port.Value;
     84    protected virtual void UpdateParameters(IMessage message, CancellationToken token) {
     85      // set template parameters
     86      lock (locker) {
     87        if (template != null) {
     88          foreach (var v in message.Values) {
     89            IParameter param = null;
     90            if (Template.Parameters.TryGetValue(v.Name, out param)) {
     91              var vp = param as IValueParameter;
     92              if (vp != null) vp.Value = v.Value;
     93            }
     94            if (Template.Problem.Parameters.TryGetValue(v.Name, out param)) {
     95              var vp = param as IValueParameter;
     96              if (vp != null) vp.Value = v.Value;
     97            }
    9198          }
    9299        }
     
    94101    }
    95102
    96     protected virtual void Execute(ServiceParameterCollection parameters, CancellationToken token) {
     103    protected virtual void Execute(IMessage message, CancellationToken token) {
    97104      if (Template == null) throw new InvalidOperationException("Template is null");
    98105
     
    104111
    105112      // set parameters
    106       foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Input)) {
     113      foreach (var v in message.Values) {
    107114        IParameter param = null;
    108         if (algorithm.Parameters.TryGetValue(p.Name, out param)) {
    109           var v = param as IValueParameter;
    110           if (v != null) v.Value = p.Value;
    111         }
    112         if (algorithm.Problem.Parameters.TryGetValue(p.Name, out param)) {
    113           var v = param as IValueParameter;
    114           if (v != null) v.Value = p.Value;
     115        if (algorithm.Parameters.TryGetValue(v.Name, out param)) {
     116          var vp = param as IValueParameter;
     117          if (vp != null) vp.Value = v.Value;
     118        }
     119        if (algorithm.Problem.Parameters.TryGetValue(v.Name, out param)) {
     120          var vp = param as IValueParameter;
     121          if (vp != null) vp.Value = v.Value;
    115122        }
    116123      }
     
    140147      // retrieve results
    141148      var run = algorithm.Runs.First();
    142       foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) {
     149      foreach (var v in message.Values) {
    143150        IItem result = null;
    144         if (run.Results.TryGetValue(p.Name, out result)) {
    145           p.Value = result;
     151        if (run.Results.TryGetValue(v.Name, out result)) {
     152          v.Value = result;
    146153        }
    147154      }
     
    205212    #region Port Events
    206213    private void RegisterPortEvents(IPort port) {
    207       IInputPort i = port as IInputPort;
    208       if (i != null) {
    209         i.NameChanged += InputPort_NameChanged;
    210         i.ValueChanged += InputPort_ValueChanged;
    211         UpdateParameter(i);
    212       }
    213       IServicePort s = port as IServicePort;
    214       if (s != null) {
    215         s.ProcessParameters += ServicePort_ProcessParameters;
    216       }
    217     }
    218 
     214      IGenericPort g = port as IGenericPort;
     215      if (g != null) {
     216        g.MessageReceived += GenericPort_MessageReceived;
     217      }
     218    }
    219219    private void DeregisterPortEvents(IPort port) {
    220       IInputPort i = port as IInputPort;
    221       if (i != null) {
    222         i.NameChanged -= InputPort_NameChanged;
    223         i.ValueChanged -= InputPort_ValueChanged;
    224       }
    225       IServicePort s = port as IServicePort;
    226       if (s != null) {
    227         s.ProcessParameters -= ServicePort_ProcessParameters;
    228       }
    229     }
    230     private void InputPort_NameChanged(object sender, EventArgs e) {
    231       UpdateParameter((IInputPort)sender);
    232     }
    233     private void InputPort_ValueChanged(object sender, EventArgs e) {
    234       UpdateParameter((IInputPort)sender);
    235     }
    236     private void ServicePort_ProcessParameters(object sender, EventArgs<ServiceParameterCollection, CancellationToken> e) {
    237       Execute(e.Value, e.Value2);
     220      IGenericPort g = port as IGenericPort;
     221      if (g != null) {
     222        g.MessageReceived -= GenericPort_MessageReceived;
     223      }
     224    }
     225    private void GenericPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) {
     226      var port = (IGenericPort)sender;
     227      if (port.Parameters.Any(p => p.Type.HasFlag(PortParameterType.Output)))
     228        Execute(e.Value, e.Value2);  // execute algorithm to compute output
     229      else
     230        UpdateParameters(e.Value, e.Value2);  // update template parameters
    238231    }
    239232    #endregion
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/GenericPort.cs

    r11500 r11501  
    6565      }
    6666    }
     67    [Storable]
     68    protected MessageCollection messages;
     69    public MessageCollection Messages {
     70      get { return messages; }
     71    }
    6772
    6873    [StorableConstructor]
    6974    protected GenericPort(bool deserializing) : base(deserializing) { }
    70     protected GenericPort(GenericPort original, Cloner cloner) : base(original, cloner) {
     75    protected GenericPort(GenericPort original, Cloner cloner)
     76      : base(original, cloner) {
    7177      connectedPort = cloner.Clone(original.connectedPort);
    7278      portConnectionValid = original.portConnectionValid;
     79      messages = cloner.Clone(original.messages);
    7380      RegisterConnectedPortEvents();
    7481    }
    75     public GenericPort() : base("GenericPort") { }
    76     public GenericPort(string name) : base(name) { }
    77     public GenericPort(string name, string description) : base(name, description) { }
     82    public GenericPort()
     83      : base("GenericPort") {
     84      portConnectionValid = true;
     85      messages = new MessageCollection();
     86    }
     87    public GenericPort(string name)
     88      : base(name) {
     89      portConnectionValid = true;
     90      messages = new MessageCollection();
     91    }
     92    public GenericPort(string name, string description)
     93      : base(name, description) {
     94      portConnectionValid = true;
     95      messages = new MessageCollection();
     96    }
    7897
    7998    [StorableHook(HookType.AfterDeserialization)]
     
    164183    public void SendMessage(IMessage message, CancellationToken token) {
    165184      if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid");
     185      Messages.Add(message);
    166186      if (ConnectedPort != null) ConnectedPort.ReceiveMessage(message, token);
    167187      OnMessageSent(message, token);
     
    180200
    181201    public void ReceiveMessage(IMessage message, CancellationToken token) {
     202      if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid");
     203      Messages.Add(message);
    182204      OnMessageReceived(message, token);
    183205    }
     
    195217
    196218    protected override void OnInterfaceChanged() {
    197       PortConnectionValid = (connectedPort != null) && CanConnectToPort(connectedPort);
     219      PortConnectionValid = CanConnectToPort(connectedPort);
    198220      base.OnInterfaceChanged();
    199221    }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/IGenericPort.cs

    r11500 r11501  
    2929    IConnectedPort ConnectedPort { get; set; }
    3030    bool PortConnectionValid { get; }
     31    MessageCollection Messages { get; }
    3132
    3233    event EventHandler ConnectedPortChanged;
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/PortParameter.cs

    r11500 r11501  
    3535    public override Image ItemImage {
    3636      get {
    37         if (Type == PortParameterType.Input) return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown;
    38         else if (Type == PortParameterType.Output) return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp;
    39         else return base.ItemImage;
     37        if (Type.HasFlag(PortParameterType.Input) && Type.HasFlag(PortParameterType.Output))
     38          return HeuristicLab.Common.Resources.VSImageLibrary.Field;
     39        else if (Type.HasFlag(PortParameterType.Input))
     40          return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown;
     41        else if (Type.HasFlag(PortParameterType.Output))
     42          return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp;
     43        else
     44          return base.ItemImage;
    4045      }
    4146    }
     
    96101      RegisterDefaultValueEvents();
    97102    }
    98     public PortParameter() : base("PortParameter") { }
    99     public PortParameter(string name) : base(name) { }
    100     public PortParameter(string name, string description) : base(name, description) { }
     103    public PortParameter()
     104      : base("PortParameter") {
     105      type = PortParameterType.Input;
     106    }
     107    public PortParameter(string name)
     108      : base(name) {
     109      type = PortParameterType.Input;
     110    }
     111    public PortParameter(string name, string description)
     112      : base(name, description) {
     113      type = PortParameterType.Input;
     114    }
    101115
    102116    [StorableHook(HookType.AfterDeserialization)]
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/PortParameterType.cs

    r11500 r11501  
    2525  [Flags]
    2626  public enum PortParameterType {
     27    None = 0,
    2728    Input = 1,
    2829    Output = 2
Note: See TracChangeset for help on using the changeset viewer.