- Timestamp:
- 11/18/10 00:53:15 (14 years ago)
- 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 83 83 </ItemGroup> 84 84 <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> 85 91 <Compile Include="NumericRangeView.cs"> 86 92 <SubType>UserControl</SubType> … … 101 107 <DependentUpon>ParameterConfigurationListView.cs</DependentUpon> 102 108 </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>109 109 <Compile Include="HeuristicLabProblemsMetaOptimizationViewsPlugin.cs" /> 110 110 <Compile Include="ParameterConfigurationView.cs"> … … 115 115 </Compile> 116 116 <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> 117 123 </ItemGroup> 118 124 <ItemGroup> … … 127 133 </ItemGroup> 128 134 <ItemGroup> 135 <EmbeddedResource Include="RootParameterConfigurationView.resx"> 136 <DependentUpon>RootParameterConfigurationView.cs</DependentUpon> 137 </EmbeddedResource> 129 138 <EmbeddedResource Include="NumericRangeView.resx"> 130 139 <DependentUpon>NumericRangeView.cs</DependentUpon> … … 136 145 <DependentUpon>ParameterConfigurationListView.cs</DependentUpon> 137 146 </EmbeddedResource> 138 <EmbeddedResource Include="NumericParameterConfigurationView.resx">139 <DependentUpon>NumericParameterConfigurationView.cs</DependentUpon>140 </EmbeddedResource>141 147 <EmbeddedResource Include="ParameterConfigurationView.resx"> 142 148 <DependentUpon>ParameterConfigurationView.cs</DependentUpon> 149 </EmbeddedResource> 150 <EmbeddedResource Include="ValueView.resx"> 151 <DependentUpon>ValueView.cs</DependentUpon> 143 152 </EmbeddedResource> 144 153 </ItemGroup> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/NumericRangeView.Designer.cs
r4516 r4830 1 1 namespace HeuristicLab.Problems.MetaOptimization.Views { 2 partial class NumericRangeView {2 partial class IntValueRangeView { 3 3 /// <summary> 4 4 /// Required designer variable. … … 56 56 this.lowerValueView.Caption = "StringConvertibleValue View"; 57 57 this.lowerValueView.Content = null; 58 this.lowerValueView.LabelVisible = true; 58 59 this.lowerValueView.Location = new System.Drawing.Point(38, 0); 59 60 this.lowerValueView.Name = "lowerValueView"; … … 68 69 this.upperValueView.Caption = "StringConvertibleValue View"; 69 70 this.upperValueView.Content = null; 71 this.upperValueView.LabelVisible = true; 70 72 this.upperValueView.Location = new System.Drawing.Point(38, 29); 71 73 this.upperValueView.Name = "upperValueView"; … … 89 91 this.stepSizeValueView.Caption = "StringConvertibleValue View"; 90 92 this.stepSizeValueView.Content = null; 93 this.stepSizeValueView.LabelVisible = true; 91 94 this.stepSizeValueView.Location = new System.Drawing.Point(38, 58); 92 95 this.stepSizeValueView.Name = "stepSizeValueView"; … … 95 98 this.stepSizeValueView.TabIndex = 5; 96 99 // 97 // NumericRangeView100 // IntValueRangeView 98 101 // 99 102 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); … … 105 108 this.Controls.Add(this.upperValueView); 106 109 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); 109 112 this.ResumeLayout(false); 110 113 this.PerformLayout(); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/NumericRangeView.cs
r4516 r4830 14 14 namespace HeuristicLab.Problems.MetaOptimization.Views { 15 15 /// <summary> 16 /// The visual representation of a <see cref="I NumericRange"/>.16 /// The visual representation of a <see cref="IIntegerRange"/>. 17 17 /// </summary> 18 18 [View("NumericRange View")] 19 [Content(typeof(I NumericRange), true)]20 public partial class NumericRangeView : ItemView {19 [Content(typeof(IRange<IntValue>), true)] 20 public partial class IntValueRangeView : ItemView { 21 21 /// <summary> 22 22 /// Gets or sets the variable to represent visually. … … 24 24 /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>. 25 25 /// No own data storage present.</remarks> 26 public new I NumericRangeContent {27 get { return (I NumericRange)base.Content; }26 public new IRange<IntValue> Content { 27 get { return (IRange<IntValue>)base.Content; } 28 28 set { base.Content = value; } 29 29 } 30 30 31 public NumericRangeView() {31 public IntValueRangeView() { 32 32 InitializeComponent(); 33 33 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ObjectSelectorDialog.cs
r4516 r4830 13 13 private bool initialized; 14 14 private List<IItem> items; 15 private IEnumerable<IGrouping< string, T>> selectableItems;15 private IEnumerable<IGrouping<Type, T>> selectableItems; 16 16 17 17 private T item; … … 20 20 } 21 21 22 public ObjectSelectorDialog(IEnumerable<IGrouping< string, T>> selectableItems) {22 public ObjectSelectorDialog(IEnumerable<IGrouping<Type, T>> selectableItems) { 23 23 this.initialized = false; 24 24 this.items = new List<IItem>(); … … 32 32 itemsListView.SmallImageList = new ImageList(); 33 33 34 foreach (IGrouping< string, T> categoryin selectableItems) {35 ListViewGroup group = new ListViewGroup( category.Key);34 foreach (IGrouping<Type, T> item in selectableItems) { 35 ListViewGroup group = new ListViewGroup(item.Key.Name); 36 36 itemsListView.Groups.Add(group); 37 foreach (T i in category) {37 foreach (T i in item) { 38 38 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); 40 40 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); 44 44 } 45 45 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ParameterConfigurationListView.cs
r4516 r4830 11 11 using HeuristicLab.Core; 12 12 using HeuristicLab.PluginInfrastructure; 13 using HeuristicLab.Collections; 13 14 14 15 namespace HeuristicLab.Problems.MetaOptimization.Views { … … 17 18 /// </summary> 18 19 [View("ParameterConfigurationList View")] 19 [Content(typeof( ParameterConfigurationList), true)]20 [Content(typeof(IItemList<IParameterConfiguration>), true)] 20 21 public partial class ParameterConfigurationListView : ItemCollectionView<IParameterConfiguration> { 21 22 /// <summary> … … 24 25 /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>. 25 26 /// No own data storage present.</remarks> 26 public new ParameterConfigurationListContent {27 get { return ( ParameterConfigurationList)base.Content; }27 public new IItemList<IParameterConfiguration> Content { 28 get { return (IItemList<IParameterConfiguration>)base.Content; } 28 29 set { base.Content = value; } 29 30 } … … 35 36 protected override void RegisterContentEvents() { 36 37 base.RegisterContentEvents(); 37 Content.CheckedItemsChanged += new Collections.CollectionItemsChangedEventHandler<IParameterConfiguration>(Content_CheckedItemsChanged);38 38 } 39 39 40 40 protected override void DeregisterContentEvents() { 41 Content.CheckedItemsChanged -= new Collections.CollectionItemsChangedEventHandler<IParameterConfiguration>(Content_CheckedItemsChanged);42 41 base.DeregisterContentEvents(); 43 42 } … … 45 44 protected override void OnContentChanged() { 46 45 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 }56 46 } 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 Content64 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 Helpers94 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 #endregion102 47 } 103 48 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ParameterConfigurationView.Designer.cs
r4516 r4830 25 25 private void InitializeComponent() { 26 26 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(); 28 38 this.SuspendLayout(); 29 39 // … … 39 49 this.optimizeCheckBox.CheckedChanged += new System.EventHandler(this.optimizeCheckBox_CheckedChanged); 40 50 // 41 // viewHost51 // tabControl 42 52 // 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) 44 54 | System.Windows.Forms.AnchorStyles.Left) 45 55 | 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; 54 139 // 55 140 // ParameterConfigurationView … … 57 142 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 58 143 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 59 this.Controls.Add(this. viewHost);144 this.Controls.Add(this.tabControl); 60 145 this.Controls.Add(this.optimizeCheckBox); 61 146 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); 63 152 this.ResumeLayout(false); 64 153 this.PerformLayout(); … … 69 158 70 159 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; 72 167 } 73 168 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ParameterConfigurationView.cs
r4525 r4830 10 10 using HeuristicLab.Core.Views; 11 11 using HeuristicLab.Core; 12 using HeuristicLab.Collections; 12 13 13 14 namespace HeuristicLab.Problems.MetaOptimization.Views { … … 16 17 /// </summary> 17 18 [View("ParameterConfiguration View")] 18 [Content(typeof(IParameterConfiguration), true)] 19 [Content(typeof(IParameterConfiguration), false)] 20 [Content(typeof(ParameterConfiguration), true)] 19 21 public partial class ParameterConfigurationView : ItemView { 20 22 /// <summary> … … 35 37 base.OnContentChanged(); 36 38 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; 38 49 } else { 39 viewHost.Content = null; 50 valueViewHost.Content = null; 51 configurationViewHost.Content = null; 52 childParameterConfigurationListView.Content = null; 40 53 } 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(); 41 74 } 42 75 43 76 protected override void SetEnabledStateOfControls() { 44 77 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(); 45 90 } 46 91 47 92 private void optimizeCheckBox_CheckedChanged(object sender, EventArgs e) { 93 Content.OptimizationEnabled = optimizeCheckBox.Checked; 94 SetEnabledStateOfControls(); 95 } 48 96 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 } 49 107 } 50 108 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestQualityAnalyzer.cs
r4516 r4830 9 9 using HeuristicLab.Parameters; 10 10 using HeuristicLab.Data; 11 using HeuristicLab.Common; 11 12 12 13 namespace HeuristicLab.Problems.MetaOptimization { … … 16 17 [Item("BestQualityAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")] 17 18 [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 19 21 20 public ScopeTreeLookupParameter<IParameter Set> ParameterSetParameter {21 get { return (ScopeTreeLookupParameter<IParameter Set>)Parameters["ParameterSet"]; }22 public ScopeTreeLookupParameter<IParameterConfiguration> ParameterVectorParameter { 23 get { return (ScopeTreeLookupParameter<IParameterConfiguration>)Parameters["ParameterConfiguration"]; } 22 24 } 23 25 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 24 26 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 25 27 } 26 public LookupParameter<IParameter Set> BestSolutionParameter {27 get { return (LookupParameter<IParameter Set>)Parameters["BestSolution"]; }28 public LookupParameter<IParameterConfiguration> BestSolutionParameter { 29 get { return (LookupParameter<IParameterConfiguration>)Parameters["BestSolution"]; } 28 30 } 29 31 public ValueLookupParameter<ResultCollection> ResultsParameter { … … 33 35 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 34 36 } 35 public LookupParameter<IParameter Set> BestKnownSolutionParameter {36 get { return (LookupParameter<IParameter Set>)Parameters["BestKnownSolution"]; }37 public LookupParameter<IParameterConfiguration> BestKnownSolutionParameter { 38 get { return (LookupParameter<IParameterConfiguration>)Parameters["BestKnownSolution"]; } 37 39 } 38 40 39 public Best QualityAnalyzer()41 public BestParameterConfigurationAnalyzer() 40 42 : base() { 41 Parameters.Add(new ScopeTreeLookupParameter<IParameter Set>("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.")); 42 44 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed.")); 43 Parameters.Add(new LookupParameter<IParameter Set>("BestSolution", "TODO The best TSP solution."));45 Parameters.Add(new LookupParameter<IParameterConfiguration>("BestSolution", "TODO The best TSP solution.")); 44 46 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored.")); 45 47 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); 47 56 } 48 57 … … 51 60 ResultCollection results = ResultsParameter.ActualValue; 52 61 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 53 ItemArray<IParameter Set> parameterSets = ParameterSetParameter.ActualValue;62 ItemArray<IParameterConfiguration> parameterVectors = ParameterVectorParameter.ActualValue; 54 63 55 64 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; … … 57 66 if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) { 58 67 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 59 BestKnownSolutionParameter.ActualValue = (IParameter Set)parameterSets[i].Clone();68 BestKnownSolutionParameter.ActualValue = (IParameterConfiguration)parameterVectors[i].Clone(); 60 69 } 61 70 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfiguration.cs
r4525 r4830 6 6 using HeuristicLab.Common; 7 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Data; 9 using HeuristicLab.Parameters; 8 10 9 11 namespace HeuristicLab.Problems.MetaOptimization { 10 12 [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 } 17 73 18 74 public ParameterConfiguration() { } 19 20 75 [StorableConstructor] 21 76 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 { 42 108 get { return Parameter.Description; } 43 109 set { throw new NotSupportedException(); } 44 110 } 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 { 51 118 get { return Parameter.ItemDescription; } 52 119 } 53 54 public System.Drawing.Image ItemImage { 120 public virtual System.Drawing.Image ItemImage { 55 121 get { return Parameter.ItemImage; } 56 122 } 57 58 public string ItemName { 123 public virtual string ItemName { 59 124 get { return Parameter.ItemName; } 60 125 } 61 62 public Version ItemVersion { 126 public virtual Version ItemVersion { 63 127 get { return Parameter.ItemVersion; } 64 128 } 129 #endregion 65 130 66 131 #region Events 67 132 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 68 138 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 69 144 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 70 150 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 71 156 public virtual event EventHandler ToStringChanged; 72 73 protected virtual void OnToStringChanged() { 157 protected virtual void OnStringChanged(object sender, EventArgs e) { 74 158 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; 75 165 if (handler != null) handler(this, EventArgs.Empty); 76 166 } 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 } 77 179 #endregion 78 180 79 #region Cloning80 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 #endregion92 93 181 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 } 98 208 99 209 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs
r4525 r4830 10 10 using HeuristicLab.Optimization; 11 11 using System.Threading; 12 using HeuristicLab.Common; 12 13 13 14 namespace HeuristicLab.Problems.MetaOptimization { … … 18 19 [StorableClass] 19 20 public class MetaOptimizationEvaluator : SingleSuccessorOperator, IMetaOptimizationEvaluator { 21 private const string RepetitionsParameterName = "Repetitions"; 22 20 23 private bool algorithmStopped; 21 24 … … 23 26 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 24 27 } 25 26 28 public ILookupParameter<IAlgorithm> AlgorithmParameter { 27 29 get { return (ILookupParameter<IAlgorithm>)Parameters["Algorithm"]; } 28 30 } 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]; } 31 39 } 32 40 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.")); 36 48 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); 38 62 } 39 63 40 64 public override IOperation Apply() { 41 65 AlgorithmParameter.ActualValue.Prepare(); 42 ParametrizeAlgorithm(); 66 //ParameterizeAlgorithm(); 67 ParameterConfigurationParameter.ActualValue.Parameterize(AlgorithmParameter.ActualValue); 43 68 algorithmStopped = false; 44 69 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; 48 81 } 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 51 86 return base.Apply(); 52 87 } … … 56 91 } 57 92 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 //} 67 102 } 68 103 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r4525 r4830 88 88 <ItemGroup> 89 89 <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" /> 99 100 <Compile Include="Evaluators\MetaOptimizationEvaluator.cs" /> 100 101 <Compile Include="Interfaces\IMetaOptimizationEvaluator.cs" /> 101 <Compile Include="Interfaces\IParameterSet.cs" />102 <Compile Include="Interfaces\IParameterSetCreator.cs" />103 102 <Compile Include="Interfaces\IParameterConfiguration.cs" /> 104 103 <Compile Include="Encodings\ParameterConfiguration.cs" /> 105 <Compile Include="Encodings\ParameterConfigurationList.cs" /> 106 <Compile Include="NumericRange.cs" /> 104 <Compile Include="Range.cs" /> 107 105 <Compile Include="Properties\AssemblyInfo.cs" /> 108 106 <Compile Include="MetaOptimizationProblem.cs" /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs
r4525 r4830 7 7 namespace HeuristicLab.Problems.MetaOptimization { 8 8 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; } 11 14 12 void SetParameterWithRandomValue(IRandom random); 15 void Parameterize(IParameterizedItem parameterizedItem); 16 17 event EventHandler OptimizationEnabledChanged; 18 event EventHandler ValueChanging; 19 event EventHandler ValueChanged; 13 20 } 14 21 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r4525 r4830 36 36 [Creatable("Problems")] 37 37 [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"; 44 43 45 44 #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]; } 49 47 } 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]; } 53 50 } 54 IParameter IProblem.SolutionCreatorParameter {55 get { return SolutionCreatorParameter; }51 public ValueParameter<IParameterConfiguration> AlgorithmParameterConfigurationParameter { 52 get { return (ValueParameter<IParameterConfiguration>)Parameters[AlgorithmParameterConfigurationParameterName]; } 56 53 } 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 //} 89 57 #endregion 90 58 91 59 #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 130 60 public IAlgorithm Algorithm { 131 61 get { return AlgorithmParameter.Value; } 132 62 set { AlgorithmParameter.Value = value; } 133 63 } 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; } 138 67 } 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; } 142 71 } 72 //public IItemList<IParameterConfiguration> ProblemParametersConfiguration { 73 // get { return ProblemParametersConfigurationParameter.Value; } 74 // set { ProblemParametersConfigurationParameter.Value = value; } 75 //} 143 76 #endregion 144 77 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 } 147 95 148 96 [StorableConstructor] 149 97 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(); 172 101 } 173 174 #region Cloning175 102 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); 181 104 } 182 #endregion183 105 184 106 #region Helpers 185 107 [StorableHook(HookType.AfterDeserialization)] 186 108 private void AfterDeserializationHook() { 187 AttachEventHandlers();109 RegisterParameterEvents(); 188 110 } 189 private void AttachEventHandlers() {111 private void RegisterParameterEvents() { 190 112 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); 191 113 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); … … 194 116 } 195 117 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()); 204 120 } 205 121 private void ParameterizeSolutionCreator() { 206 SolutionCreator.ParametersToOptimize = this.ParametersToOptimize;122 //SolutionCreator.ParametersToOptimize = this.ParametersToOptimize; 207 123 } 208 124 private void ParameterizeEvaluator() { 125 ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 209 126 } 210 127 private void ParameterizeAnalyzer() { 211 BestQualityAnalyzer.ResultsParameter.ActualName = "Results";128 //BestQualityAnalyzer.ResultsParameter.ActualName = "Results"; 212 129 } 213 130 private void ParameterizeOperators() { 131 214 132 } 215 133 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 }249 134 #endregion 250 135 251 136 #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 }272 137 273 138 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) { … … 288 153 } 289 154 void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) { 290 ClearAlgorithmParameters();291 155 if (Algorithm != null) { 292 156 Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); 293 A ddAlgorithmParameters(); // TODO: When to Detach?157 AlgorithmParameterConfiguration = ParameterConfiguration.Create(Algorithm); 294 158 } 295 159 BaseLevelAlgorithm_ProblemChanged(sender, e); … … 297 161 298 162 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 //} 303 167 } 304 168 #endregion
Note: See TracChangeset
for help on using the changeset viewer.