Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PTSP/HeuristicLab.Problems.PTSP.Views/3.3/ProbabilisticTravelingSalesmanProblemView.cs @ 12797

Last change on this file since 12797 was 12269, checked in by apolidur, 10 years ago

#2221: Adding Tests and Views for PTSP

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