Changeset 7841
- Timestamp:
- 05/16/12 16:10:55 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimizer/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.Designer.cs
r7259 r7841 46 46 private void InitializeComponent() { 47 47 this.components = new System.ComponentModel.Container(); 48 System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("QAPLIB", System.Windows.Forms.HorizontalAlignment.Left); 49 System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("TSPLIB", System.Windows.Forms.HorizontalAlignment.Left); 50 System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("bur26a"); 51 System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("esc32a"); 52 System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("berlin52"); 53 System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("ch130"); 48 54 this.okButton = new System.Windows.Forms.Button(); 49 55 this.cancelButton = new System.Windows.Forms.Button(); … … 53 59 this.repetitionsNumericUpDown = new System.Windows.Forms.NumericUpDown(); 54 60 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 61 this.instancesLabel = new System.Windows.Forms.Label(); 62 this.instancesListView = new System.Windows.Forms.ListView(); 63 this.columnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 55 64 ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).BeginInit(); 56 65 this.SuspendLayout(); … … 61 70 this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; 62 71 this.okButton.Enabled = false; 63 this.okButton.Location = new System.Drawing.Point(113, 58);72 this.okButton.Location = new System.Drawing.Point(113, 259); 64 73 this.okButton.Name = "okButton"; 65 74 this.okButton.Size = new System.Drawing.Size(75, 23); … … 73 82 this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 74 83 this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 75 this.cancelButton.Location = new System.Drawing.Point(194, 58);84 this.cancelButton.Location = new System.Drawing.Point(194, 259); 76 85 this.cancelButton.Name = "cancelButton"; 77 86 this.cancelButton.Size = new System.Drawing.Size(75, 23); … … 105 114 // 106 115 this.repetitionsLabel.AutoSize = true; 107 this.repetitionsLabel.Location = new System.Drawing.Point(12, 3 0);116 this.repetitionsLabel.Location = new System.Drawing.Point(12, 31); 108 117 this.repetitionsLabel.Name = "repetitionsLabel"; 109 118 this.repetitionsLabel.Size = new System.Drawing.Size(63, 13); … … 113 122 // repetitionsNumericUpDown 114 123 // 115 this.repetitionsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 116 124 this.repetitionsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 125 | System.Windows.Forms.AnchorStyles.Right))); 117 126 this.repetitionsNumericUpDown.Location = new System.Drawing.Point(113, 28); 118 127 this.repetitionsNumericUpDown.Maximum = new decimal(new int[] { … … 138 147 this.repetitionsNumericUpDown.Validated += new System.EventHandler(this.repetitionsNumericUpDown_Validated); 139 148 // 149 // instancesLabel 150 // 151 this.instancesLabel.AutoSize = true; 152 this.instancesLabel.Location = new System.Drawing.Point(12, 54); 153 this.instancesLabel.Name = "instancesLabel"; 154 this.instancesLabel.Size = new System.Drawing.Size(56, 13); 155 this.instancesLabel.TabIndex = 2; 156 this.instancesLabel.Text = "&Instances:"; 157 // 158 // instancesListView 159 // 160 this.instancesListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 161 | System.Windows.Forms.AnchorStyles.Left) 162 | System.Windows.Forms.AnchorStyles.Right))); 163 this.instancesListView.CheckBoxes = true; 164 this.instancesListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 165 this.columnHeader}); 166 listViewGroup1.Header = "QAPLIB"; 167 listViewGroup1.Name = "QAPLIBHeader"; 168 listViewGroup2.Header = "TSPLIB"; 169 listViewGroup2.Name = "TSPLIBHeader"; 170 listViewGroup2.Tag = ""; 171 this.instancesListView.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { 172 listViewGroup1, 173 listViewGroup2}); 174 this.instancesListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; 175 listViewItem1.Checked = true; 176 listViewItem1.Group = listViewGroup1; 177 listViewItem1.StateImageIndex = 1; 178 listViewItem2.Checked = true; 179 listViewItem2.Group = listViewGroup1; 180 listViewItem2.StateImageIndex = 1; 181 listViewItem3.Group = listViewGroup2; 182 listViewItem3.StateImageIndex = 0; 183 listViewItem4.Group = listViewGroup2; 184 listViewItem4.StateImageIndex = 0; 185 this.instancesListView.Items.AddRange(new System.Windows.Forms.ListViewItem[] { 186 listViewItem1, 187 listViewItem2, 188 listViewItem3, 189 listViewItem4}); 190 this.instancesListView.Location = new System.Drawing.Point(113, 54); 191 this.instancesListView.Name = "instancesListView"; 192 this.instancesListView.Size = new System.Drawing.Size(156, 199); 193 this.instancesListView.TabIndex = 6; 194 this.instancesListView.UseCompatibleStateImageBehavior = false; 195 this.instancesListView.View = System.Windows.Forms.View.Details; 196 // 197 // columnHeader 198 // 199 this.columnHeader.Width = 150; 200 // 140 201 // CreateExperimentDialog 141 202 // … … 144 205 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 145 206 this.CancelButton = this.cancelButton; 146 this.ClientSize = new System.Drawing.Size(281, 93); 207 this.ClientSize = new System.Drawing.Size(281, 294); 208 this.Controls.Add(this.instancesListView); 147 209 this.Controls.Add(this.repetitionsNumericUpDown); 210 this.Controls.Add(this.instancesLabel); 148 211 this.Controls.Add(this.repetitionsLabel); 149 212 this.Controls.Add(this.createBatchRunLabel); … … 173 236 private System.Windows.Forms.NumericUpDown repetitionsNumericUpDown; 174 237 private System.Windows.Forms.ToolTip toolTip; 238 private System.Windows.Forms.Label instancesLabel; 239 private System.Windows.Forms.ListView instancesListView; 240 private System.Windows.Forms.ColumnHeader columnHeader; 175 241 176 242 } -
trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs
r7259 r7841 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using System.Windows.Forms; 24 26 using HeuristicLab.Optimization; 27 using HeuristicLab.PluginInfrastructure; 28 using HeuristicLab.Problems.Instances; 25 29 26 30 namespace HeuristicLab.Optimizer { … … 41 45 } 42 46 43 public CreateExperimentDialog() { 47 public CreateExperimentDialog() : this(null) { } 48 public CreateExperimentDialog(IOptimizer optimizer) { 49 InitializeComponent(); 50 Optimizer = optimizer; 44 51 experiment = null; 45 optimizer = null; 46 InitializeComponent(); 52 instancesListView.Items.Clear(); 53 instancesListView.Groups.Clear(); 54 FillOrHideInstanceListView(); 47 55 } 48 public CreateExperimentDialog(IOptimizer optimizer) 49 : this() { 50 Optimizer = optimizer; 56 57 private void FillOrHideInstanceListView() { 58 if (Optimizer != null && optimizer is IAlgorithm) { 59 var algorithm = (IAlgorithm)Optimizer; 60 if (algorithm.Problem != null) { 61 var instanceProviders = GetProblemInstanceProviders(algorithm.Problem); 62 if (instanceProviders.Any()) { 63 foreach (var provider in instanceProviders) { 64 var group = new ListViewGroup(provider.Name, provider.Name); 65 group.Tag = provider; 66 instancesListView.Groups.Add(group); 67 IEnumerable<IDataDescriptor> descriptors = ((dynamic)provider).GetDataDescriptors(); 68 foreach (var d in descriptors) { 69 var item = new ListViewItem(d.Name, group); 70 item.Checked = true; 71 item.Tag = d; 72 instancesListView.Items.Add(item); 73 } 74 } 75 instancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); 76 if (instancesListView.Items.Count > 0) return; 77 } 78 } 79 } 80 instancesLabel.Visible = false; 81 instancesListView.Visible = false; 82 Height = 130; 83 } 84 85 private IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders(IProblem problem) { 86 var consumerTypes = problem.GetType().GetInterfaces() 87 .Where(x => x.IsGenericType 88 && x.GetGenericTypeDefinition() == typeof(IProblemInstanceConsumer<>)); 89 90 if (consumerTypes.Any()) { 91 var instanceTypes = consumerTypes 92 .Select(x => x.GetGenericArguments().First()) 93 .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x)); 94 95 foreach (var type in instanceTypes) { 96 foreach (var provider in ApplicationManager.Manager.GetInstances(type)) 97 yield return (IProblemInstanceProvider)provider; 98 } 99 } 51 100 } 52 101 … … 60 109 private void okButton_Click(object sender, EventArgs e) { 61 110 experiment = new Experiment(); 62 if (createBatchRunCheckBox.Checked) { 63 BatchRun batchRun = new BatchRun(); 64 batchRun.Repetitions = (int)repetitionsNumericUpDown.Value; 65 batchRun.Optimizer = (IOptimizer)Optimizer.Clone(); 66 Experiment.Optimizers.Add(batchRun); 111 if (instancesListView.CheckedItems.Count == 0) { 112 AddOptimizer((IOptimizer)Optimizer.Clone()); 67 113 } else { 68 Experiment.Optimizers.Add((IOptimizer)Optimizer.Clone()); 114 foreach (var item in instancesListView.CheckedItems.OfType<ListViewItem>()) { 115 var descriptor = (IDataDescriptor)item.Tag; 116 var provider = (IProblemInstanceProvider)item.Group.Tag; 117 var algorithm = (IAlgorithm)Optimizer.Clone(); 118 ((dynamic)algorithm.Problem).Load(((dynamic)provider).LoadData(descriptor)); 119 AddOptimizer(algorithm); 120 } 69 121 } 70 122 Experiment.Prepare(true); 71 123 } 124 125 private void AddOptimizer(IOptimizer optimizer) { 126 if (createBatchRunCheckBox.Checked) { 127 var batchRun = new BatchRun(); 128 batchRun.Repetitions = (int)repetitionsNumericUpDown.Value; 129 batchRun.Optimizer = optimizer; 130 experiment.Optimizers.Add(batchRun); 131 } else { 132 experiment.Optimizers.Add(optimizer); 133 } 134 } 72 135 } 73 136 } -
trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj
r7013 r7841 99 99 </PropertyGroup> 100 100 <ItemGroup> 101 <Reference Include="Microsoft.CSharp" /> 101 102 <Reference Include="System" /> 102 103 <Reference Include="System.Core"> … … 259 260 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 260 261 <Private>False</Private> 262 </ProjectReference> 263 <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj"> 264 <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project> 265 <Name>HeuristicLab.Problems.Instances-3.3</Name> 261 266 </ProjectReference> 262 267 </ItemGroup> -
trunk/sources/HeuristicLab.Optimizer/3.3/Plugin.cs.frame
r7260 r7841 37 37 [PluginDependency("HeuristicLab.Optimization", "3.3")] 38 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] 39 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 39 40 public class HeuristicLabOptimizerPlugin : PluginBase { 40 41 }
Note: See TracChangeset
for help on using the changeset viewer.