using System; using System.Linq; using System.Windows.Forms; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.MainForm; using HeuristicLab.Optimization; using HeuristicLab.Optimization.Views; using HeuristicLab.PluginInfrastructure; namespace HeuristicLab.Problems.MetaOptimization.Views { [View("MetaOptimization View")] [Content(typeof(MetaOptimizationProblem), IsDefaultView = true)] public sealed partial class MetaOptimizationProblemView : ProblemView { public new MetaOptimizationProblem Content { get { return (MetaOptimizationProblem)base.Content; } set { base.Content = value; } } public MetaOptimizationProblemView() { InitializeComponent(); } protected override void DeregisterContentEvents() { // TODO: Deregister your event handlers here base.DeregisterContentEvents(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); // TODO: Register your event handlers here } #region Event Handlers (Content) // TODO: Put event handlers of the content here #endregion protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { // TODO: Add code when content has been changed and is null } else { // TODO: Add code when content has been changed and is not null } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); // TODO: Enable or disable controls based on whether the content is null or the view is set readonly } #region Event Handlers (child controls) private void createExperimentButton_Click(object sender, EventArgs e) { if (Content != null) { long max = 100000; long count = Content.ParameterConfigurationTree.GetCombinationCount(max); System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.OK; if (count > 512) { if (count == max) { 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); } else { 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); } } if (result == System.Windows.Forms.DialogResult.OK) { CreateExperimentDialog dlg = new CreateExperimentDialog(ApplicationManager.Manager.GetInstances(), typeof(SequentialEngine.SequentialEngine)); DialogResult dlgResult = dlg.ShowDialog(); if (dlgResult == DialogResult.OK) { var algorithm = (EngineAlgorithm)Content.Algorithm.Clone(); if(Content.Problems.Count > 0) algorithm.Problem = Content.Problems.First(); algorithm.Engine = (IEngine)dlg.Engine.Clone(); Experiment experiment; if (dlg.CreateBatchRuns) { experiment = Content.ParameterConfigurationTree.GenerateExperiment(algorithm, true, dlg.Repetitions); } else { experiment = Content.ParameterConfigurationTree.GenerateExperiment(algorithm); } MainFormManager.MainForm.ShowContent(experiment); } } } } #endregion private void parameterCollectionView_DragEnterOver(object sender, System.Windows.Forms.DragEventArgs e) { e.Effect = DragDropEffects.None; var type = e.Data.GetData(Constants.DragDropDataFormat).GetType(); if (!ReadOnly && (Content.AlgorithmType.ValidTypes.Contains(type))) { IAlgorithm algorithm = e.Data.GetData(Constants.DragDropDataFormat) as IAlgorithm; if (algorithm != null && algorithm.Problem == null || Content.ProblemType.ValidTypes.Contains(algorithm.Problem.GetType())) { e.Effect = DragDropEffects.Copy; } } } private void parameterCollectionView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { if (e.Effect != DragDropEffects.None) { IAlgorithm algorithm = e.Data.GetData(Constants.DragDropDataFormat) as IAlgorithm; Content.ImportAlgorithm(algorithm); } } } }