Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.Routing.TSP/TSPInjectorView.cs @ 14051

Last change on this file since 14051 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 4.6 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31using HeuristicLab.Operators;
32
33namespace 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}
Note: See TracBrowser for help on using the repository browser.