Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

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