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 | minTargetView.Content = null;
|
---|
63 | solverParametersView.Content = null;
|
---|
64 | runsView.Content = null;
|
---|
65 | seededRunsView.Content = null;
|
---|
66 | seedingStrategyView.Content = null;
|
---|
67 | seedingSolutionsView.Content = null;
|
---|
68 | } else {
|
---|
69 | maxEvaluationsView.Content = Content.MaximumEvaluations;
|
---|
70 | minTargetView.Content = Content.MinimumTarget;
|
---|
71 | runsView.Content = Content.InstanceRuns;
|
---|
72 | seededRunsView.Content = Content.SeededRuns;
|
---|
73 | seedingStrategyView.Content = Content.SeedingStrategy;
|
---|
74 | seedingSolutionsView.Content = Content.SolutionSeedingPool;
|
---|
75 | }
|
---|
76 | } finally { SuppressEvents = false; }
|
---|
77 | UpdateSuggestedInstancesCombobox();
|
---|
78 | }
|
---|
79 |
|
---|
80 | protected override void SetEnabledStateOfControls() {
|
---|
81 | base.SetEnabledStateOfControls();
|
---|
82 | suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked;
|
---|
83 | algorithmStartButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
|
---|
84 | algorithmCloneButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
|
---|
85 | runsView.Enabled = Content != null;
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected override void OnAlgorithmInstanceStarted(IAlgorithm algorithm) {
|
---|
89 | base.OnAlgorithmInstanceStarted(algorithm);
|
---|
90 | var form = new AlgorithmControlForm(algorithm, showOnlyFinalResultCheckBox.Checked);
|
---|
91 | form.Show(resultsDockPanel);
|
---|
92 | }
|
---|
93 |
|
---|
94 | protected override void OnSuggestedInstancesChanged() {
|
---|
95 | base.OnSuggestedInstancesChanged();
|
---|
96 | UpdateSuggestedInstancesCombobox();
|
---|
97 | }
|
---|
98 |
|
---|
99 | private void UpdateSuggestedInstancesCombobox() {
|
---|
100 | var prevSelection = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
|
---|
101 | var prevNewIndex = -1;
|
---|
102 | suggestedInstancesComboBox.Items.Clear();
|
---|
103 | if (Content == null) return;
|
---|
104 |
|
---|
105 | for (var i = 0; i < Content.SuggestedInstances.Count; i++) {
|
---|
106 | suggestedInstancesComboBox.Items.Add(Content.SuggestedInstances[i]);
|
---|
107 | if (prevSelection == null || Content.SuggestedInstances[i].Name == prevSelection.Name)
|
---|
108 | prevNewIndex = prevSelection == null ? 0 : i;
|
---|
109 | }
|
---|
110 | if (prevNewIndex >= 0) {
|
---|
111 | suggestedInstancesComboBox.SelectedIndex = prevNewIndex;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | private void AlgorithmStartButtonOnClick(object sender, EventArgs e) {
|
---|
116 | if (suggestedInstancesComboBox.SelectedIndex >= 0)
|
---|
117 | Content.StartAlgorithmAsync(suggestedInstancesComboBox.SelectedIndex);
|
---|
118 | }
|
---|
119 |
|
---|
120 | private void AlgorithmCloneButtonOnClick(object sender, EventArgs e) {
|
---|
121 | if (suggestedInstancesComboBox.SelectedIndex >= 0)
|
---|
122 | MainForm.ShowContent((IAlgorithm)Content.SuggestedInstances[suggestedInstancesComboBox.SelectedIndex].Clone());
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void SuggestedInstancesComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
|
---|
126 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)SuggestedInstancesComboBoxOnSelectedIndexChanged, sender, e); return; }
|
---|
127 | if (suggestedInstancesComboBox.SelectedIndex >= 0) {
|
---|
128 | var alg = Content.SuggestedInstances[suggestedInstancesComboBox.SelectedIndex];
|
---|
129 | solverParametersView.Content = alg.Parameters;
|
---|
130 | var engineAlg = alg as EngineAlgorithm;
|
---|
131 | if (engineAlg != null) operatorGraphViewHost.Content = engineAlg.OperatorGraph;
|
---|
132 | else operatorGraphViewHost.Content = new Data.StringValue("Algorithm is not modeled as an operator graph.");
|
---|
133 | } else {
|
---|
134 | solverParametersView.Content = null;
|
---|
135 | operatorGraphViewHost.Content = null;
|
---|
136 | }
|
---|
137 | SetEnabledStateOfControls();
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|