[5563] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 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 |
|
---|
[5641] | 22 | using System;
|
---|
[6342] | 23 | using System.Drawing;
|
---|
[5563] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Common.Resources;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
[6659] | 27 | using HeuristicLab.Data;
|
---|
[5563] | 28 | using HeuristicLab.MainForm;
|
---|
| 29 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.QuadraticAssignment.Views {
|
---|
| 32 | [View("Quadratic Assignment Problem View")]
|
---|
| 33 | [Content(typeof(QuadraticAssignmentProblem), IsDefaultView = true)]
|
---|
| 34 | public sealed partial class QuadraticAssignmentProblemView : ParameterizedNamedItemView {
|
---|
| 35 | public new QuadraticAssignmentProblem Content {
|
---|
| 36 | get { return (QuadraticAssignmentProblem)base.Content; }
|
---|
| 37 | set { base.Content = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public QuadraticAssignmentProblemView() {
|
---|
| 41 | InitializeComponent();
|
---|
| 42 | importInstanceButton.Image = VSImageLibrary.Open;
|
---|
[6659] | 43 | reloadInstancesButton.Text = String.Empty;
|
---|
| 44 | reloadInstancesButton.Image = VSImageLibrary.Refresh;
|
---|
| 45 | loadInstanceButton.Image = VSImageLibrary.Internet;
|
---|
[5641] | 46 | Controls.Remove(parameterCollectionView);
|
---|
| 47 | parameterCollectionView.Dock = DockStyle.Fill;
|
---|
| 48 | problemTabPage.Controls.Add(parameterCollectionView);
|
---|
[5563] | 49 | }
|
---|
| 50 |
|
---|
[5641] | 51 | protected override void RegisterContentEvents() {
|
---|
| 52 | base.RegisterContentEvents();
|
---|
[5838] | 53 | Content.DistancesParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
|
---|
[5641] | 54 | Content.WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged);
|
---|
| 55 | Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | protected override void DeregisterContentEvents() {
|
---|
[5838] | 59 | Content.DistancesParameter.ValueChanged -= new EventHandler(DistanceMatrixParameter_ValueChanged);
|
---|
[5641] | 60 | Content.WeightsParameter.ValueChanged -= new EventHandler(WeightsParameter_ValueChanged);
|
---|
| 61 | Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
|
---|
| 62 | base.DeregisterContentEvents();
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | private void DistanceMatrixParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
[5838] | 66 | qapView.Distances = Content.Distances;
|
---|
[5641] | 67 | }
|
---|
| 68 |
|
---|
| 69 | private void WeightsParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
| 70 | qapView.Weights = Content.Weights;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | private void BestKnownSolutionParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
| 74 | qapView.Assignment = Content.BestKnownSolution;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[5563] | 77 | protected override void OnContentChanged() {
|
---|
| 78 | base.OnContentChanged();
|
---|
| 79 | instancesComboBox.Items.Clear();
|
---|
| 80 | if (Content != null) {
|
---|
| 81 | foreach (string instance in Content.EmbeddedInstances) {
|
---|
| 82 | instancesComboBox.Items.Add(instance);
|
---|
| 83 | }
|
---|
[5838] | 84 | qapView.Distances = Content.Distances;
|
---|
[5641] | 85 | qapView.Weights = Content.Weights;
|
---|
| 86 | qapView.Assignment = Content.BestKnownSolution;
|
---|
| 87 | } else {
|
---|
| 88 | qapView.Distances = null;
|
---|
| 89 | qapView.Weights = null;
|
---|
| 90 | qapView.Assignment = null;
|
---|
[5563] | 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | protected override void SetEnabledStateOfControls() {
|
---|
| 95 | base.SetEnabledStateOfControls();
|
---|
| 96 | instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null;
|
---|
| 97 | loadInstanceButton.Enabled = !ReadOnly && !Locked && Content != null && instancesComboBox.SelectedItem != null;
|
---|
| 98 | importInstanceButton.Enabled = !ReadOnly && !Locked && Content != null;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | private void instancesComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
|
---|
| 102 | loadInstanceButton.Enabled = instancesComboBox.SelectedItem != null;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | private void loadInstanceButton_Click(object sender, System.EventArgs e) {
|
---|
| 106 | string instance = instancesComboBox.SelectedItem as string;
|
---|
[5641] | 107 | try {
|
---|
[6659] | 108 | //Content.LoadEmbeddedInstance(instance);
|
---|
| 109 | using (QAPServiceReference.QAPClient client = new QAPServiceReference.QAPClient()) {
|
---|
| 110 | var data = client.GetProblemInstanceData(instance);
|
---|
| 111 | DoubleMatrix weights = new DoubleMatrix(data.Weights.Length, data.Weights.Length);
|
---|
| 112 | DoubleMatrix distances = new DoubleMatrix(data.Weights.Length, data.Weights.Length);
|
---|
| 113 | try {
|
---|
| 114 | for (int i = 0; i < data.Weights.Length; i++)
|
---|
| 115 | for (int j = 0; j < data.Weights.Length; j++) {
|
---|
| 116 | weights[i, j] = data.Weights[i][j];
|
---|
| 117 | distances[i, j] = data.Distances[i][j];
|
---|
| 118 | }
|
---|
| 119 | } catch (IndexOutOfRangeException) {
|
---|
| 120 | MessageBox.Show("The problem data is malformed, the problem could not be loaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 121 | }
|
---|
| 122 | Content.Name = data.Name;
|
---|
| 123 | Content.Description = data.Description;
|
---|
| 124 | Content.Maximization.Value = data.Maximization;
|
---|
| 125 | Content.Weights = weights;
|
---|
| 126 | Content.Distances = distances;
|
---|
| 127 | }
|
---|
[5641] | 128 | } catch (Exception ex) {
|
---|
| 129 | PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
|
---|
| 130 | }
|
---|
[5563] | 131 | }
|
---|
| 132 |
|
---|
| 133 | private void importInstanceButton_Click(object sender, System.EventArgs e) {
|
---|
| 134 | if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
---|
[5641] | 135 | try {
|
---|
| 136 | Content.ImportFileInstance(openFileDialog.FileName);
|
---|
| 137 | } catch (Exception ex) {
|
---|
| 138 | PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
|
---|
| 139 | }
|
---|
[5563] | 140 | }
|
---|
| 141 | }
|
---|
[5583] | 142 |
|
---|
| 143 | private void QAPLIBInstancesLabel_Click(object sender, System.EventArgs e) {
|
---|
| 144 | System.Diagnostics.Process.Start("http://www.seas.upenn.edu/qaplib/");
|
---|
| 145 | }
|
---|
[6342] | 146 |
|
---|
| 147 | private void QAPLIBInstancesLabel_MouseEnter(object sender, EventArgs e) {
|
---|
| 148 | Cursor = Cursors.Hand;
|
---|
| 149 | QAPLIBInstancesLabel.ForeColor = Color.Red;
|
---|
| 150 | toolTip.SetToolTip(QAPLIBInstancesLabel, "Browse to http://www.seas.upenn.edu/qaplib/");
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | private void QAPLIBInstancesLabel_MouseLeave(object sender, EventArgs e) {
|
---|
| 154 | Cursor = Cursors.Default;
|
---|
| 155 | QAPLIBInstancesLabel.ForeColor = Color.Blue;
|
---|
| 156 | toolTip.SetToolTip(QAPLIBInstancesLabel, String.Empty);
|
---|
| 157 | }
|
---|
[6659] | 158 |
|
---|
| 159 | private void reloadInstancesButton_Click(object sender, EventArgs e) {
|
---|
| 160 | try {
|
---|
| 161 | using (QAPServiceReference.QAPClient client = new QAPServiceReference.QAPClient()) {
|
---|
| 162 | instancesComboBox.Items.Clear();
|
---|
| 163 | foreach (string name in client.GetProblemInstances())
|
---|
| 164 | instancesComboBox.Items.Add(name);
|
---|
| 165 | }
|
---|
| 166 | } catch (Exception ex) {
|
---|
| 167 | PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
[5563] | 170 | }
|
---|
| 171 | }
|
---|