Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5654 was 5654, checked in by cneumuel, 13 years ago

#1215

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