Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4830


Ignore:
Timestamp:
11/18/10 00:53:15 (14 years ago)
Author:
cneumuel
Message:

#1215 worked on metaoptimization

Location:
branches/HeuristicLab.MetaOptimization
Files:
15 added
16 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj

    r4516 r4830  
    8383  </ItemGroup>
    8484  <ItemGroup>
     85    <Compile Include="RootParameterConfigurationView.cs">
     86      <SubType>UserControl</SubType>
     87    </Compile>
     88    <Compile Include="RootParameterConfigurationView.Designer.cs">
     89      <DependentUpon>RootParameterConfigurationView.cs</DependentUpon>
     90    </Compile>
    8591    <Compile Include="NumericRangeView.cs">
    8692      <SubType>UserControl</SubType>
     
    101107      <DependentUpon>ParameterConfigurationListView.cs</DependentUpon>
    102108    </Compile>
    103     <Compile Include="NumericParameterConfigurationView.cs">
    104       <SubType>UserControl</SubType>
    105     </Compile>
    106     <Compile Include="NumericParameterConfigurationView.Designer.cs">
    107       <DependentUpon>NumericParameterConfigurationView.cs</DependentUpon>
    108     </Compile>
    109109    <Compile Include="HeuristicLabProblemsMetaOptimizationViewsPlugin.cs" />
    110110    <Compile Include="ParameterConfigurationView.cs">
     
    115115    </Compile>
    116116    <Compile Include="Properties\AssemblyInfo.cs" />
     117    <Compile Include="ValueView.cs">
     118      <SubType>UserControl</SubType>
     119    </Compile>
     120    <Compile Include="ValueView.Designer.cs">
     121      <DependentUpon>ValueView.cs</DependentUpon>
     122    </Compile>
    117123  </ItemGroup>
    118124  <ItemGroup>
     
    127133  </ItemGroup>
    128134  <ItemGroup>
     135    <EmbeddedResource Include="RootParameterConfigurationView.resx">
     136      <DependentUpon>RootParameterConfigurationView.cs</DependentUpon>
     137    </EmbeddedResource>
    129138    <EmbeddedResource Include="NumericRangeView.resx">
    130139      <DependentUpon>NumericRangeView.cs</DependentUpon>
     
    136145      <DependentUpon>ParameterConfigurationListView.cs</DependentUpon>
    137146    </EmbeddedResource>
    138     <EmbeddedResource Include="NumericParameterConfigurationView.resx">
    139       <DependentUpon>NumericParameterConfigurationView.cs</DependentUpon>
    140     </EmbeddedResource>
    141147    <EmbeddedResource Include="ParameterConfigurationView.resx">
    142148      <DependentUpon>ParameterConfigurationView.cs</DependentUpon>
     149    </EmbeddedResource>
     150    <EmbeddedResource Include="ValueView.resx">
     151      <DependentUpon>ValueView.cs</DependentUpon>
    143152    </EmbeddedResource>
    144153  </ItemGroup>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/NumericRangeView.Designer.cs

    r4516 r4830  
    11namespace HeuristicLab.Problems.MetaOptimization.Views {
    2   partial class NumericRangeView {
     2  partial class IntValueRangeView {
    33    /// <summary>
    44    /// Required designer variable.
     
    5656      this.lowerValueView.Caption = "StringConvertibleValue View";
    5757      this.lowerValueView.Content = null;
     58      this.lowerValueView.LabelVisible = true;
    5859      this.lowerValueView.Location = new System.Drawing.Point(38, 0);
    5960      this.lowerValueView.Name = "lowerValueView";
     
    6869      this.upperValueView.Caption = "StringConvertibleValue View";
    6970      this.upperValueView.Content = null;
     71      this.upperValueView.LabelVisible = true;
    7072      this.upperValueView.Location = new System.Drawing.Point(38, 29);
    7173      this.upperValueView.Name = "upperValueView";
     
    8991      this.stepSizeValueView.Caption = "StringConvertibleValue View";
    9092      this.stepSizeValueView.Content = null;
     93      this.stepSizeValueView.LabelVisible = true;
    9194      this.stepSizeValueView.Location = new System.Drawing.Point(38, 58);
    9295      this.stepSizeValueView.Name = "stepSizeValueView";
     
    9598      this.stepSizeValueView.TabIndex = 5;
    9699      //
    97       // NumericRangeView
     100      // IntValueRangeView
    98101      //
    99102      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     
    105108      this.Controls.Add(this.upperValueView);
    106109      this.Controls.Add(this.lowerValueView);
    107       this.Name = "NumericRangeView";
    108       this.Size = new System.Drawing.Size(434, 145);
     110      this.Name = "IntValueRangeView";
     111      this.Size = new System.Drawing.Size(434, 85);
    109112      this.ResumeLayout(false);
    110113      this.PerformLayout();
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/NumericRangeView.cs

    r4516 r4830  
    1414namespace HeuristicLab.Problems.MetaOptimization.Views {
    1515  /// <summary>
    16   /// The visual representation of a <see cref="INumericRange"/>.
     16  /// The visual representation of a <see cref="IIntegerRange"/>.
    1717  /// </summary>
    1818  [View("NumericRange View")]
    19   [Content(typeof(INumericRange), true)]
    20   public partial class NumericRangeView : ItemView {
     19  [Content(typeof(IRange<IntValue>), true)]
     20  public partial class IntValueRangeView : ItemView {
    2121    /// <summary>
    2222    /// Gets or sets the variable to represent visually.
     
    2424    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    2525    /// No own data storage present.</remarks>
    26     public new INumericRange Content {
    27       get { return (INumericRange)base.Content; }
     26    public new IRange<IntValue> Content {
     27      get { return (IRange<IntValue>)base.Content; }
    2828      set { base.Content = value; }
    2929    }
    3030
    31     public NumericRangeView() {
     31    public IntValueRangeView() {
    3232      InitializeComponent();
    3333    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ObjectSelectorDialog.cs

    r4516 r4830  
    1313    private bool initialized;
    1414    private List<IItem> items;
    15     private IEnumerable<IGrouping<string, T>> selectableItems;
     15    private IEnumerable<IGrouping<Type, T>> selectableItems;
    1616
    1717    private T item;
     
    2020    }
    2121
    22     public ObjectSelectorDialog(IEnumerable<IGrouping<string, T>> selectableItems) {
     22    public ObjectSelectorDialog(IEnumerable<IGrouping<Type, T>> selectableItems) {
    2323      this.initialized = false;
    2424      this.items = new List<IItem>();
     
    3232        itemsListView.SmallImageList = new ImageList();
    3333
    34         foreach (IGrouping<string, T> category in selectableItems) {
    35           ListViewGroup group = new ListViewGroup(category.Key);
     34        foreach (IGrouping<Type, T> item in selectableItems) {
     35          ListViewGroup group = new ListViewGroup(item.Key.Name);
    3636          itemsListView.Groups.Add(group);
    37           foreach (T i in category) {
     37          foreach (T i in item) {
    3838            items.Add(i);
    39             ListViewItem item = new ListViewItem(new string[] { i.Name, i.Description, i.ItemName }, group);
     39            ListViewItem value = new ListViewItem(new string[] { i.Name, i.Description, i.ItemName }, group);
    4040            itemsListView.SmallImageList.Images.Add(i.ItemImage);
    41             item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
    42             item.Tag = i;
    43             itemsListView.Items.Add(item);
     41            value.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     42            value.Tag = i;
     43            itemsListView.Items.Add(value);
    4444          }
    4545        }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ParameterConfigurationListView.cs

    r4516 r4830  
    1111using HeuristicLab.Core;
    1212using HeuristicLab.PluginInfrastructure;
     13using HeuristicLab.Collections;
    1314
    1415namespace HeuristicLab.Problems.MetaOptimization.Views {
     
    1718  /// </summary>
    1819  [View("ParameterConfigurationList View")]
    19   [Content(typeof(ParameterConfigurationList), true)]
     20  [Content(typeof(IItemList<IParameterConfiguration>), true)]
    2021  public partial class ParameterConfigurationListView : ItemCollectionView<IParameterConfiguration> {
    2122    /// <summary>
     
    2425    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    2526    /// No own data storage present.</remarks>
    26     public new ParameterConfigurationList Content {
    27       get { return (ParameterConfigurationList)base.Content; }
     27    public new IItemList<IParameterConfiguration> Content {
     28      get { return (IItemList<IParameterConfiguration>)base.Content; }
    2829      set { base.Content = value; }
    2930    }
     
    3536    protected override void RegisterContentEvents() {
    3637      base.RegisterContentEvents();
    37       Content.CheckedItemsChanged += new Collections.CollectionItemsChangedEventHandler<IParameterConfiguration>(Content_CheckedItemsChanged);
    3838    }
    3939
    4040    protected override void DeregisterContentEvents() {
    41       Content.CheckedItemsChanged -= new Collections.CollectionItemsChangedEventHandler<IParameterConfiguration>(Content_CheckedItemsChanged);
    4241      base.DeregisterContentEvents();
    4342    }
     
    4544    protected override void OnContentChanged() {
    4645      base.OnContentChanged();
    47       while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
    48       viewHost.Content = null;
    49       if (Content != null) {
    50         Caption += " (" + Content.GetType().Name + ")";
    51         foreach (IParameterConfiguration item in Content.CheckedItems)
    52           AddListViewItem(CreateListViewItem(item));
    53         AdjustListViewColumnSizes();
    54         SortItemsListView(SortOrder.Ascending);
    55       }
    5646    }
    57 
    58     protected override void SetEnabledStateOfControls() {
    59       base.SetEnabledStateOfControls();
    60     }
    61 
    62     protected override void addButton_Click(object sender, EventArgs e) {
    63       var selectorDialog = new ObjectSelectorDialog<IParameterConfiguration>(from c in Content
    64                                                                              where !Content.ItemChecked(c)
    65                                                                              group c by c.Category);
    66       if (selectorDialog.ShowDialog() == DialogResult.OK) {
    67         Content.SetItemCheckedState(selectorDialog.Item, true);
    68       }
    69     }
    70 
    71     protected override void removeButton_Click(object sender, EventArgs e) {
    72       if (itemsListView.SelectedItems.Count > 0) {
    73         foreach (ListViewItem item in itemsListView.SelectedItems)
    74           Content.SetItemCheckedState((IParameterConfiguration)item.Tag, false);
    75         itemsListView.SelectedItems.Clear();
    76       }
    77     }
    78 
    79     private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IParameterConfiguration> e) {
    80       foreach (IParameterConfiguration item in e.Items) {
    81         if (!Content.ItemChecked(item)) {
    82           ListViewItem found = FindListViewItem(item);
    83           if(found != null)
    84             RemoveListViewItem(found);
    85         } else {
    86           ListViewItem found = FindListViewItem(item);
    87           if (found == null)
    88             AddListViewItem(CreateListViewItem(item));
    89         }
    90       }
    91     }
    92 
    93     #region Helpers
    94     private ListViewItem FindListViewItem(IParameterConfiguration tag) {
    95       foreach (ListViewItem item in itemsListView.Items) {
    96         if (item.Tag == tag)
    97           return item;
    98       }
    99       return null;
    100     }
    101     #endregion
    10247  }
    10348}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ParameterConfigurationView.Designer.cs

    r4516 r4830  
    2525    private void InitializeComponent() {
    2626      this.optimizeCheckBox = new System.Windows.Forms.CheckBox();
    27       this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     27      this.tabControl = new System.Windows.Forms.TabControl();
     28      this.valueTabPage = new System.Windows.Forms.TabPage();
     29      this.valueViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     30      this.configurationtabPage = new System.Windows.Forms.TabPage();
     31      this.configurationViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     32      this.childParameterTabPage = new System.Windows.Forms.TabPage();
     33      this.childParameterConfigurationListView = new HeuristicLab.Problems.MetaOptimization.Views.ParameterConfigurationListView();
     34      this.tabControl.SuspendLayout();
     35      this.valueTabPage.SuspendLayout();
     36      this.configurationtabPage.SuspendLayout();
     37      this.childParameterTabPage.SuspendLayout();
    2838      this.SuspendLayout();
    2939      //
     
    3949      this.optimizeCheckBox.CheckedChanged += new System.EventHandler(this.optimizeCheckBox_CheckedChanged);
    4050      //
    41       // viewHost
     51      // tabControl
    4252      //
    43       this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     53      this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    4454                  | System.Windows.Forms.AnchorStyles.Left)
    4555                  | System.Windows.Forms.AnchorStyles.Right)));
    46       this.viewHost.Caption = "View";
    47       this.viewHost.Content = null;
    48       this.viewHost.Location = new System.Drawing.Point(0, 26);
    49       this.viewHost.Name = "viewHost";
    50       this.viewHost.ReadOnly = false;
    51       this.viewHost.Size = new System.Drawing.Size(729, 455);
    52       this.viewHost.TabIndex = 7;
    53       this.viewHost.ViewType = null;
     56      this.tabControl.Controls.Add(this.valueTabPage);
     57      this.tabControl.Controls.Add(this.configurationtabPage);
     58      this.tabControl.Controls.Add(this.childParameterTabPage);
     59      this.tabControl.Location = new System.Drawing.Point(3, 26);
     60      this.tabControl.Name = "tabControl";
     61      this.tabControl.SelectedIndex = 0;
     62      this.tabControl.Size = new System.Drawing.Size(553, 447);
     63      this.tabControl.TabIndex = 5;
     64      //
     65      // valueTabPage
     66      //
     67      this.valueTabPage.Controls.Add(this.valueViewHost);
     68      this.valueTabPage.Location = new System.Drawing.Point(4, 22);
     69      this.valueTabPage.Name = "valueTabPage";
     70      this.valueTabPage.Padding = new System.Windows.Forms.Padding(3);
     71      this.valueTabPage.Size = new System.Drawing.Size(545, 421);
     72      this.valueTabPage.TabIndex = 0;
     73      this.valueTabPage.Text = "Value";
     74      this.valueTabPage.UseVisualStyleBackColor = true;
     75      //
     76      // valueViewHost
     77      //
     78      this.valueViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     79                  | System.Windows.Forms.AnchorStyles.Left)
     80                  | System.Windows.Forms.AnchorStyles.Right)));
     81      this.valueViewHost.Caption = "Value";
     82      this.valueViewHost.Content = null;
     83      this.valueViewHost.Enabled = false;
     84      this.valueViewHost.Location = new System.Drawing.Point(3, 3);
     85      this.valueViewHost.Name = "valueViewHost";
     86      this.valueViewHost.ReadOnly = false;
     87      this.valueViewHost.Size = new System.Drawing.Size(539, 415);
     88      this.valueViewHost.TabIndex = 0;
     89      this.valueViewHost.ViewType = null;
     90      //
     91      // configurationtabPage
     92      //
     93      this.configurationtabPage.Controls.Add(this.configurationViewHost);
     94      this.configurationtabPage.Location = new System.Drawing.Point(4, 22);
     95      this.configurationtabPage.Name = "configurationtabPage";
     96      this.configurationtabPage.Padding = new System.Windows.Forms.Padding(3);
     97      this.configurationtabPage.Size = new System.Drawing.Size(545, 421);
     98      this.configurationtabPage.TabIndex = 1;
     99      this.configurationtabPage.Text = "Configuration";
     100      this.configurationtabPage.UseVisualStyleBackColor = true;
     101      //
     102      // configurationViewHost
     103      //
     104      this.configurationViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     105                  | System.Windows.Forms.AnchorStyles.Left)
     106                  | System.Windows.Forms.AnchorStyles.Right)));
     107      this.configurationViewHost.Caption = "Configuration";
     108      this.configurationViewHost.Content = null;
     109      this.configurationViewHost.Enabled = false;
     110      this.configurationViewHost.Location = new System.Drawing.Point(4, 4);
     111      this.configurationViewHost.Name = "configurationViewHost";
     112      this.configurationViewHost.ReadOnly = false;
     113      this.configurationViewHost.Size = new System.Drawing.Size(538, 414);
     114      this.configurationViewHost.TabIndex = 0;
     115      this.configurationViewHost.ViewType = null;
     116      //
     117      // childParameterTabPage
     118      //
     119      this.childParameterTabPage.Controls.Add(this.childParameterConfigurationListView);
     120      this.childParameterTabPage.Location = new System.Drawing.Point(4, 22);
     121      this.childParameterTabPage.Name = "childParameterTabPage";
     122      this.childParameterTabPage.Size = new System.Drawing.Size(545, 421);
     123      this.childParameterTabPage.TabIndex = 2;
     124      this.childParameterTabPage.Text = "Child Parameters";
     125      this.childParameterTabPage.UseVisualStyleBackColor = true;
     126      //
     127      // childParameterConfigurationListView
     128      //
     129      this.childParameterConfigurationListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     130                  | System.Windows.Forms.AnchorStyles.Left)
     131                  | System.Windows.Forms.AnchorStyles.Right)));
     132      this.childParameterConfigurationListView.Caption = "Parameter Configuration";
     133      this.childParameterConfigurationListView.Content = null;
     134      this.childParameterConfigurationListView.Location = new System.Drawing.Point(4, 4);
     135      this.childParameterConfigurationListView.Name = "childParameterConfigurationListView";
     136      this.childParameterConfigurationListView.ReadOnly = false;
     137      this.childParameterConfigurationListView.Size = new System.Drawing.Size(538, 414);
     138      this.childParameterConfigurationListView.TabIndex = 0;
    54139      //
    55140      // ParameterConfigurationView
     
    57142      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    58143      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    59       this.Controls.Add(this.viewHost);
     144      this.Controls.Add(this.tabControl);
    60145      this.Controls.Add(this.optimizeCheckBox);
    61146      this.Name = "ParameterConfigurationView";
    62       this.Size = new System.Drawing.Size(729, 481);
     147      this.Size = new System.Drawing.Size(556, 473);
     148      this.tabControl.ResumeLayout(false);
     149      this.valueTabPage.ResumeLayout(false);
     150      this.configurationtabPage.ResumeLayout(false);
     151      this.childParameterTabPage.ResumeLayout(false);
    63152      this.ResumeLayout(false);
    64153      this.PerformLayout();
     
    69158
    70159    private System.Windows.Forms.CheckBox optimizeCheckBox;
    71     private MainForm.WindowsForms.ViewHost viewHost;
     160    private System.Windows.Forms.TabControl tabControl;
     161    private System.Windows.Forms.TabPage valueTabPage;
     162    private MainForm.WindowsForms.ViewHost valueViewHost;
     163    private System.Windows.Forms.TabPage configurationtabPage;
     164    private MainForm.WindowsForms.ViewHost configurationViewHost;
     165    private System.Windows.Forms.TabPage childParameterTabPage;
     166    private ParameterConfigurationListView childParameterConfigurationListView;
    72167  }
    73168}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ParameterConfigurationView.cs

    r4525 r4830  
    1010using HeuristicLab.Core.Views;
    1111using HeuristicLab.Core;
     12using HeuristicLab.Collections;
    1213
    1314namespace HeuristicLab.Problems.MetaOptimization.Views {
     
    1617  /// </summary>
    1718  [View("ParameterConfiguration View")]
    18   [Content(typeof(IParameterConfiguration), true)]
     19  [Content(typeof(IParameterConfiguration), false)]
     20  [Content(typeof(ParameterConfiguration), true)]
    1921  public partial class ParameterConfigurationView : ItemView {
    2022    /// <summary>
     
    3537      base.OnContentChanged();
    3638      if (Content != null) {
    37         viewHost.Content = Content.Parameter;
     39        optimizeCheckBox.Checked = Content.OptimizationEnabled;
     40        valueViewHost.ViewType = typeof(ValueView);
     41        valueViewHost.Content = Content;
     42        if (Content is IntValueParameterConfiguration) {
     43          configurationViewHost.Content = ((IntValueParameterConfiguration)Content).Ranges;
     44        } else {
     45          configurationViewHost.Content = null;
     46        }
     47
     48        childParameterConfigurationListView.Content = ((ParameterConfiguration)Content).ChildParameterConfigurations;
    3849      } else {
    39         viewHost.Content = null;
     50        valueViewHost.Content = null;
     51        configurationViewHost.Content = null;
     52        childParameterConfigurationListView.Content = null;
    4053      }
     54      SetEnabledStateOfControls();
     55    }
     56
     57    protected override void RegisterContentEvents() {
     58      base.RegisterContentEvents();
     59      Content.ChildParameterConfigurations.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IParameterConfiguration>>(ChildParameterConfigurations_ItemsAdded);
     60      Content.ChildParameterConfigurations.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IParameterConfiguration>>(ChildParameterConfigurations_ItemsRemoved);
     61    }
     62    protected override void DeregisterContentEvents() {
     63      Content.ChildParameterConfigurations.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IParameterConfiguration>>(ChildParameterConfigurations_ItemsAdded);
     64      Content.ChildParameterConfigurations.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IParameterConfiguration>>(ChildParameterConfigurations_ItemsRemoved);
     65      base.DeregisterContentEvents();
     66    }
     67
     68    void ChildParameterConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<IParameterConfiguration>> e) {
     69      SetEnabledStateOfControls();
     70    }
     71   
     72    void ChildParameterConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<IParameterConfiguration>> e) {
     73      SetEnabledStateOfControls();
    4174    }
    4275
    4376    protected override void SetEnabledStateOfControls() {
    4477      base.SetEnabledStateOfControls();
     78      this.SuspendLayout();
     79      if (optimizeCheckBox.Checked) {
     80        DisableTabPage(valueTabPage);
     81        EnableTabPage(configurationtabPage);
     82        if (Content.ChildParameterConfigurations.Count > 0)
     83          EnableTabPage(childParameterTabPage);
     84      } else {
     85        DisableTabPage(configurationtabPage);
     86        DisableTabPage(childParameterTabPage);
     87        EnableTabPage(valueTabPage);
     88      }
     89      this.ResumeLayout();
    4590    }
    4691
    4792    private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) {
     93      Content.OptimizationEnabled = optimizeCheckBox.Checked;
     94      SetEnabledStateOfControls();
     95    }
    4896
     97    protected void EnableTabPage(TabPage tabPage) {
     98      if (!tabControl.TabPages.Contains(tabPage)) {
     99        tabControl.TabPages.Add(tabPage);
     100      }
     101    }
     102
     103    protected void DisableTabPage(TabPage tabPage) {
     104      if (tabControl.TabPages.Contains(tabPage)) {
     105        tabControl.TabPages.Remove(tabPage);
     106      }
    49107    }
    50108  }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestQualityAnalyzer.cs

    r4516 r4830  
    99using HeuristicLab.Parameters;
    1010using HeuristicLab.Data;
     11using HeuristicLab.Common;
    1112
    1213namespace HeuristicLab.Problems.MetaOptimization {
     
    1617  [Item("BestQualityAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]
    1718  [StorableClass]
    18   public sealed class BestQualityAnalyzer : SingleSuccessorOperator, IAnalyzer {
     19  public sealed class BestParameterConfigurationAnalyzer : SingleSuccessorOperator, IAnalyzer {
     20    // Wagner: Spezielle View für die Lösungen (ParameterConfigurations): So wie bei Runs: die zu Optimierenden Parameter(-werte) der besten solution anzeigen
    1921
    20     public ScopeTreeLookupParameter<IParameterSet> ParameterSetParameter {
    21       get { return (ScopeTreeLookupParameter<IParameterSet>)Parameters["ParameterSet"]; }
     22    public ScopeTreeLookupParameter<IParameterConfiguration> ParameterVectorParameter {
     23      get { return (ScopeTreeLookupParameter<IParameterConfiguration>)Parameters["ParameterConfiguration"]; }
    2224    }
    2325    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    2426      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    2527    }
    26     public LookupParameter<IParameterSet> BestSolutionParameter {
    27       get { return (LookupParameter<IParameterSet>)Parameters["BestSolution"]; }
     28    public LookupParameter<IParameterConfiguration> BestSolutionParameter {
     29      get { return (LookupParameter<IParameterConfiguration>)Parameters["BestSolution"]; }
    2830    }
    2931    public ValueLookupParameter<ResultCollection> ResultsParameter {
     
    3335      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    3436    }
    35     public LookupParameter<IParameterSet> BestKnownSolutionParameter {
    36       get { return (LookupParameter<IParameterSet>)Parameters["BestKnownSolution"]; }
     37    public LookupParameter<IParameterConfiguration> BestKnownSolutionParameter {
     38      get { return (LookupParameter<IParameterConfiguration>)Parameters["BestKnownSolution"]; }
    3739    }
    3840
    39     public BestQualityAnalyzer()
     41    public BestParameterConfigurationAnalyzer()
    4042      : base() {
    41       Parameters.Add(new ScopeTreeLookupParameter<IParameterSet>("ParameterSet", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
     43      Parameters.Add(new ScopeTreeLookupParameter<IParameterConfiguration>("ParameterConfiguration", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
    4244      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed."));
    43       Parameters.Add(new LookupParameter<IParameterSet>("BestSolution", "TODO The best TSP solution."));
     45      Parameters.Add(new LookupParameter<IParameterConfiguration>("BestSolution", "TODO The best TSP solution."));
    4446      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored."));
    4547      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "TODO The quality of the best known solution of this TSP instance."));
    46       Parameters.Add(new LookupParameter<IParameterSet>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
     48      Parameters.Add(new LookupParameter<IParameterConfiguration>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
     49    }
     50
     51    [StorableConstructor]
     52    private BestParameterConfigurationAnalyzer(bool deserializing) : base(deserializing) { }
     53    private BestParameterConfigurationAnalyzer(BestParameterConfigurationAnalyzer original, Cloner cloner) : base(original, cloner) { }
     54    public override IDeepCloneable Clone(Cloner cloner) {
     55      return new BestParameterConfigurationAnalyzer(this, cloner);
    4756    }
    4857
     
    5160      ResultCollection results = ResultsParameter.ActualValue;
    5261      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    53       ItemArray<IParameterSet> parameterSets = ParameterSetParameter.ActualValue;
     62      ItemArray<IParameterConfiguration> parameterVectors = ParameterVectorParameter.ActualValue;
    5463
    5564      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     
    5766      if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) {
    5867        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    59         BestKnownSolutionParameter.ActualValue = (IParameterSet)parameterSets[i].Clone();
     68        BestKnownSolutionParameter.ActualValue = (IParameterConfiguration)parameterVectors[i].Clone();
    6069      }
    6170
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfiguration.cs

    r4525 r4830  
    66using HeuristicLab.Common;
    77using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     8using HeuristicLab.Data;
     9using HeuristicLab.Parameters;
    810
    911namespace HeuristicLab.Problems.MetaOptimization {
    1012  [StorableClass]
    11   public abstract class ParameterConfiguration : IParameterConfiguration {
    12     [Storable]
    13     public IParameter Parameter { get; set; }
    14 
    15     [Storable]
    16     public string Category { get; set; }
     13  public class ParameterConfiguration : DeepCloneable, IParameterConfiguration, IStorableContent {
     14    protected ParameterConfiguration parentConfiguration;
     15
     16    [Storable]
     17    public string Filename { get; set; }
     18
     19    [Storable]
     20    protected bool optimizationEnabled;
     21    public bool OptimizationEnabled {
     22      get { return optimizationEnabled; }
     23      set {
     24        if (optimizationEnabled != value) {
     25          optimizationEnabled = value;
     26          OnOptimizationEnabledChanged();
     27        }
     28      }
     29    }
     30
     31    [Storable]
     32    protected string parameterName;
     33    public string ParameterName {
     34      get { return parameterName; }
     35      set {
     36        if (parameterName != value) {
     37          parameterName = value;
     38        }
     39      }
     40    }
     41
     42    [Storable]
     43    protected IItemList<IParameterConfiguration> childParameterConfigurations = new ItemList<IParameterConfiguration>();
     44    public IItemList<IParameterConfiguration> ChildParameterConfigurations {
     45      get { return childParameterConfigurations; }
     46    }
     47
     48    public virtual IParameter Parameter {
     49      get {
     50        return parentConfiguration.GetChildParameter(this.parameterName);
     51      }
     52    }
     53
     54    protected IItem value;
     55    public IItem Value {
     56      get { return value; }
     57      set {
     58        if (this.value != value) {
     59          ClearChildParameterConfigurations();
     60          OnValueChanging();
     61          this.value = value;
     62          if(this.value is IParameterizedNamedItem) AddChildParameterConfigurations(this.value as IParameterizedNamedItem);
     63          OnValueChanged();
     64        }
     65      }
     66    }
     67
     68    public ParameterConfiguration(ParameterConfiguration parentConfiguration, string parameterName, IItem value) {
     69      this.parentConfiguration = parentConfiguration;
     70      this.ParameterName = parameterName;
     71      this.Value = value;
     72    }
    1773
    1874    public ParameterConfiguration() { }
    19    
    2075    [StorableConstructor]
    2176    protected ParameterConfiguration(bool deserializing) { }
    22 
    23     public ParameterConfiguration(IParameter parameter, string category) {
    24       this.Parameter = parameter;
    25       this.Category = category;
    26       Parameter.NameChanged += this.NameChanged;
    27       Parameter.NameChanging += this.NameChanging;
    28       Parameter.DescriptionChanged += this.DescriptionChanged;
    29       Parameter.ItemImageChanged += this.ItemImageChanged;
    30       parameter.ToStringChanged += this.ToStringChanged;
    31     }
    32 
    33     public bool CanChangeDescription {
    34       get { return false; }
    35     }
    36 
    37     public bool CanChangeName {
    38       get { return false; }
    39     }
    40 
    41     public string Description {
     77    protected ParameterConfiguration(ParameterConfiguration original, Cloner cloner)
     78      : base(original, cloner) {
     79      this.OptimizationEnabled = original.optimizationEnabled;
     80      this.ParameterName = original.parameterName;
     81      this.Value = cloner.Clone(original.Value);
     82      this.childParameterConfigurations = cloner.Clone(original.childParameterConfigurations);
     83    }
     84    public override IDeepCloneable Clone(Cloner cloner) {
     85      return new ParameterConfiguration(this, cloner);
     86    }
     87
     88    protected virtual IValueParameter GetChildParameter(string childParameterName) {
     89      return (IValueParameter)((IParameterizedItem)Value).Parameters[childParameterName];
     90    }
     91
     92    protected virtual void AddChildParameterConfigurations(IParameterizedNamedItem parameterizedItem) {
     93      foreach (var childParameter in parameterizedItem.Parameters) {
     94        var pc = ParameterConfiguration.Create(this, parameterizedItem, childParameter);
     95        if (pc != null) this.childParameterConfigurations.Add(pc);
     96      }
     97    }
     98    protected virtual void ClearChildParameterConfigurations() {
     99      childParameterConfigurations.Clear();
     100    }
     101
     102    #region INamedItem Properties
     103    public virtual string Name {
     104      get { return Parameter.Name; }
     105      set { throw new NotSupportedException(); }
     106    }
     107    public virtual string Description {
    42108      get { return Parameter.Description; }
    43109      set { throw new NotSupportedException(); }
    44110    }
    45     public string Name {
    46       get { return Parameter.Name; }
    47       set { throw new NotSupportedException(); }
    48     }
    49 
    50     public string ItemDescription {
     111    public virtual bool CanChangeDescription {
     112      get { return false; }
     113    }
     114    public virtual bool CanChangeName {
     115      get { return false; }
     116    }
     117    public virtual string ItemDescription {
    51118      get { return Parameter.ItemDescription; }
    52119    }
    53 
    54     public System.Drawing.Image ItemImage {
     120    public virtual System.Drawing.Image ItemImage {
    55121      get { return Parameter.ItemImage; }
    56122    }
    57 
    58     public string ItemName {
     123    public virtual string ItemName {
    59124      get { return Parameter.ItemName; }
    60125    }
    61 
    62     public Version ItemVersion {
     126    public virtual Version ItemVersion {
    63127      get { return Parameter.ItemVersion; }
    64128    }
     129    #endregion
    65130
    66131    #region Events
    67132    public virtual event EventHandler NameChanged;
     133    protected virtual void OnNameChanged(object sender, EventArgs e) {
     134      var handler = NameChanged;
     135      if (handler != null) handler(sender, e);
     136    }
     137
    68138    public virtual event EventHandler<CancelEventArgs<string>> NameChanging;
     139    protected virtual void OnNameChanging(object sender, CancelEventArgs<string> e) {
     140      var handler = NameChanging;
     141      if (handler != null) handler(sender, e);
     142    }
     143
    69144    public virtual event EventHandler DescriptionChanged;
     145    protected virtual void OnDescriptionChanged(object sender, EventArgs e) {
     146      var handler = DescriptionChanged;
     147      if (handler != null) handler(sender, e);
     148    }
     149
    70150    public virtual event EventHandler ItemImageChanged;
     151    protected virtual void OnItemImageChanged(object sender, EventArgs e) {
     152      var handler = ItemImageChanged;
     153      if (handler != null) handler(sender, e);
     154    }
     155
    71156    public virtual event EventHandler ToStringChanged;
    72 
    73     protected virtual void OnToStringChanged() {
     157    protected virtual void OnStringChanged(object sender, EventArgs e) {
    74158      var handler = ToStringChanged;
     159      if (handler != null) handler(this, e); // important to set 'this' as sender
     160    }
     161
     162    public virtual event EventHandler OptimizationEnabledChanged;
     163    protected virtual void OnOptimizationEnabledChanged() {
     164      var handler = OptimizationEnabledChanged;
    75165      if (handler != null) handler(this, EventArgs.Empty);
    76166    }
     167
     168    public virtual event EventHandler ValueChanging;
     169    protected virtual void OnValueChanging() {
     170      var handler = ValueChanging;
     171      if (handler != null) handler(this, EventArgs.Empty);
     172    }
     173
     174    public virtual event EventHandler ValueChanged;
     175    protected virtual void OnValueChanged() {
     176      var handler = ValueChanged;
     177      if (handler != null) handler(this, EventArgs.Empty);
     178    }
    77179    #endregion
    78180
    79     #region Cloning
    80     public virtual IDeepCloneable Clone(Cloner cloner) {
    81       ParameterConfiguration clone = (ParameterConfiguration)Activator.CreateInstance(this.GetType(), true);
    82       cloner.RegisterClonedObject(this, clone);
    83       clone.Parameter = (IParameter)cloner.Clone(this.Parameter);
    84       clone.Category = this.Category;
    85       return clone;
    86     }
    87 
    88     public object Clone() {
    89       return Clone(new Cloner());
    90     }
    91     #endregion
    92 
    93181    public override string ToString() {
    94       return string.Format("{0}.{1}", Category, Parameter.Name);
    95     }
    96    
    97     public abstract void SetParameterWithRandomValue(IRandom random);
     182      return string.Format("{0} ({1})", ParameterName, Value);
     183    }
     184
     185    public static IParameterConfiguration Create(IParameterizedNamedItem parent) {
     186      return new RootParameterConfiguration(parent);
     187    }
     188
     189    public static IParameterConfiguration Create(ParameterConfiguration parentConfiguration, IParameterizedNamedItem parent, IParameter parameter) {
     190      if (parameter is IValueParameter) {
     191        IValueParameter valueParameter = parameter as IValueParameter;
     192
     193        if (typeof(IntValue).IsAssignableFrom(parameter.DataType)) {
     194          return new IntValueParameterConfiguration(parentConfiguration, parameter.Name, valueParameter.Value);
     195        } else if (typeof(IParameterizedItem).IsAssignableFrom(parameter.DataType)) {
     196          return new ParameterConfiguration(parentConfiguration, parameter.Name, valueParameter.Value);
     197        } else {
     198          // todo
     199          return new IntValueParameterConfiguration(parentConfiguration, parameter.Name, valueParameter.Value);
     200        }
     201      }
     202      return null;
     203    }
     204
     205    public void Parameterize(IParameterizedItem parameterizedItem) {
     206      throw new NotImplementedException();
     207    }
    98208
    99209  }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs

    r4525 r4830  
    1010using HeuristicLab.Optimization;
    1111using System.Threading;
     12using HeuristicLab.Common;
    1213
    1314namespace HeuristicLab.Problems.MetaOptimization {
     
    1819  [StorableClass]
    1920  public class MetaOptimizationEvaluator : SingleSuccessorOperator, IMetaOptimizationEvaluator {
     21    private const string RepetitionsParameterName = "Repetitions";
     22
    2023    private bool algorithmStopped;
    2124
     
    2326      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    2427    }
    25 
    2628    public ILookupParameter<IAlgorithm> AlgorithmParameter {
    2729      get { return (ILookupParameter<IAlgorithm>)Parameters["Algorithm"]; }
    2830    }
    29     public ILookupParameter<IParameterSet> ParameterSetParameter {
    30       get { return (ILookupParameter<IParameterSet>)Parameters["ParameterSet"]; }
     31    public ILookupParameter<IItemList<IProblem>> ProblemsParameter {
     32      get { return (ILookupParameter<IItemList<IProblem>>)Parameters["Problems"]; }
     33    }
     34    public ILookupParameter<IParameterConfiguration> ParameterConfigurationParameter {
     35      get { return (ILookupParameter<IParameterConfiguration>)Parameters["ParameterConfiguration"]; }
     36    }
     37    public ValueParameter<IntValue> RepetitionsParameter {
     38      get { return (ValueParameter<IntValue>)Parameters[RepetitionsParameterName]; }
    3139    }
    3240
    33     public MetaOptimizationEvaluator()
    34       : base() {
    35       Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the TSP solution."));
     41    public IntValue Repetitions {
     42      get { return RepetitionsParameter.Value; }
     43      set { RepetitionsParameter.Value = value; }
     44    }
     45
     46    public MetaOptimizationEvaluator() : base() {
     47      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector."));
    3648      Parameters.Add(new LookupParameter<IAlgorithm>("Algorithm", "Missing description."));
    37       Parameters.Add(new LookupParameter<IParameterSet>("ParameterSet", "Missing description."));
     49      Parameters.Add(new LookupParameter<IItemList<IProblem>>("Problems", "Missing description."));
     50      Parameters.Add(new LookupParameter<IParameterConfiguration>("ParameterConfiguration", "Missing description."));
     51      Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "Number of evaluations for one individual.", new IntValue(3)));
     52    }
     53
     54    [StorableConstructor]
     55    protected MetaOptimizationEvaluator(bool deserializing) : base(deserializing) { }
     56    protected MetaOptimizationEvaluator(MetaOptimizationEvaluator original, Cloner cloner)
     57      : base(original, cloner) {
     58      this.algorithmStopped = original.algorithmStopped;
     59    }
     60    public override IDeepCloneable Clone(Cloner cloner) {
     61      return new MetaOptimizationEvaluator(this, cloner);
    3862    }
    3963
    4064    public override IOperation Apply() {
    4165      AlgorithmParameter.ActualValue.Prepare();
    42       ParametrizeAlgorithm();
     66      //ParameterizeAlgorithm();
     67      ParameterConfigurationParameter.ActualValue.Parameterize(AlgorithmParameter.ActualValue);
    4368      algorithmStopped = false;
    4469      AlgorithmParameter.ActualValue.Stopped += new EventHandler(ActualValue_Stopped);
    45       AlgorithmParameter.ActualValue.Start();
    46       while (!algorithmStopped) {
    47         Thread.Sleep(1000); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already)
     70
     71      double qualitySum = 0;
     72
     73      foreach (IProblem problem in ProblemsParameter.ActualValue) {
     74        AlgorithmParameter.ActualValue.Problem = problem;
     75        AlgorithmParameter.ActualValue.Start();
     76        while (!algorithmStopped) {
     77          Thread.Sleep(1000); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already)
     78        }
     79        AlgorithmParameter.ActualValue.Stopped -= new EventHandler(ActualValue_Stopped);
     80        qualitySum += ((DoubleValue)AlgorithmParameter.ActualValue.Results["BestQuality"].Value).Value;
    4881      }
    49       AlgorithmParameter.ActualValue.Stopped -= new EventHandler(ActualValue_Stopped);
    50       this.QualityParameter.ActualValue = (DoubleValue)AlgorithmParameter.ActualValue.Results["BestQuality"].Value;
     82
     83      double qualityAvg = qualitySum / ProblemsParameter.ActualValue.Count;
     84      this.QualityParameter.ActualValue = new DoubleValue(qualityAvg);
     85
    5186      return base.Apply();
    5287    }
     
    5691    }
    5792
    58     private void ParametrizeAlgorithm() {
    59       foreach (IParameterConfiguration parameter in ParameterSetParameter.ActualValue.Parameters) {
    60         if (parameter.Category == "Algorithm") {
    61           this.AlgorithmParameter.ActualValue.Parameters[parameter.Parameter.Name].ActualValue = parameter.Parameter.ActualValue;
    62         } else if (parameter.Category == "Problem") {
    63           this.AlgorithmParameter.ActualValue.Problem.Parameters[parameter.Parameter.Name].ActualValue = parameter.Parameter.ActualValue;
    64         }
    65       }
    66     }
     93    //private void ParameterizeAlgorithm() {
     94    //  foreach (IParameterConfiguration parameter in ParameterVectorParameter.ActualValue) {
     95    //    if (typeof(IAlgorithm).IsAssignableFrom(parameter.OperatorType)) {
     96    //      this.AlgorithmParameter.ActualValue.Parameters[parameter.Parameter.Name].ActualValue = parameter.Parameter.ActualValue;
     97    //    } else if (typeof(IProblem).IsAssignableFrom(parameter.OperatorType)) {
     98    //      this.AlgorithmParameter.ActualValue.Problem.Parameters[parameter.Parameter.Name].ActualValue = parameter.Parameter.ActualValue;
     99    //    }
     100    //  }
     101    //}
    67102  }
    68103}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r4525 r4830  
    8888  <ItemGroup>
    8989    <Compile Include="Analyzers\BestQualityAnalyzer.cs" />
    90     <Compile Include="Creators\RandomParameterSetCreator.cs" />
    91     <Compile Include="Encodings\BooleanParameterConfiguration.cs" />
    92     <Compile Include="Encodings\Crossovers\ParameterSetCrossover.cs" />
    93     <Compile Include="Interfaces\IParameterSetOperator.cs" />
    94     <Compile Include="NumericRangeList.cs" />
    95     <Compile Include="Encodings\EnumerableParameterConfiguration.cs" />
    96     <Compile Include="Interfaces\INumericRange.cs" />
    97     <Compile Include="Encodings\NumericParameterConfiguration.cs" />
    98     <Compile Include="Encodings\ParameterSet.cs" />
     90    <Compile Include="Interfaces\IParameterConfigurationCreator.cs" />
     91    <Compile Include="Creators\RandomParameterConfigurationCreator.cs" />
     92    <Compile Include="Encodings\Crossovers\ParameterVectorCrossover.cs" />
     93    <Compile Include="Encodings\IntValueParameterConfiguration.cs" />
     94    <Compile Include="Encodings\ValueTypeParameterConfiguration.cs">
     95      <SubType>Code</SubType>
     96    </Compile>
     97    <Compile Include="Encodings\RootParameterConfiguration.cs" />
     98    <Compile Include="Interfaces\IParameterConfigurationOperator.cs" />
     99    <Compile Include="Interfaces\IRange.cs" />
    99100    <Compile Include="Evaluators\MetaOptimizationEvaluator.cs" />
    100101    <Compile Include="Interfaces\IMetaOptimizationEvaluator.cs" />
    101     <Compile Include="Interfaces\IParameterSet.cs" />
    102     <Compile Include="Interfaces\IParameterSetCreator.cs" />
    103102    <Compile Include="Interfaces\IParameterConfiguration.cs" />
    104103    <Compile Include="Encodings\ParameterConfiguration.cs" />
    105     <Compile Include="Encodings\ParameterConfigurationList.cs" />
    106     <Compile Include="NumericRange.cs" />
     104    <Compile Include="Range.cs" />
    107105    <Compile Include="Properties\AssemblyInfo.cs" />
    108106    <Compile Include="MetaOptimizationProblem.cs" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs

    r4525 r4830  
    77namespace HeuristicLab.Problems.MetaOptimization {
    88  public interface IParameterConfiguration : INamedItem {
    9     IParameter Parameter { get; set; }
    10     string Category { get; set; }
     9    bool OptimizationEnabled { get; set; }
     10    string ParameterName { get; set; }
     11    IParameter Parameter { get; }
     12    IItem Value { get; set; }
     13    IItemList<IParameterConfiguration> ChildParameterConfigurations { get; }
    1114
    12     void SetParameterWithRandomValue(IRandom random);
     15    void Parameterize(IParameterizedItem parameterizedItem);
     16
     17    event EventHandler OptimizationEnabledChanged;
     18    event EventHandler ValueChanging;
     19    event EventHandler ValueChanged;
    1320  }
    1421}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r4525 r4830  
    3636  [Creatable("Problems")]
    3737  [StorableClass]
    38   public sealed class MetaOptimizationProblem : ParameterizedNamedItem, ISingleObjectiveProblem, IStorableContent {
    39     public string Filename { get; set; }
    40 
    41     public override Image ItemImage {
    42       get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
    43     }
     38  public sealed class MetaOptimizationProblem : SingleObjectiveProblem<IMetaOptimizationEvaluator, IParameterConfigurationCreator> {
     39    private const string AlgorithmParameterName = "Algorithm";
     40    private const string ProblemsParameterName = "Problems";
     41    private const string AlgorithmParameterConfigurationParameterName = "AlgorithmParameterConfiguration";
     42    private const string ProblemParametersConfigurationParameterName = "ProblemParametersConfiguration";
    4443
    4544    #region Parameter Properties
    46 
    47     public ValueParameter<IntValue> RepetitionsParameter {
    48       get { return (ValueParameter<IntValue>)Parameters["Repetitions"]; }
     45    public ValueParameter<IAlgorithm> AlgorithmParameter {
     46      get { return (ValueParameter<IAlgorithm>)Parameters[AlgorithmParameterName]; }
    4947    }
    50 
    51     public ValueParameter<IParameterSetCreator> SolutionCreatorParameter {
    52       get { return (ValueParameter<IParameterSetCreator>)Parameters["SolutionCreator"]; }
     48    public ValueParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
     49      get { return (ValueParameter<IItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; }
    5350    }
    54     IParameter IProblem.SolutionCreatorParameter {
    55       get { return SolutionCreatorParameter; }
     51    public ValueParameter<IParameterConfiguration> AlgorithmParameterConfigurationParameter {
     52      get { return (ValueParameter<IParameterConfiguration>)Parameters[AlgorithmParameterConfigurationParameterName]; }
    5653    }
    57 
    58     public ValueParameter<IMetaOptimizationEvaluator> EvaluatorParameter {
    59       get { return (ValueParameter<IMetaOptimizationEvaluator>)Parameters["Evaluator"]; }
    60     }
    61     IParameter IProblem.EvaluatorParameter {
    62       get { return EvaluatorParameter; }
    63     }
    64 
    65     public OptionalValueParameter<ParameterSet> BestKnownSolutionParameter {
    66       get { return (OptionalValueParameter<ParameterSet>)Parameters["BestKnownSolution"]; }
    67     }
    68 
    69     public ValueParameter<BoolValue> MaximizationParameter {
    70       get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
    71     }
    72     IParameter ISingleObjectiveProblem.MaximizationParameter {
    73       get { return MaximizationParameter; }
    74     }
    75 
    76     public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
    77       get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    78     }
    79     IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
    80       get { return BestKnownQualityParameter; }
    81     }
    82 
    83     public ValueParameter<IAlgorithm> AlgorithmParameter {
    84       get { return (ValueParameter<IAlgorithm>)Parameters["Algorithm"]; }
    85     }
    86     public ValueParameter<ParameterConfigurationList> ParametersToOptimizeParameter {
    87       get { return (ValueParameter<ParameterConfigurationList>)Parameters["ParametersToOptimize"]; }
    88     }
     54    //public ValueParameter<IItemList<IParameterConfiguration>> ProblemParametersConfigurationParameter {
     55    //  get { return (ValueParameter<IItemList<IParameterConfiguration>>)Parameters[ProblemParametersConfigurationParameterName]; }
     56    //}
    8957    #endregion
    9058
    9159    #region Properties
    92 
    93     public IntValue Repetitions {
    94       get { return RepetitionsParameter.Value; }
    95       set { RepetitionsParameter.Value = value; }
    96     }
    97 
    98     public IEnumerable<IOperator> Operators {
    99       get { return operators; }
    100     }
    101 
    102     IEvaluator IProblem.Evaluator {
    103       get { return EvaluatorParameter.Value; }
    104     }
    105     public IMetaOptimizationEvaluator Evaluator {
    106       get { return EvaluatorParameter.Value; }
    107       set { EvaluatorParameter.Value = value; }
    108     }
    109 
    110     ISolutionCreator IProblem.SolutionCreator {
    111       get { return SolutionCreatorParameter.Value; }
    112     }
    113     public IParameterSetCreator SolutionCreator {
    114       get { return SolutionCreatorParameter.Value; }
    115     }
    116 
    117     ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
    118       get { return this.Evaluator; }
    119     }
    120 
    121     public DoubleValue BestKnownQuality {
    122       get { return BestKnownQualityParameter.Value; }
    123       set { BestKnownQualityParameter.Value = value; }
    124     }
    125     public ParameterSet BestKnownSolution {
    126       get { return BestKnownSolutionParameter.Value; }
    127       set { BestKnownSolutionParameter.Value = value; }
    128     }
    129 
    13060    public IAlgorithm Algorithm {
    13161      get { return AlgorithmParameter.Value; }
    13262      set { AlgorithmParameter.Value = value; }
    13363    }
    134 
    135     public ParameterConfigurationList ParametersToOptimize {
    136       get { return ParametersToOptimizeParameter.Value; }
    137       set { ParametersToOptimizeParameter.Value = value; }
     64    public IItemList<ISingleObjectiveProblem> Problems {
     65      get { return ProblemsParameter.Value; }
     66      set { ProblemsParameter.Value = value; }
    13867    }
    139 
    140     private BestQualityAnalyzer BestQualityAnalyzer {
    141       get { return operators.OfType<BestQualityAnalyzer>().FirstOrDefault(); }
     68    public IParameterConfiguration AlgorithmParameterConfiguration {
     69      get { return AlgorithmParameterConfigurationParameter.Value; }
     70      set { AlgorithmParameterConfigurationParameter.Value = value; }
    14271    }
     72    //public IItemList<IParameterConfiguration> ProblemParametersConfiguration {
     73    //  get { return ProblemParametersConfigurationParameter.Value; }
     74    //  set { ProblemParametersConfigurationParameter.Value = value; }
     75    //}
    14376    #endregion
    14477
    145     [Storable]
    146     private List<IOperator> operators;
     78    public MetaOptimizationProblem()
     79      : base() {
     80      Parameters.Add(new ValueParameter<IAlgorithm>(AlgorithmParameterName, "The algorithm which's parameters should be optimized."));
     81      Parameters.Add(new ValueParameter<IItemList<IProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ItemList<IProblem>()));
     82      Parameters.Add(new ValueParameter<IParameterConfiguration>(AlgorithmParameterConfigurationParameterName, "List of algorithm parameters that should be optimized."));
     83      //Parameters.Add(new ValueParameter<IItemList<IParameterConfiguration>>(ProblemParametersConfigurationParameterName, "List of problem parameters that should be optimized.", new ItemList<IParameterConfiguration>()));
     84     
     85      Maximization = new BoolValue(false);
     86      SolutionCreator = new RandomParameterConfigurationCreator();
     87      Evaluator = new MetaOptimizationEvaluator();
     88
     89      InitializeOperators();
     90      RegisterParameterEvents();
     91      ParameterizeSolutionCreator();
     92      ParameterizeEvaluator();
     93      ParameterizeOperators();
     94    }
    14795
    14896    [StorableConstructor]
    14997    private MetaOptimizationProblem(bool deserializing) : base(deserializing) { }
    150     public MetaOptimizationProblem()
    151       : base() {
    152 
    153       IParameterSetCreator creator = new RandomParameterSetCreator();
    154       MetaOptimizationEvaluator evaluator = new MetaOptimizationEvaluator();
    155       ParameterConfigurationList parametersToOptimize = new ParameterConfigurationList();
    156 
    157       Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolValue(false)));
    158       Parameters.Add(new ValueParameter<IntValue>("Repetitions", "Number of evaluations for one individual.", new IntValue(3)));
    159       Parameters.Add(new ValueParameter<IParameterSetCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.", creator));
    160       Parameters.Add(new ValueParameter<IMetaOptimizationEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.", evaluator));
    161       Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
    162       Parameters.Add(new OptionalValueParameter<ParameterSet>("BestKnownSolution", "The best known solution of this TSP instance."));
    163 
    164       Parameters.Add(new ValueParameter<IAlgorithm>("Algorithm", "The algorithm and problem which's parameters should be optimized."));
    165       Parameters.Add(new ValueParameter<ParameterConfigurationList>("ParametersToOptimize", "List of parameters that should be optimized.", parametersToOptimize));
    166 
    167       ParameterizeSolutionCreator();
    168       ParameterizeEvaluator();
    169 
    170       InitializeOperators();
    171       AttachEventHandlers();
     98    private MetaOptimizationProblem(MetaOptimizationProblem original, Cloner cloner) : base(original, cloner) {
     99      // todo
     100      this.RegisterParameterEvents();
    172101    }
    173 
    174     #region Cloning
    175102    public override IDeepCloneable Clone(Cloner cloner) {
    176       MetaOptimizationProblem clone = (MetaOptimizationProblem)base.Clone(cloner);
    177       clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
    178       // todo
    179       clone.AttachEventHandlers();
    180       return clone;
     103      return new MetaOptimizationProblem(this, cloner);
    181104    }
    182     #endregion
    183105
    184106    #region Helpers
    185107    [StorableHook(HookType.AfterDeserialization)]
    186108    private void AfterDeserializationHook() {
    187       AttachEventHandlers();
     109      RegisterParameterEvents();
    188110    }
    189     private void AttachEventHandlers() {
     111    private void RegisterParameterEvents() {
    190112      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    191113      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
     
    194116    }
    195117    private void InitializeOperators() {
    196       operators = new List<IOperator>();
    197       operators.Add(new BestQualityAnalyzer());
    198       ParameterizeAnalyzer();
    199       operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterSetOperator>().Cast<IOperator>());
    200       ParameterizeOperators();
    201 
    202       //UpdateMoveEvaluators();
    203       //InitializeMoveGenerators();
     118      Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>());
     119      Operators.Add(new BestParameterConfigurationAnalyzer());
    204120    }
    205121    private void ParameterizeSolutionCreator() {
    206       SolutionCreator.ParametersToOptimize = this.ParametersToOptimize;
     122      //SolutionCreator.ParametersToOptimize = this.ParametersToOptimize;
    207123    }
    208124    private void ParameterizeEvaluator() {
     125      ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
    209126    }
    210127    private void ParameterizeAnalyzer() {
    211       BestQualityAnalyzer.ResultsParameter.ActualName = "Results";
     128      //BestQualityAnalyzer.ResultsParameter.ActualName = "Results";
    212129    }
    213130    private void ParameterizeOperators() {
     131     
    214132    }
    215133
    216     private void AddAlgorithmParameters() {
    217       foreach (IParameter parameter in Algorithm.Parameters) {
    218         this.ParametersToOptimize.Add(new NumericParameterConfiguration(parameter, "Algorithm"), false);
    219       }
    220     }
    221     private void RemoveAlgorithmParameters() {
    222       foreach (IParameter parameter in Algorithm.Parameters) {
    223         IParameterConfiguration parameterConfiguration = this.ParametersToOptimize.Single(p => p.Parameter == parameter);
    224         if (parameterConfiguration != null) {
    225           this.ParametersToOptimize.Remove(parameterConfiguration);
    226         }
    227       }
    228     }
    229     private void ClearAlgorithmParameters() {
    230       //this.ParametersToOptimize.Clear();
    231     }
    232 
    233     private void AddProblemParameters() {
    234       foreach (IParameter parameter in Algorithm.Problem.Parameters) {
    235         this.ParametersToOptimize.Add(new NumericParameterConfiguration(parameter, "Problem"), false);
    236       }
    237     }
    238     private void RemoveProblemParameters() {
    239       foreach (IParameter parameter in Algorithm.Problem.Parameters) {
    240         IParameterConfiguration parameterConfiguration = this.ParametersToOptimize.Single(p => p.Parameter == parameter);
    241         if (parameterConfiguration != null) {
    242           this.ParametersToOptimize.Remove(parameterConfiguration);
    243         }
    244       }
    245     }
    246     private void ClearProblemParameters() {
    247       //this.ParametersToOptimize.Clear();
    248     }
    249134    #endregion
    250135
    251136    #region Events
    252     public event EventHandler SolutionCreatorChanged;
    253     private void OnSolutionCreatorChanged() {
    254       EventHandler handler = SolutionCreatorChanged;
    255       if (handler != null) handler(this, EventArgs.Empty);
    256     }
    257     public event EventHandler EvaluatorChanged;
    258     private void OnEvaluatorChanged() {
    259       EventHandler handler = EvaluatorChanged;
    260       if (handler != null) handler(this, EventArgs.Empty);
    261     }
    262     public event EventHandler OperatorsChanged;
    263     private void OnOperatorsChanged() {
    264       EventHandler handler = OperatorsChanged;
    265       if (handler != null) handler(this, EventArgs.Empty);
    266     }
    267     public event EventHandler Reset;
    268     private void OnReset() {
    269       EventHandler handler = Reset;
    270       if (handler != null) handler(this, EventArgs.Empty);
    271     }
    272137
    273138    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
     
    288153    }
    289154    void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) {
    290       ClearAlgorithmParameters();
    291155      if (Algorithm != null) {
    292156        Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged);
    293         AddAlgorithmParameters(); // TODO: When to Detach?
     157        AlgorithmParameterConfiguration = ParameterConfiguration.Create(Algorithm);
    294158      }
    295159      BaseLevelAlgorithm_ProblemChanged(sender, e);
     
    297161
    298162    void BaseLevelAlgorithm_ProblemChanged(object sender, EventArgs e) {
    299       ClearProblemParameters();
    300       if (Algorithm.Problem != null) {
    301         AddProblemParameters();
    302       }
     163      //ClearProblemParameters();
     164      //if (Algorithm.Problem != null) {
     165      //  AddProblemParameters();
     166      //}
    303167    }
    304168    #endregion
Note: See TracChangeset for help on using the changeset viewer.