[2] | 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 {
|
---|
[884] | 34 | /// <summary>
|
---|
| 35 | /// Class to represent a <see cref="TSPInjector"/> visually.
|
---|
| 36 | /// </summary>
|
---|
[2] | 37 | public partial class TSPInjectorView : ViewBase {
|
---|
[884] | 38 | /// <summary>
|
---|
| 39 | /// Gets or set the <see cref="TSPInjector"/> to represent visually.
|
---|
| 40 | /// </summary>
|
---|
| 41 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
| 42 | /// No own data storage present.</remarks>
|
---|
[2] | 43 | public TSPInjector TSPInjector {
|
---|
| 44 | get { return (TSPInjector)Item; }
|
---|
| 45 | set { base.Item = value; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[884] | 48 | /// <summary>
|
---|
| 49 | /// Initializes a new instance of <see cref="TSPInjectorView"/>.
|
---|
| 50 | /// </summary>
|
---|
[2] | 51 | public TSPInjectorView() {
|
---|
| 52 | InitializeComponent();
|
---|
| 53 | }
|
---|
[884] | 54 | /// <summary>
|
---|
| 55 | /// Initializes a new instance of <see cref="TSPInjectorView"/> with the given
|
---|
| 56 | /// <paramref name="tspInjector"/>.
|
---|
| 57 | /// </summary>
|
---|
| 58 | /// <param name="tspInjector">The <see cref="TSPInjector"/> to display.</param>
|
---|
[2] | 59 | public TSPInjectorView(TSPInjector tspInjector)
|
---|
| 60 | : this() {
|
---|
| 61 | TSPInjector = tspInjector;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[884] | 64 | /// <summary>
|
---|
| 65 | /// Removes the event handlers in all children.
|
---|
| 66 | /// </summary>
|
---|
| 67 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2] | 68 | protected override void RemoveItemEvents() {
|
---|
| 69 | operatorBaseVariableInfosView.Operator = null;
|
---|
| 70 | operatorBaseDescriptionView.Operator = null;
|
---|
| 71 | base.RemoveItemEvents();
|
---|
| 72 | }
|
---|
[884] | 73 | /// <summary>
|
---|
| 74 | /// Adds event handlers in all children.
|
---|
| 75 | /// </summary>
|
---|
| 76 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2] | 77 | protected override void AddItemEvents() {
|
---|
| 78 | base.AddItemEvents();
|
---|
| 79 | operatorBaseVariableInfosView.Operator = TSPInjector;
|
---|
| 80 | operatorBaseDescriptionView.Operator = TSPInjector;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[884] | 83 | /// <summary>
|
---|
| 84 | /// Updates all controls with the latest data of the model.
|
---|
| 85 | /// </summary>
|
---|
| 86 | /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2] | 87 | protected override void UpdateControls() {
|
---|
| 88 | base.UpdateControls();
|
---|
| 89 | if (TSPInjector == null) {
|
---|
| 90 | citiesTextBox.Text = "-";
|
---|
| 91 | bestKnownQualityAvailableCheckBox.Checked = false;
|
---|
| 92 | bestKnownQualityAvailableCheckBox.Enabled = false;
|
---|
| 93 | bestKnownQualityTextBox.Text = "-";
|
---|
| 94 | bestKnownQualityTextBox.Enabled = false;
|
---|
| 95 | importInstanceButton.Enabled = false;
|
---|
| 96 | } else {
|
---|
| 97 | citiesTextBox.Text = TSPInjector.GetVariable("Cities").Value.ToString();
|
---|
| 98 | bestKnownQualityAvailableCheckBox.Checked = TSPInjector.GetVariable("InjectBestKnownQuality").GetValue<BoolData>().Data;
|
---|
| 99 | bestKnownQualityAvailableCheckBox.Enabled = true;
|
---|
| 100 | if (bestKnownQualityAvailableCheckBox.Checked) {
|
---|
| 101 | bestKnownQualityTextBox.Text = TSPInjector.GetVariable("BestKnownQuality").Value.ToString();
|
---|
| 102 | bestKnownQualityTextBox.Enabled = true;
|
---|
| 103 | } else {
|
---|
| 104 | bestKnownQualityTextBox.Text = "-";
|
---|
| 105 | bestKnownQualityTextBox.Enabled = false;
|
---|
| 106 | }
|
---|
| 107 | importInstanceButton.Enabled = true;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | private void bestKnownQualityAvailableCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 112 | TSPInjector.GetVariable("InjectBestKnownQuality").GetValue<BoolData>().Data = bestKnownQualityAvailableCheckBox.Checked;
|
---|
| 113 | if (bestKnownQualityAvailableCheckBox.Checked) {
|
---|
| 114 | bestKnownQualityTextBox.Text = TSPInjector.GetVariable("BestKnownQuality").Value.ToString();
|
---|
| 115 | bestKnownQualityTextBox.Enabled = true;
|
---|
| 116 | } else {
|
---|
| 117 | bestKnownQualityTextBox.Text = "-";
|
---|
| 118 | bestKnownQualityTextBox.Enabled = false;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | private void bestKnownQualityTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 123 | e.Cancel = false;
|
---|
| 124 | try {
|
---|
| 125 | TSPInjector.GetVariable("BestKnownQuality").GetValue<DoubleData>().Data = double.Parse(bestKnownQualityTextBox.Text);
|
---|
| 126 | }
|
---|
| 127 | catch (Exception) {
|
---|
| 128 | bestKnownQualityTextBox.SelectAll();
|
---|
| 129 | e.Cancel = true;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | private void importInstanceButton_Click(object sender, EventArgs e) {
|
---|
| 134 | if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 135 | TSPParser parser = null;
|
---|
| 136 | bool success = false;
|
---|
| 137 | try {
|
---|
| 138 | parser = new TSPParser(openFileDialog.FileName);
|
---|
| 139 | parser.Parse();
|
---|
| 140 | success = true;
|
---|
| 141 | }
|
---|
| 142 | catch (Exception ex) {
|
---|
| 143 | MessageBox.Show(this, ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 144 | }
|
---|
| 145 | if (success) {
|
---|
| 146 | TSPInjector.GetVariable("Cities").Value = new IntData(parser.Vertices.GetLength(0));
|
---|
| 147 | TSPInjector.GetVariable("Coordinates").Value = new DoubleMatrixData(parser.Vertices);
|
---|
| 148 | Refresh();
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 | }
|
---|