Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13814


Ignore:
Timestamp:
04/28/16 15:58:06 (9 years ago)
Author:
bburlacu
Message:

#2288: Improve the CreateTargetVariationExperimentDialog

Location:
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.Designer.cs

    r13806 r13814  
    3535      this.combinationGroupSizeNumericUpDown = new System.Windows.Forms.NumericUpDown();
    3636      this.label1 = new System.Windows.Forms.Label();
    37       this.warningLabel = new System.Windows.Forms.Label();
     37      this.combinationsLabel = new System.Windows.Forms.Label();
     38      this.combinationCountLabel = new System.Windows.Forms.Label();
     39      this.progressBar = new System.Windows.Forms.ProgressBar();
     40      this.worker = new System.ComponentModel.BackgroundWorker();
    3841      ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).BeginInit();
    3942      ((System.ComponentModel.ISupportInitialize)(this.combinationGroupSizeNumericUpDown)).BeginInit();
     
    4447      this.repetitionsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    4548            | System.Windows.Forms.AnchorStyles.Right)));
    46       this.repetitionsNumericUpDown.Location = new System.Drawing.Point(128, 12);
     49      this.repetitionsNumericUpDown.Location = new System.Drawing.Point(81, 12);
    4750      this.repetitionsNumericUpDown.Maximum = new decimal(new int[] {
    4851            1000000,
     
    5659            0});
    5760      this.repetitionsNumericUpDown.Name = "repetitionsNumericUpDown";
    58       this.repetitionsNumericUpDown.Size = new System.Drawing.Size(185, 20);
     61      this.repetitionsNumericUpDown.Size = new System.Drawing.Size(240, 20);
    5962      this.repetitionsNumericUpDown.TabIndex = 4;
    6063      this.repetitionsNumericUpDown.ThousandsSeparator = true;
     
    6972      //
    7073      this.repetitionsLabel.AutoSize = true;
    71       this.repetitionsLabel.Location = new System.Drawing.Point(26, 14);
     74      this.repetitionsLabel.Location = new System.Drawing.Point(12, 12);
    7275      this.repetitionsLabel.Name = "repetitionsLabel";
    7376      this.repetitionsLabel.Size = new System.Drawing.Size(63, 13);
     
    7982      this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    8083      this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    81       this.cancelButton.Location = new System.Drawing.Point(177, 130);
     84      this.cancelButton.Location = new System.Drawing.Point(246, 66);
    8285      this.cancelButton.Name = "cancelButton";
    8386      this.cancelButton.Size = new System.Drawing.Size(75, 23);
     
    8588      this.cancelButton.Text = "&Cancel";
    8689      this.cancelButton.UseVisualStyleBackColor = true;
     90      this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
    8791      //
    8892      // okButton
    8993      //
    9094      this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    91       this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    92       this.okButton.Location = new System.Drawing.Point(80, 130);
     95      this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
     96      this.okButton.Location = new System.Drawing.Point(165, 66);
    9397      this.okButton.Name = "okButton";
    9498      this.okButton.Size = new System.Drawing.Size(75, 23);
     
    102106      this.combinationGroupSizeNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    103107            | System.Windows.Forms.AnchorStyles.Right)));
    104       this.combinationGroupSizeNumericUpDown.Location = new System.Drawing.Point(128, 38);
     108      this.combinationGroupSizeNumericUpDown.Location = new System.Drawing.Point(81, 38);
    105109      this.combinationGroupSizeNumericUpDown.Maximum = new decimal(new int[] {
    106110            1000000,
     
    114118            0});
    115119      this.combinationGroupSizeNumericUpDown.Name = "combinationGroupSizeNumericUpDown";
    116       this.combinationGroupSizeNumericUpDown.Size = new System.Drawing.Size(185, 20);
     120      this.combinationGroupSizeNumericUpDown.Size = new System.Drawing.Size(240, 20);
    117121      this.combinationGroupSizeNumericUpDown.TabIndex = 4;
    118122      this.combinationGroupSizeNumericUpDown.ThousandsSeparator = true;
     
    129133      //
    130134      this.label1.AutoSize = true;
    131       this.label1.Location = new System.Drawing.Point(26, 40);
     135      this.label1.Location = new System.Drawing.Point(12, 40);
    132136      this.label1.Name = "label1";
    133137      this.label1.Size = new System.Drawing.Size(60, 13);
     
    135139      this.label1.Text = "&Group size:";
    136140      //
    137       // warningLabel
    138       //
    139       this.warningLabel.ForeColor = System.Drawing.Color.Red;
    140       this.warningLabel.Location = new System.Drawing.Point(26, 67);
    141       this.warningLabel.Name = "warningLabel";
    142       this.warningLabel.Size = new System.Drawing.Size(287, 50);
    143       this.warningLabel.TabIndex = 5;
    144       this.warningLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
     141      // combinationsLabel
     142      //
     143      this.combinationsLabel.AutoSize = true;
     144      this.combinationsLabel.Location = new System.Drawing.Point(12, 71);
     145      this.combinationsLabel.Name = "combinationsLabel";
     146      this.combinationsLabel.Size = new System.Drawing.Size(73, 13);
     147      this.combinationsLabel.TabIndex = 11;
     148      this.combinationsLabel.Text = "Combinations:";
     149      //
     150      // combinationCountLabel
     151      //
     152      this.combinationCountLabel.AutoSize = true;
     153      this.combinationCountLabel.Location = new System.Drawing.Point(91, 71);
     154      this.combinationCountLabel.Name = "combinationCountLabel";
     155      this.combinationCountLabel.Size = new System.Drawing.Size(0, 13);
     156      this.combinationCountLabel.TabIndex = 12;
     157      //
     158      // progressBar
     159      //
     160      this.progressBar.Location = new System.Drawing.Point(15, 66);
     161      this.progressBar.Name = "progressBar";
     162      this.progressBar.Size = new System.Drawing.Size(144, 23);
     163      this.progressBar.Step = 1;
     164      this.progressBar.TabIndex = 13;
     165      this.progressBar.Visible = false;
     166      //
     167      // worker
     168      //
     169      this.worker.WorkerReportsProgress = true;
     170      this.worker.WorkerSupportsCancellation = true;
     171      this.worker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.worker_DoWork);
     172      this.worker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.worker_ProgressChanged);
     173      this.worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.worker_RunWorkerCompleted);
    145174      //
    146175      // CreateTargetVariationExperimentDialog
     
    150179      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    151180      this.CancelButton = this.cancelButton;
    152       this.ClientSize = new System.Drawing.Size(349, 165);
     181      this.ClientSize = new System.Drawing.Size(333, 101);
     182      this.Controls.Add(this.progressBar);
     183      this.Controls.Add(this.combinationCountLabel);
     184      this.Controls.Add(this.combinationsLabel);
    153185      this.Controls.Add(this.okButton);
    154186      this.Controls.Add(this.cancelButton);
    155       this.Controls.Add(this.warningLabel);
    156187      this.Controls.Add(this.label1);
    157188      this.Controls.Add(this.repetitionsLabel);
     
    159190      this.Controls.Add(this.repetitionsNumericUpDown);
    160191      this.Name = "CreateTargetVariationExperimentDialog";
     192      this.ShowIcon = false;
    161193      this.Text = "Create Target Variation Experiment";
     194      this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CreateTargetVariationExperimentDialog_FormClosing);
    162195      ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).EndInit();
    163196      ((System.ComponentModel.ISupportInitialize)(this.combinationGroupSizeNumericUpDown)).EndInit();
     
    175208    private System.Windows.Forms.NumericUpDown combinationGroupSizeNumericUpDown;
    176209    private System.Windows.Forms.Label label1;
    177     private System.Windows.Forms.Label warningLabel;
     210    private System.Windows.Forms.Label combinationsLabel;
     211    private System.Windows.Forms.Label combinationCountLabel;
     212    private System.Windows.Forms.ProgressBar progressBar;
     213    private System.ComponentModel.BackgroundWorker worker;
    178214  }
    179215}
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.cs

    r13806 r13814  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    3233  public partial class CreateTargetVariationExperimentDialog : Form {
    3334    public Experiment Experiment { get; private set; }
    34     private int repetitions;
    35     private int combinationGroupSize;
    3635
    3736    public CreateTargetVariationExperimentDialog() : this(null) { }
    3837    public CreateTargetVariationExperimentDialog(IAlgorithm alg) {
    3938      InitializeComponent();
    40       repetitions = (int)repetitionsNumericUpDown.Value;
    41       combinationGroupSize = (int)combinationGroupSizeNumericUpDown.Value;
    4239
    4340      var problem = alg.Problem as IDataAnalysisProblem;
    44       var inputCount = problem.ProblemData.AllowedInputVariables.Count();
    45       if (combinationGroupSize > inputCount)
    46         combinationGroupSize = inputCount;
    47       warningLabel.Text = string.Format("Warning: this will create {0} combinations.", EnumerableExtensions.BinomialCoefficient(inputCount, combinationGroupSize));
     41      var inputCount = problem.ProblemData.AllowedInputVariables.Count() - 1; // -1 because one will be the target
     42      if (combinationGroupSizeNumericUpDown.Value > inputCount)
     43        combinationGroupSizeNumericUpDown.Value = inputCount;
     44      var combinationGroupSize = (int)combinationGroupSizeNumericUpDown.Value;
     45      combinationCountLabel.Text = ((inputCount + 1) * EnumerableExtensions.BinomialCoefficient(inputCount, combinationGroupSize)).ToString();
    4846
    4947      Experiment = null;
     
    5149    }
    5250
    53     public Experiment CreateVariableCombinations(IAlgorithm algorithm) {
    54       var experiment = new Experiment("Target Variation Experiment");
    55 
     51    public static IEnumerable<IOptimizer> CreateVariableCombinations(IAlgorithm algorithm, int combinationGroupSize, int repetitions) {
    5652      if (algorithm == null)
    5753        throw new ArgumentNullException("The algorithm parameter must be a valid IAlgorithm instance.");
     
    6157
    6258      var variables = problemData.AllowedInputVariables.ToList();
    63 
    64       for (int i = 0; i < variables.Count; i++) {
    65         var target = variables[i];
     59      int count = 1;
     60      foreach (var target in variables) {
    6661        var inputs = variables.Where(x => x != target).ToList();
    67         if (combinationGroupSize > inputs.Count)
    68           combinationGroupSize = inputs.Count;
    69 
    7062        var combinations = inputs.Combinations(combinationGroupSize);
    7163
     
    8173          SetTargetName(problemData, target);
    8274
    83           var batchrun = new BatchRun(string.Format("Batchrun {0}", i + 1)) {
     75          var batchRun = new BatchRun(string.Format("Batchrun {0}", count++)) {
    8476            Repetitions = repetitions,
    8577            Optimizer = alg
    8678          };
    87 
    88           experiment.Optimizers.Add(batchrun);
     79          yield return batchRun;
    8980        }
    9081      }
    91       return experiment;
    9282    }
    9383
     
    117107
    118108    #region events
    119     private void okButton_Click(object sender, EventArgs e) {
    120       IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    121       if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IAlgorithm) && !activeView.Locked) {
    122         Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content);
    123         DialogResult = DialogResult.OK;
    124         Close();
    125       }
     109    private void CreateTargetVariationExperimentDialog_FormClosing(object sender, FormClosingEventArgs e) {
     110      if (worker.IsBusy) {
     111        if (DialogResult != DialogResult.OK) {
     112          if (worker.IsBusy) worker.CancelAsync();
     113        }
     114        e.Cancel = true;
     115      }
     116    }
     117
     118    private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
     119      if (repetitionsNumericUpDown.Text == string.Empty)
     120        repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
    126121    }
    127122
     
    132127      var problem = algorithm.Problem as IDataAnalysisProblem;
    133128      if (problem == null) return;
    134       var inputCount = problem.ProblemData.AllowedInputVariables.Count();
     129      var inputCount = problem.ProblemData.AllowedInputVariables.Count() - 1;
    135130      if (combinationGroupSizeNumericUpDown.Value > inputCount)
    136131        combinationGroupSizeNumericUpDown.Value = inputCount;
    137     }
    138 
    139     private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
    140       if (repetitionsNumericUpDown.Text == string.Empty)
    141         repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
    142       repetitions = (int)repetitionsNumericUpDown.Value;
    143132    }
    144133
     
    146135      if (combinationGroupSizeNumericUpDown.Text == string.Empty)
    147136        combinationGroupSizeNumericUpDown.Text = combinationGroupSizeNumericUpDown.Value.ToString();
    148       combinationGroupSize = (int)combinationGroupSizeNumericUpDown.Value;
     137
    149138      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    150139      if (activeView == null) return;
    151140      var algorithm = (IAlgorithm)activeView.Content;
    152141      var problem = (IDataAnalysisProblem)algorithm.Problem;
    153       var inputCount = problem.ProblemData.AllowedInputVariables.Count();
    154       warningLabel.Text = string.Format("Warning: this will create {0} combinations.", EnumerableExtensions.BinomialCoefficient(inputCount, combinationGroupSize));
     142      var inputCount = problem.ProblemData.AllowedInputVariables.Count() - 1;
     143      if (combinationGroupSizeNumericUpDown.Value > inputCount)
     144        combinationGroupSizeNumericUpDown.Value = inputCount;
     145      combinationCountLabel.Text = ((inputCount + 1) * EnumerableExtensions.BinomialCoefficient(inputCount, (int)combinationGroupSizeNumericUpDown.Value)).ToString();
     146    }
     147
     148    private void worker_DoWork(object sender, DoWorkEventArgs e) {
     149      IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
     150      var algorithm = (IAlgorithm)activeView.Content;
     151      var problem = (IDataAnalysisProblem)algorithm.Problem;
     152      var experiment = new Experiment("Target Variation Experiment");
     153      var repetitions = (int)repetitionsNumericUpDown.Value;
     154      var inputCount = problem.ProblemData.AllowedInputVariables.Count() - 1;
     155      var combinationGroupSize = (int)combinationGroupSizeNumericUpDown.Value;
     156      var totalNumberOfCombinations = (inputCount + 1) * EnumerableExtensions.BinomialCoefficient(inputCount, combinationGroupSize);
     157      int progress = 0;
     158      foreach (var optimizer in CreateVariableCombinations(algorithm, combinationGroupSize, repetitions)) {
     159        experiment.Optimizers.Add(optimizer);
     160        progress++;
     161        worker.ReportProgress((int)Math.Round(100d * progress / totalNumberOfCombinations));
     162      }
     163      Experiment = experiment;
     164    }
     165
     166    private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
     167      if (InvokeRequired) {
     168        Invoke((Action<int>)UpdateProgress, e.ProgressPercentage);
     169      } else {
     170        UpdateProgress(e.ProgressPercentage);
     171      }
     172    }
     173
     174    private void UpdateProgress(int percentage) {
     175      progressBar.Value = percentage;
     176    }
     177
     178    private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
     179      if (e.Cancelled || e.Error != null)
     180        return;
     181      DialogResult = DialogResult.OK;
     182      Close();
     183    }
     184
     185    private void okButton_Click(object sender, EventArgs args) {
     186      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
     187      if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IAlgorithm) && !activeView.Locked) {
     188        okButton.Enabled = false;
     189        combinationsLabel.Visible = false;
     190        combinationCountLabel.Visible = false;
     191        progressBar.Visible = true;
     192        worker.RunWorkerAsync();
     193      }
     194    }
     195
     196    private void cancelButton_Click(object sender, EventArgs e) {
     197      if (worker.IsBusy)
     198        worker.CancelAsync();
    155199    }
    156200    #endregion
Note: See TracChangeset for help on using the changeset viewer.