Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.PTSP.Views/3.3/ProbabilisticTravelingSalesmanProblemView.cs @ 17604

Last change on this file since 17604 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.7 KB
RevLine 
[12269]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[12269]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;
[13412]23using HeuristicLab.Data;
[12269]24using HeuristicLab.MainForm;
25using HeuristicLab.Optimization.Views;
[13412]26using HeuristicLab.Random;
[12269]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>
[13412]41    /// Initializes a new instance of <see cref="ProbabilisticTravelingSalesmanProblemView"/>.
[12269]42    /// </summary>
43    public ProbabilisticTravelingSalesmanProblemView() {
44      InitializeComponent();
45    }
46
47    protected override void DeregisterContentEvents() {
[13412]48      Content.CoordinatesParameter.ValueChanged -= CoordinatesParameter_ValueChanged;
49      Content.ProbabilitiesParameter.ValueChanged -= ProbabilityParameter_ValueChanged;
50      Content.BestKnownSolutionParameter.ValueChanged -= BestKnownSolutionParameter_ValueChanged;
[12269]51      base.DeregisterContentEvents();
52    }
53    protected override void RegisterContentEvents() {
54      base.RegisterContentEvents();
[13412]55      Content.CoordinatesParameter.ValueChanged += CoordinatesParameter_ValueChanged;
56      Content.ProbabilitiesParameter.ValueChanged += ProbabilityParameter_ValueChanged;
57      Content.BestKnownSolutionParameter.ValueChanged += BestKnownSolutionParameter_ValueChanged;
[12269]58    }
59    protected override void OnContentChanged() {
60      base.OnContentChanged();
61      if (Content == null) {
62        pathPTSPTourView.Content = null;
63      } else {
[13412]64        pathPTSPTourView.Content = new PathPTSPTour(Content.Coordinates, Content.Probabilities, Content.BestKnownSolution, new DoubleValue(Content.BestKnownQuality));
[12269]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) {
[13412]77      pathPTSPTourView.Content.Probabilities = Content.Probabilities;
[12269]78    }
79    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
80      pathPTSPTourView.Content.Permutation = Content.BestKnownSolution;
[13470]81      if (Content.BestKnownSolution != null)
82        pathPTSPTourView.Content.Quality = new DoubleValue(Content.Evaluate(Content.BestKnownSolution, new MersenneTwister(13)));
83      else pathPTSPTourView.Content.Quality = null;
[12269]84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.