Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

  • made all IAlgorithm types compatible to be loaded into MetaOptimization.
  • valid problem types are now automatically set
File size: 4.3 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 max = 100000;
59        long count = Content.ParameterConfigurationTree.GetCombinationCount(max);
60
61        System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.OK;
62        if (count > 512) {
63          if (count == max) {
64            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);
65          } else {
66            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);
67          }
68        }
69        if (result == System.Windows.Forms.DialogResult.OK) {
70          CreateExperimentDialog dlg = new CreateExperimentDialog();
71          DialogResult dlgResult = dlg.ShowDialog();
72
73          if (dlgResult == DialogResult.OK) {
74            IAlgorithm algorithm = Content.Algorithm;
75            if(Content.Problems.Count > 0) algorithm.Problem = Content.Problems.First();
76            Experiment experiment;
77
78            if (dlg.CreateBatchRuns) {
79              experiment = Content.ParameterConfigurationTree.GenerateExperiment(algorithm, true, dlg.Repetitions);
80            } else {
81              experiment = Content.ParameterConfigurationTree.GenerateExperiment(algorithm);
82            }
83            MainFormManager.MainForm.ShowContent(experiment);
84          }
85        }
86      }
87    }
88
89    #endregion
90
91    protected void parameterCollectionView_DragEnterOver(object sender, System.Windows.Forms.DragEventArgs e) {
92      e.Effect = DragDropEffects.None;
93      Type type = e.Data.GetData("Type") as Type;
94      if ((type != null) && (Content.AlgorithmType.ValidTypes.Contains(type))) {
95        IAlgorithm algorithm = e.Data.GetData("Value") as IAlgorithm;
96        if (algorithm != null && algorithm.Problem == null || Content.ProblemType.ValidTypes.Contains(algorithm.Problem.GetType())) {
97          e.Effect = DragDropEffects.Copy;
98        }
99      }
100    }
101    protected void parameterCollectionView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) {
102      if (e.Effect != DragDropEffects.None) {
103        IAlgorithm algorithm = e.Data.GetData("Value") as IAlgorithm;
104        Content.ImportAlgorithm(algorithm);
105      }
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.