1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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 System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.IO;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Reflection;
|
---|
27 | using System.Threading;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HEAL.Attic;
|
---|
30 | using HeuristicLab.Common;
|
---|
31 | using HeuristicLab.Core;
|
---|
32 | using HeuristicLab.MainForm;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Optimizer {
|
---|
35 | [View("Start Page")]
|
---|
36 | public partial class StartPage : HeuristicLab.MainForm.WindowsForms.View {
|
---|
37 | private const string StandardProblemsGroupName = "Standard Problems";
|
---|
38 | private const string DataAnalysisGroupName = "Data Analysis";
|
---|
39 | private const string ScriptsGroupName = "Scripts";
|
---|
40 | private const string UncategorizedGroupName = "Uncategorized";
|
---|
41 | private const string SampleNamePrefix = "HeuristicLab.Optimizer.Documents.";
|
---|
42 | private const string SampleNameSuffix = ".hl";
|
---|
43 |
|
---|
44 | private readonly Dictionary<ListViewGroup, List<string>> groupLookup = new Dictionary<ListViewGroup, List<string>>();
|
---|
45 | private readonly ListViewGroup standardProblemsGroup = new ListViewGroup(StandardProblemsGroupName);
|
---|
46 | private readonly ListViewGroup dataAnalysisGroup = new ListViewGroup(DataAnalysisGroupName);
|
---|
47 | private readonly ListViewGroup scriptsGroup = new ListViewGroup(ScriptsGroupName);
|
---|
48 | private readonly ListViewGroup uncategorizedGroup = new ListViewGroup(UncategorizedGroupName);
|
---|
49 |
|
---|
50 | private IProgress progress;
|
---|
51 |
|
---|
52 | public StartPage() {
|
---|
53 | InitializeComponent();
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected override void OnInitialized(EventArgs e) {
|
---|
57 | base.OnInitialized(e);
|
---|
58 | Assembly assembly = Assembly.GetExecutingAssembly();
|
---|
59 | AssemblyFileVersionAttribute version = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).
|
---|
60 | Cast<AssemblyFileVersionAttribute>().FirstOrDefault();
|
---|
61 | titleLabel.Text = "HeuristicLab Optimizer";
|
---|
62 | if (version != null) titleLabel.Text += " " + version.Version;
|
---|
63 |
|
---|
64 | try {
|
---|
65 | using (Stream stream = assembly.GetManifestResourceStream(typeof(StartPage), "Documents.FirstSteps.rtf"))
|
---|
66 | firstStepsRichTextBox.LoadFile(stream, RichTextBoxStreamType.RichText);
|
---|
67 | } catch (Exception) { }
|
---|
68 |
|
---|
69 | samplesListView.Enabled = false;
|
---|
70 | samplesListView.Groups.Add(standardProblemsGroup);
|
---|
71 | samplesListView.Groups.Add(dataAnalysisGroup);
|
---|
72 | samplesListView.Groups.Add(scriptsGroup);
|
---|
73 | samplesListView.Groups.Add(uncategorizedGroup);
|
---|
74 | FillGroupLookup();
|
---|
75 |
|
---|
76 | showStartPageCheckBox.Checked = Properties.Settings.Default.ShowStartPage;
|
---|
77 |
|
---|
78 | ThreadPool.QueueUserWorkItem(new WaitCallback(LoadSamples));
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected override void OnClosing(FormClosingEventArgs e) {
|
---|
82 | base.OnClosing(e);
|
---|
83 | if (e.CloseReason == CloseReason.UserClosing) {
|
---|
84 | e.Cancel = true;
|
---|
85 | this.Hide();
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | private void LoadSamples(object state) {
|
---|
90 | progress = Progress.ShowOnControl(samplesListView, "Loading...");
|
---|
91 | try {
|
---|
92 | var assembly = Assembly.GetExecutingAssembly();
|
---|
93 | var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(SampleNameSuffix));
|
---|
94 | int count = samples.Count();
|
---|
95 |
|
---|
96 | foreach (var entry in groupLookup) {
|
---|
97 | var group = entry.Key;
|
---|
98 | var sampleList = entry.Value;
|
---|
99 | foreach (var sampleName in sampleList) {
|
---|
100 | string resourceName = SampleNamePrefix + sampleName + SampleNameSuffix;
|
---|
101 | LoadSample(resourceName, assembly, group, count);
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | var categorizedSamples = groupLookup.Select(x => x.Value).SelectMany(x => x).Select(x => SampleNamePrefix + x + SampleNameSuffix);
|
---|
106 | var uncategorizedSamples = samples.Except(categorizedSamples);
|
---|
107 |
|
---|
108 | foreach (var resourceName in uncategorizedSamples) {
|
---|
109 | LoadSample(resourceName, assembly, uncategorizedGroup, count);
|
---|
110 | }
|
---|
111 |
|
---|
112 | } catch {
|
---|
113 | } finally {
|
---|
114 | OnAllSamplesLoaded();
|
---|
115 | Progress.HideFromControl(samplesListView);
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | private void LoadSample(string name, Assembly assembly, ListViewGroup group, int count) {
|
---|
120 | using (var stream = assembly.GetManifestResourceStream(name)) {
|
---|
121 | var serializer = new ProtoBufSerializer();
|
---|
122 | var item = (NamedItem)serializer.Deserialize(stream, false);
|
---|
123 | OnSampleLoaded(item, group, 1.0 / count);
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | private void FillGroupLookup() {
|
---|
128 | //TODO: uncomment whole sample and script list and readd in project
|
---|
129 | //var standardProblems = new List<string> { "ALPSGA_TSP", "ES_Griewank", "OSES_Griewank", "GA_Grouping", "GA_TSP", "GA_VRP", "GE_ArtificialAnt",
|
---|
130 | // "IslandGA_TSP", "LS_Knapsack", "PSO_Rastrigin", "RAPGA_JSSP",
|
---|
131 | // "SA_Rastrigin", "SGP_SantaFe", "GP_Multiplexer", "SGP_Robocode", "SS_VRP", "TS_TSP", "TS_VRP", "VNS_OP", "VNS_TSP", "GA_BPP"
|
---|
132 | // };
|
---|
133 | var standardProblems = new List<string> { "ALPSGA_TSP", "ES_Griewank", "OSES_Griewank", "GA_Grouping", "GA_TSP", "GA_VRP", "GE_ArtificialAnt",
|
---|
134 | "IslandGA_TSP", "PSO_Rastrigin",
|
---|
135 | "SGP_SantaFe", "GP_Multiplexer", "SGP_Robocode", "SS_VRP", "TS_TSP", "TS_VRP", "VNS_OP"
|
---|
136 | };
|
---|
137 | groupLookup[standardProblemsGroup] = standardProblems;
|
---|
138 | var dataAnalysisProblems = new List<string> { "ALPSGP_SymReg", "SGP_SymbClass", "SGP_SymbReg", "OSGP_SymReg", "OSGP_TimeSeries", "GE_SymbReg", "GPR" };
|
---|
139 | groupLookup[dataAnalysisGroup] = dataAnalysisProblems;
|
---|
140 | var scripts = new List<string> { "GA_QAP_Script", "GUI_Automation_Script", "OSGA_Rastrigin_Script",
|
---|
141 | "GridSearch_RF_Classification_Script", "GridSearch_RF_Regression_Script",
|
---|
142 | "GridSearch_SVM_Classification_Script", "GridSearch_SVM_Regression_Script" };
|
---|
143 | groupLookup[scriptsGroup] = scripts;
|
---|
144 | }
|
---|
145 |
|
---|
146 | private void OnSampleLoaded(INamedItem sample, ListViewGroup group, double progress) {
|
---|
147 | if (InvokeRequired)
|
---|
148 | Invoke(new Action<INamedItem, ListViewGroup, double>(OnSampleLoaded), sample, group, progress);
|
---|
149 | else {
|
---|
150 | ListViewItem item = new ListViewItem(new string[] { sample.Name, sample.Description }, group);
|
---|
151 | item.ToolTipText = sample.ItemName + ": " + sample.ItemDescription;
|
---|
152 | samplesListView.SmallImageList.Images.Add(sample.ItemImage);
|
---|
153 | item.ImageIndex = samplesListView.SmallImageList.Images.Count - 1;
|
---|
154 | item.Tag = sample;
|
---|
155 | samplesListView.Items.Add(item);
|
---|
156 | this.progress.ProgressValue += progress;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | private void OnAllSamplesLoaded() {
|
---|
160 | if (InvokeRequired)
|
---|
161 | Invoke(new Action(OnAllSamplesLoaded));
|
---|
162 | else {
|
---|
163 | samplesListView.Enabled = samplesListView.Items.Count > 0;
|
---|
164 | if (samplesListView.Items.Count > 0) {
|
---|
165 | for (int i = 0; i < samplesListView.Columns.Count; i++)
|
---|
166 | samplesListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | private void firstStepsRichTextBox_LinkClicked(object sender, LinkClickedEventArgs e) {
|
---|
172 | System.Diagnostics.Process.Start(e.LinkText);
|
---|
173 | }
|
---|
174 |
|
---|
175 | private void samplesListView_DoubleClick(object sender, EventArgs e) {
|
---|
176 | if (samplesListView.SelectedItems.Count == 1) {
|
---|
177 | var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
|
---|
178 | try {
|
---|
179 | mainForm.SetWaitCursor();
|
---|
180 | mainForm.ShowContent((IContent)((IItem)samplesListView.SelectedItems[0].Tag).Clone());
|
---|
181 | } finally {
|
---|
182 | mainForm.ResetWaitCursor();
|
---|
183 | }
|
---|
184 |
|
---|
185 | }
|
---|
186 | }
|
---|
187 | private void samplesListView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
188 | ListViewItem listViewItem = (ListViewItem)e.Item;
|
---|
189 | IItem item = (IItem)listViewItem.Tag;
|
---|
190 | DataObject data = new DataObject();
|
---|
191 | data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, item);
|
---|
192 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
|
---|
193 | }
|
---|
194 |
|
---|
195 | private void showStartPageCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
196 | Properties.Settings.Default.ShowStartPage = showStartPageCheckBox.Checked;
|
---|
197 | Properties.Settings.Default.Save();
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|