[4104] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4104] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[7841] | 23 | using System.Collections.Generic;
|
---|
[7846] | 24 | using System.ComponentModel;
|
---|
[7908] | 25 | using System.Globalization;
|
---|
[7841] | 26 | using System.Linq;
|
---|
[7885] | 27 | using System.Text;
|
---|
[7846] | 28 | using System.Threading;
|
---|
[4104] | 29 | using System.Windows.Forms;
|
---|
[7908] | 30 | using HeuristicLab.Core;
|
---|
| 31 | using HeuristicLab.Data;
|
---|
[4650] | 32 | using HeuristicLab.Optimization;
|
---|
[7908] | 33 | using HeuristicLab.Parameters;
|
---|
[7841] | 34 | using HeuristicLab.Problems.Instances;
|
---|
[4104] | 35 |
|
---|
[4650] | 36 | namespace HeuristicLab.Optimizer {
|
---|
[4104] | 37 | public partial class CreateExperimentDialog : Form {
|
---|
[7974] | 38 | private enum DialogMode { Normal = 1, DiscoveringInstances = 2, CreatingExperiment = 3, PreparingExperiment = 4 };
|
---|
[7908] | 39 |
|
---|
[5300] | 40 | private IOptimizer optimizer;
|
---|
| 41 | public IOptimizer Optimizer {
|
---|
| 42 | get { return optimizer; }
|
---|
[4104] | 43 | set {
|
---|
[5300] | 44 | optimizer = value;
|
---|
[7908] | 45 | Experiment = null;
|
---|
[5300] | 46 | okButton.Enabled = optimizer != null;
|
---|
[7908] | 47 | SetTabControlVisibility();
|
---|
[7957] | 48 | FillInstanceTreeViewAsync();
|
---|
[7908] | 49 | FillParametersListView();
|
---|
[4104] | 50 | }
|
---|
| 51 | }
|
---|
[5300] | 52 |
|
---|
[7908] | 53 | public Experiment Experiment { get; private set; }
|
---|
[4104] | 54 |
|
---|
[7846] | 55 | private bool createBatchRun;
|
---|
| 56 | private int repetitions;
|
---|
[7908] | 57 | private Dictionary<IProblemInstanceProvider, HashSet<IDataDescriptor>> instances;
|
---|
| 58 | private Dictionary<IValueParameter, Tuple<int, int, int>> intParameters;
|
---|
| 59 | private Dictionary<IValueParameter, Tuple<double, double, double>> doubleParameters;
|
---|
| 60 | private HashSet<IValueParameter> boolParameters;
|
---|
[7974] | 61 | private Dictionary<IValueParameter, HashSet<IItem>> multipleChoiceParameters;
|
---|
[7908] | 62 |
|
---|
| 63 | private StringBuilder failedInstances;
|
---|
[7846] | 64 | private EventWaitHandle backgroundWorkerWaitHandle = new ManualResetEvent(false);
|
---|
[7957] | 65 | private bool suppressTreeViewEventHandling, suppressCheckAllNoneEventHandling;
|
---|
[7846] | 66 |
|
---|
[7841] | 67 | public CreateExperimentDialog() : this(null) { }
|
---|
| 68 | public CreateExperimentDialog(IOptimizer optimizer) {
|
---|
[4104] | 69 | InitializeComponent();
|
---|
[7957] | 70 | instanceDiscoveryProgressLabel.BackColor = instancesTabPage.BackColor;
|
---|
[7846] | 71 | createBatchRun = createBatchRunCheckBox.Checked;
|
---|
| 72 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
[7885] | 73 | // do not set the Optimizer property here, because we want to delay instance discovery to the time when the form loads
|
---|
| 74 | this.optimizer = optimizer;
|
---|
[7908] | 75 | Experiment = null;
|
---|
[7885] | 76 | okButton.Enabled = optimizer != null;
|
---|
[7908] | 77 |
|
---|
| 78 | instances = new Dictionary<IProblemInstanceProvider, HashSet<IDataDescriptor>>();
|
---|
| 79 | intParameters = new Dictionary<IValueParameter, Tuple<int, int, int>>();
|
---|
| 80 | doubleParameters = new Dictionary<IValueParameter, Tuple<double, double, double>>();
|
---|
| 81 | boolParameters = new HashSet<IValueParameter>();
|
---|
[7974] | 82 | multipleChoiceParameters = new Dictionary<IValueParameter, HashSet<IItem>>();
|
---|
[4104] | 83 | }
|
---|
| 84 |
|
---|
[7885] | 85 | #region Event handlers
|
---|
| 86 | private void CreateExperimentDialog_Load(object sender, EventArgs e) {
|
---|
[7908] | 87 | SetTabControlVisibility();
|
---|
[7957] | 88 | FillInstanceTreeViewAsync();
|
---|
[7908] | 89 | FillParametersListView();
|
---|
[7841] | 90 | }
|
---|
| 91 |
|
---|
[7885] | 92 | private void CreateExperimentDialog_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
| 93 | if (experimentCreationBackgroundWorker.IsBusy) {
|
---|
| 94 | if (DialogResult != System.Windows.Forms.DialogResult.OK) {
|
---|
| 95 | if (experimentCreationBackgroundWorker.IsBusy) experimentCreationBackgroundWorker.CancelAsync();
|
---|
| 96 | if (instanceDiscoveryBackgroundWorker.IsBusy) instanceDiscoveryBackgroundWorker.CancelAsync();
|
---|
[7841] | 97 | }
|
---|
[7885] | 98 | e.Cancel = true;
|
---|
[7841] | 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[7885] | 102 | private void okButton_Click(object sender, EventArgs e) {
|
---|
[7908] | 103 | SetMode(DialogMode.CreatingExperiment);
|
---|
| 104 | experimentCreationBackgroundWorker.RunWorkerAsync();
|
---|
[7885] | 105 | backgroundWorkerWaitHandle.WaitOne(); // make sure the background worker has started before exiting
|
---|
[4104] | 106 | }
|
---|
[7885] | 107 |
|
---|
[7908] | 108 | #region Parameters variation
|
---|
| 109 | private void parametersListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
|
---|
| 110 | var parameter = (IValueParameter)e.Item.Tag;
|
---|
| 111 | var isConstrainedValueParameter = typeof(OptionalConstrainedValueParameter<>).Equals(parameter.GetType().GetGenericTypeDefinition())
|
---|
| 112 | || typeof(ConstrainedValueParameter<>).Equals(parameter.GetType().GetGenericTypeDefinition());
|
---|
| 113 |
|
---|
| 114 | if (!isConstrainedValueParameter && parameter.Value == null) {
|
---|
| 115 | if (e.Item.Checked) e.Item.Checked = false;
|
---|
| 116 | return;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | if (isConstrainedValueParameter) {
|
---|
| 120 | if (e.Item.Checked) {
|
---|
[7974] | 121 | multipleChoiceParameters.Add(parameter, new HashSet<IItem>());
|
---|
[7957] | 122 | } else {
|
---|
| 123 | multipleChoiceParameters.Remove(parameter);
|
---|
| 124 | }
|
---|
[7908] | 125 | }
|
---|
| 126 |
|
---|
| 127 | var intValue = parameter.Value as ValueTypeValue<int>;
|
---|
| 128 | if (intValue != null) {
|
---|
| 129 | if (e.Item.Checked) {
|
---|
| 130 | int minimum = intValue.Value;
|
---|
| 131 | int maximum = intValue.Value;
|
---|
| 132 | int step = 1;
|
---|
| 133 | intParameters.Add(parameter, new Tuple<int, int, int>(minimum, maximum, step));
|
---|
| 134 | } else intParameters.Remove(parameter);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | var doubleValue = parameter.Value as ValueTypeValue<double>;
|
---|
| 138 | if (doubleValue != null) {
|
---|
| 139 | if (e.Item.Checked) {
|
---|
| 140 | double minimum = doubleValue.Value;
|
---|
| 141 | double maximum = doubleValue.Value;
|
---|
| 142 | double step = 1;
|
---|
| 143 | doubleParameters.Add(parameter, new Tuple<double, double, double>(minimum, maximum, step));
|
---|
| 144 | } else doubleParameters.Remove(parameter);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | var boolValue = parameter.Value as ValueTypeValue<bool>;
|
---|
| 148 | if (boolValue != null) {
|
---|
| 149 | if (e.Item.Checked) boolParameters.Add(parameter);
|
---|
| 150 | else boolParameters.Remove(parameter);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[7957] | 153 | UpdateVariationsLabel();
|
---|
[7908] | 154 | if (e.Item.Selected) UpdateDetailsView(parameter);
|
---|
| 155 | else e.Item.Selected = true;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | private void parametersListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 159 | if (parametersListView.SelectedItems.Count == 0) {
|
---|
| 160 | ClearDetailsView();
|
---|
| 161 | } else {
|
---|
| 162 | var parameter = parametersListView.SelectedItems[0].Tag as IValueParameter;
|
---|
| 163 | UpdateDetailsView(parameter);
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | private void UpdateDetailsView(IValueParameter parameter) {
|
---|
| 168 | ClearDetailsView();
|
---|
| 169 |
|
---|
| 170 | var isConstrainedValueParameter =
|
---|
| 171 | typeof(OptionalConstrainedValueParameter<>).IsAssignableFrom(parameter.GetType().GetGenericTypeDefinition())
|
---|
| 172 | || typeof(ConstrainedValueParameter<>).Equals(parameter.GetType().GetGenericTypeDefinition());
|
---|
| 173 |
|
---|
| 174 | if (isConstrainedValueParameter) {
|
---|
[7957] | 175 | detailsTypeLabel.Text = "Choices:";
|
---|
[7908] | 176 | choicesListView.Enabled = true;
|
---|
| 177 | choicesListView.Visible = true;
|
---|
| 178 | choicesListView.Tag = parameter;
|
---|
| 179 |
|
---|
| 180 | if (!multipleChoiceParameters.ContainsKey(parameter)) return;
|
---|
| 181 | dynamic constrainedValuedParameter = parameter;
|
---|
| 182 | dynamic validValues = constrainedValuedParameter.ValidValues;
|
---|
| 183 | foreach (var choice in validValues) {
|
---|
| 184 | choicesListView.Items.Add(new ListViewItem(choice.ToString()) {
|
---|
| 185 | Tag = choice,
|
---|
[7974] | 186 | Checked = multipleChoiceParameters[parameter].Contains(choice)
|
---|
[7908] | 187 | });
|
---|
| 188 | }
|
---|
| 189 | return;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[7957] | 192 | if (!(parameter.Value is ValueTypeValue<bool>)) {
|
---|
| 193 | minimumLabel.Visible = true; minimumTextBox.Visible = true;
|
---|
| 194 | maximumLabel.Visible = true; maximumTextBox.Visible = true;
|
---|
| 195 | stepSizeLabel.Visible = true; stepSizeTextBox.Visible = true;
|
---|
| 196 | } else detailsTypeLabel.Text = "Boolean parameter: True / False";
|
---|
[7908] | 197 |
|
---|
| 198 | var intValue = parameter.Value as ValueTypeValue<int>;
|
---|
| 199 | if (intValue != null) {
|
---|
[7957] | 200 | detailsTypeLabel.Text = "Integer parameter:";
|
---|
[7908] | 201 | if (!intParameters.ContainsKey(parameter)) return;
|
---|
| 202 | string min = intParameters[parameter].Item1.ToString();
|
---|
| 203 | string max = intParameters[parameter].Item2.ToString();
|
---|
| 204 | string step = intParameters[parameter].Item3.ToString();
|
---|
| 205 | UpdateMinMaxStepSize(parameter, min, max, step);
|
---|
| 206 | return;
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | var doubleValue = parameter.Value as ValueTypeValue<double>;
|
---|
| 210 | if (doubleValue != null) {
|
---|
[7957] | 211 | detailsTypeLabel.Text = "Double parameter:";
|
---|
[7908] | 212 | if (!doubleParameters.ContainsKey(parameter)) return;
|
---|
| 213 | string min = doubleParameters[parameter].Item1.ToString();
|
---|
| 214 | string max = doubleParameters[parameter].Item2.ToString();
|
---|
| 215 | string step = doubleParameters[parameter].Item3.ToString();
|
---|
| 216 | UpdateMinMaxStepSize(parameter, min, max, step);
|
---|
| 217 | return;
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | #region Detail controls
|
---|
| 222 | private void choiceListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
|
---|
| 223 | var parameter = (IValueParameter)choicesListView.Tag;
|
---|
| 224 | if (e.Item.Checked) {
|
---|
[7974] | 225 | multipleChoiceParameters[parameter].Add((IItem)e.Item.Tag);
|
---|
| 226 | } else multipleChoiceParameters[parameter].Remove((IItem)e.Item.Tag);
|
---|
[7908] | 227 |
|
---|
[7957] | 228 | UpdateVariationsLabel();
|
---|
[7908] | 229 | }
|
---|
| 230 |
|
---|
| 231 | private void detailsTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 232 | var parameter = (IValueParameter)((TextBox)sender).Tag;
|
---|
| 233 | errorProvider.Clear();
|
---|
| 234 |
|
---|
| 235 | var intValue = parameter.Value as ValueTypeValue<int>;
|
---|
| 236 | if (intValue != null) {
|
---|
| 237 | int value;
|
---|
| 238 | if (!int.TryParse(((TextBox)sender).Text, out value)) {
|
---|
| 239 | errorProvider.SetError(((TextBox)sender), "Please enter a valid integer number.");
|
---|
| 240 | e.Cancel = true;
|
---|
| 241 | } else {
|
---|
| 242 | var before = intParameters[parameter];
|
---|
| 243 | var after = default(Tuple<int, int, int>);
|
---|
| 244 | if (sender == minimumTextBox) after = new Tuple<int, int, int>(value, before.Item2, before.Item3);
|
---|
| 245 | else if (sender == maximumTextBox) after = new Tuple<int, int, int>(before.Item1, value, before.Item3);
|
---|
| 246 | else if (sender == stepSizeTextBox) after = new Tuple<int, int, int>(before.Item1, before.Item2, value);
|
---|
| 247 | intParameters[parameter] = after;
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | var doubleValue = parameter.Value as ValueTypeValue<double>;
|
---|
| 252 | if (doubleValue != null) {
|
---|
| 253 | double value;
|
---|
| 254 | if (!double.TryParse(((TextBox)sender).Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) {
|
---|
| 255 | errorProvider.SetError(((TextBox)sender), "Please enter a valid number.");
|
---|
| 256 | e.Cancel = true;
|
---|
| 257 | } else {
|
---|
| 258 | var before = doubleParameters[parameter];
|
---|
| 259 | var after = default(Tuple<double, double, double>);
|
---|
| 260 | if (sender == minimumTextBox) after = new Tuple<double, double, double>(value, before.Item2, before.Item3);
|
---|
| 261 | else if (sender == maximumTextBox) after = new Tuple<double, double, double>(before.Item1, value, before.Item3);
|
---|
| 262 | else if (sender == stepSizeTextBox) after = new Tuple<double, double, double>(before.Item1, before.Item2, value);
|
---|
| 263 | doubleParameters[parameter] = after;
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
| 266 |
|
---|
[7957] | 267 | UpdateVariationsLabel();
|
---|
[7908] | 268 | }
|
---|
| 269 | #endregion
|
---|
| 270 | #endregion
|
---|
| 271 |
|
---|
| 272 | #region Instances
|
---|
[7957] | 273 | private void instancesTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
|
---|
| 274 | if (!suppressTreeViewEventHandling) {
|
---|
| 275 | if (e.Node.Nodes.Count > 0) { // provider node was (un)checked
|
---|
| 276 | SyncProviderNode(e.Node);
|
---|
| 277 | } else { // descriptor node was (un)checked
|
---|
| 278 | SyncInstanceNode(e.Node);
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | suppressCheckAllNoneEventHandling = true;
|
---|
| 282 | try {
|
---|
| 283 | var treeViewNodes = instancesTreeView.Nodes.OfType<TreeNode>().SelectMany(x => x.Nodes.OfType<TreeNode>());
|
---|
| 284 | selectAllCheckBox.Checked = treeViewNodes.Count() == instances.SelectMany(x => x.Value).Count();
|
---|
| 285 | selectNoneCheckBox.Checked = !treeViewNodes.Any(x => x.Checked);
|
---|
[7975] | 286 | }
|
---|
| 287 | finally { suppressCheckAllNoneEventHandling = false; }
|
---|
[7957] | 288 | UpdateVariationsLabel();
|
---|
[7885] | 289 | }
|
---|
[7957] | 290 | }
|
---|
| 291 |
|
---|
| 292 | private void SyncProviderNode(TreeNode node) {
|
---|
| 293 | suppressTreeViewEventHandling = true;
|
---|
| 294 | try {
|
---|
| 295 | foreach (TreeNode n in node.Nodes) {
|
---|
| 296 | if (n.Checked != node.Checked) {
|
---|
| 297 | n.Checked = node.Checked;
|
---|
| 298 | SyncInstanceNode(n, false);
|
---|
| 299 | }
|
---|
| 300 | }
|
---|
[7975] | 301 | }
|
---|
| 302 | finally { suppressTreeViewEventHandling = false; }
|
---|
[7957] | 303 | }
|
---|
| 304 |
|
---|
| 305 | private void SyncInstanceNode(TreeNode node, bool providerCheck = true) {
|
---|
| 306 | var provider = (IProblemInstanceProvider)node.Parent.Tag;
|
---|
| 307 | var descriptor = (IDataDescriptor)node.Tag;
|
---|
| 308 | if (node.Checked) {
|
---|
[7908] | 309 | if (!instances.ContainsKey(provider))
|
---|
| 310 | instances.Add(provider, new HashSet<IDataDescriptor>());
|
---|
| 311 | instances[provider].Add(descriptor);
|
---|
| 312 | } else {
|
---|
| 313 | if (instances.ContainsKey(provider)) {
|
---|
| 314 | instances[provider].Remove(descriptor);
|
---|
| 315 | if (instances[provider].Count == 0)
|
---|
| 316 | instances.Remove(provider);
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
[7957] | 319 | if (providerCheck) {
|
---|
| 320 | bool allChecked = node.Parent.Nodes.OfType<TreeNode>().All(x => x.Checked);
|
---|
| 321 | suppressTreeViewEventHandling = true;
|
---|
| 322 | try {
|
---|
| 323 | node.Parent.Checked = allChecked;
|
---|
[7975] | 324 | }
|
---|
| 325 | finally { suppressTreeViewEventHandling = false; }
|
---|
[7957] | 326 | }
|
---|
[4104] | 327 | }
|
---|
[7885] | 328 |
|
---|
[7846] | 329 | private void selectAllCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[7957] | 330 | if (!suppressCheckAllNoneEventHandling) {
|
---|
| 331 | if (selectAllCheckBox.Checked) {
|
---|
| 332 | suppressCheckAllNoneEventHandling = true;
|
---|
[7975] | 333 | try { selectNoneCheckBox.Checked = false; }
|
---|
| 334 | finally { suppressCheckAllNoneEventHandling = false; }
|
---|
[7957] | 335 | try {
|
---|
| 336 | suppressTreeViewEventHandling = true;
|
---|
| 337 | foreach (TreeNode node in instancesTreeView.Nodes) {
|
---|
| 338 | if (!node.Checked) {
|
---|
| 339 | node.Checked = true;
|
---|
| 340 | SyncProviderNode(node);
|
---|
| 341 | }
|
---|
| 342 | }
|
---|
[7975] | 343 | }
|
---|
| 344 | finally { suppressTreeViewEventHandling = false; }
|
---|
[7957] | 345 | }
|
---|
[7846] | 346 | }
|
---|
| 347 | }
|
---|
[7885] | 348 |
|
---|
[7846] | 349 | private void selectNoneCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[7957] | 350 | if (!suppressCheckAllNoneEventHandling) {
|
---|
| 351 | if (selectNoneCheckBox.Checked) {
|
---|
| 352 | suppressCheckAllNoneEventHandling = true;
|
---|
[7975] | 353 | try { selectAllCheckBox.Checked = false; }
|
---|
| 354 | finally { suppressCheckAllNoneEventHandling = false; }
|
---|
[7957] | 355 | try {
|
---|
| 356 | suppressTreeViewEventHandling = true;
|
---|
| 357 | foreach (TreeNode node in instancesTreeView.Nodes) {
|
---|
| 358 | if (node.Checked) {
|
---|
| 359 | node.Checked = false;
|
---|
| 360 | SyncProviderNode(node);
|
---|
| 361 | }
|
---|
| 362 | }
|
---|
[7975] | 363 | }
|
---|
| 364 | finally { suppressTreeViewEventHandling = false; }
|
---|
[7957] | 365 | }
|
---|
[7846] | 366 | }
|
---|
| 367 | }
|
---|
[7908] | 368 | #endregion
|
---|
[7885] | 369 |
|
---|
| 370 | private void createBatchRunCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 371 | repetitionsNumericUpDown.Enabled = createBatchRunCheckBox.Checked;
|
---|
| 372 | createBatchRun = createBatchRunCheckBox.Checked;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
|
---|
| 376 | if (repetitionsNumericUpDown.Text == string.Empty)
|
---|
| 377 | repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
|
---|
| 378 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
| 379 | }
|
---|
[7957] | 380 |
|
---|
| 381 | private void experimentsLabel_TextChanged(object sender, EventArgs e) {
|
---|
| 382 | long number;
|
---|
| 383 | if (long.TryParse(variationsLabel.Text, NumberStyles.AllowThousands, CultureInfo.CurrentCulture.NumberFormat, out number)) {
|
---|
| 384 | if (number > 1000) warningProvider.SetError(variationsLabel, "Consider reducing the number of variations!");
|
---|
| 385 | else warningProvider.SetError(variationsLabel, null);
|
---|
| 386 | }
|
---|
| 387 | }
|
---|
[7885] | 388 | #endregion
|
---|
| 389 |
|
---|
| 390 | #region Helpers
|
---|
[7908] | 391 | private void SetTabControlVisibility() {
|
---|
| 392 | bool isAlgorithm = optimizer != null && optimizer is IAlgorithm;
|
---|
| 393 | bool instancesAvailable = isAlgorithm
|
---|
[7885] | 394 | && ((IAlgorithm)optimizer).Problem != null
|
---|
| 395 | && ProblemInstanceManager.GetProviders(((IAlgorithm)optimizer).Problem).Any();
|
---|
[7908] | 396 | if (instancesAvailable && tabControl.TabCount == 1)
|
---|
| 397 | tabControl.TabPages.Add(instancesTabPage);
|
---|
| 398 | else if (!instancesAvailable && tabControl.TabCount == 2)
|
---|
| 399 | tabControl.TabPages.Remove(instancesTabPage);
|
---|
| 400 | tabControl.Visible = isAlgorithm;
|
---|
| 401 | if (isAlgorithm) {
|
---|
[7957] | 402 | variationsLabel.Visible = true;
|
---|
[7908] | 403 | experimentsToCreateDescriptionLabel.Visible = true;
|
---|
| 404 | Height = 430;
|
---|
| 405 | } else {
|
---|
[7957] | 406 | variationsLabel.Visible = false;
|
---|
[7908] | 407 | experimentsToCreateDescriptionLabel.Visible = false;
|
---|
| 408 | Height = 130;
|
---|
| 409 | }
|
---|
[7885] | 410 | }
|
---|
| 411 |
|
---|
[7908] | 412 | private void FillParametersListView() {
|
---|
| 413 | parametersListView.Items.Clear();
|
---|
| 414 | intParameters.Clear();
|
---|
| 415 | doubleParameters.Clear();
|
---|
| 416 | boolParameters.Clear();
|
---|
| 417 | multipleChoiceParameters.Clear();
|
---|
| 418 |
|
---|
| 419 | if (Optimizer is IAlgorithm) {
|
---|
| 420 | var parameters = ((IAlgorithm)optimizer).Parameters;
|
---|
| 421 | foreach (var param in parameters) {
|
---|
| 422 | var valueParam = param as IValueParameter;
|
---|
| 423 | if (valueParam != null && (valueParam.Value is ValueTypeValue<bool>
|
---|
| 424 | || valueParam.Value is ValueTypeValue<int>
|
---|
| 425 | || valueParam.Value is ValueTypeValue<double>)
|
---|
| 426 | || typeof(OptionalConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition())
|
---|
| 427 | || typeof(ConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition()))
|
---|
| 428 | parametersListView.Items.Add(new ListViewItem(param.Name) { Tag = param });
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 | }
|
---|
| 432 |
|
---|
[7957] | 433 | private void FillInstanceTreeViewAsync() {
|
---|
[7908] | 434 | instances.Clear();
|
---|
[7957] | 435 | instancesTreeView.Nodes.Clear();
|
---|
[7908] | 436 |
|
---|
[7957] | 437 | if (Optimizer is IAlgorithm && ((IAlgorithm)Optimizer).Problem != null) {
|
---|
[7908] | 438 | SetMode(DialogMode.DiscoveringInstances);
|
---|
[7957] | 439 | instanceDiscoveryBackgroundWorker.RunWorkerAsync();
|
---|
[7908] | 440 | }
|
---|
[7885] | 441 | }
|
---|
| 442 |
|
---|
| 443 | private void AddOptimizer(IOptimizer optimizer, Experiment experiment) {
|
---|
| 444 | if (createBatchRun) {
|
---|
| 445 | var batchRun = new BatchRun();
|
---|
| 446 | batchRun.Repetitions = repetitions;
|
---|
| 447 | batchRun.Optimizer = optimizer;
|
---|
| 448 | experiment.Optimizers.Add(batchRun);
|
---|
| 449 | } else {
|
---|
| 450 | experiment.Optimizers.Add(optimizer);
|
---|
[7846] | 451 | }
|
---|
| 452 | }
|
---|
[7885] | 453 |
|
---|
[7908] | 454 | private int GetNumberOfVariations() {
|
---|
| 455 | int instancesCount = 1;
|
---|
| 456 | if (instances.Values.Any())
|
---|
| 457 | instancesCount = Math.Max(instances.Values.SelectMany(x => x).Count(), 1);
|
---|
[7885] | 458 |
|
---|
[7908] | 459 | int intParameterVariations = 1;
|
---|
| 460 | foreach (var intParam in intParameters.Values) {
|
---|
| 461 | if (intParam.Item3 == 0) continue;
|
---|
| 462 | intParameterVariations *= (intParam.Item2 - intParam.Item1) / intParam.Item3 + 1;
|
---|
[7885] | 463 | }
|
---|
[7908] | 464 | int doubleParameterVariations = 1;
|
---|
| 465 | foreach (var doubleParam in doubleParameters.Values) {
|
---|
| 466 | if (doubleParam.Item3 == 0) continue;
|
---|
| 467 | doubleParameterVariations *= (int)Math.Floor((doubleParam.Item2 - doubleParam.Item1) / doubleParam.Item3) + 1;
|
---|
| 468 | }
|
---|
| 469 | int boolParameterVariations = 1;
|
---|
| 470 | foreach (var boolParam in boolParameters) {
|
---|
| 471 | boolParameterVariations *= 2;
|
---|
| 472 | }
|
---|
| 473 | int choiceParameterVariations = 1;
|
---|
| 474 | foreach (var choiceParam in multipleChoiceParameters.Values) {
|
---|
| 475 | choiceParameterVariations *= Math.Max(choiceParam.Count, 1);
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | return (instancesCount * intParameterVariations * doubleParameterVariations * boolParameterVariations * choiceParameterVariations);
|
---|
[7885] | 479 | }
|
---|
[7908] | 480 |
|
---|
| 481 | private void SetMode(DialogMode mode) {
|
---|
| 482 | createBatchRunCheckBox.Enabled = mode == DialogMode.Normal;
|
---|
| 483 | repetitionsNumericUpDown.Enabled = mode == DialogMode.Normal;
|
---|
[7974] | 484 | parametersSplitContainer.Enabled = mode == DialogMode.Normal || mode == DialogMode.DiscoveringInstances;
|
---|
[7908] | 485 | selectAllCheckBox.Enabled = mode == DialogMode.Normal;
|
---|
| 486 | selectNoneCheckBox.Enabled = mode == DialogMode.Normal;
|
---|
[7957] | 487 | instancesTreeView.Enabled = mode == DialogMode.Normal;
|
---|
[7974] | 488 | instancesTreeView.Visible = mode == DialogMode.Normal || mode == DialogMode.CreatingExperiment || mode == DialogMode.PreparingExperiment;
|
---|
[7908] | 489 | okButton.Enabled = mode == DialogMode.Normal;
|
---|
[7974] | 490 | okButton.Visible = mode != DialogMode.CreatingExperiment && mode != DialogMode.PreparingExperiment;
|
---|
| 491 | cancelButton.Enabled = mode != DialogMode.PreparingExperiment;
|
---|
[7908] | 492 | instanceDiscoveryProgressLabel.Visible = mode == DialogMode.DiscoveringInstances;
|
---|
| 493 | instanceDiscoveryProgressBar.Visible = mode == DialogMode.DiscoveringInstances;
|
---|
[7974] | 494 | experimentCreationProgressBar.Visible = mode == DialogMode.CreatingExperiment || mode == DialogMode.PreparingExperiment;
|
---|
[7908] | 495 | }
|
---|
| 496 |
|
---|
| 497 | private void ClearDetailsView() {
|
---|
| 498 | minimumLabel.Visible = false;
|
---|
| 499 | minimumTextBox.Text = string.Empty;
|
---|
| 500 | minimumTextBox.Enabled = false;
|
---|
| 501 | minimumTextBox.Visible = false;
|
---|
| 502 | maximumLabel.Visible = false;
|
---|
| 503 | maximumTextBox.Text = string.Empty;
|
---|
| 504 | maximumTextBox.Enabled = false;
|
---|
| 505 | maximumTextBox.Visible = false;
|
---|
| 506 | stepSizeLabel.Visible = false;
|
---|
| 507 | stepSizeTextBox.Text = string.Empty;
|
---|
| 508 | stepSizeTextBox.Enabled = false;
|
---|
| 509 | stepSizeTextBox.Visible = false;
|
---|
| 510 | choicesListView.Items.Clear();
|
---|
| 511 | choicesListView.Enabled = false;
|
---|
| 512 | choicesListView.Visible = false;
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 | private void UpdateMinMaxStepSize(IValueParameter parameter, string min, string max, string step) {
|
---|
| 516 | minimumLabel.Visible = true;
|
---|
| 517 | minimumTextBox.Text = min;
|
---|
| 518 | minimumTextBox.Enabled = true;
|
---|
| 519 | minimumTextBox.Visible = true;
|
---|
| 520 | minimumTextBox.Tag = parameter;
|
---|
| 521 | maximumLabel.Visible = true;
|
---|
| 522 | maximumTextBox.Text = max;
|
---|
| 523 | maximumTextBox.Enabled = true;
|
---|
| 524 | maximumTextBox.Visible = true;
|
---|
| 525 | maximumTextBox.Tag = parameter;
|
---|
| 526 | stepSizeLabel.Visible = true;
|
---|
| 527 | stepSizeTextBox.Text = step;
|
---|
| 528 | stepSizeTextBox.Enabled = true;
|
---|
| 529 | stepSizeTextBox.Visible = true;
|
---|
| 530 | stepSizeTextBox.Tag = parameter;
|
---|
| 531 | }
|
---|
| 532 |
|
---|
[7957] | 533 | private void UpdateVariationsLabel() {
|
---|
| 534 | variationsLabel.Text = GetNumberOfVariations().ToString("#,#", CultureInfo.CurrentCulture);
|
---|
| 535 | }
|
---|
| 536 |
|
---|
[7908] | 537 | #region Retrieve parameter combinations
|
---|
| 538 | private IEnumerable<Dictionary<IValueParameter, int>> GetIntParameterConfigurations() {
|
---|
| 539 | var configuration = new Dictionary<IValueParameter, int>();
|
---|
| 540 | var indices = new Dictionary<IValueParameter, int>();
|
---|
| 541 | bool finished;
|
---|
| 542 | do {
|
---|
| 543 | foreach (var p in intParameters) {
|
---|
| 544 | if (!indices.ContainsKey(p.Key)) indices.Add(p.Key, 0);
|
---|
| 545 | var value = p.Value.Item1 + p.Value.Item3 * indices[p.Key];
|
---|
| 546 | configuration[p.Key] = value;
|
---|
| 547 | }
|
---|
| 548 | yield return configuration;
|
---|
| 549 |
|
---|
| 550 | finished = true;
|
---|
| 551 | foreach (var p in intParameters.Keys) {
|
---|
| 552 | var newValue = intParameters[p].Item1 + intParameters[p].Item3 * (indices[p] + 1);
|
---|
| 553 | if (newValue > intParameters[p].Item2 || intParameters[p].Item3 == 0)
|
---|
| 554 | indices[p] = 0;
|
---|
| 555 | else {
|
---|
| 556 | indices[p]++;
|
---|
| 557 | finished = false;
|
---|
| 558 | break;
|
---|
| 559 | }
|
---|
| 560 | }
|
---|
| 561 | } while (!finished);
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | private IEnumerable<Dictionary<IValueParameter, double>> GetDoubleParameterConfigurations() {
|
---|
| 565 | var configuration = new Dictionary<IValueParameter, double>();
|
---|
| 566 | var indices = new Dictionary<IValueParameter, int>();
|
---|
| 567 | bool finished;
|
---|
| 568 | do {
|
---|
| 569 | foreach (var p in doubleParameters) {
|
---|
| 570 | if (!indices.ContainsKey(p.Key)) indices.Add(p.Key, 0);
|
---|
| 571 | var value = p.Value.Item1 + p.Value.Item3 * indices[p.Key];
|
---|
| 572 | configuration[p.Key] = value;
|
---|
| 573 | }
|
---|
| 574 | yield return configuration;
|
---|
| 575 |
|
---|
| 576 | finished = true;
|
---|
| 577 | foreach (var p in doubleParameters.Keys) {
|
---|
| 578 | var newValue = doubleParameters[p].Item1 + doubleParameters[p].Item3 * (indices[p] + 1);
|
---|
| 579 | if (newValue > doubleParameters[p].Item2 || doubleParameters[p].Item3 == 0)
|
---|
| 580 | indices[p] = 0;
|
---|
| 581 | else {
|
---|
| 582 | indices[p]++;
|
---|
| 583 | finished = false;
|
---|
| 584 | break;
|
---|
| 585 | }
|
---|
| 586 | }
|
---|
| 587 | } while (!finished);
|
---|
| 588 | }
|
---|
| 589 |
|
---|
| 590 | private IEnumerable<Dictionary<IValueParameter, bool>> GetBoolParameterConfigurations() {
|
---|
| 591 | var configuration = new Dictionary<IValueParameter, bool>();
|
---|
| 592 | bool finished;
|
---|
| 593 | do {
|
---|
| 594 | finished = true;
|
---|
| 595 | foreach (var p in boolParameters) {
|
---|
| 596 | if (!configuration.ContainsKey(p)) configuration.Add(p, false);
|
---|
| 597 | else {
|
---|
| 598 | if (configuration[p]) {
|
---|
| 599 | configuration[p] = false;
|
---|
| 600 | } else {
|
---|
| 601 | configuration[p] = true;
|
---|
| 602 | finished = false;
|
---|
| 603 | break;
|
---|
| 604 | }
|
---|
| 605 | }
|
---|
| 606 | }
|
---|
| 607 | yield return configuration;
|
---|
| 608 | } while (!finished);
|
---|
| 609 | }
|
---|
| 610 |
|
---|
[7974] | 611 | private IEnumerable<Dictionary<IValueParameter, IItem>> GetMultipleChoiceConfigurations() {
|
---|
| 612 | var configuration = new Dictionary<IValueParameter, IItem>();
|
---|
| 613 | var enumerators = new Dictionary<IValueParameter, IEnumerator<IItem>>();
|
---|
[7908] | 614 | bool finished;
|
---|
| 615 | do {
|
---|
| 616 | foreach (var p in multipleChoiceParameters.Keys.ToArray()) {
|
---|
| 617 | if (!enumerators.ContainsKey(p)) {
|
---|
| 618 | enumerators.Add(p, multipleChoiceParameters[p].GetEnumerator());
|
---|
| 619 | if (!enumerators[p].MoveNext()) {
|
---|
| 620 | multipleChoiceParameters.Remove(p);
|
---|
| 621 | continue;
|
---|
| 622 | }
|
---|
| 623 | }
|
---|
| 624 | configuration[p] = enumerators[p].Current;
|
---|
| 625 | }
|
---|
| 626 |
|
---|
| 627 | finished = true;
|
---|
| 628 | foreach (var p in multipleChoiceParameters.Keys) {
|
---|
| 629 | if (!enumerators[p].MoveNext()) {
|
---|
| 630 | enumerators[p] = multipleChoiceParameters[p].GetEnumerator();
|
---|
[7974] | 631 | enumerators[p].MoveNext();
|
---|
[7908] | 632 | } else {
|
---|
| 633 | finished = false;
|
---|
| 634 | break;
|
---|
| 635 | }
|
---|
| 636 | }
|
---|
| 637 | yield return configuration;
|
---|
| 638 | } while (!finished);
|
---|
| 639 | }
|
---|
[7885] | 640 | #endregion
|
---|
[7908] | 641 | #endregion
|
---|
[7885] | 642 |
|
---|
| 643 | #region Background workers
|
---|
[7908] | 644 | #region Instance discovery
|
---|
[7885] | 645 | private void instanceDiscoveryBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
[7957] | 646 | var instanceProviders = ProblemInstanceManager.GetProviders(((IAlgorithm)Optimizer).Problem).ToArray();
|
---|
| 647 | var nodes = new TreeNode[instanceProviders.Length];
|
---|
[7885] | 648 | for (int i = 0; i < instanceProviders.Length; i++) {
|
---|
| 649 | var provider = instanceProviders[i];
|
---|
[7957] | 650 | nodes[i] = new TreeNode(provider.Name) { Tag = provider };
|
---|
[7885] | 651 | }
|
---|
[7957] | 652 | e.Result = nodes;
|
---|
| 653 | for (int i = 0; i < nodes.Length; i++) {
|
---|
| 654 | var providerNode = nodes[i];
|
---|
| 655 | var provider = providerNode.Tag as IProblemInstanceProvider;
|
---|
| 656 | double progress = i / (double)nodes.Length;
|
---|
| 657 | instanceDiscoveryBackgroundWorker.ReportProgress((int)(100 * progress), provider.Name);
|
---|
[7885] | 658 | var descriptors = ProblemInstanceManager.GetDataDescriptors(provider).ToArray();
|
---|
| 659 | for (int j = 0; j < descriptors.Length; j++) {
|
---|
| 660 | #region Check cancellation request
|
---|
| 661 | if (instanceDiscoveryBackgroundWorker.CancellationPending) {
|
---|
| 662 | e.Cancel = true;
|
---|
| 663 | return;
|
---|
| 664 | }
|
---|
| 665 | #endregion
|
---|
[7957] | 666 | var node = new TreeNode(descriptors[j].Name) { Tag = descriptors[j] };
|
---|
| 667 | providerNode.Nodes.Add(node);
|
---|
[7885] | 668 | }
|
---|
| 669 | }
|
---|
| 670 | instanceDiscoveryBackgroundWorker.ReportProgress(100, string.Empty);
|
---|
| 671 | }
|
---|
| 672 |
|
---|
[7908] | 673 | private void instanceDiscoveryBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
[7957] | 674 | if (instanceDiscoveryProgressBar.Value != e.ProgressPercentage)
|
---|
| 675 | instanceDiscoveryProgressBar.Value = e.ProgressPercentage;
|
---|
[7908] | 676 | instanceDiscoveryProgressLabel.Text = (string)e.UserState;
|
---|
[7957] | 677 | Application.DoEvents();
|
---|
[7908] | 678 | }
|
---|
| 679 |
|
---|
[7885] | 680 | private void instanceDiscoveryBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 681 | try {
|
---|
[7957] | 682 | instancesTreeView.Nodes.AddRange((TreeNode[])e.Result);
|
---|
| 683 | foreach (TreeNode node in instancesTreeView.Nodes)
|
---|
| 684 | node.Collapse();
|
---|
[7908] | 685 | selectNoneCheckBox.Checked = true;
|
---|
[7975] | 686 | }
|
---|
| 687 | catch { }
|
---|
[7885] | 688 | try {
|
---|
[7908] | 689 | SetMode(DialogMode.Normal);
|
---|
[7885] | 690 | if (e.Error != null) MessageBox.Show(e.Error.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
[7975] | 691 | }
|
---|
| 692 | catch { }
|
---|
[7885] | 693 | }
|
---|
[7908] | 694 | #endregion
|
---|
[7885] | 695 |
|
---|
[7908] | 696 | #region Experiment creation
|
---|
[7846] | 697 | private void experimentCreationBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
[7908] | 698 | backgroundWorkerWaitHandle.Set(); // notify the ok button that we're busy now
|
---|
[7885] | 699 | failedInstances = new StringBuilder();
|
---|
[7846] | 700 | var localExperiment = new Experiment();
|
---|
[7908] | 701 |
|
---|
[7974] | 702 | int counter = 0, totalVariations = GetNumberOfVariations();
|
---|
[7908] | 703 | if (instances.Count == 0) {
|
---|
[7974] | 704 | AddParameterVariations(localExperiment, ref counter, totalVariations);
|
---|
[7846] | 705 | experimentCreationBackgroundWorker.ReportProgress(100, string.Empty);
|
---|
[7908] | 706 |
|
---|
[7841] | 707 | } else {
|
---|
[7908] | 708 | foreach (var provider in instances.Keys) {
|
---|
| 709 | foreach (var descriptor in instances[provider]) {
|
---|
[7885] | 710 | #region Check cancellation request
|
---|
[7846] | 711 | if (experimentCreationBackgroundWorker.CancellationPending) {
|
---|
| 712 | e.Cancel = true;
|
---|
| 713 | localExperiment = null;
|
---|
[7885] | 714 | return;
|
---|
[7846] | 715 | }
|
---|
[7885] | 716 | #endregion
|
---|
| 717 | var algorithm = (IAlgorithm)Optimizer.Clone();
|
---|
| 718 | bool failed = false;
|
---|
| 719 | try {
|
---|
| 720 | ProblemInstanceManager.LoadData(provider, descriptor, (IProblemInstanceConsumer)algorithm.Problem);
|
---|
[7975] | 721 | }
|
---|
| 722 | catch (Exception ex) {
|
---|
[7885] | 723 | failedInstances.AppendLine(descriptor.Name + ": " + ex.Message);
|
---|
| 724 | failed = true;
|
---|
| 725 | }
|
---|
| 726 | if (!failed) {
|
---|
[7974] | 727 | AddParameterVariations(localExperiment, ref counter, totalVariations);
|
---|
| 728 | } else experimentCreationBackgroundWorker.ReportProgress((int)Math.Round((100.0 * counter) / totalVariations), "Loading failed (" + descriptor.Name + ")");
|
---|
[7846] | 729 | }
|
---|
[7841] | 730 | }
|
---|
| 731 | }
|
---|
[7974] | 732 | if (localExperiment != null) {
|
---|
[7975] | 733 | // don't do GUI stuff in do_work
|
---|
[7974] | 734 | // this step can take some time
|
---|
| 735 | experimentCreationBackgroundWorker.ReportProgress(-1);
|
---|
| 736 | localExperiment.Prepare(true);
|
---|
| 737 | experimentCreationBackgroundWorker.ReportProgress(100);
|
---|
| 738 | }
|
---|
[7908] | 739 | Experiment = localExperiment;
|
---|
[7841] | 740 | }
|
---|
[7885] | 741 |
|
---|
[7974] | 742 | private void AddParameterVariations(Experiment localExperiment, ref int counter, int totalVariations) {
|
---|
| 743 | var variations = experimentCreationBackgroundWorker_CalculateParameterVariations(optimizer);
|
---|
| 744 | foreach (var v in variations) {
|
---|
| 745 | AddOptimizer(v, localExperiment);
|
---|
| 746 | counter++;
|
---|
| 747 | experimentCreationBackgroundWorker.ReportProgress((int)Math.Round((100.0 * counter) / totalVariations), string.Empty);
|
---|
| 748 | }
|
---|
| 749 | }
|
---|
| 750 |
|
---|
[7908] | 751 | private IEnumerable<IOptimizer> experimentCreationBackgroundWorker_CalculateParameterVariations(IOptimizer optimizer) {
|
---|
| 752 | if (!boolParameters.Any() && !intParameters.Any() && !doubleParameters.Any() && !multipleChoiceParameters.Any()) {
|
---|
| 753 | yield return (IOptimizer)optimizer.Clone();
|
---|
| 754 | yield break;
|
---|
| 755 | }
|
---|
| 756 | bool finished;
|
---|
| 757 | var mcEnumerator = GetMultipleChoiceConfigurations().GetEnumerator();
|
---|
| 758 | var boolEnumerator = GetBoolParameterConfigurations().GetEnumerator();
|
---|
| 759 | var intEnumerator = GetIntParameterConfigurations().GetEnumerator();
|
---|
| 760 | var doubleEnumerator = GetDoubleParameterConfigurations().GetEnumerator();
|
---|
| 761 | mcEnumerator.MoveNext(); boolEnumerator.MoveNext(); intEnumerator.MoveNext(); doubleEnumerator.MoveNext();
|
---|
| 762 | do {
|
---|
| 763 | var variant = (IAlgorithm)optimizer.Clone();
|
---|
| 764 | variant.Name += " {";
|
---|
| 765 | finished = true;
|
---|
| 766 | if (doubleParameters.Any()) {
|
---|
| 767 | foreach (var d in doubleEnumerator.Current) {
|
---|
| 768 | var value = (ValueTypeValue<double>)((IValueParameter)variant.Parameters[d.Key.Name]).Value;
|
---|
| 769 | value.Value = d.Value;
|
---|
| 770 | variant.Name += d.Key.Name + "=" + d.Value.ToString() + ", ";
|
---|
| 771 | }
|
---|
| 772 | if (finished) {
|
---|
| 773 | if (doubleEnumerator.MoveNext()) {
|
---|
| 774 | finished = false;
|
---|
| 775 | } else {
|
---|
| 776 | doubleEnumerator = GetDoubleParameterConfigurations().GetEnumerator();
|
---|
| 777 | doubleEnumerator.MoveNext();
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
| 780 | }
|
---|
| 781 | if (intParameters.Any()) {
|
---|
| 782 | foreach (var i in intEnumerator.Current) {
|
---|
| 783 | var value = (ValueTypeValue<int>)((IValueParameter)variant.Parameters[i.Key.Name]).Value;
|
---|
| 784 | value.Value = i.Value;
|
---|
| 785 | variant.Name += i.Key.Name + "=" + i.Value.ToString() + ", ";
|
---|
| 786 | }
|
---|
| 787 | if (finished) {
|
---|
| 788 | if (intEnumerator.MoveNext()) {
|
---|
| 789 | finished = false;
|
---|
| 790 | } else {
|
---|
| 791 | intEnumerator = GetIntParameterConfigurations().GetEnumerator();
|
---|
| 792 | intEnumerator.MoveNext();
|
---|
| 793 | }
|
---|
| 794 | }
|
---|
| 795 | }
|
---|
| 796 | if (boolParameters.Any()) {
|
---|
| 797 | foreach (var b in boolEnumerator.Current) {
|
---|
| 798 | var value = (ValueTypeValue<bool>)((IValueParameter)variant.Parameters[b.Key.Name]).Value;
|
---|
| 799 | value.Value = b.Value;
|
---|
| 800 | variant.Name += b.Key.Name + "=" + b.Value.ToString() + ", ";
|
---|
| 801 | }
|
---|
| 802 | if (finished) {
|
---|
| 803 | if (boolEnumerator.MoveNext()) {
|
---|
| 804 | finished = false;
|
---|
| 805 | } else {
|
---|
| 806 | boolEnumerator = GetBoolParameterConfigurations().GetEnumerator();
|
---|
| 807 | boolEnumerator.MoveNext();
|
---|
| 808 | }
|
---|
| 809 | }
|
---|
| 810 | }
|
---|
| 811 | if (multipleChoiceParameters.Any()) {
|
---|
| 812 | foreach (var m in mcEnumerator.Current) {
|
---|
| 813 | dynamic variantParam = variant.Parameters[m.Key.Name];
|
---|
| 814 | var variantEnumerator = ((IEnumerable<object>)variantParam.ValidValues).GetEnumerator();
|
---|
| 815 | var originalEnumerator = ((IEnumerable<object>)((dynamic)m.Key).ValidValues).GetEnumerator();
|
---|
| 816 | while (variantEnumerator.MoveNext() && originalEnumerator.MoveNext()) {
|
---|
[7974] | 817 | if (m.Value == (IItem)originalEnumerator.Current) {
|
---|
[7908] | 818 | variantParam.Value = (dynamic)variantEnumerator.Current;
|
---|
[7974] | 819 | if (m.Value is INamedItem)
|
---|
| 820 | variant.Name += m.Key.Name + "=" + ((INamedItem)m.Value).Name + ", ";
|
---|
| 821 | else variant.Name += m.Key.Name + "=" + m.Value.ToString() + ", ";
|
---|
[7908] | 822 | break;
|
---|
| 823 | }
|
---|
| 824 | }
|
---|
| 825 | }
|
---|
| 826 | if (finished) {
|
---|
| 827 | if (mcEnumerator.MoveNext()) {
|
---|
| 828 | finished = false;
|
---|
| 829 | } else {
|
---|
| 830 | mcEnumerator = GetMultipleChoiceConfigurations().GetEnumerator();
|
---|
| 831 | mcEnumerator.MoveNext();
|
---|
| 832 | }
|
---|
| 833 | }
|
---|
| 834 | }
|
---|
| 835 | variant.Name = variant.Name.Substring(0, variant.Name.Length - 2) + "}";
|
---|
| 836 | yield return variant;
|
---|
| 837 | } while (!finished);
|
---|
| 838 | }
|
---|
| 839 |
|
---|
| 840 | private void experimentCreationBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
[7974] | 841 | if (e.ProgressPercentage >= 0 && e.ProgressPercentage <= 100) {
|
---|
| 842 | experimentCreationProgressBar.Style = ProgressBarStyle.Continuous;
|
---|
| 843 | experimentCreationProgressBar.Value = e.ProgressPercentage;
|
---|
| 844 | } else {
|
---|
[7975] | 845 | SetMode(DialogMode.PreparingExperiment);
|
---|
| 846 |
|
---|
[7974] | 847 | experimentCreationProgressBar.Style = ProgressBarStyle.Marquee;
|
---|
| 848 | }
|
---|
[7957] | 849 | Application.DoEvents();
|
---|
[7908] | 850 | }
|
---|
| 851 |
|
---|
[7846] | 852 | private void experimentCreationBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
[7885] | 853 | try {
|
---|
[7908] | 854 | SetMode(DialogMode.Normal);
|
---|
[7885] | 855 | if (e.Error != null) MessageBox.Show(e.Error.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 856 | if (failedInstances.Length > 0) MessageBox.Show("Some instances could not be loaded: " + Environment.NewLine + failedInstances.ToString(), "Some instances failed to load", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 857 | if (!e.Cancelled && e.Error == null) {
|
---|
| 858 | DialogResult = System.Windows.Forms.DialogResult.OK;
|
---|
| 859 | Close();
|
---|
| 860 | }
|
---|
[7975] | 861 | }
|
---|
| 862 | catch { }
|
---|
[7846] | 863 | }
|
---|
[7885] | 864 | #endregion
|
---|
[7908] | 865 | #endregion
|
---|
[4104] | 866 | }
|
---|
| 867 | }
|
---|