Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.PTSP.Views/3.3/ProbabilisticTravelingSalesmanProblemView.cs @ 17541

Last change on this file since 17541 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

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