Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/06/21 13:13:32 (3 years ago)
Author:
dpiringe
Message:

#3026

  • merged trunk into branch
Location:
branches/3026_IntegrationIntoSymSpace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs

    r17180 r17928  
    5757      this.grpViewHost = new System.Windows.Forms.GroupBox();
    5858      this.treeChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.InteractiveSymbolicExpressionTreeChart();
     59      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    5960      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    6061      this.splitContainer.Panel1.SuspendLayout();
     
    148149      this.btnSimplify.Text = "Simplify";
    149150      this.btnSimplify.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
     151      this.toolTip.SetToolTip(this.btnSimplify, "Simplifies the model structure based on mathematical simplification rules.");
    150152      this.btnSimplify.UseVisualStyleBackColor = true;
    151153      this.btnSimplify.Click += new System.EventHandler(this.btnSimplify_Click);
     
    162164      this.btnOptimizeConstants.Text = "Optimize";
    163165      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.");
    164168      this.btnOptimizeConstants.UseVisualStyleBackColor = true;
    165169      this.btnOptimizeConstants.Click += new System.EventHandler(this.btnOptimizeConstants_Click);
     
    226230    protected System.Windows.Forms.Button btnOptimizeConstants;
    227231    private System.Windows.Forms.Label treeStatusValue;
     232    private System.Windows.Forms.ToolTip toolTip;
    228233  }
    229234}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r17180 r17928  
    3535namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    3636  public abstract partial class InteractiveSymbolicDataAnalysisSolutionSimplifierView : AsynchronousContentView {
    37     private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> foldedNodes;
    38     private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes;
    39     private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts;
     37    private readonly Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     38    private readonly Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     39    private readonly Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
     40    private readonly Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
    4041
    4142    private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator;
     
    4950    protected InteractiveSymbolicDataAnalysisSolutionSimplifierView(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator) {
    5051      InitializeComponent();
    51       foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
    52       changedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
    53       nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
    5452      this.Caption = "Interactive Solution Simplifier";
    5553      this.impactCalculator = impactCalculator;
     
    168166    private void Content_Changed(object sender, EventArgs e) {
    169167      UpdateView();
     168      SetEnabledStateOfControls();
    170169    }
    171170
    172171    protected override void OnContentChanged() {
    173172      base.OnContentChanged();
    174       foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     173      foldedNodes.Clear();
     174      changedNodes.Clear();
     175      nodeIntervals.Clear();
     176      nodeImpacts.Clear();
    175177      UpdateView();
    176178      viewHost.Content = this.Content;
     
    192194
    193195      progress.Start("Calculate Impact and Replacement Values ...");
     196      cancellationTokenSource = new CancellationTokenSource();
    194197      progress.CanBeStopped = true;
    195       cancellationTokenSource = new CancellationTokenSource();
    196       var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree));
    197198      try {
    198         await Task.Delay(500, cancellationTokenSource.Token); // wait for progressbar to finish animation
    199       } catch (OperationCanceledException) { }
    200       var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
    201       foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
    202         foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
    203       }
    204       nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
    205       progress.Finish();
     199        var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree));
     200        try {
     201          await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation
     202        } catch (OperationCanceledException) { }
     203
     204        var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
     205        foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
     206          foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
     207        }
     208       
     209        foreach (var pair in impactAndReplacementValues) {
     210          nodeImpacts[pair.Key] = pair.Value.Item1;
     211        }
     212
     213        if (IntervalInterpreter.IsCompatible(tree)) {
     214          var regressionProblemData = Content.ProblemData as IRegressionProblemData;
     215          if (regressionProblemData != null) {
     216            var interpreter = new IntervalInterpreter();
     217            var variableRanges = regressionProblemData.VariableRanges.GetReadonlyDictionary();
     218            IDictionary<ISymbolicExpressionTreeNode, Interval> intervals;
     219            interpreter.GetSymbolicExpressionTreeIntervals(tree, variableRanges, out intervals);
     220            foreach (var kvp in intervals) {
     221              nodeIntervals[kvp.Key] = kvp.Value;
     222            }
     223          }
     224        }
     225      } finally {
     226        progress.Finish();
     227      }
     228
    206229      progress.CanBeStopped = false;
    207230      PaintNodeImpacts();
     
    296319          }
    297320        }
    298         if (visualTree != null)
     321        if (visualTree != null) {
     322          if (nodeIntervals.ContainsKey(treeNode))
     323            visualTree.ToolTip += String.Format($"{Environment.NewLine}Intervals: [{nodeIntervals[treeNode].LowerBound:G5} ... {nodeIntervals[treeNode].UpperBound:G5}]");
    299324          if (changedNodes.ContainsKey(treeNode)) {
    300325            visualTree.LineColor = Color.DodgerBlue;
     
    302327            visualTree.LineColor = Color.DarkOrange;
    303328          }
     329        }
    304330      }
    305331      treeChart.RepaintNodes();
     
    313339    private async void btnOptimizeConstants_Click(object sender, EventArgs e) {
    314340      progress.Start("Optimizing Constants ...");
    315       var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
    316       var newTree = await Task.Run(() => OptimizeConstants(tree, progress));
    317       await Task.Delay(500); // wait for progressbar to finish animation
    318       UpdateModel(newTree); // UpdateModel calls Progress.Finish (via Content_Changed)
     341      cancellationTokenSource = new CancellationTokenSource();
     342      progress.CanBeStopped = true;
     343      try {
     344        var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
     345
     346        var newTree = await Task.Run(() => OptimizeConstants(tree, progress));
     347        try {
     348          await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation
     349        } catch (OperationCanceledException) { }
     350        UpdateModel(newTree); // triggers progress.Finish after calculating the node impacts when model is changed
     351      } catch {
     352        progress.Finish();
     353      }
    319354    }
    320355  }
Note: See TracChangeset for help on using the changeset viewer.