1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Text;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HeuristicLab.Core;
|
---|
30 | using HeuristicLab.Data;
|
---|
31 | using HeuristicLab.Operators;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Routing.TSP {
|
---|
34 | public partial class TSPInjectorView : ViewBase {
|
---|
35 | public TSPInjector TSPInjector {
|
---|
36 | get { return (TSPInjector)Item; }
|
---|
37 | set { base.Item = value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public TSPInjectorView() {
|
---|
41 | InitializeComponent();
|
---|
42 | }
|
---|
43 | public TSPInjectorView(TSPInjector tspInjector)
|
---|
44 | : this() {
|
---|
45 | TSPInjector = tspInjector;
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected override void RemoveItemEvents() {
|
---|
49 | operatorBaseVariableInfosView.Operator = null;
|
---|
50 | operatorBaseDescriptionView.Operator = null;
|
---|
51 | base.RemoveItemEvents();
|
---|
52 | }
|
---|
53 | protected override void AddItemEvents() {
|
---|
54 | base.AddItemEvents();
|
---|
55 | operatorBaseVariableInfosView.Operator = TSPInjector;
|
---|
56 | operatorBaseDescriptionView.Operator = TSPInjector;
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected override void UpdateControls() {
|
---|
60 | base.UpdateControls();
|
---|
61 | if (TSPInjector == null) {
|
---|
62 | citiesTextBox.Text = "-";
|
---|
63 | bestKnownQualityAvailableCheckBox.Checked = false;
|
---|
64 | bestKnownQualityAvailableCheckBox.Enabled = false;
|
---|
65 | bestKnownQualityTextBox.Text = "-";
|
---|
66 | bestKnownQualityTextBox.Enabled = false;
|
---|
67 | importInstanceButton.Enabled = false;
|
---|
68 | } else {
|
---|
69 | citiesTextBox.Text = TSPInjector.GetVariable("Cities").Value.ToString();
|
---|
70 | bestKnownQualityAvailableCheckBox.Checked = TSPInjector.GetVariable("InjectBestKnownQuality").GetValue<BoolData>().Data;
|
---|
71 | bestKnownQualityAvailableCheckBox.Enabled = true;
|
---|
72 | if (bestKnownQualityAvailableCheckBox.Checked) {
|
---|
73 | bestKnownQualityTextBox.Text = TSPInjector.GetVariable("BestKnownQuality").Value.ToString();
|
---|
74 | bestKnownQualityTextBox.Enabled = true;
|
---|
75 | } else {
|
---|
76 | bestKnownQualityTextBox.Text = "-";
|
---|
77 | bestKnownQualityTextBox.Enabled = false;
|
---|
78 | }
|
---|
79 | importInstanceButton.Enabled = true;
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void bestKnownQualityAvailableCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
84 | TSPInjector.GetVariable("InjectBestKnownQuality").GetValue<BoolData>().Data = bestKnownQualityAvailableCheckBox.Checked;
|
---|
85 | if (bestKnownQualityAvailableCheckBox.Checked) {
|
---|
86 | bestKnownQualityTextBox.Text = TSPInjector.GetVariable("BestKnownQuality").Value.ToString();
|
---|
87 | bestKnownQualityTextBox.Enabled = true;
|
---|
88 | } else {
|
---|
89 | bestKnownQualityTextBox.Text = "-";
|
---|
90 | bestKnownQualityTextBox.Enabled = false;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | private void bestKnownQualityTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
95 | e.Cancel = false;
|
---|
96 | try {
|
---|
97 | TSPInjector.GetVariable("BestKnownQuality").GetValue<DoubleData>().Data = double.Parse(bestKnownQualityTextBox.Text);
|
---|
98 | }
|
---|
99 | catch (Exception) {
|
---|
100 | bestKnownQualityTextBox.SelectAll();
|
---|
101 | e.Cancel = true;
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | private void importInstanceButton_Click(object sender, EventArgs e) {
|
---|
106 | if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
107 | TSPParser parser = null;
|
---|
108 | bool success = false;
|
---|
109 | try {
|
---|
110 | parser = new TSPParser(openFileDialog.FileName);
|
---|
111 | parser.Parse();
|
---|
112 | success = true;
|
---|
113 | }
|
---|
114 | catch (Exception ex) {
|
---|
115 | MessageBox.Show(this, ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
116 | }
|
---|
117 | if (success) {
|
---|
118 | TSPInjector.GetVariable("Cities").Value = new IntData(parser.Vertices.GetLength(0));
|
---|
119 | TSPInjector.GetVariable("Coordinates").Value = new DoubleMatrixData(parser.Vertices);
|
---|
120 | Refresh();
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|