[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;
|
---|
[7985] | 58 | private Dictionary<IValueParameter, IntArray> intParameters;
|
---|
| 59 | private Dictionary<IValueParameter, DoubleArray> doubleParameters;
|
---|
[7908] | 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>>();
|
---|
[7985] | 79 | intParameters = new Dictionary<IValueParameter, IntArray>();
|
---|
| 80 | doubleParameters = new Dictionary<IValueParameter, DoubleArray>();
|
---|
[7908] | 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) {
|
---|
[7985] | 120 | if (e.Item.Checked) multipleChoiceParameters.Add(parameter, new HashSet<IItem>());
|
---|
| 121 | else multipleChoiceParameters.Remove(parameter);
|
---|
[7908] | 122 | }
|
---|
| 123 |
|
---|
| 124 | var intValue = parameter.Value as ValueTypeValue<int>;
|
---|
| 125 | if (intValue != null) {
|
---|
| 126 | if (e.Item.Checked) {
|
---|
[7985] | 127 | intParameters.Add(parameter, new IntArray());
|
---|
| 128 | intParameters[parameter].Reset += new EventHandler(ValuesArray_Reset);
|
---|
[7908] | 129 | } else intParameters.Remove(parameter);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | var doubleValue = parameter.Value as ValueTypeValue<double>;
|
---|
| 133 | if (doubleValue != null) {
|
---|
| 134 | if (e.Item.Checked) {
|
---|
[7985] | 135 | doubleParameters.Add(parameter, new DoubleArray());
|
---|
| 136 | doubleParameters[parameter].Reset += new EventHandler(ValuesArray_Reset);
|
---|
[7908] | 137 | } else doubleParameters.Remove(parameter);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | var boolValue = parameter.Value as ValueTypeValue<bool>;
|
---|
| 141 | if (boolValue != null) {
|
---|
| 142 | if (e.Item.Checked) boolParameters.Add(parameter);
|
---|
| 143 | else boolParameters.Remove(parameter);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[7957] | 146 | UpdateVariationsLabel();
|
---|
[7908] | 147 | if (e.Item.Selected) UpdateDetailsView(parameter);
|
---|
| 148 | else e.Item.Selected = true;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | private void parametersListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 152 | if (parametersListView.SelectedItems.Count == 0) {
|
---|
| 153 | ClearDetailsView();
|
---|
| 154 | } else {
|
---|
| 155 | var parameter = parametersListView.SelectedItems[0].Tag as IValueParameter;
|
---|
| 156 | UpdateDetailsView(parameter);
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | private void UpdateDetailsView(IValueParameter parameter) {
|
---|
| 161 | ClearDetailsView();
|
---|
| 162 |
|
---|
| 163 | var isConstrainedValueParameter =
|
---|
| 164 | typeof(OptionalConstrainedValueParameter<>).IsAssignableFrom(parameter.GetType().GetGenericTypeDefinition())
|
---|
| 165 | || typeof(ConstrainedValueParameter<>).Equals(parameter.GetType().GetGenericTypeDefinition());
|
---|
| 166 |
|
---|
| 167 | if (isConstrainedValueParameter) {
|
---|
[7957] | 168 | detailsTypeLabel.Text = "Choices:";
|
---|
[7908] | 169 | choicesListView.Tag = parameter;
|
---|
| 170 |
|
---|
| 171 | dynamic constrainedValuedParameter = parameter;
|
---|
| 172 | dynamic validValues = constrainedValuedParameter.ValidValues;
|
---|
| 173 | foreach (var choice in validValues) {
|
---|
| 174 | choicesListView.Items.Add(new ListViewItem(choice.ToString()) {
|
---|
| 175 | Tag = choice,
|
---|
[7985] | 176 | Checked = multipleChoiceParameters.ContainsKey(parameter)
|
---|
| 177 | && multipleChoiceParameters[parameter].Contains(choice)
|
---|
[7908] | 178 | });
|
---|
| 179 | }
|
---|
[7985] | 180 | choicesListView.Enabled = multipleChoiceParameters.ContainsKey(parameter);
|
---|
| 181 | detailsTypeLabel.Visible = true;
|
---|
| 182 | choicesListView.Visible = true;
|
---|
[7908] | 183 | return;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[7985] | 186 | if (parameter.Value is ValueTypeValue<bool>) {
|
---|
| 187 | detailsTypeLabel.Text = "Boolean parameter: True / False";
|
---|
| 188 | detailsTypeLabel.Visible = true;
|
---|
| 189 | }
|
---|
[7908] | 190 |
|
---|
| 191 | var intValue = parameter.Value as ValueTypeValue<int>;
|
---|
| 192 | if (intValue != null) {
|
---|
[7985] | 193 | if (intParameters.ContainsKey(parameter))
|
---|
| 194 | stringConvertibleArrayView.Content = intParameters[parameter];
|
---|
| 195 | stringConvertibleArrayView.Visible = true;
|
---|
| 196 | stringConvertibleArrayView.ReadOnly = !intParameters.ContainsKey(parameter);
|
---|
| 197 | generateButton.Tag = parameter;
|
---|
| 198 | generateButton.Enabled = intParameters.ContainsKey(parameter);
|
---|
| 199 | generateButton.Visible = true;
|
---|
[7908] | 200 | return;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | var doubleValue = parameter.Value as ValueTypeValue<double>;
|
---|
| 204 | if (doubleValue != null) {
|
---|
[7985] | 205 | if (doubleParameters.ContainsKey(parameter))
|
---|
| 206 | stringConvertibleArrayView.Content = doubleParameters[parameter];
|
---|
| 207 | stringConvertibleArrayView.Visible = true;
|
---|
| 208 | stringConvertibleArrayView.ReadOnly = !doubleParameters.ContainsKey(parameter);
|
---|
| 209 | generateButton.Tag = parameter;
|
---|
| 210 | generateButton.Enabled = doubleParameters.ContainsKey(parameter);
|
---|
| 211 | generateButton.Visible = true;
|
---|
[7908] | 212 | return;
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | #region Detail controls
|
---|
| 217 | private void choiceListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
|
---|
| 218 | var parameter = (IValueParameter)choicesListView.Tag;
|
---|
[7985] | 219 | if (multipleChoiceParameters.ContainsKey(parameter)) {
|
---|
| 220 | if (e.Item.Checked) {
|
---|
| 221 | multipleChoiceParameters[parameter].Add((IItem)e.Item.Tag);
|
---|
| 222 | } else multipleChoiceParameters[parameter].Remove((IItem)e.Item.Tag);
|
---|
[7908] | 223 |
|
---|
[7985] | 224 | UpdateVariationsLabel();
|
---|
| 225 | }
|
---|
[7908] | 226 | }
|
---|
| 227 |
|
---|
[7985] | 228 | private void generateButton_Click(object sender, EventArgs e) {
|
---|
| 229 | var parameter = (IValueParameter)generateButton.Tag;
|
---|
| 230 | bool integerOnly = intParameters.ContainsKey(parameter);
|
---|
| 231 | double min = 0, max = 1, step = 1;
|
---|
| 232 | #region Try to calculate some meaningful values
|
---|
| 233 | if (integerOnly) {
|
---|
| 234 | int len = intParameters[parameter].Length;
|
---|
| 235 | if (len > 0) {
|
---|
| 236 | min = intParameters[parameter].Min();
|
---|
| 237 | max = intParameters[parameter].Max();
|
---|
| 238 | step = len >= 2 ? Math.Abs((intParameters[parameter][len - 1] - intParameters[parameter][len - 2])) : 1;
|
---|
[7908] | 239 | }
|
---|
[7985] | 240 | } else {
|
---|
| 241 | int len = doubleParameters[parameter].Length;
|
---|
| 242 | if (len > 0) {
|
---|
| 243 | min = doubleParameters[parameter].Min();
|
---|
| 244 | max = doubleParameters[parameter].Max();
|
---|
| 245 | step = len >= 2 ? Math.Abs((doubleParameters[parameter][len - 1] - doubleParameters[parameter][len - 2])) : 1;
|
---|
| 246 | }
|
---|
[7908] | 247 | }
|
---|
[7985] | 248 | #endregion
|
---|
| 249 | using (var dialog = new DefineArithmeticProgressionDialog(integerOnly, min, max, step)) {
|
---|
[8011] | 250 | if (dialog.ShowDialog(this) == DialogResult.OK) {
|
---|
[7985] | 251 | var values = dialog.Values;
|
---|
| 252 | if (integerOnly) {
|
---|
| 253 | intParameters[parameter].Reset -= new EventHandler(ValuesArray_Reset);
|
---|
| 254 | intParameters[parameter] = new IntArray(values.Select(x => (int)x).ToArray());
|
---|
| 255 | intParameters[parameter].Reset += new EventHandler(ValuesArray_Reset);
|
---|
| 256 | stringConvertibleArrayView.Content = intParameters[parameter];
|
---|
| 257 | } else {
|
---|
| 258 | doubleParameters[parameter].Reset -= new EventHandler(ValuesArray_Reset);
|
---|
| 259 | doubleParameters[parameter] = new DoubleArray(values.ToArray());
|
---|
| 260 | doubleParameters[parameter].Reset += new EventHandler(ValuesArray_Reset);
|
---|
| 261 | stringConvertibleArrayView.Content = doubleParameters[parameter];
|
---|
| 262 | }
|
---|
| 263 | UpdateVariationsLabel();
|
---|
[7908] | 264 | }
|
---|
| 265 | }
|
---|
[7985] | 266 | }
|
---|
[7908] | 267 |
|
---|
[7985] | 268 | private void ValuesArray_Reset(object sender, EventArgs e) {
|
---|
[7957] | 269 | UpdateVariationsLabel();
|
---|
[7908] | 270 | }
|
---|
| 271 | #endregion
|
---|
| 272 | #endregion
|
---|
| 273 |
|
---|
| 274 | #region Instances
|
---|
[7957] | 275 | private void instancesTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
|
---|
| 276 | if (!suppressTreeViewEventHandling) {
|
---|
| 277 | if (e.Node.Nodes.Count > 0) { // provider node was (un)checked
|
---|
| 278 | SyncProviderNode(e.Node);
|
---|
| 279 | } else { // descriptor node was (un)checked
|
---|
| 280 | SyncInstanceNode(e.Node);
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | suppressCheckAllNoneEventHandling = true;
|
---|
| 284 | try {
|
---|
| 285 | var treeViewNodes = instancesTreeView.Nodes.OfType<TreeNode>().SelectMany(x => x.Nodes.OfType<TreeNode>());
|
---|
| 286 | selectAllCheckBox.Checked = treeViewNodes.Count() == instances.SelectMany(x => x.Value).Count();
|
---|
| 287 | selectNoneCheckBox.Checked = !treeViewNodes.Any(x => x.Checked);
|
---|
[7975] | 288 | }
|
---|
| 289 | finally { suppressCheckAllNoneEventHandling = false; }
|
---|
[7957] | 290 | UpdateVariationsLabel();
|
---|
[7885] | 291 | }
|
---|
[7957] | 292 | }
|
---|
| 293 |
|
---|
| 294 | private void SyncProviderNode(TreeNode node) {
|
---|
| 295 | suppressTreeViewEventHandling = true;
|
---|
| 296 | try {
|
---|
| 297 | foreach (TreeNode n in node.Nodes) {
|
---|
| 298 | if (n.Checked != node.Checked) {
|
---|
| 299 | n.Checked = node.Checked;
|
---|
| 300 | SyncInstanceNode(n, false);
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
[7975] | 303 | }
|
---|
| 304 | finally { suppressTreeViewEventHandling = false; }
|
---|
[7957] | 305 | }
|
---|
| 306 |
|
---|
| 307 | private void SyncInstanceNode(TreeNode node, bool providerCheck = true) {
|
---|
| 308 | var provider = (IProblemInstanceProvider)node.Parent.Tag;
|
---|
| 309 | var descriptor = (IDataDescriptor)node.Tag;
|
---|
| 310 | if (node.Checked) {
|
---|
[7908] | 311 | if (!instances.ContainsKey(provider))
|
---|
| 312 | instances.Add(provider, new HashSet<IDataDescriptor>());
|
---|
| 313 | instances[provider].Add(descriptor);
|
---|
| 314 | } else {
|
---|
| 315 | if (instances.ContainsKey(provider)) {
|
---|
| 316 | instances[provider].Remove(descriptor);
|
---|
| 317 | if (instances[provider].Count == 0)
|
---|
| 318 | instances.Remove(provider);
|
---|
| 319 | }
|
---|
| 320 | }
|
---|
[7957] | 321 | if (providerCheck) {
|
---|
| 322 | bool allChecked = node.Parent.Nodes.OfType<TreeNode>().All(x => x.Checked);
|
---|
| 323 | suppressTreeViewEventHandling = true;
|
---|
| 324 | try {
|
---|
| 325 | node.Parent.Checked = allChecked;
|
---|
[7975] | 326 | }
|
---|
| 327 | finally { suppressTreeViewEventHandling = false; }
|
---|
[7957] | 328 | }
|
---|
[4104] | 329 | }
|
---|
[7885] | 330 |
|
---|
[7846] | 331 | private void selectAllCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[7957] | 332 | if (!suppressCheckAllNoneEventHandling) {
|
---|
| 333 | if (selectAllCheckBox.Checked) {
|
---|
| 334 | suppressCheckAllNoneEventHandling = true;
|
---|
[7975] | 335 | try { selectNoneCheckBox.Checked = false; }
|
---|
| 336 | finally { suppressCheckAllNoneEventHandling = false; }
|
---|
[7957] | 337 | try {
|
---|
| 338 | suppressTreeViewEventHandling = true;
|
---|
| 339 | foreach (TreeNode node in instancesTreeView.Nodes) {
|
---|
| 340 | if (!node.Checked) {
|
---|
| 341 | node.Checked = true;
|
---|
| 342 | SyncProviderNode(node);
|
---|
| 343 | }
|
---|
| 344 | }
|
---|
[7975] | 345 | }
|
---|
| 346 | finally { suppressTreeViewEventHandling = false; }
|
---|
[7957] | 347 | }
|
---|
[7846] | 348 | }
|
---|
| 349 | }
|
---|
[7885] | 350 |
|
---|
[7846] | 351 | private void selectNoneCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[7957] | 352 | if (!suppressCheckAllNoneEventHandling) {
|
---|
| 353 | if (selectNoneCheckBox.Checked) {
|
---|
| 354 | suppressCheckAllNoneEventHandling = true;
|
---|
[7975] | 355 | try { selectAllCheckBox.Checked = false; }
|
---|
| 356 | finally { suppressCheckAllNoneEventHandling = false; }
|
---|
[7957] | 357 | try {
|
---|
| 358 | suppressTreeViewEventHandling = true;
|
---|
| 359 | foreach (TreeNode node in instancesTreeView.Nodes) {
|
---|
| 360 | if (node.Checked) {
|
---|
| 361 | node.Checked = false;
|
---|
| 362 | SyncProviderNode(node);
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
[7975] | 365 | }
|
---|
| 366 | finally { suppressTreeViewEventHandling = false; }
|
---|
[7957] | 367 | }
|
---|
[7846] | 368 | }
|
---|
| 369 | }
|
---|
[7908] | 370 | #endregion
|
---|
[7885] | 371 |
|
---|
| 372 | private void createBatchRunCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 373 | repetitionsNumericUpDown.Enabled = createBatchRunCheckBox.Checked;
|
---|
| 374 | createBatchRun = createBatchRunCheckBox.Checked;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
|
---|
| 378 | if (repetitionsNumericUpDown.Text == string.Empty)
|
---|
| 379 | repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
|
---|
| 380 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
| 381 | }
|
---|
[7957] | 382 |
|
---|
| 383 | private void experimentsLabel_TextChanged(object sender, EventArgs e) {
|
---|
| 384 | long number;
|
---|
| 385 | if (long.TryParse(variationsLabel.Text, NumberStyles.AllowThousands, CultureInfo.CurrentCulture.NumberFormat, out number)) {
|
---|
| 386 | if (number > 1000) warningProvider.SetError(variationsLabel, "Consider reducing the number of variations!");
|
---|
| 387 | else warningProvider.SetError(variationsLabel, null);
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
[7885] | 390 | #endregion
|
---|
| 391 |
|
---|
| 392 | #region Helpers
|
---|
[7908] | 393 | private void SetTabControlVisibility() {
|
---|
| 394 | bool isAlgorithm = optimizer != null && optimizer is IAlgorithm;
|
---|
| 395 | bool instancesAvailable = isAlgorithm
|
---|
[7885] | 396 | && ((IAlgorithm)optimizer).Problem != null
|
---|
| 397 | && ProblemInstanceManager.GetProviders(((IAlgorithm)optimizer).Problem).Any();
|
---|
[7908] | 398 | if (instancesAvailable && tabControl.TabCount == 1)
|
---|
| 399 | tabControl.TabPages.Add(instancesTabPage);
|
---|
| 400 | else if (!instancesAvailable && tabControl.TabCount == 2)
|
---|
| 401 | tabControl.TabPages.Remove(instancesTabPage);
|
---|
| 402 | tabControl.Visible = isAlgorithm;
|
---|
| 403 | if (isAlgorithm) {
|
---|
[7957] | 404 | variationsLabel.Visible = true;
|
---|
[7908] | 405 | experimentsToCreateDescriptionLabel.Visible = true;
|
---|
| 406 | Height = 430;
|
---|
| 407 | } else {
|
---|
[7957] | 408 | variationsLabel.Visible = false;
|
---|
[7908] | 409 | experimentsToCreateDescriptionLabel.Visible = false;
|
---|
| 410 | Height = 130;
|
---|
| 411 | }
|
---|
[7885] | 412 | }
|
---|
| 413 |
|
---|
[7908] | 414 | private void FillParametersListView() {
|
---|
| 415 | parametersListView.Items.Clear();
|
---|
| 416 | intParameters.Clear();
|
---|
| 417 | doubleParameters.Clear();
|
---|
| 418 | boolParameters.Clear();
|
---|
| 419 | multipleChoiceParameters.Clear();
|
---|
| 420 |
|
---|
| 421 | if (Optimizer is IAlgorithm) {
|
---|
| 422 | var parameters = ((IAlgorithm)optimizer).Parameters;
|
---|
| 423 | foreach (var param in parameters) {
|
---|
| 424 | var valueParam = param as IValueParameter;
|
---|
| 425 | if (valueParam != null && (valueParam.Value is ValueTypeValue<bool>
|
---|
| 426 | || valueParam.Value is ValueTypeValue<int>
|
---|
| 427 | || valueParam.Value is ValueTypeValue<double>)
|
---|
| 428 | || typeof(OptionalConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition())
|
---|
| 429 | || typeof(ConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition()))
|
---|
| 430 | parametersListView.Items.Add(new ListViewItem(param.Name) { Tag = param });
|
---|
| 431 | }
|
---|
| 432 | }
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[7957] | 435 | private void FillInstanceTreeViewAsync() {
|
---|
[7908] | 436 | instances.Clear();
|
---|
[7957] | 437 | instancesTreeView.Nodes.Clear();
|
---|
[7908] | 438 |
|
---|
[7957] | 439 | if (Optimizer is IAlgorithm && ((IAlgorithm)Optimizer).Problem != null) {
|
---|
[7908] | 440 | SetMode(DialogMode.DiscoveringInstances);
|
---|
[7957] | 441 | instanceDiscoveryBackgroundWorker.RunWorkerAsync();
|
---|
[7908] | 442 | }
|
---|
[7885] | 443 | }
|
---|
| 444 |
|
---|
| 445 | private void AddOptimizer(IOptimizer optimizer, Experiment experiment) {
|
---|
| 446 | if (createBatchRun) {
|
---|
| 447 | var batchRun = new BatchRun();
|
---|
| 448 | batchRun.Repetitions = repetitions;
|
---|
| 449 | batchRun.Optimizer = optimizer;
|
---|
| 450 | experiment.Optimizers.Add(batchRun);
|
---|
| 451 | } else {
|
---|
| 452 | experiment.Optimizers.Add(optimizer);
|
---|
[7846] | 453 | }
|
---|
| 454 | }
|
---|
[7885] | 455 |
|
---|
[7908] | 456 | private int GetNumberOfVariations() {
|
---|
| 457 | int instancesCount = 1;
|
---|
| 458 | if (instances.Values.Any())
|
---|
| 459 | instancesCount = Math.Max(instances.Values.SelectMany(x => x).Count(), 1);
|
---|
[7885] | 460 |
|
---|
[7908] | 461 | int intParameterVariations = 1;
|
---|
| 462 | foreach (var intParam in intParameters.Values) {
|
---|
[7985] | 463 | intParameterVariations *= Math.Max(intParam.Length, 1);
|
---|
[7885] | 464 | }
|
---|
[7908] | 465 | int doubleParameterVariations = 1;
|
---|
| 466 | foreach (var doubleParam in doubleParameters.Values) {
|
---|
[7985] | 467 | doubleParameterVariations *= Math.Max(doubleParam.Length, 1);
|
---|
[7908] | 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) {
|
---|
[7985] | 482 | if (InvokeRequired) Invoke((Action<DialogMode>)SetMode, mode);
|
---|
| 483 | else {
|
---|
| 484 | createBatchRunCheckBox.Enabled = mode == DialogMode.Normal;
|
---|
| 485 | repetitionsNumericUpDown.Enabled = mode == DialogMode.Normal;
|
---|
| 486 | parametersSplitContainer.Enabled = mode == DialogMode.Normal || mode == DialogMode.DiscoveringInstances;
|
---|
| 487 | selectAllCheckBox.Enabled = mode == DialogMode.Normal;
|
---|
| 488 | selectNoneCheckBox.Enabled = mode == DialogMode.Normal;
|
---|
| 489 | instancesTreeView.Enabled = mode == DialogMode.Normal;
|
---|
| 490 | instancesTreeView.Visible = mode == DialogMode.Normal || mode == DialogMode.CreatingExperiment || mode == DialogMode.PreparingExperiment;
|
---|
| 491 | okButton.Enabled = mode == DialogMode.Normal;
|
---|
| 492 | okButton.Visible = mode != DialogMode.CreatingExperiment && mode != DialogMode.PreparingExperiment;
|
---|
| 493 | cancelButton.Enabled = mode != DialogMode.PreparingExperiment;
|
---|
| 494 | instanceDiscoveryProgressLabel.Visible = mode == DialogMode.DiscoveringInstances;
|
---|
| 495 | instanceDiscoveryProgressBar.Visible = mode == DialogMode.DiscoveringInstances;
|
---|
| 496 | experimentCreationProgressBar.Visible = mode == DialogMode.CreatingExperiment || mode == DialogMode.PreparingExperiment;
|
---|
| 497 | }
|
---|
[7908] | 498 | }
|
---|
| 499 |
|
---|
| 500 | private void ClearDetailsView() {
|
---|
[7985] | 501 | stringConvertibleArrayView.Visible = false;
|
---|
| 502 | stringConvertibleArrayView.Content = null;
|
---|
| 503 | stringConvertibleArrayView.ReadOnly = true;
|
---|
| 504 | generateButton.Visible = false;
|
---|
| 505 | detailsTypeLabel.Visible = false;
|
---|
[7908] | 506 | choicesListView.Items.Clear();
|
---|
| 507 | choicesListView.Enabled = false;
|
---|
| 508 | choicesListView.Visible = false;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
[7957] | 511 | private void UpdateVariationsLabel() {
|
---|
| 512 | variationsLabel.Text = GetNumberOfVariations().ToString("#,#", CultureInfo.CurrentCulture);
|
---|
| 513 | }
|
---|
| 514 |
|
---|
[7908] | 515 | #region Retrieve parameter combinations
|
---|
| 516 | private IEnumerable<Dictionary<IValueParameter, int>> GetIntParameterConfigurations() {
|
---|
| 517 | var configuration = new Dictionary<IValueParameter, int>();
|
---|
[7985] | 518 | var enumerators = new Dictionary<IValueParameter, IEnumerator<int>>();
|
---|
[7908] | 519 | bool finished;
|
---|
| 520 | do {
|
---|
| 521 | foreach (var p in intParameters) {
|
---|
[7985] | 522 | if (!enumerators.ContainsKey(p.Key)) {
|
---|
| 523 | enumerators[p.Key] = p.Value.GetEnumerator();
|
---|
| 524 | enumerators[p.Key].MoveNext();
|
---|
| 525 | }
|
---|
| 526 | configuration[p.Key] = enumerators[p.Key].Current;
|
---|
[7908] | 527 | }
|
---|
| 528 | yield return configuration;
|
---|
| 529 |
|
---|
| 530 | finished = true;
|
---|
[7985] | 531 | foreach (var p in intParameters) {
|
---|
| 532 | if (!enumerators[p.Key].MoveNext()) {
|
---|
| 533 | enumerators[p.Key] = p.Value.GetEnumerator();
|
---|
| 534 | enumerators[p.Key].MoveNext();
|
---|
| 535 | } else {
|
---|
[7908] | 536 | finished = false;
|
---|
| 537 | break;
|
---|
| 538 | }
|
---|
| 539 | }
|
---|
| 540 | } while (!finished);
|
---|
| 541 | }
|
---|
| 542 |
|
---|
| 543 | private IEnumerable<Dictionary<IValueParameter, double>> GetDoubleParameterConfigurations() {
|
---|
| 544 | var configuration = new Dictionary<IValueParameter, double>();
|
---|
[7985] | 545 | var enumerators = new Dictionary<IValueParameter, IEnumerator<double>>();
|
---|
[7908] | 546 | bool finished;
|
---|
| 547 | do {
|
---|
| 548 | foreach (var p in doubleParameters) {
|
---|
[7985] | 549 | if (!enumerators.ContainsKey(p.Key)) {
|
---|
| 550 | enumerators[p.Key] = p.Value.GetEnumerator();
|
---|
| 551 | enumerators[p.Key].MoveNext();
|
---|
| 552 | }
|
---|
| 553 | configuration[p.Key] = enumerators[p.Key].Current;
|
---|
[7908] | 554 | }
|
---|
| 555 | yield return configuration;
|
---|
| 556 |
|
---|
| 557 | finished = true;
|
---|
[7985] | 558 | foreach (var p in doubleParameters) {
|
---|
| 559 | if (!enumerators[p.Key].MoveNext()) {
|
---|
| 560 | enumerators[p.Key] = p.Value.GetEnumerator();
|
---|
| 561 | enumerators[p.Key].MoveNext();
|
---|
| 562 | } else {
|
---|
[7908] | 563 | finished = false;
|
---|
| 564 | break;
|
---|
| 565 | }
|
---|
| 566 | }
|
---|
| 567 | } while (!finished);
|
---|
| 568 | }
|
---|
| 569 |
|
---|
| 570 | private IEnumerable<Dictionary<IValueParameter, bool>> GetBoolParameterConfigurations() {
|
---|
| 571 | var configuration = new Dictionary<IValueParameter, bool>();
|
---|
| 572 | bool finished;
|
---|
| 573 | do {
|
---|
| 574 | finished = true;
|
---|
| 575 | foreach (var p in boolParameters) {
|
---|
| 576 | if (!configuration.ContainsKey(p)) configuration.Add(p, false);
|
---|
| 577 | else {
|
---|
| 578 | if (configuration[p]) {
|
---|
| 579 | configuration[p] = false;
|
---|
| 580 | } else {
|
---|
| 581 | configuration[p] = true;
|
---|
| 582 | finished = false;
|
---|
| 583 | break;
|
---|
| 584 | }
|
---|
| 585 | }
|
---|
| 586 | }
|
---|
| 587 | yield return configuration;
|
---|
| 588 | } while (!finished);
|
---|
| 589 | }
|
---|
| 590 |
|
---|
[7974] | 591 | private IEnumerable<Dictionary<IValueParameter, IItem>> GetMultipleChoiceConfigurations() {
|
---|
| 592 | var configuration = new Dictionary<IValueParameter, IItem>();
|
---|
| 593 | var enumerators = new Dictionary<IValueParameter, IEnumerator<IItem>>();
|
---|
[7908] | 594 | bool finished;
|
---|
| 595 | do {
|
---|
| 596 | foreach (var p in multipleChoiceParameters.Keys.ToArray()) {
|
---|
| 597 | if (!enumerators.ContainsKey(p)) {
|
---|
| 598 | enumerators.Add(p, multipleChoiceParameters[p].GetEnumerator());
|
---|
| 599 | if (!enumerators[p].MoveNext()) {
|
---|
| 600 | multipleChoiceParameters.Remove(p);
|
---|
| 601 | continue;
|
---|
| 602 | }
|
---|
| 603 | }
|
---|
| 604 | configuration[p] = enumerators[p].Current;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | finished = true;
|
---|
| 608 | foreach (var p in multipleChoiceParameters.Keys) {
|
---|
| 609 | if (!enumerators[p].MoveNext()) {
|
---|
| 610 | enumerators[p] = multipleChoiceParameters[p].GetEnumerator();
|
---|
[7974] | 611 | enumerators[p].MoveNext();
|
---|
[7908] | 612 | } else {
|
---|
| 613 | finished = false;
|
---|
| 614 | break;
|
---|
| 615 | }
|
---|
| 616 | }
|
---|
| 617 | yield return configuration;
|
---|
| 618 | } while (!finished);
|
---|
| 619 | }
|
---|
[7885] | 620 | #endregion
|
---|
[7908] | 621 | #endregion
|
---|
[7885] | 622 |
|
---|
| 623 | #region Background workers
|
---|
[7908] | 624 | #region Instance discovery
|
---|
[7885] | 625 | private void instanceDiscoveryBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
[7957] | 626 | var instanceProviders = ProblemInstanceManager.GetProviders(((IAlgorithm)Optimizer).Problem).ToArray();
|
---|
| 627 | var nodes = new TreeNode[instanceProviders.Length];
|
---|
[7885] | 628 | for (int i = 0; i < instanceProviders.Length; i++) {
|
---|
| 629 | var provider = instanceProviders[i];
|
---|
[7957] | 630 | nodes[i] = new TreeNode(provider.Name) { Tag = provider };
|
---|
[7885] | 631 | }
|
---|
[7957] | 632 | e.Result = nodes;
|
---|
| 633 | for (int i = 0; i < nodes.Length; i++) {
|
---|
| 634 | var providerNode = nodes[i];
|
---|
| 635 | var provider = providerNode.Tag as IProblemInstanceProvider;
|
---|
| 636 | double progress = i / (double)nodes.Length;
|
---|
| 637 | instanceDiscoveryBackgroundWorker.ReportProgress((int)(100 * progress), provider.Name);
|
---|
[7885] | 638 | var descriptors = ProblemInstanceManager.GetDataDescriptors(provider).ToArray();
|
---|
| 639 | for (int j = 0; j < descriptors.Length; j++) {
|
---|
| 640 | #region Check cancellation request
|
---|
| 641 | if (instanceDiscoveryBackgroundWorker.CancellationPending) {
|
---|
| 642 | e.Cancel = true;
|
---|
| 643 | return;
|
---|
| 644 | }
|
---|
| 645 | #endregion
|
---|
[7957] | 646 | var node = new TreeNode(descriptors[j].Name) { Tag = descriptors[j] };
|
---|
| 647 | providerNode.Nodes.Add(node);
|
---|
[7885] | 648 | }
|
---|
| 649 | }
|
---|
| 650 | instanceDiscoveryBackgroundWorker.ReportProgress(100, string.Empty);
|
---|
| 651 | }
|
---|
| 652 |
|
---|
[7908] | 653 | private void instanceDiscoveryBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
[7957] | 654 | if (instanceDiscoveryProgressBar.Value != e.ProgressPercentage)
|
---|
| 655 | instanceDiscoveryProgressBar.Value = e.ProgressPercentage;
|
---|
[7908] | 656 | instanceDiscoveryProgressLabel.Text = (string)e.UserState;
|
---|
[7957] | 657 | Application.DoEvents();
|
---|
[7908] | 658 | }
|
---|
| 659 |
|
---|
[7885] | 660 | private void instanceDiscoveryBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 661 | try {
|
---|
[7957] | 662 | instancesTreeView.Nodes.AddRange((TreeNode[])e.Result);
|
---|
| 663 | foreach (TreeNode node in instancesTreeView.Nodes)
|
---|
| 664 | node.Collapse();
|
---|
[7908] | 665 | selectNoneCheckBox.Checked = true;
|
---|
[7975] | 666 | }
|
---|
| 667 | catch { }
|
---|
[7885] | 668 | try {
|
---|
[7908] | 669 | SetMode(DialogMode.Normal);
|
---|
[7885] | 670 | if (e.Error != null) MessageBox.Show(e.Error.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
[7975] | 671 | }
|
---|
| 672 | catch { }
|
---|
[7885] | 673 | }
|
---|
[7908] | 674 | #endregion
|
---|
[7885] | 675 |
|
---|
[7908] | 676 | #region Experiment creation
|
---|
[7846] | 677 | private void experimentCreationBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
[7908] | 678 | backgroundWorkerWaitHandle.Set(); // notify the ok button that we're busy now
|
---|
[7885] | 679 | failedInstances = new StringBuilder();
|
---|
[7846] | 680 | var localExperiment = new Experiment();
|
---|
[7908] | 681 |
|
---|
[7974] | 682 | int counter = 0, totalVariations = GetNumberOfVariations();
|
---|
[7908] | 683 | if (instances.Count == 0) {
|
---|
[8012] | 684 | try {
|
---|
| 685 | AddParameterVariations(Optimizer, localExperiment, ref counter, totalVariations);
|
---|
| 686 | } catch (OperationCanceledException) {
|
---|
| 687 | e.Cancel = true;
|
---|
| 688 | localExperiment = null;
|
---|
| 689 | return;
|
---|
| 690 | }
|
---|
[7846] | 691 | experimentCreationBackgroundWorker.ReportProgress(100, string.Empty);
|
---|
[7841] | 692 | } else {
|
---|
[7908] | 693 | foreach (var provider in instances.Keys) {
|
---|
| 694 | foreach (var descriptor in instances[provider]) {
|
---|
[7885] | 695 | var algorithm = (IAlgorithm)Optimizer.Clone();
|
---|
| 696 | bool failed = false;
|
---|
| 697 | try {
|
---|
| 698 | ProblemInstanceManager.LoadData(provider, descriptor, (IProblemInstanceConsumer)algorithm.Problem);
|
---|
[8012] | 699 | } catch (Exception ex) {
|
---|
[7885] | 700 | failedInstances.AppendLine(descriptor.Name + ": " + ex.Message);
|
---|
| 701 | failed = true;
|
---|
| 702 | }
|
---|
| 703 | if (!failed) {
|
---|
[8012] | 704 | try {
|
---|
| 705 | AddParameterVariations(algorithm, localExperiment, ref counter, totalVariations);
|
---|
| 706 | } catch (OperationCanceledException) {
|
---|
| 707 | e.Cancel = true;
|
---|
| 708 | localExperiment = null;
|
---|
| 709 | return;
|
---|
| 710 | }
|
---|
[7974] | 711 | } else experimentCreationBackgroundWorker.ReportProgress((int)Math.Round((100.0 * counter) / totalVariations), "Loading failed (" + descriptor.Name + ")");
|
---|
[7846] | 712 | }
|
---|
[7841] | 713 | }
|
---|
| 714 | }
|
---|
[7974] | 715 | if (localExperiment != null) {
|
---|
| 716 | // this step can take some time
|
---|
[7985] | 717 | SetMode(DialogMode.PreparingExperiment);
|
---|
[7974] | 718 | experimentCreationBackgroundWorker.ReportProgress(-1);
|
---|
| 719 | localExperiment.Prepare(true);
|
---|
| 720 | experimentCreationBackgroundWorker.ReportProgress(100);
|
---|
| 721 | }
|
---|
[7908] | 722 | Experiment = localExperiment;
|
---|
[7841] | 723 | }
|
---|
[7885] | 724 |
|
---|
[7976] | 725 | private void AddParameterVariations(IOptimizer optimizer, Experiment localExperiment, ref int counter, int totalVariations) {
|
---|
[7974] | 726 | var variations = experimentCreationBackgroundWorker_CalculateParameterVariations(optimizer);
|
---|
| 727 | foreach (var v in variations) {
|
---|
[8012] | 728 | if (experimentCreationBackgroundWorker.CancellationPending)
|
---|
| 729 | throw new OperationCanceledException();
|
---|
[7974] | 730 | AddOptimizer(v, localExperiment);
|
---|
| 731 | counter++;
|
---|
| 732 | experimentCreationBackgroundWorker.ReportProgress((int)Math.Round((100.0 * counter) / totalVariations), string.Empty);
|
---|
| 733 | }
|
---|
| 734 | }
|
---|
| 735 |
|
---|
[7908] | 736 | private IEnumerable<IOptimizer> experimentCreationBackgroundWorker_CalculateParameterVariations(IOptimizer optimizer) {
|
---|
| 737 | if (!boolParameters.Any() && !intParameters.Any() && !doubleParameters.Any() && !multipleChoiceParameters.Any()) {
|
---|
| 738 | yield return (IOptimizer)optimizer.Clone();
|
---|
| 739 | yield break;
|
---|
| 740 | }
|
---|
| 741 | bool finished;
|
---|
| 742 | var mcEnumerator = GetMultipleChoiceConfigurations().GetEnumerator();
|
---|
| 743 | var boolEnumerator = GetBoolParameterConfigurations().GetEnumerator();
|
---|
| 744 | var intEnumerator = GetIntParameterConfigurations().GetEnumerator();
|
---|
| 745 | var doubleEnumerator = GetDoubleParameterConfigurations().GetEnumerator();
|
---|
| 746 | mcEnumerator.MoveNext(); boolEnumerator.MoveNext(); intEnumerator.MoveNext(); doubleEnumerator.MoveNext();
|
---|
| 747 | do {
|
---|
| 748 | var variant = (IAlgorithm)optimizer.Clone();
|
---|
| 749 | variant.Name += " {";
|
---|
| 750 | finished = true;
|
---|
| 751 | if (doubleParameters.Any()) {
|
---|
| 752 | foreach (var d in doubleEnumerator.Current) {
|
---|
| 753 | var value = (ValueTypeValue<double>)((IValueParameter)variant.Parameters[d.Key.Name]).Value;
|
---|
| 754 | value.Value = d.Value;
|
---|
| 755 | variant.Name += d.Key.Name + "=" + d.Value.ToString() + ", ";
|
---|
| 756 | }
|
---|
| 757 | if (finished) {
|
---|
| 758 | if (doubleEnumerator.MoveNext()) {
|
---|
| 759 | finished = false;
|
---|
| 760 | } else {
|
---|
| 761 | doubleEnumerator = GetDoubleParameterConfigurations().GetEnumerator();
|
---|
| 762 | doubleEnumerator.MoveNext();
|
---|
| 763 | }
|
---|
| 764 | }
|
---|
| 765 | }
|
---|
| 766 | if (intParameters.Any()) {
|
---|
| 767 | foreach (var i in intEnumerator.Current) {
|
---|
| 768 | var value = (ValueTypeValue<int>)((IValueParameter)variant.Parameters[i.Key.Name]).Value;
|
---|
| 769 | value.Value = i.Value;
|
---|
| 770 | variant.Name += i.Key.Name + "=" + i.Value.ToString() + ", ";
|
---|
| 771 | }
|
---|
| 772 | if (finished) {
|
---|
| 773 | if (intEnumerator.MoveNext()) {
|
---|
| 774 | finished = false;
|
---|
| 775 | } else {
|
---|
| 776 | intEnumerator = GetIntParameterConfigurations().GetEnumerator();
|
---|
| 777 | intEnumerator.MoveNext();
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
| 780 | }
|
---|
| 781 | if (boolParameters.Any()) {
|
---|
| 782 | foreach (var b in boolEnumerator.Current) {
|
---|
| 783 | var value = (ValueTypeValue<bool>)((IValueParameter)variant.Parameters[b.Key.Name]).Value;
|
---|
| 784 | value.Value = b.Value;
|
---|
| 785 | variant.Name += b.Key.Name + "=" + b.Value.ToString() + ", ";
|
---|
| 786 | }
|
---|
| 787 | if (finished) {
|
---|
| 788 | if (boolEnumerator.MoveNext()) {
|
---|
| 789 | finished = false;
|
---|
| 790 | } else {
|
---|
| 791 | boolEnumerator = GetBoolParameterConfigurations().GetEnumerator();
|
---|
| 792 | boolEnumerator.MoveNext();
|
---|
| 793 | }
|
---|
| 794 | }
|
---|
| 795 | }
|
---|
| 796 | if (multipleChoiceParameters.Any()) {
|
---|
| 797 | foreach (var m in mcEnumerator.Current) {
|
---|
| 798 | dynamic variantParam = variant.Parameters[m.Key.Name];
|
---|
| 799 | var variantEnumerator = ((IEnumerable<object>)variantParam.ValidValues).GetEnumerator();
|
---|
| 800 | var originalEnumerator = ((IEnumerable<object>)((dynamic)m.Key).ValidValues).GetEnumerator();
|
---|
| 801 | while (variantEnumerator.MoveNext() && originalEnumerator.MoveNext()) {
|
---|
[7974] | 802 | if (m.Value == (IItem)originalEnumerator.Current) {
|
---|
[7908] | 803 | variantParam.Value = (dynamic)variantEnumerator.Current;
|
---|
[7974] | 804 | if (m.Value is INamedItem)
|
---|
| 805 | variant.Name += m.Key.Name + "=" + ((INamedItem)m.Value).Name + ", ";
|
---|
| 806 | else variant.Name += m.Key.Name + "=" + m.Value.ToString() + ", ";
|
---|
[7908] | 807 | break;
|
---|
| 808 | }
|
---|
| 809 | }
|
---|
| 810 | }
|
---|
| 811 | if (finished) {
|
---|
| 812 | if (mcEnumerator.MoveNext()) {
|
---|
| 813 | finished = false;
|
---|
| 814 | } else {
|
---|
| 815 | mcEnumerator = GetMultipleChoiceConfigurations().GetEnumerator();
|
---|
| 816 | mcEnumerator.MoveNext();
|
---|
| 817 | }
|
---|
| 818 | }
|
---|
| 819 | }
|
---|
| 820 | variant.Name = variant.Name.Substring(0, variant.Name.Length - 2) + "}";
|
---|
| 821 | yield return variant;
|
---|
| 822 | } while (!finished);
|
---|
| 823 | }
|
---|
| 824 |
|
---|
| 825 | private void experimentCreationBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
[7974] | 826 | if (e.ProgressPercentage >= 0 && e.ProgressPercentage <= 100) {
|
---|
| 827 | experimentCreationProgressBar.Style = ProgressBarStyle.Continuous;
|
---|
| 828 | experimentCreationProgressBar.Value = e.ProgressPercentage;
|
---|
| 829 | } else {
|
---|
| 830 | experimentCreationProgressBar.Style = ProgressBarStyle.Marquee;
|
---|
| 831 | }
|
---|
[7957] | 832 | Application.DoEvents();
|
---|
[7908] | 833 | }
|
---|
| 834 |
|
---|
[7846] | 835 | private void experimentCreationBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
[7885] | 836 | try {
|
---|
[7908] | 837 | SetMode(DialogMode.Normal);
|
---|
[7885] | 838 | if (e.Error != null) MessageBox.Show(e.Error.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 839 | 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);
|
---|
| 840 | if (!e.Cancelled && e.Error == null) {
|
---|
| 841 | DialogResult = System.Windows.Forms.DialogResult.OK;
|
---|
| 842 | Close();
|
---|
| 843 | }
|
---|
[7975] | 844 | }
|
---|
| 845 | catch { }
|
---|
[7846] | 846 | }
|
---|
[7885] | 847 | #endregion
|
---|
[7908] | 848 | #endregion
|
---|
[4104] | 849 | }
|
---|
| 850 | }
|
---|