Changeset 11409


Ignore:
Timestamp:
10/02/14 03:30:30 (5 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

Location:
branches/OptimizationNetworks
Files:
12 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/HeuristicLab.Optimization.Networks.Views-3.3.csproj

    r11069 r11409  
    4040    <Reference Include="System" />
    4141    <Reference Include="System.Core" />
     42    <Reference Include="System.Drawing" />
     43    <Reference Include="System.Windows.Forms" />
    4244    <Reference Include="System.Xml.Linq" />
    4345    <Reference Include="System.Data.DataSetExtensions" />
     
    4749  </ItemGroup>
    4850  <ItemGroup>
     51    <Compile Include="AlgorithmNodeView.cs">
     52      <SubType>UserControl</SubType>
     53    </Compile>
     54    <Compile Include="AlgorithmNodeView.Designer.cs">
     55      <DependentUpon>AlgorithmNodeView.cs</DependentUpon>
     56    </Compile>
     57    <Compile Include="PortView.cs">
     58      <SubType>UserControl</SubType>
     59    </Compile>
     60    <Compile Include="PortView.Designer.cs">
     61      <DependentUpon>PortView.cs</DependentUpon>
     62    </Compile>
     63    <Compile Include="NodeView.cs">
     64      <SubType>UserControl</SubType>
     65    </Compile>
     66    <Compile Include="NodeView.Designer.cs">
     67      <DependentUpon>NodeView.cs</DependentUpon>
     68    </Compile>
     69    <Compile Include="PortCollectionView.cs">
     70      <SubType>UserControl</SubType>
     71    </Compile>
     72    <Compile Include="PortCollectionView.Designer.cs">
     73      <DependentUpon>PortCollectionView.cs</DependentUpon>
     74    </Compile>
    4975    <Compile Include="Plugin.cs" />
    5076    <Compile Include="Properties\AssemblyInfo.cs" />
     77    <Compile Include="NetworkView.cs">
     78      <SubType>UserControl</SubType>
     79    </Compile>
     80    <Compile Include="NetworkView.Designer.cs">
     81      <DependentUpon>NetworkView.cs</DependentUpon>
     82    </Compile>
     83    <Compile Include="NodeCollectionView.cs">
     84      <SubType>UserControl</SubType>
     85    </Compile>
     86    <Compile Include="NodeCollectionView.Designer.cs">
     87      <DependentUpon>NodeCollectionView.cs</DependentUpon>
     88    </Compile>
    5189  </ItemGroup>
    5290  <ItemGroup>
     
    5694  </ItemGroup>
    5795  <ItemGroup>
     96    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
     97      <Project>{958b43bc-cc5c-4fa2-8628-2b3b01d890b6}</Project>
     98      <Name>HeuristicLab.Collections-3.3</Name>
     99    </ProjectReference>
     100    <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj">
     101      <Project>{0e27a536-1c4a-4624-a65e-dc4f4f23e3e1}</Project>
     102      <Name>HeuristicLab.Common.Resources-3.3</Name>
     103    </ProjectReference>
     104    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
     105      <Project>{a9ad58b9-3ef9-4cc1-97e5-8d909039ff5c}</Project>
     106      <Name>HeuristicLab.Common-3.3</Name>
     107    </ProjectReference>
     108    <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">
     109      <Project>{e226881d-315f-423d-b419-a766fe0d8685}</Project>
     110      <Name>HeuristicLab.Core.Views-3.3</Name>
     111    </ProjectReference>
     112    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
     113      <Project>{c36bd924-a541-4a00-afa8-41701378ddc5}</Project>
     114      <Name>HeuristicLab.Core-3.3</Name>
     115    </ProjectReference>
     116    <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.3\HeuristicLab.MainForm.WindowsForms-3.3.csproj">
     117      <Project>{ab687bbe-1bfe-476b-906d-44237135431d}</Project>
     118      <Name>HeuristicLab.MainForm.WindowsForms-3.3</Name>
     119    </ProjectReference>
     120    <ProjectReference Include="..\..\HeuristicLab.MainForm\3.3\HeuristicLab.MainForm-3.3.csproj">
     121      <Project>{3bd61258-31da-4b09-89c0-4f71fef5f05a}</Project>
     122      <Name>HeuristicLab.MainForm-3.3</Name>
     123    </ProjectReference>
     124    <ProjectReference Include="..\..\HeuristicLab.Optimization.Networks\3.3\HeuristicLab.Optimization.Networks-3.3.csproj">
     125      <Project>{7cf51332-0e37-447c-8017-82a258c59ef2}</Project>
     126      <Name>HeuristicLab.Optimization.Networks-3.3</Name>
     127    </ProjectReference>
     128    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
     129      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
     130      <Name>HeuristicLab.Optimization-3.3</Name>
     131    </ProjectReference>
    58132    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    59133      <Project>{94186a6a-5176-4402-ae83-886557b53cca}</Project>
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/Plugin.cs.frame

    r11401 r11409  
    2828  [Plugin("HeuristicLab.Optimization.Networks.Views", "3.3.11.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Optimization.Networks.Views-3.3.dll", PluginFileType.Assembly)]
    30 //  [PluginDependency("HeuristicLab.Collections", "3.3")]
    31 //  [PluginDependency("HeuristicLab.Common", "3.3")]
    32 //  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
    33 //  [PluginDependency("HeuristicLab.Core", "3.3")]
    34 //  [PluginDependency("HeuristicLab.Data", "3.3")]
    35 //  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    36 //  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     30  [PluginDependency("HeuristicLab.Collections", "3.3")]
     31  [PluginDependency("HeuristicLab.Common", "3.3")]
     32  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
     33  [PluginDependency("HeuristicLab.Core", "3.3")]
     34  [PluginDependency("HeuristicLab.Core.Views", "3.3")]
     35  [PluginDependency("HeuristicLab.MainForm", "3.3")]
     36  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
     37  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     38  [PluginDependency("HeuristicLab.Optimization.Networks", "3.3")]
    3739  public class HeuristicLabOptimizationNetworksViewsPlugin : PluginBase {
    3840  }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmNode.cs

    r11406 r11409  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Drawing;
    2522using HeuristicLab.Common;
    2623using HeuristicLab.Core;
    2724using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using System;
    2826
    2927namespace HeuristicLab.Optimization.Networks {
    3028  [Item("AlgorithmNode", "A node of an optimization network which contains a HeuristicLab algorithm.")]
    3129  [StorableClass]
    32   public class AlgorithmNode : Node {
     30  public class AlgorithmNode : Node, IAlgorithmNode {
     31    new public PortCollection Ports {
     32      get { return base.Ports; }
     33    }
     34
    3335    [Storable]
    3436    private IAlgorithm algorithm;
     
    5456    }
    5557    public AlgorithmNode()
    56       : base("Node") {
     58      : base("AlgorithmNode") {
    5759      RegisterPortsEvents();
    5860    }
     
    6971    private void AfterDeserialization() {
    7072      RegisterPortsEvents();
     73      RegisterAlgorithmEvents();
    7174    }
    7275
     
    7780    private void UpdateParameter(IInputPort port) {
    7881      if (algorithm != null) {
    79         foreach (var param in algorithm.Parameters) {
     82        IParameter param = null;
     83        if (algorithm.Parameters.TryGetValue(port.Name, out param)) {
    8084          IValueParameter p = param as IValueParameter;
    81           if ((p != null) && (p.Name == port.Name)) {
     85          if (p != null) {
    8286            p.Value = (IItem)port.Value;
    8387          }
     
    8690    }
    8791    private void UpdateOutputPort(IResult result) {
    88       foreach (var port in Ports) {
     92      IPort port = null;
     93      if (Ports.TryGetValue(result.Name, out port)) {
    8994        IOutputPort p = port as IOutputPort;
    90         if ((p != null) && (p.Name == result.Name)) {
     95        if (p != null) {
    9196          p.Value = result.Value;
     97        }
     98      }
     99    }
     100    private void UpdateOutputPort(IOutputPort port) {
     101      if ((algorithm != null) && (algorithm.Results != null)) {
     102        IResult result = null;
     103        if (algorithm.Results.TryGetValue(port.Name, out result)) {
     104          port.Value = result != null ? result.Value : null;
     105        } else {
     106          port.Value = null;
    92107        }
    93108      }
     
    106121      Ports.ItemsReplaced += Ports_ItemsReplaced;
    107122      Ports.CollectionReset += Ports_CollectionReset;
     123      foreach (var p in Ports)
     124        RegisterPortEvents(p);
    108125    }
    109126    void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
     
    131148    #region Port Events
    132149    private void RegisterPortEvents(IPort port) {
    133       IInputPort p = port as IInputPort;
    134       if (p != null) {
    135         p.ValueChanged += InputPort_ValueChanged;
     150      IInputPort i = port as IInputPort;
     151      if (i != null) {
     152        i.NameChanged += InputPort_NameChanged;
     153        i.ValueChanged += InputPort_ValueChanged;
     154        UpdateParameter(i);
     155      }
     156      IOutputPort o = port as IOutputPort;
     157      if (o != null) {
     158        o.NameChanged += OutputPort_NameChanged;
     159        UpdateOutputPort(o);
    136160      }
    137161    }
    138162    private void DeregisterPortEvents(IPort port) {
    139       IInputPort p = port as IInputPort;
    140       if (p != null) {
    141         p.ValueChanged -= InputPort_ValueChanged;
    142       }
     163      IInputPort i = port as IInputPort;
     164      if (i != null) {
     165        i.NameChanged -= InputPort_NameChanged;
     166        i.ValueChanged -= InputPort_ValueChanged;
     167      }
     168      IOutputPort o = port as IOutputPort;
     169      if (o != null) {
     170        o.NameChanged -= OutputPort_NameChanged;
     171      }
     172    }
     173    private void InputPort_NameChanged(object sender, EventArgs e) {
     174      UpdateParameter((IInputPort)sender);
    143175    }
    144176    private void InputPort_ValueChanged(object sender, EventArgs e) {
    145177      UpdateParameter((IInputPort)sender);
     178    }
     179    private void OutputPort_NameChanged(object sender, EventArgs e) {
     180      UpdateOutputPort((IOutputPort)sender);
    146181    }
    147182    #endregion
     
    150185    private void RegisterAlgorithmEvents() {
    151186      if (algorithm != null) {
     187        algorithm.Prepared += Algorithm_Prepared;
     188        RegisterResultsEvents();
     189      }
     190    }
     191
     192    private void DeregisterAlgorithmEvents() {
     193      if (algorithm != null) {
     194        algorithm.Prepared -= Algorithm_Prepared;
     195        DeregisterResultsEvents();
     196      }
     197    }
     198    private void Algorithm_Prepared(object sender, EventArgs e) {
     199      RegisterResultsEvents();
     200    }
     201    #endregion
     202
     203    #region Results Events
     204    private void RegisterResultsEvents() {
     205      if ((algorithm != null) && (algorithm.Results != null)) {
    152206        algorithm.Results.ItemsAdded += Results_ItemsAdded;
    153207        algorithm.Results.ItemsRemoved += Results_ItemsRemoved;
    154208        algorithm.Results.ItemsReplaced += Results_ItemsReplaced;
    155209        algorithm.Results.CollectionReset += Results_CollectionReset;
    156       }
    157     }
    158     private void DeregisterAlgorithmEvents() {
    159       if (algorithm != null) {
     210        foreach (var r in algorithm.Results)
     211          RegisterResultEvents(r);
     212      }
     213    }
     214    private void DeregisterResultsEvents() {
     215      if ((algorithm != null) && (algorithm.Results != null)) {
    160216        algorithm.Results.ItemsAdded -= Results_ItemsAdded;
    161217        algorithm.Results.ItemsRemoved -= Results_ItemsRemoved;
    162218        algorithm.Results.ItemsReplaced -= Results_ItemsReplaced;
    163219        algorithm.Results.CollectionReset -= Results_CollectionReset;
     220        foreach (var r in algorithm.Results)
     221          DeregisterResultEvents(r);
    164222      }
    165223    }
     
    190248      if (result != null) {
    191249        result.ValueChanged += Result_ValueChanged;
     250        result.ToStringChanged += Result_ToStringChanged;
     251        UpdateOutputPort(result);
    192252      }
    193253    }
     
    195255      if (result != null) {
    196256        result.ValueChanged -= Result_ValueChanged;
     257        result.ToStringChanged += Result_ToStringChanged;
    197258      }
    198259    }
     
    200261      UpdateOutputPort((IResult)sender);
    201262    }
     263    private void Result_ToStringChanged(object sender, EventArgs e) {
     264      UpdateOutputPort((IResult)sender);
     265    }
    202266    #endregion
    203267  }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IAlgorithmNode.cs

    r11406 r11409  
    2424namespace HeuristicLab.Optimization.Networks {
    2525  public interface IAlgorithmNode : INode {
     26    new PortCollection Ports { get; }
     27
    2628    IAlgorithm Algorithm { get; set; }
    2729    event EventHandler AlgorithmChanged;
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IPort.cs

    r11401 r11409  
    2525namespace HeuristicLab.Optimization.Networks {
    2626  public interface IPort : INamedItem {
     27    //DISCUSS: Should there be a reference to the node of this port?
     28
    2729    object Value { get; }
    2830
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs

    r11406 r11409  
    2424using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2525using System;
     26using System.Drawing;
    2627
    2728namespace HeuristicLab.Optimization.Networks {
     
    2930  [StorableClass]
    3031  public class InputPort<T> : Port<T>, IInputPort<T> where T : class, IItem {
     32    public static new Image StaticItemImage {
     33      get { return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown; }
     34    }
     35
    3136    [Storable]
    3237    private IOutputPort<T> outputPort;
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Network.cs

    r11401 r11409  
    2929  [Creatable("Optimization Networks")]
    3030  [StorableClass]
    31   public class Network : Node, INetwork {
     31  public class Network : Node, INetwork, IStorableContent {
     32    public string Filename { get; set; }
     33
    3234    public static new Image StaticItemImage {
    3335      get { return HeuristicLab.Common.Resources.VSImageLibrary.Module; }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputPort.cs

    r11401 r11409  
    2424using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2525using System;
     26using System.Drawing;
    2627
    2728namespace HeuristicLab.Optimization.Networks {
     
    2930  [StorableClass]
    3031  public class OutputPort<T> : Port<T>, IOutputPort<T> where T : class, IItem {
     32    public static new Image StaticItemImage {
     33      get { return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp; }
     34    }
     35
    3136    new public T Value {
    3237      get { return base.Value; }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Plugin.cs.frame

    r11406 r11409  
    3232  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
    3333  [PluginDependency("HeuristicLab.Core", "3.3")]
    34 //  [PluginDependency("HeuristicLab.Data", "3.3")]
    35 //  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3634  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3735  [PluginDependency("HeuristicLab.Persistence", "3.3")]
Note: See TracChangeset for help on using the changeset viewer.