Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MemPRAlgorithm/HeuristicLab.Problems.TravelingSalesman.Views/3.3/TravelingSalesmanProblemView.cs @ 14454

Last change on this file since 14454 was 14454, checked in by abeham, 7 years ago

#2701:

  • Worked on MemPR algorithm for permutations
  • Refactored TSP
File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Windows.Forms;
24using HeuristicLab.Data;
25using HeuristicLab.MainForm;
26using HeuristicLab.Optimization.Views;
27
28namespace HeuristicLab.Problems.TravelingSalesman.Views {
29  /// <summary>
30  /// A view for a Traveling Salesman Problem instance.
31  /// </summary>
32  [View("Traveling Salesman Problem View")]
33  [Content(typeof(TravelingSalesmanProblem), true)]
34  public sealed partial class TravelingSalesmanProblemView : ProblemView {
35    public new TravelingSalesmanProblem Content {
36      get { return (TravelingSalesmanProblem)base.Content; }
37      set { base.Content = value; }
38    }
39
40    /// <summary>
41    /// Initializes a new instance of <see cref="TravelingSalesmanProblemView"/>.
42    /// </summary>
43    public TravelingSalesmanProblemView() {
44      InitializeComponent();
45    }
46
47    protected override void DeregisterContentEvents() {
48      Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
49      //Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged);
50      Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
51      base.DeregisterContentEvents();
52    }
53    protected override void RegisterContentEvents() {
54      base.RegisterContentEvents();
55      Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
56      //Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
57      Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
58    }
59
60    protected override void OnContentChanged() {
61      base.OnContentChanged();
62      if (Content == null) {
63        pathTSPTourView.Content = null;
64      } else {
65        pathTSPTourView.Content = new PathTSPTour(Content.Coordinates, Content.BestKnownSolution, new DoubleValue(Content.BestKnownQuality));
66      }
67    }
68
69    protected override void SetEnabledStateOfControls() {
70      base.SetEnabledStateOfControls();
71      pathTSPTourView.Enabled = Content != null;
72      updateDistanceMatrixButton.Enabled = Content != null && !ReadOnly && !Locked;
73    }
74
75    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
76      pathTSPTourView.Content.Coordinates = Content.Coordinates;
77    }
78    private void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
79      pathTSPTourView.Content.Quality = new DoubleValue(Content.BestKnownQuality);
80    }
81    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
82      pathTSPTourView.Content.Permutation = Content.BestKnownSolution;
83    }
84
85    private void updateDistanceMatrixButton_Click(object sender, EventArgs e) {
86      Content.UpdateDistanceMatrix();
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.