#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common.Resources; using HeuristicLab.Core; using HeuristicLab.Core.Views; using HeuristicLab.Data.Views; using HeuristicLab.MainForm; using HeuristicLab.Optimization; using HeuristicLab.OptimizationExpertSystem.Common; using System; using System.Windows.Forms; namespace HeuristicLab.OptimizationExpertSystem { [View("Solver View")] [Content(typeof(KnowledgeCenter), IsDefaultView = false)] public partial class SolverView : KnowledgeCenterViewBase { private EnumValueView seedingStrategyView; private CheckedItemListView seedingSolutionsView; protected virtual bool SuppressEvents { get; set; } public SolverView() { InitializeComponent(); algorithmStartButton.Text = string.Empty; algorithmStartButton.Image = VSImageLibrary.Play; algorithmCloneButton.Text = string.Empty; algorithmCloneButton.Image = VSImageLibrary.Clone; seedingStrategyView = new EnumValueView() { Dock = DockStyle.Fill }; seedingSolutionsView = new CheckedItemListView() { Dock = DockStyle.Fill }; seedingStrategyPanel.Controls.Add(seedingStrategyView); solutionSeedingTabPage.Controls.Add(seedingSolutionsView); } protected override void OnContentChanged() { base.OnContentChanged(); SuppressEvents = true; try { if (Content == null) { maxEvaluationsView.Content = null; solverParametersView.Content = null; runsView.Content = null; seededRunsView.Content = null; seedingStrategyView.Content = null; seedingSolutionsView.Content = null; } else { maxEvaluationsView.Content = Content.MaximumEvaluations; runsView.Content = Content.InstanceRuns; seededRunsView.Content = Content.SeededRuns; seedingStrategyView.Content = Content.SeedingStrategy; seedingSolutionsView.Content = Content.SolutionSeedingPool; } } finally { SuppressEvents = false; } UpdateSuggestedInstancesCombobox(); } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked; algorithmStartButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0; algorithmCloneButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0; runsView.Enabled = Content != null; } protected override void OnAlgorithmInstanceStarted(IAlgorithm algorithm) { base.OnAlgorithmInstanceStarted(algorithm); var form = new AlgorithmControlForm(algorithm, showOnlyFinalResultCheckBox.Checked); form.Show(resultsDockPanel); } protected override void OnSuggestedInstancesChanged() { base.OnSuggestedInstancesChanged(); UpdateSuggestedInstancesCombobox(); } private void UpdateSuggestedInstancesCombobox() { var prevSelection = (IAlgorithm)suggestedInstancesComboBox.SelectedItem; var prevNewIndex = -1; suggestedInstancesComboBox.Items.Clear(); if (Content == null) return; for (var i = 0; i < Content.SuggestedInstances.Count; i++) { suggestedInstancesComboBox.Items.Add(Content.SuggestedInstances[i]); if (prevSelection == null || Content.SuggestedInstances[i].Name == prevSelection.Name) prevNewIndex = prevSelection == null ? 0 : i; } if (prevNewIndex >= 0) { suggestedInstancesComboBox.SelectedIndex = prevNewIndex; } } private void AlgorithmStartButtonOnClick(object sender, EventArgs e) { if (suggestedInstancesComboBox.SelectedIndex >= 0) Content.StartAlgorithmAsync(suggestedInstancesComboBox.SelectedIndex); } private void AlgorithmCloneButtonOnClick(object sender, EventArgs e) { if (suggestedInstancesComboBox.SelectedIndex >= 0) MainForm.ShowContent((IAlgorithm)Content.SuggestedInstances[suggestedInstancesComboBox.SelectedIndex].Clone()); } private void SuggestedInstancesComboBoxOnSelectedIndexChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke((Action)SuggestedInstancesComboBoxOnSelectedIndexChanged, sender, e); return; } if (suggestedInstancesComboBox.SelectedIndex >= 0) { var alg = Content.SuggestedInstances[suggestedInstancesComboBox.SelectedIndex]; solverParametersView.Content = alg.Parameters; var engineAlg = alg as EngineAlgorithm; if (engineAlg != null) operatorGraphViewHost.Content = engineAlg.OperatorGraph; else operatorGraphViewHost.Content = new Data.StringValue("Algorithm is not modeled as an operator graph."); } else { solverParametersView.Content = null; operatorGraphViewHost.Content = null; } SetEnabledStateOfControls(); } } }