Changeset 13814
- Timestamp:
- 04/28/16 15:58:06 (9 years ago)
- 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 35 35 this.combinationGroupSizeNumericUpDown = new System.Windows.Forms.NumericUpDown(); 36 36 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(); 38 41 ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).BeginInit(); 39 42 ((System.ComponentModel.ISupportInitialize)(this.combinationGroupSizeNumericUpDown)).BeginInit(); … … 44 47 this.repetitionsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 45 48 | 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); 47 50 this.repetitionsNumericUpDown.Maximum = new decimal(new int[] { 48 51 1000000, … … 56 59 0}); 57 60 this.repetitionsNumericUpDown.Name = "repetitionsNumericUpDown"; 58 this.repetitionsNumericUpDown.Size = new System.Drawing.Size( 185, 20);61 this.repetitionsNumericUpDown.Size = new System.Drawing.Size(240, 20); 59 62 this.repetitionsNumericUpDown.TabIndex = 4; 60 63 this.repetitionsNumericUpDown.ThousandsSeparator = true; … … 69 72 // 70 73 this.repetitionsLabel.AutoSize = true; 71 this.repetitionsLabel.Location = new System.Drawing.Point( 26, 14);74 this.repetitionsLabel.Location = new System.Drawing.Point(12, 12); 72 75 this.repetitionsLabel.Name = "repetitionsLabel"; 73 76 this.repetitionsLabel.Size = new System.Drawing.Size(63, 13); … … 79 82 this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 80 83 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); 82 85 this.cancelButton.Name = "cancelButton"; 83 86 this.cancelButton.Size = new System.Drawing.Size(75, 23); … … 85 88 this.cancelButton.Text = "&Cancel"; 86 89 this.cancelButton.UseVisualStyleBackColor = true; 90 this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); 87 91 // 88 92 // okButton 89 93 // 90 94 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); 93 97 this.okButton.Name = "okButton"; 94 98 this.okButton.Size = new System.Drawing.Size(75, 23); … … 102 106 this.combinationGroupSizeNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 103 107 | 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); 105 109 this.combinationGroupSizeNumericUpDown.Maximum = new decimal(new int[] { 106 110 1000000, … … 114 118 0}); 115 119 this.combinationGroupSizeNumericUpDown.Name = "combinationGroupSizeNumericUpDown"; 116 this.combinationGroupSizeNumericUpDown.Size = new System.Drawing.Size( 185, 20);120 this.combinationGroupSizeNumericUpDown.Size = new System.Drawing.Size(240, 20); 117 121 this.combinationGroupSizeNumericUpDown.TabIndex = 4; 118 122 this.combinationGroupSizeNumericUpDown.ThousandsSeparator = true; … … 129 133 // 130 134 this.label1.AutoSize = true; 131 this.label1.Location = new System.Drawing.Point( 26, 40);135 this.label1.Location = new System.Drawing.Point(12, 40); 132 136 this.label1.Name = "label1"; 133 137 this.label1.Size = new System.Drawing.Size(60, 13); … … 135 139 this.label1.Text = "&Group size:"; 136 140 // 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); 145 174 // 146 175 // CreateTargetVariationExperimentDialog … … 150 179 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 151 180 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); 153 185 this.Controls.Add(this.okButton); 154 186 this.Controls.Add(this.cancelButton); 155 this.Controls.Add(this.warningLabel);156 187 this.Controls.Add(this.label1); 157 188 this.Controls.Add(this.repetitionsLabel); … … 159 190 this.Controls.Add(this.repetitionsNumericUpDown); 160 191 this.Name = "CreateTargetVariationExperimentDialog"; 192 this.ShowIcon = false; 161 193 this.Text = "Create Target Variation Experiment"; 194 this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CreateTargetVariationExperimentDialog_FormClosing); 162 195 ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).EndInit(); 163 196 ((System.ComponentModel.ISupportInitialize)(this.combinationGroupSizeNumericUpDown)).EndInit(); … … 175 208 private System.Windows.Forms.NumericUpDown combinationGroupSizeNumericUpDown; 176 209 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; 178 214 } 179 215 } -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.cs
r13806 r13814 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 32 33 public partial class CreateTargetVariationExperimentDialog : Form { 33 34 public Experiment Experiment { get; private set; } 34 private int repetitions;35 private int combinationGroupSize;36 35 37 36 public CreateTargetVariationExperimentDialog() : this(null) { } 38 37 public CreateTargetVariationExperimentDialog(IAlgorithm alg) { 39 38 InitializeComponent(); 40 repetitions = (int)repetitionsNumericUpDown.Value;41 combinationGroupSize = (int)combinationGroupSizeNumericUpDown.Value;42 39 43 40 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(); 48 46 49 47 Experiment = null; … … 51 49 } 52 50 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) { 56 52 if (algorithm == null) 57 53 throw new ArgumentNullException("The algorithm parameter must be a valid IAlgorithm instance."); … … 61 57 62 58 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) { 66 61 var inputs = variables.Where(x => x != target).ToList(); 67 if (combinationGroupSize > inputs.Count)68 combinationGroupSize = inputs.Count;69 70 62 var combinations = inputs.Combinations(combinationGroupSize); 71 63 … … 81 73 SetTargetName(problemData, target); 82 74 83 var batch run = new BatchRun(string.Format("Batchrun {0}", i + 1)) {75 var batchRun = new BatchRun(string.Format("Batchrun {0}", count++)) { 84 76 Repetitions = repetitions, 85 77 Optimizer = alg 86 78 }; 87 88 experiment.Optimizers.Add(batchrun); 79 yield return batchRun; 89 80 } 90 81 } 91 return experiment;92 82 } 93 83 … … 117 107 118 108 #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(); 126 121 } 127 122 … … 132 127 var problem = algorithm.Problem as IDataAnalysisProblem; 133 128 if (problem == null) return; 134 var inputCount = problem.ProblemData.AllowedInputVariables.Count() ;129 var inputCount = problem.ProblemData.AllowedInputVariables.Count() - 1; 135 130 if (combinationGroupSizeNumericUpDown.Value > inputCount) 136 131 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;143 132 } 144 133 … … 146 135 if (combinationGroupSizeNumericUpDown.Text == string.Empty) 147 136 combinationGroupSizeNumericUpDown.Text = combinationGroupSizeNumericUpDown.Value.ToString(); 148 combinationGroupSize = (int)combinationGroupSizeNumericUpDown.Value; 137 149 138 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 150 139 if (activeView == null) return; 151 140 var algorithm = (IAlgorithm)activeView.Content; 152 141 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(); 155 199 } 156 200 #endregion
Note: See TracChangeset
for help on using the changeset viewer.