1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using HeuristicLab.Common.Resources;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Core.Views;
|
---|
25 | using HeuristicLab.Data.Views;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.OptimizationExpertSystem.Common;
|
---|
29 | using System;
|
---|
30 | using System.Windows.Forms;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.OptimizationExpertSystem {
|
---|
33 | [View("Solver View")]
|
---|
34 | [Content(typeof(KnowledgeCenter), IsDefaultView = false)]
|
---|
35 | public partial class SolverView : KnowledgeCenterViewBase {
|
---|
36 | private EnumValueView<SeedingStrategyTypes> seedingStrategyView;
|
---|
37 | private CheckedItemListView<IScope> seedingSolutionsView;
|
---|
38 | protected virtual bool SuppressEvents { get; set; }
|
---|
39 |
|
---|
40 | public SolverView() {
|
---|
41 | InitializeComponent();
|
---|
42 | algorithmStartButton.Text = string.Empty;
|
---|
43 | algorithmStartButton.Image = VSImageLibrary.Play;
|
---|
44 | algorithmCloneButton.Text = string.Empty;
|
---|
45 | algorithmCloneButton.Image = VSImageLibrary.Clone;
|
---|
46 | seedingStrategyView = new EnumValueView<SeedingStrategyTypes>() {
|
---|
47 | Dock = DockStyle.Fill
|
---|
48 | };
|
---|
49 | seedingSolutionsView = new CheckedItemListView<IScope>() {
|
---|
50 | Dock = DockStyle.Fill
|
---|
51 | };
|
---|
52 | seedingStrategyPanel.Controls.Add(seedingStrategyView);
|
---|
53 | solutionSeedingTabPage.Controls.Add(seedingSolutionsView);
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected override void OnContentChanged() {
|
---|
57 | base.OnContentChanged();
|
---|
58 | SuppressEvents = true;
|
---|
59 | try {
|
---|
60 | if (Content == null) {
|
---|
61 | maxEvaluationsView.Content = null;
|
---|
62 | solverParametersView.Content = null;
|
---|
63 | runsView.Content = null;
|
---|
64 | seededRunsView.Content = null;
|
---|
65 | seedingStrategyView.Content = null;
|
---|
66 | seedingSolutionsView.Content = null;
|
---|
67 | } else {
|
---|
68 | maxEvaluationsView.Content = Content.MaximumEvaluations;
|
---|
69 | runsView.Content = Content.InstanceRuns;
|
---|
70 | seededRunsView.Content = Content.SeededRuns;
|
---|
71 | seedingStrategyView.Content = Content.SeedingStrategy;
|
---|
72 | seedingSolutionsView.Content = Content.SolutionSeedingPool;
|
---|
73 | }
|
---|
74 | } finally { SuppressEvents = false; }
|
---|
75 | UpdateSuggestedInstancesCombobox();
|
---|
76 | }
|
---|
77 |
|
---|
78 | protected override void SetEnabledStateOfControls() {
|
---|
79 | base.SetEnabledStateOfControls();
|
---|
80 | suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked;
|
---|
81 | algorithmStartButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
|
---|
82 | algorithmCloneButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
|
---|
83 | runsView.Enabled = Content != null;
|
---|
84 | }
|
---|
85 |
|
---|
86 | protected override void OnAlgorithmInstanceStarted(IAlgorithm algorithm) {
|
---|
87 | base.OnAlgorithmInstanceStarted(algorithm);
|
---|
88 | var form = new AlgorithmControlForm(algorithm, showOnlyFinalResultCheckBox.Checked);
|
---|
89 | form.Show(resultsDockPanel);
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected override void OnSuggestedInstancesChanged() {
|
---|
93 | base.OnSuggestedInstancesChanged();
|
---|
94 | UpdateSuggestedInstancesCombobox();
|
---|
95 | }
|
---|
96 |
|
---|
97 | private void UpdateSuggestedInstancesCombobox() {
|
---|
98 | var prevSelection = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
|
---|
99 | var prevNewIndex = -1;
|
---|
100 | suggestedInstancesComboBox.Items.Clear();
|
---|
101 | if (Content == null) return;
|
---|
102 |
|
---|
103 | for (var i = 0; i < Content.SuggestedInstances.Count; i++) {
|
---|
104 | suggestedInstancesComboBox.Items.Add(Content.SuggestedInstances[i]);
|
---|
105 | if (prevSelection == null || Content.SuggestedInstances[i].Name == prevSelection.Name)
|
---|
106 | prevNewIndex = prevSelection == null ? 0 : i;
|
---|
107 | }
|
---|
108 | if (prevNewIndex >= 0) {
|
---|
109 | suggestedInstancesComboBox.SelectedIndex = prevNewIndex;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | private void AlgorithmStartButtonOnClick(object sender, EventArgs e) {
|
---|
114 | if (suggestedInstancesComboBox.SelectedIndex >= 0)
|
---|
115 | Content.StartAlgorithmAsync(suggestedInstancesComboBox.SelectedIndex);
|
---|
116 | }
|
---|
117 |
|
---|
118 | private void AlgorithmCloneButtonOnClick(object sender, EventArgs e) {
|
---|
119 | if (suggestedInstancesComboBox.SelectedIndex >= 0)
|
---|
120 | MainForm.ShowContent((IAlgorithm)Content.SuggestedInstances[suggestedInstancesComboBox.SelectedIndex].Clone());
|
---|
121 | }
|
---|
122 |
|
---|
123 | private void SuggestedInstancesComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
|
---|
124 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)SuggestedInstancesComboBoxOnSelectedIndexChanged, sender, e); return; }
|
---|
125 | if (suggestedInstancesComboBox.SelectedIndex >= 0) {
|
---|
126 | var alg = Content.SuggestedInstances[suggestedInstancesComboBox.SelectedIndex];
|
---|
127 | solverParametersView.Content = alg.Parameters;
|
---|
128 | var engineAlg = alg as EngineAlgorithm;
|
---|
129 | if (engineAlg != null) operatorGraphViewHost.Content = engineAlg.OperatorGraph;
|
---|
130 | else operatorGraphViewHost.Content = new Data.StringValue("Algorithm is not modeled as an operator graph.");
|
---|
131 | } else {
|
---|
132 | solverParametersView.Content = null;
|
---|
133 | operatorGraphViewHost.Content = null;
|
---|
134 | }
|
---|
135 | SetEnabledStateOfControls();
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|