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 | recommendRefreshButton.Text = string.Empty;
|
---|
47 | recommendRefreshButton.Image = VSImageLibrary.Refresh;
|
---|
48 | seedingStrategyView = new EnumValueView<SeedingStrategyTypes>() {
|
---|
49 | Dock = DockStyle.Fill
|
---|
50 | };
|
---|
51 | seedingSolutionsView = new CheckedItemListView<IScope>() {
|
---|
52 | Dock = DockStyle.Fill
|
---|
53 | };
|
---|
54 | seedingStrategyPanel.Controls.Add(seedingStrategyView);
|
---|
55 | solutionSeedingTabPage.Controls.Add(seedingSolutionsView);
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void OnContentChanged() {
|
---|
59 | base.OnContentChanged();
|
---|
60 | SuppressEvents = true;
|
---|
61 | try {
|
---|
62 | if (Content == null) {
|
---|
63 | maxEvaluationsView.Content = null;
|
---|
64 | minTargetView.Content = null;
|
---|
65 | solverParametersView.Content = null;
|
---|
66 | runsView.Content = null;
|
---|
67 | seededRunsView.Content = null;
|
---|
68 | seedingStrategyView.Content = null;
|
---|
69 | seedingSolutionsView.Content = null;
|
---|
70 | recommenderViewHost.Content = null;
|
---|
71 | } else {
|
---|
72 | maxEvaluationsView.Content = Content.MaximumEvaluations;
|
---|
73 | minTargetView.Content = Content.MinimumTarget;
|
---|
74 | runsView.Content = Content.InstanceRuns;
|
---|
75 | seededRunsView.Content = Content.SeededRuns;
|
---|
76 | seedingStrategyView.Content = Content.SeedingStrategy;
|
---|
77 | seedingSolutionsView.Content = Content.SolutionSeedingPool;
|
---|
78 | recommenderViewHost.Content = Content.AlgorithmInstanceRecommender;
|
---|
79 | }
|
---|
80 | } finally { SuppressEvents = false; }
|
---|
81 | UpdateSuggestedInstancesCombobox();
|
---|
82 | UpdateRecommenderCombobox();
|
---|
83 | }
|
---|
84 |
|
---|
85 | protected override void SetEnabledStateOfControls() {
|
---|
86 | base.SetEnabledStateOfControls();
|
---|
87 | suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked;
|
---|
88 | algorithmStartButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
|
---|
89 | algorithmCloneButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
|
---|
90 | runsView.Enabled = Content != null;
|
---|
91 | }
|
---|
92 |
|
---|
93 | protected override void OnAlgorithmInstanceStarted(IAlgorithm algorithm) {
|
---|
94 | base.OnAlgorithmInstanceStarted(algorithm);
|
---|
95 | var form = new AlgorithmControlForm(algorithm, showOnlyFinalResultCheckBox.Checked);
|
---|
96 | form.Show(resultsDockPanel);
|
---|
97 | }
|
---|
98 |
|
---|
99 | protected override void OnSuggestedInstancesChanged() {
|
---|
100 | base.OnSuggestedInstancesChanged();
|
---|
101 | UpdateSuggestedInstancesCombobox();
|
---|
102 | }
|
---|
103 |
|
---|
104 | private void UpdateSuggestedInstancesCombobox() {
|
---|
105 | var prevSelection = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
|
---|
106 | var prevNewIndex = -1;
|
---|
107 | suggestedInstancesComboBox.Items.Clear();
|
---|
108 | if (Content == null) return;
|
---|
109 |
|
---|
110 | for (var i = 0; i < Content.AlgorithmInstances.Count; i++) {
|
---|
111 | suggestedInstancesComboBox.Items.Add(Content.AlgorithmInstances[i]);
|
---|
112 | if (prevSelection == null || Content.AlgorithmInstances[i].Name == prevSelection.Name)
|
---|
113 | prevNewIndex = prevSelection == null ? 0 : i;
|
---|
114 | }
|
---|
115 | if (prevNewIndex >= 0) suggestedInstancesComboBox.SelectedIndex = prevNewIndex;
|
---|
116 | }
|
---|
117 |
|
---|
118 | private void UpdateRecommenderCombobox() {
|
---|
119 | var prevSelection = Content.AlgorithmInstanceRecommender;
|
---|
120 | var prevNewIndex = -1;
|
---|
121 | recommenderComboBox.Items.Clear();
|
---|
122 | if (Content == null) return;
|
---|
123 |
|
---|
124 | /*var i = 0;
|
---|
125 | foreach (var type in ApplicationManager.Manager.GetTypes(typeof (IAlgorithmInstanceRecommender))) {
|
---|
126 | var r = (IAlgorithmInstanceRecommender)Activator.CreateInstance(type, BindingFlags.CreateInstance, Content);
|
---|
127 | recommenderComboBox.Items.Add(r);
|
---|
128 | if (prevSelection == null || type == prevSelection.GetType())
|
---|
129 | prevNewIndex = prevSelection == null ? 0 : i;
|
---|
130 | i++;
|
---|
131 | }
|
---|
132 | if (prevNewIndex >= 0) recommenderComboBox.SelectedIndex = prevNewIndex;*/
|
---|
133 | recommenderComboBox.Items.Add(new OverallBestRecommender(Content));
|
---|
134 | if (prevSelection is OverallBestRecommender) recommenderComboBox.SelectedIndex = recommenderComboBox.Items.Count - 1;
|
---|
135 | recommenderComboBox.Items.Add(new KNearestNeighborRecommender(Content));
|
---|
136 | if (prevSelection is KNearestNeighborRecommender) recommenderComboBox.SelectedIndex = recommenderComboBox.Items.Count - 1;
|
---|
137 | recommenderComboBox.Items.Add(new DistanceWeightedRecommender(Content));
|
---|
138 | if (prevSelection is DistanceWeightedRecommender) recommenderComboBox.SelectedIndex = recommenderComboBox.Items.Count - 1;
|
---|
139 | }
|
---|
140 |
|
---|
141 | private void AlgorithmStartButtonOnClick(object sender, EventArgs e) {
|
---|
142 | if (suggestedInstancesComboBox.SelectedIndex >= 0)
|
---|
143 | Content.StartAlgorithmAsync(suggestedInstancesComboBox.SelectedIndex);
|
---|
144 | }
|
---|
145 |
|
---|
146 | private void AlgorithmCloneButtonOnClick(object sender, EventArgs e) {
|
---|
147 | if (suggestedInstancesComboBox.SelectedIndex >= 0)
|
---|
148 | MainForm.ShowContent((IAlgorithm)Content.AlgorithmInstances[suggestedInstancesComboBox.SelectedIndex].Clone());
|
---|
149 | }
|
---|
150 |
|
---|
151 | private void SuggestedInstancesComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
|
---|
152 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)SuggestedInstancesComboBoxOnSelectedIndexChanged, sender, e); return; }
|
---|
153 | if (suggestedInstancesComboBox.SelectedIndex >= 0) {
|
---|
154 | var alg = Content.AlgorithmInstances[suggestedInstancesComboBox.SelectedIndex];
|
---|
155 | solverParametersView.Content = alg.Parameters;
|
---|
156 | var engineAlg = alg as EngineAlgorithm;
|
---|
157 | if (engineAlg != null) operatorGraphViewHost.Content = engineAlg.OperatorGraph;
|
---|
158 | else operatorGraphViewHost.Content = new Data.StringValue("Algorithm is not modeled as an operator graph.");
|
---|
159 | } else {
|
---|
160 | solverParametersView.Content = null;
|
---|
161 | operatorGraphViewHost.Content = null;
|
---|
162 | }
|
---|
163 | SetEnabledStateOfControls();
|
---|
164 | }
|
---|
165 |
|
---|
166 | private void RecommenderComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
|
---|
167 | if (InvokeRequired) { Invoke((Action<object, EventArgs>)RecommenderComboBoxOnSelectedIndexChanged, sender, e); return; }
|
---|
168 | if (recommenderComboBox.SelectedIndex < 0) return;
|
---|
169 | Content.AlgorithmInstanceRecommender = (IAlgorithmInstanceRecommender)recommenderComboBox.SelectedItem;
|
---|
170 | recommenderViewHost.Content = Content.AlgorithmInstanceRecommender;
|
---|
171 | Content.UpdateSuggestions();
|
---|
172 | }
|
---|
173 |
|
---|
174 | private void button1_Click(object sender, EventArgs e) {
|
---|
175 | Content.UpdateSuggestions();
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|