Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7974 for trunk


Ignore:
Timestamp:
06/08/12 20:33:00 (12 years ago)
Author:
abeham
Message:

#1851:

  • fixed problem with choices that are not INamedItem
  • fixed a bug in the enumeration of choice parameters
  • improved UI feedback
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs

    r7957 r7974  
    3636namespace HeuristicLab.Optimizer {
    3737  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 };
    3939
    4040    private IOptimizer optimizer;
     
    5959    private Dictionary<IValueParameter, Tuple<double, double, double>> doubleParameters;
    6060    private HashSet<IValueParameter> boolParameters;
    61     private Dictionary<IValueParameter, HashSet<INamedItem>> multipleChoiceParameters;
     61    private Dictionary<IValueParameter, HashSet<IItem>> multipleChoiceParameters;
    6262
    6363    private StringBuilder failedInstances;
     
    8080      doubleParameters = new Dictionary<IValueParameter, Tuple<double, double, double>>();
    8181      boolParameters = new HashSet<IValueParameter>();
    82       multipleChoiceParameters = new Dictionary<IValueParameter, HashSet<INamedItem>>();
     82      multipleChoiceParameters = new Dictionary<IValueParameter, HashSet<IItem>>();
    8383    }
    8484
     
    119119      if (isConstrainedValueParameter) {
    120120        if (e.Item.Checked) {
    121           multipleChoiceParameters.Add(parameter, new HashSet<INamedItem>());
     121          multipleChoiceParameters.Add(parameter, new HashSet<IItem>());
    122122        } else {
    123123          multipleChoiceParameters.Remove(parameter);
     
    184184          choicesListView.Items.Add(new ListViewItem(choice.ToString()) {
    185185            Tag = choice,
    186             Checked = multipleChoiceParameters[parameter].Contains((INamedItem)choice)
     186            Checked = multipleChoiceParameters[parameter].Contains(choice)
    187187          });
    188188        }
     
    223223      var parameter = (IValueParameter)choicesListView.Tag;
    224224      if (e.Item.Checked) {
    225         multipleChoiceParameters[parameter].Add((INamedItem)e.Item.Tag);
    226       } else multipleChoiceParameters[parameter].Remove((INamedItem)e.Item.Tag);
     225        multipleChoiceParameters[parameter].Add((IItem)e.Item.Tag);
     226      } else multipleChoiceParameters[parameter].Remove((IItem)e.Item.Tag);
    227227
    228228      UpdateVariationsLabel();
     
    475475      createBatchRunCheckBox.Enabled = mode == DialogMode.Normal;
    476476      repetitionsNumericUpDown.Enabled = mode == DialogMode.Normal;
     477      parametersSplitContainer.Enabled = mode == DialogMode.Normal || mode == DialogMode.DiscoveringInstances;
    477478      selectAllCheckBox.Enabled = mode == DialogMode.Normal;
    478479      selectNoneCheckBox.Enabled = mode == DialogMode.Normal;
    479480      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;
    481482      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;
    483485      instanceDiscoveryProgressLabel.Visible = mode == DialogMode.DiscoveringInstances;
    484486      instanceDiscoveryProgressBar.Visible = mode == DialogMode.DiscoveringInstances;
    485       experimentCreationProgressBar.Visible = mode == DialogMode.CreatingExperiment;
     487      experimentCreationProgressBar.Visible = mode == DialogMode.CreatingExperiment || mode == DialogMode.PreparingExperiment;
    486488    }
    487489
     
    600602    }
    601603
    602     private IEnumerable<Dictionary<IValueParameter, INamedItem>> GetMultipleChoiceConfigurations() {
    603       var configuration = new Dictionary<IValueParameter, INamedItem>();
    604       var enumerators = new Dictionary<IValueParameter, IEnumerator<INamedItem>>();
     604    private IEnumerable<Dictionary<IValueParameter, IItem>> GetMultipleChoiceConfigurations() {
     605      var configuration = new Dictionary<IValueParameter, IItem>();
     606      var enumerators = new Dictionary<IValueParameter, IEnumerator<IItem>>();
    605607      bool finished;
    606608      do {
     
    620622          if (!enumerators[p].MoveNext()) {
    621623            enumerators[p] = multipleChoiceParameters[p].GetEnumerator();
     624            enumerators[p].MoveNext();
    622625          } else {
    623626            finished = false;
     
    688691      var localExperiment = new Experiment();
    689692
     693      int counter = 0, totalVariations = GetNumberOfVariations();
    690694      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);
    694696        experimentCreationBackgroundWorker.ReportProgress(100, string.Empty);
    695697
    696698      } else {
    697         int counter = 0, totalVariations = GetNumberOfVariations();
    698699        foreach (var provider in instances.Keys) {
    699700          foreach (var descriptor in instances[provider]) {
     
    714715            }
    715716            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      }
    727729      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      }
    728739    }
    729740
     
    794805            var originalEnumerator = ((IEnumerable<object>)((dynamic)m.Key).ValidValues).GetEnumerator();
    795806            while (variantEnumerator.MoveNext() && originalEnumerator.MoveNext()) {
    796               if (m.Value == (INamedItem)originalEnumerator.Current) {
     807              if (m.Value == (IItem)originalEnumerator.Current) {
    797808                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() + ", ";
    799812                break;
    800813              }
     
    816829
    817830    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      }
    819837      Application.DoEvents();
    820838    }
Note: See TracChangeset for help on using the changeset viewer.