Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/13 21:52:28 (12 years ago)
Author:
mkommend
Message:

#2023: Adapted bubble chart to fire the ViewChanged event, if the selected runs are changed. Added event forwarding for the ViewChanged event in the ViewHost and updated the CreateEnsembleMenuItem to work with the selected runs from the bubble chart.FF

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/CreateEnsembleMenuItem.cs

    r7738 r9315  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.MainForm;
     28using HeuristicLab.MainForm.WindowsForms;
    2829using HeuristicLab.Optimization;
     30using HeuristicLab.Optimization.Views;
    2931using HeuristicLab.Optimizer;
    3032
     
    4951    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    5052      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    51       if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) {
    52         var optimizer = activeView.Content as IOptimizer;
    53         ToolStripItem.Enabled = GetDataAnalysisResults(optimizer).Any();
    54       } else {
    55         ToolStripItem.Enabled = false;
    56       }
     53      ToolStripItem.Enabled = GetDataAnalysisResults(activeView).Any();
     54    }
     55    protected override void OnViewChanged(object sender, EventArgs e) {
     56      base.OnViewChanged(sender, e);
     57      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
     58      ToolStripItem.Enabled = GetDataAnalysisResults(activeView).Any();
    5759    }
    5860
    5961    public override void Execute() {
    6062      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    61       if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) {
    62         var optimizer = activeView.Content as IOptimizer;
    63         var solutionGroups = from pair in GetDataAnalysisResults(optimizer)
    64                              group pair.Value by pair.Key into g
    65                              select g;
    66         foreach (var group in solutionGroups) {
    67           // check if all solutions in the group are either only regression or only classification solutions
    68           if (group.All(s => s is IRegressionSolution)) {
    69             // show all regression ensembles
    70             // clone problemdata (N.B. this assumes all solutions are based on the same problem data!)
    71             var problemData = (RegressionProblemData)group
    72               .OfType<IRegressionSolution>()
    73               .First()
    74               .ProblemData.Clone();
    75             var ensemble = new RegressionEnsembleSolution(problemData);
    76             ensemble.Name = group.Key + " ensemble";
    77             var nestedSolutions = group.OfType<RegressionEnsembleSolution>().SelectMany(e => e.RegressionSolutions);
    78             var solutions = group.Where(s => !(s is RegressionEnsembleSolution)).OfType<IRegressionSolution>();
    79             ensemble.AddRegressionSolutions(nestedSolutions.Concat(solutions));
    80             MainFormManager.MainForm.ShowContent(ensemble);
    81           } else if (group.All(s => s is IClassificationSolution)) {
    82             // show all classification ensembles
    83             var problemData = (ClassificationProblemData)group
    84               .OfType<IClassificationSolution>()
    85               .First()
    86               .ProblemData.Clone();
    87             var ensemble = new ClassificationEnsembleSolution(Enumerable.Empty<IClassificationModel>(), problemData);
    88             ensemble.Name = group.Key + " ensemble";
    89             var nestedSolutions = group.OfType<ClassificationEnsembleSolution>().SelectMany(e => e.ClassificationSolutions);
    90             var solutions = group.Where(s => !(s is ClassificationEnsembleSolution)).OfType<IClassificationSolution>();
    91             ensemble.AddClassificationSolutions(nestedSolutions.Concat(solutions));
    92             MainFormManager.MainForm.ShowContent(ensemble);
    93           }
     63      var solutionGroups = from pair in GetDataAnalysisResults(activeView)
     64                           group pair.Value by pair.Key into g
     65                           select g;
     66      foreach (var group in solutionGroups) {
     67        // check if all solutions in the group are either only regression or only classification solutions
     68        if (group.All(s => s is IRegressionSolution)) {
     69          // show all regression ensembles
     70          // clone problemdata (N.B. this assumes all solutions are based on the same problem data!)
     71          var problemData = (RegressionProblemData)group
     72            .OfType<IRegressionSolution>()
     73            .First()
     74            .ProblemData.Clone();
     75          var ensemble = new RegressionEnsembleSolution(problemData);
     76          ensemble.Name = group.Key + " ensemble";
     77          var nestedSolutions = group.OfType<RegressionEnsembleSolution>().SelectMany(e => e.RegressionSolutions);
     78          var solutions = group.Where(s => !(s is RegressionEnsembleSolution)).OfType<IRegressionSolution>();
     79          ensemble.AddRegressionSolutions(nestedSolutions.Concat(solutions));
     80          MainFormManager.MainForm.ShowContent(ensemble);
     81        } else if (group.All(s => s is IClassificationSolution)) {
     82          // show all classification ensembles
     83          var problemData = (ClassificationProblemData)group
     84            .OfType<IClassificationSolution>()
     85            .First()
     86            .ProblemData.Clone();
     87          var ensemble = new ClassificationEnsembleSolution(Enumerable.Empty<IClassificationModel>(), problemData);
     88          ensemble.Name = group.Key + " ensemble";
     89          var nestedSolutions = group.OfType<ClassificationEnsembleSolution>().SelectMany(e => e.ClassificationSolutions);
     90          var solutions = group.Where(s => !(s is ClassificationEnsembleSolution)).OfType<IClassificationSolution>();
     91          ensemble.AddClassificationSolutions(nestedSolutions.Concat(solutions));
     92          MainFormManager.MainForm.ShowContent(ensemble);
    9493        }
    9594      }
    9695    }
    9796
    98     private IEnumerable<KeyValuePair<string, IItem>> GetDataAnalysisResults(IOptimizer optimizer) {
    99       var allResults = from r in optimizer.Runs
     97    private IEnumerable<KeyValuePair<string, IItem>> GetDataAnalysisResults(IContentView view) {
     98      var empty = Enumerable.Empty<KeyValuePair<string, IItem>>();
     99      if (view == null) return empty;
     100      if (view.Content == null) return empty;
     101      if (view.Locked) return empty;
     102
     103      var optimizer = view.Content as IOptimizer;
     104      if (optimizer != null) return GetDataAnalysisResults(optimizer.Runs);
     105
     106      RunCollectionBubbleChartView bubbleChart;
     107      var viewHost = view as ViewHost;
     108      if (viewHost != null)
     109        bubbleChart = viewHost.ActiveView as RunCollectionBubbleChartView;
     110      else bubbleChart = view as RunCollectionBubbleChartView;
     111      if (bubbleChart != null && bubbleChart.SelectedRuns.Any()) return GetDataAnalysisResults(bubbleChart.SelectedRuns);
     112
     113      return empty;
     114    }
     115
     116    private IEnumerable<KeyValuePair<string, IItem>> GetDataAnalysisResults(IEnumerable<IRun> runs) {
     117      var allResults = from r in runs
    100118                       select r.Results;
    101119      return from r in allResults
Note: See TracChangeset for help on using the changeset viewer.