Changeset 17500
- Timestamp:
- 04/06/20 17:55:24 (5 years ago)
- Location:
- stable
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 17276,17426,17430,17488
- Property svn:mergeinfo changed
-
stable/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs
r17181 r17500 25 25 namespace HeuristicLab.MainForm.WindowsForms { 26 26 internal sealed partial class ProgressView : UserControl { 27 private readonly Control control; 28 public Control Control { 29 get { return control; } 30 } 31 32 private readonly IProgress content; 33 public IProgress Content { 34 get { return content; } 35 } 36 37 public ProgressView(Control control, IProgress content) 27 public Control TargetControl { get; } 28 public IProgress Content { get; } 29 30 public ProgressView(Control targetControl, IProgress content) 38 31 : base() { 39 if ( control == null) throw new ArgumentNullException("control");40 if ( control.Parent == null) throw new InvalidOperationException("A Progress can only be shown on controls that have a Parent-control. Therefore, Dialogs and Forms cannot have an associated ProgressView.");41 if (content == null) throw new ArgumentNullException( "content");32 if (targetControl == null) throw new ArgumentNullException(nameof(targetControl)); 33 if (targetControl.Parent == null) throw new InvalidOperationException("A Progress can only be shown on controls that have a Parent-control. Therefore, Dialogs and Forms cannot have an associated ProgressView."); 34 if (content == null) throw new ArgumentNullException(nameof(content)); 42 35 InitializeComponent(); 43 36 44 this. control = control;45 this. content = content;37 this.TargetControl = targetControl; 38 this.Content = content; 46 39 47 40 if (content.ProgressState != ProgressState.Finished) … … 52 45 protected override void Dispose(bool disposing) { 53 46 DeregisterContentEvents(); 54 HideProgress(); 55 56 if (disposing && (components != null)) { 47 48 if (!TargetControl.IsDisposed) 49 HideProgress(); 50 51 if (disposing && components != null) { 57 52 components.Dispose(); 58 53 } … … 101 96 102 97 private void ShowProgress() { 103 if ( Control.InvokeRequired) {104 Control.Invoke((Action)ShowProgress);98 if (TargetControl.InvokeRequired) { 99 TargetControl.Invoke((Action)ShowProgress); 105 100 return; 106 101 } 107 102 if (Parent != null) return; 108 103 109 Left = ( Control.ClientRectangle.Width / 2) - (Width / 2);110 Top = ( Control.ClientRectangle.Height / 2) - (Height / 2);104 Left = (TargetControl.ClientRectangle.Width / 2) - (Width / 2); 105 Top = (TargetControl.ClientRectangle.Height / 2) - (Height / 2); 111 106 Anchor = AnchorStyles.None; 112 107 … … 115 110 UpdateButtonsState(); 116 111 117 Control.SuspendRepaint(); 118 Control.Enabled = false; 119 Parent = Control.Parent; 112 TargetControl.SuspendRepaint(); 113 TargetControl.Enabled = false; 114 RegisterTargetControlEvents(); 115 Parent = TargetControl.Parent; 120 116 BringToFront(); 121 Control.ResumeRepaint(true);117 TargetControl.ResumeRepaint(true); 122 118 Visible = true; 123 119 } 124 120 125 121 private void HideProgress() { 126 if ( Control.InvokeRequired) {127 Control.Invoke((Action)HideProgress);122 if (TargetControl.InvokeRequired) { 123 TargetControl.Invoke((Action)HideProgress); 128 124 return; 129 125 } … … 131 127 132 128 Visible = false; 133 Control.SuspendRepaint();134 Control.Enabled = true;135 Control.ResumeRepaint(true);129 TargetControl.SuspendRepaint(); 130 TargetControl.Enabled = true; 131 DeregisterTargetControlEvents(); 136 132 Parent = null; 133 TargetControl.ResumeRepaint(TargetControl.Visible); 134 } 135 136 137 private void RegisterTargetControlEvents() { 138 TargetControl.Disposed += TargetControl_Disposed; 139 TargetControl.VisibleChanged += TargetControl_VisibleChanged; 140 TargetControl.ParentChanged += TargetControl_ParentChanged; 141 } 142 143 private void DeregisterTargetControlEvents() { 144 TargetControl.Disposed -= TargetControl_Disposed; 145 TargetControl.VisibleChanged -= TargetControl_VisibleChanged; 146 TargetControl.ParentChanged -= TargetControl_ParentChanged; 147 } 148 149 private void TargetControl_Disposed(object sender, EventArgs e) { 150 Dispose(); 151 } 152 private void TargetControl_VisibleChanged(object sender, EventArgs e) { 153 Visible = TargetControl.Visible; 154 } 155 private void TargetControl_ParentChanged(object sender, EventArgs e) { 156 Parent = TargetControl.Parent; 137 157 } 138 158 139 159 private void UpdateProgressState() { 140 if ( Control.InvokeRequired) {141 Control.Invoke((Action)UpdateProgressState);160 if (TargetControl.InvokeRequired) { 161 TargetControl.Invoke((Action)UpdateProgressState); 142 162 return; 143 163 } … … 150 170 151 171 private void UpdateProgressMessage() { 152 if ( Control.InvokeRequired) {153 Control.Invoke((Action)UpdateProgressMessage);154 return; 155 } 156 157 messageLabel.Text = content.Message;172 if (TargetControl.InvokeRequired) { 173 TargetControl.Invoke((Action)UpdateProgressMessage); 174 return; 175 } 176 177 messageLabel.Text = Content.Message; 158 178 } 159 179 … … 167 187 case ProgressMode.Determinate: 168 188 progressBar.Style = ProgressBarStyle.Continuous; 169 progressBar.Value = (int)Math.Round(progressBar.Minimum + content.ProgressValue * (progressBar.Maximum - progressBar.Minimum));189 progressBar.Value = (int)Math.Round(progressBar.Minimum + Content.ProgressValue * (progressBar.Maximum - progressBar.Minimum)); 170 190 break; 171 191 case ProgressMode.Indeterminate: … … 174 194 break; 175 195 default: 176 throw new NotImplementedException($"Invalid Progress Mode: { content.ProgressMode}");196 throw new NotImplementedException($"Invalid Progress Mode: {Content.ProgressMode}"); 177 197 } 178 198 } 179 199 180 200 private void UpdateButtonsState() { 181 if ( Control.InvokeRequired) {182 Control.Invoke((Action)UpdateButtonsState);201 if (TargetControl.InvokeRequired) { 202 TargetControl.Invoke((Action)UpdateButtonsState); 183 203 return; 184 204 } 185 205 186 206 stopButton.Visible = Content.CanBeStopped; 187 stopButton.Enabled = Content.CanBeStopped && content.ProgressState == ProgressState.Started;207 stopButton.Enabled = Content.CanBeStopped && Content.ProgressState == ProgressState.Started; 188 208 189 209 cancelButton.Visible = Content.CanBeCanceled; 190 cancelButton.Enabled = Content.CanBeCanceled && content.ProgressState == ProgressState.Started;210 cancelButton.Enabled = Content.CanBeCanceled && Content.ProgressState == ProgressState.Started; 191 211 } 192 212 -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views merged: 17488
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicClassificationSolutionView.Designer.cs
r17181 r17500 73 73 this.btnSimplify.UseVisualStyleBackColor = true; 74 74 this.btnSimplify.Click += new System.EventHandler(this.btn_SimplifyModel_Click); 75 this.toolTip.SetToolTip(this.btnSimplify, " Simplify solution");75 this.toolTip.SetToolTip(this.btnSimplify, "Opens a new view for model simplification and manipulation."); 76 76 // 77 77 // exportButton -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionView.Designer.cs
r17181 r17500 73 73 this.btnSimplify.UseVisualStyleBackColor = true; 74 74 this.btnSimplify.Click += new System.EventHandler(this.btn_SimplifyModel_Click); 75 this.toolTip.SetToolTip(this.btnSimplify, " Simplify solution");75 this.toolTip.SetToolTip(this.btnSimplify, "Opens a new view for model simplification and manipulation."); 76 76 // 77 77 // exportButton -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views merged: 17430,17488
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r17499 r17500 53 53 protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, IProgress progress) { 54 54 const int constOptIterations = 50; 55 const int maxRepetitions = 1000; 55 const int maxRepetitions = 100; 56 const double minimumImprovement = 1e-10; 56 57 var regressionProblemData = Content.ProblemData; 57 58 var model = Content.Model; 58 59 progress.CanBeStopped = true; 59 var prevResult = 0.0;60 double prevResult = 0.0, improvement = 0.0; 60 61 var result = 0.0; 61 62 int reps = 0; … … 66 67 applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit, 67 68 iterationCallback: (args, func, obj) => { 68 double newProgressValue = progress.ProgressValue + 1.0 / (constOptIterations + 2); // (maxIterations + 2) iterations are reported69 double newProgressValue = progress.ProgressValue + (1.0 / (constOptIterations + 2) / maxRepetitions); // (constOptIterations + 2) iterations are reported 69 70 progress.ProgressValue = Math.Min(newProgressValue, 1.0); 70 71 }); 71 72 reps++; 72 } while (prevResult < result && reps < maxRepetitions && 73 improvement = result - prevResult; 74 } while (improvement > minimumImprovement && reps < maxRepetitions && 73 75 progress.ProgressState != ProgressState.StopRequested && 74 76 progress.ProgressState != ProgressState.CancelRequested); -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.Designer.cs
r17181 r17500 75 75 this.btnSimplify.UseVisualStyleBackColor = true; 76 76 this.btnSimplify.Click += new System.EventHandler(this.btn_SimplifyModel_Click); 77 this.toolTip.SetToolTip(this.btnSimplify, " Simplify solution");77 this.toolTip.SetToolTip(this.btnSimplify, "Opens a new view for model simplification and manipulation."); 78 78 // 79 79 // exportButton -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views merged: 17488
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/SymbolicTimeSeriesPrognosisSolutionView.Designer.cs
r17181 r17500 70 70 this.btnSimplify.UseVisualStyleBackColor = true; 71 71 this.btnSimplify.Click += new System.EventHandler(this.btn_SimplifyModel_Click); 72 this.toolTip.SetToolTip(this.btnSimplify, " Simplify solution");72 this.toolTip.SetToolTip(this.btnSimplify, "Opens a new view for model simplification and manipulation."); 73 73 // 74 74 // SymbolicTimeSeriesPrognosisSolutionView -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Views merged: 17430
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs
r17181 r17500 57 57 this.grpViewHost = new System.Windows.Forms.GroupBox(); 58 58 this.treeChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.InteractiveSymbolicExpressionTreeChart(); 59 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 59 60 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 60 61 this.splitContainer.Panel1.SuspendLayout(); … … 148 149 this.btnSimplify.Text = "Simplify"; 149 150 this.btnSimplify.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; 151 this.toolTip.SetToolTip(this.btnSimplify, "Simplifies the model structure based on mathematical simplification rules."); 150 152 this.btnSimplify.UseVisualStyleBackColor = true; 151 153 this.btnSimplify.Click += new System.EventHandler(this.btnSimplify_Click); … … 162 164 this.btnOptimizeConstants.Text = "Optimize"; 163 165 this.btnOptimizeConstants.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; 166 this.toolTip.SetToolTip(this.btnOptimizeConstants, "Optimizes the numerical constants of the model. \r\nIf the algorithm converges, opt" + 167 "imization is stopped."); 164 168 this.btnOptimizeConstants.UseVisualStyleBackColor = true; 165 169 this.btnOptimizeConstants.Click += new System.EventHandler(this.btnOptimizeConstants_Click); … … 226 230 protected System.Windows.Forms.Button btnOptimizeConstants; 227 231 private System.Windows.Forms.Label treeStatusValue; 232 private System.Windows.Forms.ToolTip toolTip; 228 233 } 229 234 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r17499 r17500 193 193 194 194 progress.Start("Calculate Impact and Replacement Values ..."); 195 cancellationTokenSource = new CancellationTokenSource(); 195 196 progress.CanBeStopped = true; 196 cancellationTokenSource = new CancellationTokenSource();197 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree));198 197 try { 199 await Task.Delay(500, cancellationTokenSource.Token); // wait for progressbar to finish animation 200 } catch (OperationCanceledException) { } 201 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); 202 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) { 203 foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value); 204 } 205 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 206 progress.Finish(); 198 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 199 try { 200 await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation 201 } catch (OperationCanceledException) { } 202 203 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); 204 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) { 205 foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value); 206 } 207 208 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 209 } finally { 210 progress.Finish(); 211 } 212 207 213 progress.CanBeStopped = false; 208 214 PaintNodeImpacts(); … … 314 320 private async void btnOptimizeConstants_Click(object sender, EventArgs e) { 315 321 progress.Start("Optimizing Constants ..."); 322 cancellationTokenSource = new CancellationTokenSource(); 323 progress.CanBeStopped = true; 316 324 try { 317 325 var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone(); 326 318 327 var newTree = await Task.Run(() => OptimizeConstants(tree, progress)); 319 await Task.Delay(500); // wait for progressbar to finish animation 320 UpdateModel(newTree); 321 } finally { 328 try { 329 await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation 330 } catch (OperationCanceledException) { } 331 UpdateModel(newTree); // triggers progress.Finish after calculating the node impacts when model is changed 332 } catch { 322 333 progress.Finish(); 323 334 } -
stable/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Views merged: 17276,17426
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4 merged: 17276,17426
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.Designer.cs
r17181 r17500 192 192 this.Name = "ClassificationSolutionVariableImpactsView"; 193 193 this.Size = new System.Drawing.Size(712, 365); 194 this.VisibleChanged += new System.EventHandler(this.ClassificationSolutionVariableImpactsView_VisibleChanged);195 194 this.ResumeLayout(false); 196 195 this.PerformLayout(); -
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r17181 r17500 25 25 using System.Threading; 26 26 using System.Threading.Tasks; 27 using System.Windows.Forms; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Data; … … 86 87 } 87 88 } 88 private void ClassificationSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) { 89 protected override void OnVisibleChanged(EventArgs e) { 90 base.OnVisibleChanged(e); 91 if (!this.Visible) { 92 cancellationToken.Cancel(); 93 } 94 } 95 96 protected override void OnClosed(FormClosedEventArgs e) { 97 base.OnClosed(e); 89 98 cancellationToken.Cancel(); 90 99 } … … 137 146 .ToList(); 138 147 139 List<Tuple<string, double>> impacts = null; 140 await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); }); 141 if (impacts == null) { return; } 148 var impacts = await Task.Run(() => CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress)); 142 149 143 150 rawVariableImpacts.AddRange(impacts); 144 151 UpdateOrdering(); 152 } catch (OperationCanceledException) { 145 153 } finally { 146 154 Progress.Hide(this); … … 169 177 var clonedModel = (IClassificationModel)model.Clone(); 170 178 foreach (var variableName in originalVariableOrdering) { 171 if (cancellationToken.Token.IsCancellationRequested) { return null; }179 token.ThrowIfCancellationRequested(); 172 180 progress.ProgressValue = (double)++i / count; 173 181 progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count); -
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs
r17181 r17500 192 192 this.Name = "RegressionSolutionVariableImpactsView"; 193 193 this.Size = new System.Drawing.Size(712, 365); 194 this.VisibleChanged += new System.EventHandler(this.RegressionSolutionVariableImpactsView_VisibleChanged);195 194 this.ResumeLayout(false); 196 195 this.PerformLayout(); -
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r17181 r17500 25 25 using System.Threading; 26 26 using System.Threading.Tasks; 27 using System.Windows.Forms; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Data; … … 86 87 } 87 88 } 88 private void RegressionSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) { 89 90 protected override void OnVisibleChanged(EventArgs e) { 91 base.OnVisibleChanged(e); 92 if (!this.Visible) { 93 cancellationToken.Cancel(); 94 } 95 } 96 97 protected override void OnClosed(FormClosedEventArgs e) { 98 base.OnClosed(e); 89 99 cancellationToken.Cancel(); 90 100 } … … 135 145 .ToList(); 136 146 137 List<Tuple<string, double>> impacts = null; 138 await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); }); 139 if (impacts == null) { return; } 147 var impacts = await Task.Run(() => CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress)); 140 148 141 149 rawVariableImpacts.AddRange(impacts); 142 150 UpdateOrdering(); 143 } 144 finally {151 } catch (OperationCanceledException) { 152 } finally { 145 153 Progress.Hide(this); 146 154 } … … 168 176 169 177 foreach (var variableName in originalVariableOrdering) { 170 if (cancellationToken.Token.IsCancellationRequested) { return null; }178 token.ThrowIfCancellationRequested(); 171 179 progress.ProgressValue = (double)++i / count; 172 180 progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
Note: See TracChangeset
for help on using the changeset viewer.