Changeset 7974
- Timestamp:
- 06/08/12 20:33:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs
r7957 r7974 36 36 namespace HeuristicLab.Optimizer { 37 37 public partial class CreateExperimentDialog : Form { 38 private enum DialogMode { Normal = 1, DiscoveringInstances = 2, CreatingExperiment = 3 };38 private enum DialogMode { Normal = 1, DiscoveringInstances = 2, CreatingExperiment = 3, PreparingExperiment = 4 }; 39 39 40 40 private IOptimizer optimizer; … … 59 59 private Dictionary<IValueParameter, Tuple<double, double, double>> doubleParameters; 60 60 private HashSet<IValueParameter> boolParameters; 61 private Dictionary<IValueParameter, HashSet<I NamedItem>> multipleChoiceParameters;61 private Dictionary<IValueParameter, HashSet<IItem>> multipleChoiceParameters; 62 62 63 63 private StringBuilder failedInstances; … … 80 80 doubleParameters = new Dictionary<IValueParameter, Tuple<double, double, double>>(); 81 81 boolParameters = new HashSet<IValueParameter>(); 82 multipleChoiceParameters = new Dictionary<IValueParameter, HashSet<I NamedItem>>();82 multipleChoiceParameters = new Dictionary<IValueParameter, HashSet<IItem>>(); 83 83 } 84 84 … … 119 119 if (isConstrainedValueParameter) { 120 120 if (e.Item.Checked) { 121 multipleChoiceParameters.Add(parameter, new HashSet<I NamedItem>());121 multipleChoiceParameters.Add(parameter, new HashSet<IItem>()); 122 122 } else { 123 123 multipleChoiceParameters.Remove(parameter); … … 184 184 choicesListView.Items.Add(new ListViewItem(choice.ToString()) { 185 185 Tag = choice, 186 Checked = multipleChoiceParameters[parameter].Contains( (INamedItem)choice)186 Checked = multipleChoiceParameters[parameter].Contains(choice) 187 187 }); 188 188 } … … 223 223 var parameter = (IValueParameter)choicesListView.Tag; 224 224 if (e.Item.Checked) { 225 multipleChoiceParameters[parameter].Add((I NamedItem)e.Item.Tag);226 } else multipleChoiceParameters[parameter].Remove((I NamedItem)e.Item.Tag);225 multipleChoiceParameters[parameter].Add((IItem)e.Item.Tag); 226 } else multipleChoiceParameters[parameter].Remove((IItem)e.Item.Tag); 227 227 228 228 UpdateVariationsLabel(); … … 475 475 createBatchRunCheckBox.Enabled = mode == DialogMode.Normal; 476 476 repetitionsNumericUpDown.Enabled = mode == DialogMode.Normal; 477 parametersSplitContainer.Enabled = mode == DialogMode.Normal || mode == DialogMode.DiscoveringInstances; 477 478 selectAllCheckBox.Enabled = mode == DialogMode.Normal; 478 479 selectNoneCheckBox.Enabled = mode == DialogMode.Normal; 479 480 instancesTreeView.Enabled = mode == DialogMode.Normal; 480 instancesTreeView.Visible = mode == DialogMode.Normal || mode == DialogMode.CreatingExperiment ;481 instancesTreeView.Visible = mode == DialogMode.Normal || mode == DialogMode.CreatingExperiment || mode == DialogMode.PreparingExperiment; 481 482 okButton.Enabled = mode == DialogMode.Normal; 482 okButton.Visible = mode != DialogMode.CreatingExperiment; 483 okButton.Visible = mode != DialogMode.CreatingExperiment && mode != DialogMode.PreparingExperiment; 484 cancelButton.Enabled = mode != DialogMode.PreparingExperiment; 483 485 instanceDiscoveryProgressLabel.Visible = mode == DialogMode.DiscoveringInstances; 484 486 instanceDiscoveryProgressBar.Visible = mode == DialogMode.DiscoveringInstances; 485 experimentCreationProgressBar.Visible = mode == DialogMode.CreatingExperiment ;487 experimentCreationProgressBar.Visible = mode == DialogMode.CreatingExperiment || mode == DialogMode.PreparingExperiment; 486 488 } 487 489 … … 600 602 } 601 603 602 private IEnumerable<Dictionary<IValueParameter, I NamedItem>> GetMultipleChoiceConfigurations() {603 var configuration = new Dictionary<IValueParameter, I NamedItem>();604 var enumerators = new Dictionary<IValueParameter, IEnumerator<I NamedItem>>();604 private IEnumerable<Dictionary<IValueParameter, IItem>> GetMultipleChoiceConfigurations() { 605 var configuration = new Dictionary<IValueParameter, IItem>(); 606 var enumerators = new Dictionary<IValueParameter, IEnumerator<IItem>>(); 605 607 bool finished; 606 608 do { … … 620 622 if (!enumerators[p].MoveNext()) { 621 623 enumerators[p] = multipleChoiceParameters[p].GetEnumerator(); 624 enumerators[p].MoveNext(); 622 625 } else { 623 626 finished = false; … … 688 691 var localExperiment = new Experiment(); 689 692 693 int counter = 0, totalVariations = GetNumberOfVariations(); 690 694 if (instances.Count == 0) { 691 var variations = experimentCreationBackgroundWorker_CalculateParameterVariations(optimizer); 692 foreach (var v in variations) 693 AddOptimizer(v, localExperiment); 695 AddParameterVariations(localExperiment, ref counter, totalVariations); 694 696 experimentCreationBackgroundWorker.ReportProgress(100, string.Empty); 695 697 696 698 } else { 697 int counter = 0, totalVariations = GetNumberOfVariations();698 699 foreach (var provider in instances.Keys) { 699 700 foreach (var descriptor in instances[provider]) { … … 714 715 } 715 716 if (!failed) { 716 var variations = experimentCreationBackgroundWorker_CalculateParameterVariations(algorithm); 717 foreach (var v in variations) { 718 AddOptimizer(v, localExperiment); 719 counter++; 720 experimentCreationBackgroundWorker.ReportProgress((int)Math.Round(100.0 * counter / totalVariations), descriptor.Name); 721 } 722 } else experimentCreationBackgroundWorker.ReportProgress((int)Math.Round(100.0 * counter / totalVariations), "Loading failed (" + descriptor.Name + ")"); 723 } 724 } 725 } 726 if (localExperiment != null) localExperiment.Prepare(true); 717 AddParameterVariations(localExperiment, ref counter, totalVariations); 718 } else experimentCreationBackgroundWorker.ReportProgress((int)Math.Round((100.0 * counter) / totalVariations), "Loading failed (" + descriptor.Name + ")"); 719 } 720 } 721 } 722 if (localExperiment != null) { 723 // this step can take some time 724 SetMode(DialogMode.PreparingExperiment); 725 experimentCreationBackgroundWorker.ReportProgress(-1); 726 localExperiment.Prepare(true); 727 experimentCreationBackgroundWorker.ReportProgress(100); 728 } 727 729 Experiment = localExperiment; 730 } 731 732 private void AddParameterVariations(Experiment localExperiment, ref int counter, int totalVariations) { 733 var variations = experimentCreationBackgroundWorker_CalculateParameterVariations(optimizer); 734 foreach (var v in variations) { 735 AddOptimizer(v, localExperiment); 736 counter++; 737 experimentCreationBackgroundWorker.ReportProgress((int)Math.Round((100.0 * counter) / totalVariations), string.Empty); 738 } 728 739 } 729 740 … … 794 805 var originalEnumerator = ((IEnumerable<object>)((dynamic)m.Key).ValidValues).GetEnumerator(); 795 806 while (variantEnumerator.MoveNext() && originalEnumerator.MoveNext()) { 796 if (m.Value == (I NamedItem)originalEnumerator.Current) {807 if (m.Value == (IItem)originalEnumerator.Current) { 797 808 variantParam.Value = (dynamic)variantEnumerator.Current; 798 variant.Name += m.Key.Name + "=" + m.Value.Name + ", "; 809 if (m.Value is INamedItem) 810 variant.Name += m.Key.Name + "=" + ((INamedItem)m.Value).Name + ", "; 811 else variant.Name += m.Key.Name + "=" + m.Value.ToString() + ", "; 799 812 break; 800 813 } … … 816 829 817 830 private void experimentCreationBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { 818 experimentCreationProgressBar.Value = e.ProgressPercentage; 831 if (e.ProgressPercentage >= 0 && e.ProgressPercentage <= 100) { 832 experimentCreationProgressBar.Style = ProgressBarStyle.Continuous; 833 experimentCreationProgressBar.Value = e.ProgressPercentage; 834 } else { 835 experimentCreationProgressBar.Style = ProgressBarStyle.Marquee; 836 } 819 837 Application.DoEvents(); 820 838 }
Note: See TracChangeset
for help on using the changeset viewer.