Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11519


Ignore:
Timestamp:
11/02/14 03:03:21 (10 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

Location:
branches/OptimizationNetworks
Files:
9 added
4 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/### obsolete/ServiceParameterView.cs

    r11500 r11519  
    112112        typeSelectorDialog = new TypeSelectorDialog();
    113113        typeSelectorDialog.Caption = "Select Value";
    114         typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);
    115114      }
     115      typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);
    116116      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    117117        try {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/AlgorithmNodeView.Designer.cs

    r11409 r11519  
    3434    /// </summary>
    3535    private void InitializeComponent() {
     36      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AlgorithmNodeView));
    3637      this.portCollectionView = new HeuristicLab.Optimization.Networks.Views.PortCollectionView();
    3738      this.tabControl = new HeuristicLab.MainForm.WindowsForms.DragOverTabControl();
     
    4243      this.clearAlgorithmButton = new System.Windows.Forms.Button();
    4344      this.setAlgorithmButton = new System.Windows.Forms.Button();
     45      this.runsTabPage = new System.Windows.Forms.TabPage();
     46      this.runCollectionView = new HeuristicLab.Optimization.Views.RunCollectionView();
    4447      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    4548      this.tabControl.SuspendLayout();
     
    4750      this.algorithmTabPage.SuspendLayout();
    4851      this.algorithmPanel.SuspendLayout();
     52      this.runsTabPage.SuspendLayout();
    4953      this.SuspendLayout();
    5054      //
     
    5660      // portCollectionView
    5761      //
    58       this.portCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    59             | System.Windows.Forms.AnchorStyles.Left) 
     62      this.portCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     63            | System.Windows.Forms.AnchorStyles.Left)
    6064            | System.Windows.Forms.AnchorStyles.Right)));
    6165      this.portCollectionView.Caption = "PortCollection View";
     
    7074      // tabControl
    7175      //
    72       this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    73             | System.Windows.Forms.AnchorStyles.Left)
     76      this.tabControl.AllowDrop = true;
     77      this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     78            | System.Windows.Forms.AnchorStyles.Left)
    7479            | System.Windows.Forms.AnchorStyles.Right)));
    7580      this.tabControl.Controls.Add(this.portsTabPage);
    7681      this.tabControl.Controls.Add(this.algorithmTabPage);
     82      this.tabControl.Controls.Add(this.runsTabPage);
    7783      this.tabControl.Location = new System.Drawing.Point(0, 26);
    7884      this.tabControl.Name = "tabControl";
     
    108114      //
    109115      this.algorithmPanel.AllowDrop = true;
    110       this.algorithmPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    111             | System.Windows.Forms.AnchorStyles.Left) 
     116      this.algorithmPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     117            | System.Windows.Forms.AnchorStyles.Left)
    112118            | System.Windows.Forms.AnchorStyles.Right)));
    113119      this.algorithmPanel.Controls.Add(this.algorithmViewHost);
     
    153159      this.setAlgorithmButton.UseVisualStyleBackColor = true;
    154160      this.setAlgorithmButton.Click += new System.EventHandler(this.setAlgorithmButton_Click);
     161      //
     162      // runsTabPage
     163      //
     164      this.runsTabPage.Controls.Add(this.runCollectionView);
     165      this.runsTabPage.Location = new System.Drawing.Point(4, 22);
     166      this.runsTabPage.Name = "runsTabPage";
     167      this.runsTabPage.Size = new System.Drawing.Size(637, 465);
     168      this.runsTabPage.TabIndex = 2;
     169      this.runsTabPage.Text = "Runs";
     170      this.runsTabPage.UseVisualStyleBackColor = true;
     171      //
     172      // runCollectionView
     173      //
     174      this.runCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     175            | System.Windows.Forms.AnchorStyles.Left)
     176            | System.Windows.Forms.AnchorStyles.Right)));
     177      this.runCollectionView.Caption = "RunCollection View";
     178      this.runCollectionView.Content = null;
     179      this.runCollectionView.Location = new System.Drawing.Point(3, 3);
     180      this.runCollectionView.Name = "runCollectionView";
     181      this.runCollectionView.ReadOnly = false;
     182      this.runCollectionView.Size = new System.Drawing.Size(631, 459);
     183      this.runCollectionView.TabIndex = 0;
    155184      //
    156185      // AlgorithmNodeView
     
    168197      this.algorithmTabPage.ResumeLayout(false);
    169198      this.algorithmPanel.ResumeLayout(false);
     199      this.runsTabPage.ResumeLayout(false);
    170200      this.ResumeLayout(false);
    171201      this.PerformLayout();
     
    183213    protected System.Windows.Forms.TabPage algorithmTabPage;
    184214    protected MainForm.WindowsForms.ViewHost algorithmViewHost;
     215    protected System.Windows.Forms.TabPage runsTabPage;
     216    protected Optimization.Views.RunCollectionView runCollectionView;
    185217
    186218
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/AlgorithmNodeView.cs

    r11452 r11519  
    6464        portCollectionView.Content = null;
    6565        algorithmViewHost.Content = null;
     66        runCollectionView.Content = null;
    6667      } else {
    6768        portCollectionView.Content = Content.Ports;
    6869        algorithmViewHost.ViewType = null;
    6970        algorithmViewHost.Content = Content.Algorithm;
     71        runCollectionView.Content = Content.Runs;
    7072      }
    7173    }
     
    7779      clearAlgorithmButton.Enabled = Content != null && Content.Algorithm != null && !ReadOnly;
    7880      algorithmPanel.Enabled = Content != null;
     81      runCollectionView.Enabled = Content != null && !ReadOnly;
    7982    }
    8083
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.Designer.cs

    r11501 r11519  
    4343      this.portParameterCollectionView = new HeuristicLab.Optimization.Networks.Views.PortParameterCollectionView();
    4444      this.messageCollectionView = new HeuristicLab.Optimization.Networks.Views.MessageCollectionView();
     45      this.logMessagesCheckBox = new System.Windows.Forms.CheckBox();
    4546      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    4647      this.connectedPortGroupBox.SuspendLayout();
     
    7980      this.setConnectedPortButton.Size = new System.Drawing.Size(24, 24);
    8081      this.setConnectedPortButton.TabIndex = 0;
     82      this.toolTip.SetToolTip(this.setConnectedPortButton, "Set Connected Port");
    8183      this.setConnectedPortButton.UseVisualStyleBackColor = true;
    8284      this.setConnectedPortButton.Click += new System.EventHandler(this.setConnectedPortButton_Click);
     
    8991      this.clearConnectedPortButton.Size = new System.Drawing.Size(24, 24);
    9092      this.clearConnectedPortButton.TabIndex = 1;
     93      this.toolTip.SetToolTip(this.clearConnectedPortButton, "Remove Connected Port");
    9194      this.clearConnectedPortButton.UseVisualStyleBackColor = true;
    9295      this.clearConnectedPortButton.Click += new System.EventHandler(this.clearConnectedPortButton_Click);
     
    146149      // splitContainer.Panel2
    147150      //
     151      this.splitContainer.Panel2.Controls.Add(this.logMessagesCheckBox);
    148152      this.splitContainer.Panel2.Controls.Add(this.messageCollectionView);
    149153      this.splitContainer.Size = new System.Drawing.Size(645, 435);
     
    174178      this.messageCollectionView.Size = new System.Drawing.Size(645, 213);
    175179      this.messageCollectionView.TabIndex = 0;
     180      //
     181      // logMessagesCheckBox
     182      //
     183      this.logMessagesCheckBox.AutoSize = true;
     184      this.logMessagesCheckBox.Location = new System.Drawing.Point(156, 24);
     185      this.logMessagesCheckBox.Name = "logMessagesCheckBox";
     186      this.logMessagesCheckBox.Size = new System.Drawing.Size(95, 17);
     187      this.logMessagesCheckBox.TabIndex = 1;
     188      this.logMessagesCheckBox.Text = "&Log Messages";
     189      this.logMessagesCheckBox.UseVisualStyleBackColor = true;
     190      this.logMessagesCheckBox.CheckedChanged += new System.EventHandler(this.logMessagesCheckBox_CheckedChanged);
    176191      //
    177192      // GenericPortView
     
    194209      this.splitContainer.Panel1.ResumeLayout(false);
    195210      this.splitContainer.Panel2.ResumeLayout(false);
     211      this.splitContainer.Panel2.PerformLayout();
    196212      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
    197213      this.splitContainer.ResumeLayout(false);
     
    212228    protected PortParameterCollectionView portParameterCollectionView;
    213229    protected MessageCollectionView messageCollectionView;
     230    protected System.Windows.Forms.CheckBox logMessagesCheckBox;
    214231
    215232
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.cs

    r11501 r11519  
    5252
    5353    protected override void DeregisterContentEvents() {
    54       Content.InterfaceChanged -= Content_InterfaceChanged;
    5554      Content.ConnectedPortChanged -= Content_ConnectedPortChanged;
     55      Content.PortConnectionValidChanged -= Content_PortConnectionValidChanged;
     56      Content.LogMessagesChanged -= Content_LogMessagesChanged;
    5657      base.DeregisterContentEvents();
    5758    }
    5859    protected override void RegisterContentEvents() {
    5960      base.RegisterContentEvents();
    60       Content.InterfaceChanged += Content_InterfaceChanged;
    6161      Content.ConnectedPortChanged += Content_ConnectedPortChanged;
     62      Content.PortConnectionValidChanged += Content_PortConnectionValidChanged;
     63      Content.LogMessagesChanged += Content_LogMessagesChanged;
    6264    }
    6365
     
    6668      connectedPortView.Content = Content == null ? null : Content.ConnectedPort;
    6769      portParameterCollectionView.Content = Content == null ? null : Content.Parameters;
     70      logMessagesCheckBox.Checked = Content == null ? false : Content.LogMessages;
    6871      messageCollectionView.Content = Content == null ? null : Content.Messages;
    6972      errorProvider.SetError(connectedPortView, ((Content == null) || Content.PortConnectionValid) ? string.Empty : "Port connection is not valid");
     
    7881      portParameterCollectionView.Enabled = Content != null && !ReadOnly;
    7982      cloneConnectedPortParametersButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly;
     83      logMessagesCheckBox.Enabled = Content != null && !ReadOnly;
    8084      messageCollectionView.Enabled = Content != null && !ReadOnly;
    8185    }
     
    9094      }
    9195    }
    92     protected virtual void Content_InterfaceChanged(object sender, EventArgs e) {
     96    protected virtual void Content_PortConnectionValidChanged(object sender, EventArgs e) {
    9397      if (InvokeRequired)
    94         Invoke(new EventHandler(Content_InterfaceChanged), sender, e);
     98        Invoke(new EventHandler(Content_PortConnectionValidChanged), sender, e);
    9599      else {
    96100        errorProvider.SetError(connectedPortView, Content.PortConnectionValid ? string.Empty : "Port connection is not valid");
     101      }
     102    }
     103    protected virtual void Content_LogMessagesChanged(object sender, EventArgs e) {
     104      if (InvokeRequired)
     105        Invoke(new EventHandler(Content_LogMessagesChanged), sender, e);
     106      else {
     107        logMessagesCheckBox.Checked = Content.LogMessages;
    97108      }
    98109    }
     
    148159      Content.CloneConnectedPortParameters();
    149160    }
     161    protected virtual void logMessagesCheckBox_CheckedChanged(object sender, EventArgs e) {
     162      Content.LogMessages = logMessagesCheckBox.Checked;
     163    }
    150164  }
    151165}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/HeuristicLab.Optimization.Networks.Views-3.3.csproj

    r11501 r11519  
    151151      <DependentUpon>ClientNodeView.cs</DependentUpon>
    152152    </Compile>
    153     <Compile Include="AlgorithmServiceNodeView.cs">
    154       <SubType>UserControl</SubType>
    155     </Compile>
    156     <Compile Include="AlgorithmServiceNodeView.Designer.cs">
    157       <DependentUpon>AlgorithmServiceNodeView.cs</DependentUpon>
    158     </Compile>
    159153    <Compile Include="GenericPortView.cs">
    160154      <SubType>UserControl</SubType>
     
    180174    <Compile Include="GenericNodeView.Designer.cs">
    181175      <DependentUpon>GenericNodeView.cs</DependentUpon>
     176    </Compile>
     177    <Compile Include="HookOperatorView.cs">
     178      <SubType>UserControl</SubType>
     179    </Compile>
     180    <Compile Include="HookOperatorView.Designer.cs">
     181      <DependentUpon>HookOperatorView.cs</DependentUpon>
    182182    </Compile>
    183183    <Compile Include="ParameterizedPortView.cs">
     
    306306      <Name>HeuristicLab.MainForm-3.3</Name>
    307307    </ProjectReference>
     308    <ProjectReference Include="..\..\HeuristicLab.Operators.Views\3.3\HeuristicLab.Operators.Views-3.3.csproj">
     309      <Project>{c49cb749-8b24-4628-8003-e86475749410}</Project>
     310      <Name>HeuristicLab.Operators.Views-3.3</Name>
     311    </ProjectReference>
     312    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
     313      <Project>{23da7ff4-d5b8-41b6-aa96-f0561d24f3ee}</Project>
     314      <Name>HeuristicLab.Operators-3.3</Name>
     315    </ProjectReference>
    308316    <ProjectReference Include="..\..\HeuristicLab.Optimization.Networks\3.3\HeuristicLab.Optimization.Networks-3.3.csproj">
    309317      <Project>{7cf51332-0e37-447c-8017-82a258c59ef2}</Project>
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/Plugin.cs.frame

    r11463 r11519  
    3636  [PluginDependency("HeuristicLab.MainForm", "3.3")]
    3737  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
     38  [PluginDependency("HeuristicLab.Operators", "3.3")]
     39  [PluginDependency("HeuristicLab.Operators.Views", "3.3")]
    3840  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3941  [PluginDependency("HeuristicLab.Optimization.Views", "3.3")]
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/PortParameterView.cs

    r11500 r11519  
    119119        typeSelectorDialog = new TypeSelectorDialog();
    120120        typeSelectorDialog.Caption = "Select Default Value";
    121         typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);
    122121      }
     122      typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);
    123123      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    124124        try {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj

    r11501 r11519  
    108108    <Compile Include="### obsolete\ServiceParameter.cs" />
    109109    <Compile Include="### obsolete\ServiceParameterCollection.cs" />
     110    <Compile Include="IHookOperator.cs" />
     111    <Compile Include="Nodes\KSPTSPConnector.cs" />
    110112    <Compile Include="Nodes\GenericNode.cs" />
    111113    <Compile Include="Nodes\IGenericNode.cs" />
     114    <Compile Include="Ports\ConfigurationPort.cs" />
     115    <Compile Include="Ports\ExecutionPort.cs" />
     116    <Compile Include="Ports\IConfigurationPort.cs" />
     117    <Compile Include="Ports\IExecutionPort.cs" />
    112118    <Compile Include="Ports\MessageCollection.cs" />
    113119    <Compile Include="### obsolete\ServiceParameterCollectionCollection.cs" />
     
    116122    <Compile Include="### obsolete\ValuePort.cs" />
    117123    <Compile Include="Nodes\AlgorithmNode.cs" />
    118     <Compile Include="Nodes\AlgorithmServiceNode.cs" />
    119124    <Compile Include="Nodes\ClientNode.cs" />
    120125    <Compile Include="Nodes\IAlgorithmNode.cs" />
    121     <Compile Include="Nodes\IAlgorithmServiceNode.cs" />
    122126    <Compile Include="Nodes\IClientNode.cs" />
    123127    <Compile Include="Nodes\INetwork.cs" />
     
    150154    <Compile Include="Plugin.cs" />
    151155    <Compile Include="Properties\AssemblyInfo.cs" />
     156    <Compile Include="HookOperator.cs" />
    152157  </ItemGroup>
    153158  <ItemGroup>
     
    177182      <Project>{bbab9df5-5ef3-4ba8-ade9-b36e82114937}</Project>
    178183      <Name>HeuristicLab.Data-3.3</Name>
     184    </ProjectReference>
     185    <ProjectReference Include="..\..\HeuristicLab.Encodings.BinaryVectorEncoding\3.3\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj">
     186      <Project>{66d249c3-a01d-42a8-82a2-919bc8ec3d83}</Project>
     187      <Name>HeuristicLab.Encodings.BinaryVectorEncoding-3.3</Name>
     188    </ProjectReference>
     189    <ProjectReference Include="..\..\HeuristicLab.Encodings.PermutationEncoding\3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.csproj">
     190      <Project>{dbecb8b0-b166-4133-baf1-ed67c3fd7fca}</Project>
     191      <Name>HeuristicLab.Encodings.PermutationEncoding-3.3</Name>
     192    </ProjectReference>
     193    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
     194      <Project>{23da7ff4-d5b8-41b6-aa96-f0561d24f3ee}</Project>
     195      <Name>HeuristicLab.Operators-3.3</Name>
    179196    </ProjectReference>
    180197    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Nodes/AlgorithmNode.cs

    r11500 r11519  
    2424using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2525using System;
     26using System.Collections.Generic;
     27using System.Linq;
     28using System.Threading;
    2629
    2730namespace HeuristicLab.Optimization.Networks {
     
    2932  [StorableClass]
    3033  public class AlgorithmNode : Node, IAlgorithmNode {
     34    private object locker = new object();
     35    private Dictionary<IAlgorithm, AutoResetEvent> waitHandles = new Dictionary<IAlgorithm, AutoResetEvent>();
     36    private Dictionary<IAlgorithm, Exception> exceptions = new Dictionary<IAlgorithm, Exception>();
     37
    3138    new public PortCollection Ports {
    3239      get { return base.Ports; }
     
    3946      set {
    4047        if (value != algorithm) {
    41           DeregisterAlgorithmEvents();
    4248          algorithm = value;
    43           RegisterAlgorithmEvents();
    4449          OnAlgorithmChanged();
    4550        }
    4651      }
     52    }
     53
     54    [Storable]
     55    private RunCollection runs;
     56    public RunCollection Runs {
     57      get { return runs; }
    4758    }
    4859
     
    5263      : base(original, cloner) {
    5364      algorithm = cloner.Clone(original.algorithm);
    54       RegisterAlgorithmEvents();
    55     }
    56     public AlgorithmNode() : base("AlgorithmNode") { }
    57     public AlgorithmNode(string name) : base(name) { }
    58     public AlgorithmNode(string name, string description) : base(name, description) { }
    59 
    60     [StorableHook(HookType.AfterDeserialization)]
    61     private void AfterDeserialization() {
    62       RegisterAlgorithmEvents();
     65      runs = cloner.Clone(original.runs);
     66    }
     67    public AlgorithmNode()
     68      : base("AlgorithmNode") {
     69      runs = new RunCollection();
     70    }
     71    public AlgorithmNode(string name)
     72      : base(name) {
     73      runs = new RunCollection();
     74    }
     75    public AlgorithmNode(string name, string description)
     76      : base(name, description) {
     77      runs = new RunCollection();
    6378    }
    6479
     
    6782    }
    6883
    69     private void UpdateParameter(IInputPort port) {
    70       if (algorithm != null) {
     84    protected virtual void Configure(IConfigurationPort port, IMessage message, CancellationToken token) {
     85      // set algorithm and problem parameters
     86      lock (locker) {
     87        if (algorithm != null) {
     88          foreach (var v in message.Values) {
     89            IParameter param = null;
     90            if (Algorithm.Parameters.TryGetValue(v.Name, out param)) {
     91              var vp = param as IValueParameter;
     92              if (vp != null) vp.Value = v.Value;
     93            }
     94            if (Algorithm.Problem.Parameters.TryGetValue(v.Name, out param)) {
     95              var vp = param as IValueParameter;
     96              if (vp != null) vp.Value = v.Value;
     97            }
     98          }
     99        }
     100      }
     101    }
     102
     103    protected virtual void Execute(IExecutionPort port, IMessage message, CancellationToken token) {
     104      if (Algorithm == null) throw new InvalidOperationException("Algorithm is null");
     105
     106      IAlgorithm algorithm;
     107      lock (locker) {
     108        algorithm = (IAlgorithm)Algorithm.Clone();
     109        waitHandles.Add(algorithm, new AutoResetEvent(false));
     110      }
     111
     112      // set parameters
     113      foreach (var v in message.Values) {
    71114        IParameter param = null;
    72         if (algorithm.Parameters.TryGetValue(port.Name, out param)) {
    73           IValueParameter p = param as IValueParameter;
    74           if ((p != null) && (port.Value != null)) {
    75             p.Value = (IItem)port.Value;
    76           }
    77         }
    78       }
    79     }
    80     private void UpdateOutputPort(IResult result) {
    81       IPort port = null;
    82       if (Ports.TryGetValue(result.Name, out port)) {
    83         IOutputPort p = port as IOutputPort;
    84         if (p != null) {
    85           p.Value = result.Value;
    86         }
    87       }
    88     }
    89     private void UpdateOutputPort(IOutputPort port) {
    90       if ((algorithm != null) && (algorithm.Results != null)) {
    91         IResult result = null;
    92         if (algorithm.Results.TryGetValue(port.Name, out result)) {
    93           port.Value = result != null ? result.Value : null;
    94         } else {
    95           port.Value = null;
    96         }
     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;
     122        }
     123      }
     124
     125      algorithm.StoreAlgorithmInEachRun = false;
     126      algorithm.Runs.Clear();
     127      algorithm.Prepare();
     128      algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred;
     129      algorithm.Stopped += Algorithm_Stopped;
     130
     131      using (token.Register(() => { algorithm.Stop(); })) {
     132        algorithm.Start();
     133        waitHandles[algorithm].WaitOne();
     134      }
     135
     136      lock (locker) {
     137        waitHandles[algorithm].Dispose();
     138        waitHandles.Remove(algorithm);
     139
     140        Exception ex = null;
     141        if (exceptions.TryGetValue(algorithm, out ex)) {
     142          exceptions.Remove(algorithm);
     143          throw ex;
     144        }
     145      }
     146
     147      // retrieve results
     148      var run = algorithm.Runs.First();
     149      foreach (var v in message.Values) {
     150        IItem result = null;
     151        if (run.Results.TryGetValue(v.Name, out result)) {
     152          v.Value = result;
     153        }
     154      }
     155
     156      lock (locker) {
     157        Runs.Add(run);
     158      }
     159    }
     160
     161    private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     162      var algorithm = (IAlgorithm)sender;
     163      lock (locker) {
     164        exceptions.Add(algorithm, e.Value);
     165      }
     166      algorithm.Stop();
     167    }
     168    private void Algorithm_Stopped(object sender, EventArgs e) {
     169      lock (locker) {
     170        waitHandles[(IAlgorithm)sender].Set();
    97171      }
    98172    }
     
    138212    #region Port Events
    139213    private void RegisterPortEvents(IPort port) {
    140       IInputPort i = port as IInputPort;
    141       if (i != null) {
    142         i.NameChanged += InputPort_NameChanged;
    143         i.ValueChanged += InputPort_ValueChanged;
    144         UpdateParameter(i);
    145       }
    146       IOutputPort o = port as IOutputPort;
    147       if (o != null) {
    148         o.NameChanged += OutputPort_NameChanged;
    149         UpdateOutputPort(o);
     214      IConfigurationPort c = port as IConfigurationPort;
     215      if (c != null) {
     216        c.MessageReceived += ConfigurationPort_MessageReceived;
     217      }
     218      IExecutionPort e = port as IExecutionPort;
     219      if (e != null) {
     220        e.MessageReceived += ExecutionPort_MessageReceived;
    150221      }
    151222    }
    152223    private void DeregisterPortEvents(IPort port) {
    153       IInputPort i = port as IInputPort;
    154       if (i != null) {
    155         i.NameChanged -= InputPort_NameChanged;
    156         i.ValueChanged -= InputPort_ValueChanged;
    157       }
    158       IOutputPort o = port as IOutputPort;
    159       if (o != null) {
    160         o.NameChanged -= OutputPort_NameChanged;
    161       }
    162     }
    163     private void InputPort_NameChanged(object sender, EventArgs e) {
    164       UpdateParameter((IInputPort)sender);
    165     }
    166     private void InputPort_ValueChanged(object sender, EventArgs e) {
    167       UpdateParameter((IInputPort)sender);
    168     }
    169     private void OutputPort_NameChanged(object sender, EventArgs e) {
    170       UpdateOutputPort((IOutputPort)sender);
    171     }
    172     #endregion
    173 
    174     #region Algorithm Events
    175     private void RegisterAlgorithmEvents() {
    176       if (algorithm != null) {
    177         algorithm.Prepared += Algorithm_Prepared;
    178         RegisterResultsEvents();
    179       }
    180     }
    181 
    182     private void DeregisterAlgorithmEvents() {
    183       if (algorithm != null) {
    184         algorithm.Prepared -= Algorithm_Prepared;
    185         DeregisterResultsEvents();
    186       }
    187     }
    188     private void Algorithm_Prepared(object sender, EventArgs e) {
    189       RegisterResultsEvents();
    190     }
    191     #endregion
    192 
    193     #region Results Events
    194     private void RegisterResultsEvents() {
    195       if ((algorithm != null) && (algorithm.Results != null)) {
    196         algorithm.Results.ItemsAdded += Results_ItemsAdded;
    197         algorithm.Results.ItemsRemoved += Results_ItemsRemoved;
    198         algorithm.Results.ItemsReplaced += Results_ItemsReplaced;
    199         algorithm.Results.CollectionReset += Results_CollectionReset;
    200         foreach (var r in algorithm.Results)
    201           RegisterResultEvents(r);
    202       }
    203     }
    204     private void DeregisterResultsEvents() {
    205       if ((algorithm != null) && (algorithm.Results != null)) {
    206         algorithm.Results.ItemsAdded -= Results_ItemsAdded;
    207         algorithm.Results.ItemsRemoved -= Results_ItemsRemoved;
    208         algorithm.Results.ItemsReplaced -= Results_ItemsReplaced;
    209         algorithm.Results.CollectionReset -= Results_CollectionReset;
    210         foreach (var r in algorithm.Results)
    211           DeregisterResultEvents(r);
    212       }
    213     }
    214     private void Results_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) {
    215       foreach (var r in e.Items)
    216         RegisterResultEvents(r);
    217     }
    218     private void Results_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) {
    219       foreach (var r in e.Items)
    220         DeregisterResultEvents(r);
    221     }
    222     private void Results_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) {
    223       foreach (var r in e.OldItems)
    224         DeregisterResultEvents(r);
    225       foreach (var r in e.Items)
    226         RegisterResultEvents(r);
    227     }
    228     private void Results_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) {
    229       foreach (var r in e.OldItems)
    230         DeregisterResultEvents(r);
    231       foreach (var r in e.Items)
    232         RegisterResultEvents(r);
    233     }
    234     #endregion
    235 
    236     #region Result Events
    237     private void RegisterResultEvents(IResult result) {
    238       if (result != null) {
    239         result.ValueChanged += Result_ValueChanged;
    240         result.ToStringChanged += Result_ToStringChanged;
    241         UpdateOutputPort(result);
    242       }
    243     }
    244     private void DeregisterResultEvents(IResult result) {
    245       if (result != null) {
    246         result.ValueChanged -= Result_ValueChanged;
    247         result.ToStringChanged += Result_ToStringChanged;
    248       }
    249     }
    250     private void Result_ValueChanged(object sender, EventArgs e) {
    251       UpdateOutputPort((IResult)sender);
    252     }
    253     private void Result_ToStringChanged(object sender, EventArgs e) {
    254       UpdateOutputPort((IResult)sender);
     224      IConfigurationPort c = port as IConfigurationPort;
     225      if (c != null) {
     226        c.MessageReceived -= ConfigurationPort_MessageReceived;
     227      }
     228      IExecutionPort e = port as IExecutionPort;
     229      if (e != null) {
     230        e.MessageReceived -= ExecutionPort_MessageReceived;
     231      }
     232    }
     233    protected virtual void ConfigurationPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) {
     234      Configure((IConfigurationPort)sender, e.Value, e.Value2);
     235    }
     236    protected virtual void ExecutionPort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) {
     237      Execute((IExecutionPort)sender, e.Value, e.Value2);
    255238    }
    256239    #endregion
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Nodes/IAlgorithmNode.cs

    r11500 r11519  
    2626    new PortCollection Ports { get; }
    2727    IAlgorithm Algorithm { get; set; }
     28    RunCollection Runs { get; }
    2829
    2930    event EventHandler AlgorithmChanged;
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Plugin.cs.frame

    r11452 r11519  
    3333  [PluginDependency("HeuristicLab.Core", "3.3")]
    3434  [PluginDependency("HeuristicLab.Data", "3.3")]
     35  [PluginDependency("HeuristicLab.Encodings.BinaryVectorEncoding", "3.3")]
     36  [PluginDependency("HeuristicLab.Encodings.PermutationEncoding", "3.3")]
     37  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3538  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3639  [PluginDependency("HeuristicLab.Persistence", "3.3")]
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/GenericPort.cs

    r11501 r11519  
    6161        if (value != portConnectionValid) {
    6262          portConnectionValid = value;
     63          OnPortConnectionValidChanged();
    6364          OnItemImageChanged();
     65        }
     66      }
     67    }
     68    [Storable]
     69    protected bool logMessages;
     70    public bool LogMessages {
     71      get { return logMessages; }
     72      set {
     73        if (value != logMessages) {
     74          logMessages = value;
     75          OnLogMessagesChanged();
    6476        }
    6577      }
     
    7789      connectedPort = cloner.Clone(original.connectedPort);
    7890      portConnectionValid = original.portConnectionValid;
     91      logMessages = original.logMessages;
    7992      messages = cloner.Clone(original.messages);
    8093      RegisterConnectedPortEvents();
     
    8396      : base("GenericPort") {
    8497      portConnectionValid = true;
     98      logMessages = false;
    8599      messages = new MessageCollection();
    86100    }
     
    88102      : base(name) {
    89103      portConnectionValid = true;
     104      logMessages = false;
    90105      messages = new MessageCollection();
    91106    }
     
    93108      : base(name, description) {
    94109      portConnectionValid = true;
     110      logMessages = false;
    95111      messages = new MessageCollection();
    96112    }
     
    183199    public void SendMessage(IMessage message, CancellationToken token) {
    184200      if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid");
    185       Messages.Add(message);
     201      if (LogMessages) Messages.Add(message);
    186202      if (ConnectedPort != null) ConnectedPort.ReceiveMessage(message, token);
    187203      OnMessageSent(message, token);
     
    201217    public void ReceiveMessage(IMessage message, CancellationToken token) {
    202218      if (!PortConnectionValid) throw new InvalidOperationException("Port connection is not valid");
    203       Messages.Add(message);
     219      if (LogMessages) Messages.Add(message);
    204220      OnMessageReceived(message, token);
    205221    }
     
    213229    protected virtual void OnConnectedPortChanged() {
    214230      var handler = ConnectedPortChanged;
     231      if (handler != null) handler(this, EventArgs.Empty);
     232    }
     233    public event EventHandler PortConnectionValidChanged;
     234    protected virtual void OnPortConnectionValidChanged() {
     235      var handler = PortConnectionValidChanged;
     236      if (handler != null) handler(this, EventArgs.Empty);
     237    }
     238    public event EventHandler LogMessagesChanged;
     239    protected virtual void OnLogMessagesChanged() {
     240      var handler = LogMessagesChanged;
    215241      if (handler != null) handler(this, EventArgs.Empty);
    216242    }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/IGenericPort.cs

    r11501 r11519  
    2929    IConnectedPort ConnectedPort { get; set; }
    3030    bool PortConnectionValid { get; }
     31    bool LogMessages { get; set; }
    3132    MessageCollection Messages { get; }
    3233
    3334    event EventHandler ConnectedPortChanged;
     35    event EventHandler PortConnectionValidChanged;
     36    event EventHandler LogMessagesChanged;
    3437
    3538    bool CanConnectToPort(IPort port);
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/IMessage.cs

    r11500 r11519  
    2525  public interface IMessage : IItem {
    2626    MessageValueCollection Values { get; }
    27     IItem this[string valueName] { get; }
     27    IItem this[string valueName] { get; set; }
    2828  }
    2929}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Ports/Message.cs

    r11500 r11519  
    4040    public IItem this[string valueName] {
    4141      get { return Values[valueName].Value; }
     42      set { Values[valueName].Value = value; }
    4243    }
    4344
Note: See TracChangeset for help on using the changeset viewer.