Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/MetaOptimizationProblemView.cs @ 5313

Last change on this file since 5313 was 5313, checked in by cneumuel, 14 years ago

#1215

  • changed AlgorithType and ProblemType to actually be types not objects. this eliminates redundant views for MetaOptimizationProblem
  • import algorithm for MetaOptimizationProblem
  • nicer dialog for combination creation
  • fixed iconimage for ParameterConfigurations
  • fixed ValidValues
File size: 3.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using HeuristicLab.MainForm;
9using HeuristicLab.Optimization.Views;
10using HeuristicLab.Optimization;
11using System.Windows.Forms;
12
13namespace HeuristicLab.Problems.MetaOptimization.Views {
14  [View("MetaOptimization View")]
15  [Content(typeof(MetaOptimizationProblem), IsDefaultView = true)]
16  public sealed partial class MetaOptimizationProblemView : ProblemView {
17    public new MetaOptimizationProblem Content {
18      get { return (MetaOptimizationProblem)base.Content; }
19      set { base.Content = value; }
20    }
21
22    public MetaOptimizationProblemView() {
23      InitializeComponent();
24    }
25
26    protected override void DeregisterContentEvents() {
27      // TODO: Deregister your event handlers here
28      base.DeregisterContentEvents();
29    }
30
31    protected override void RegisterContentEvents() {
32      base.RegisterContentEvents();
33      // TODO: Register your event handlers here
34    }
35
36    #region Event Handlers (Content)
37    // TODO: Put event handlers of the content here
38    #endregion
39
40    protected override void OnContentChanged() {
41      base.OnContentChanged();
42      if (Content == null) {
43        // TODO: Add code when content has been changed and is null
44      } else {
45        // TODO: Add code when content has been changed and is not null
46      }
47    }
48
49    protected override void SetEnabledStateOfControls() {
50      base.SetEnabledStateOfControls();
51      // TODO: Enable or disable controls based on whether the content is null or the view is set readonly
52    }
53
54    #region Event Handlers (child controls)
55
56    private void createExperimentButton_Click(object sender, EventArgs e) {
57      if (Content != null) {
58        long count = Content.ParameterConfigurationTree.GetCombinationCount();
59
60        System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.OK;
61        if (count > 512) {
62          result = System.Windows.Forms.MessageBox.Show(string.Format("Do you really want to create {0} optimizers? Be aware that this might take a significant amount of time and memory.", count), "Create Experiment", System.Windows.Forms.MessageBoxButtons.OKCancel);
63        }
64        if (result == System.Windows.Forms.DialogResult.OK) {
65          CreateExperimentDialog dlg = new CreateExperimentDialog();
66          DialogResult dlgResult = dlg.ShowDialog();
67
68          if (dlgResult == DialogResult.OK) {
69            EngineAlgorithm algorithm = Content.Algorithm;
70            if(Content.Problems.Count > 0) algorithm.Problem = Content.Problems.First();
71            Experiment experiment;
72
73            if (dlg.CreateBatchRuns) {
74              experiment = Content.ParameterConfigurationTree.GenerateExperiment(algorithm, true, dlg.Repetitions);
75            } else {
76              experiment = Content.ParameterConfigurationTree.GenerateExperiment(algorithm);
77            }
78            MainFormManager.MainForm.ShowContent(experiment);
79          }
80        }
81      }
82    }
83
84    #endregion
85
86    protected void parameterCollectionView_DragEnterOver(object sender, System.Windows.Forms.DragEventArgs e) {
87      e.Effect = DragDropEffects.None;
88      Type type = e.Data.GetData("Type") as Type;
89      if ((type != null) && (Content.AlgorithmType.ValidTypes.Contains(type))) {
90        EngineAlgorithm algorithm = e.Data.GetData("Value") as EngineAlgorithm;
91        if (algorithm.Problem == null || Content.ProblemType.ValidTypes.Contains(algorithm.Problem.GetType())) {
92          e.Effect = DragDropEffects.Copy;
93        }
94      }
95    }
96    protected void parameterCollectionView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) {
97      if (e.Effect != DragDropEffects.None) {
98        EngineAlgorithm algorithm = e.Data.GetData("Value") as EngineAlgorithm;
99        Content.ImportAlgorithm(algorithm);
100      }
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.