Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemView.cs @ 16147

Last change on this file since 16147 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 4.9 KB
RevLine 
[11189]1#region License Information
2/* HeuristicLab
[15584]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[11189]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
[11245]22using System;
[11189]23using HeuristicLab.MainForm;
24using HeuristicLab.Optimization.Views;
25
26namespace HeuristicLab.Problems.Orienteering.Views {
27  [View("Orienteering Problem View")]
28  [Content(typeof(OrienteeringProblem), true)]
29  public partial class OrienteeringProblemView : ProblemView {
30    public new OrienteeringProblem Content {
31      get { return (OrienteeringProblem)base.Content; }
32      set { base.Content = value; }
33    }
34
35    public OrienteeringProblemView() {
36      InitializeComponent();
37    }
[11245]38
39    protected override void DeregisterContentEvents() {
[12721]40      Content.CoordinatesParameter.ValueChanged -= CoordinatesParameter_ValueChanged;
41      Content.StartingPointParameter.ValueChanged -= StartingPointParameter_ValueChanged;
42      Content.TerminalPointParameter.ValueChanged -= TerminalPointParameter_ValueChanged;
43      Content.ScoresParameter.ValueChanged -= ScoresParameter_ValueChanged;
44      Content.BestKnownQualityParameter.ValueChanged -= BestKnownQualityParameter_ValueChanged;
45      Content.BestKnownSolutionParameter.ValueChanged -= BestKnownSolutionParameter_ValueChanged;
[11245]46      base.DeregisterContentEvents();
47    }
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
[12721]50      Content.CoordinatesParameter.ValueChanged += CoordinatesParameter_ValueChanged;
51      Content.StartingPointParameter.ValueChanged += StartingPointParameter_ValueChanged;
52      Content.TerminalPointParameter.ValueChanged += TerminalPointParameter_ValueChanged;
53      Content.ScoresParameter.ValueChanged += ScoresParameter_ValueChanged;
54      Content.BestKnownQualityParameter.ValueChanged += BestKnownQualityParameter_ValueChanged;
55      Content.BestKnownSolutionParameter.ValueChanged += BestKnownSolutionParameter_ValueChanged;
[11245]56    }
57
58    protected override void OnContentChanged() {
59      base.OnContentChanged();
60      if (Content == null) {
61        orienteeringSolutionView.Content = null;
62      } else {
[11327]63        orienteeringSolutionView.Content = new OrienteeringSolution(Content.BestKnownSolution,
64          Content.Coordinates, Content.StartingPointParameter.Value, Content.TerminalPointParameter.Value, Content.Scores);
65        if (Content.BestKnownSolution != null) {
66          EvaluateBestSolution();
67        }
[11245]68      }
69    }
70
71    protected override void SetEnabledStateOfControls() {
72      base.SetEnabledStateOfControls();
73      orienteeringSolutionView.Enabled = Content != null;
74    }
75
76    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
77      orienteeringSolutionView.Content.Coordinates = Content.Coordinates;
78    }
[12721]79
[11267]80    private void StartingPointParameter_ValueChanged(object sender, EventArgs e) {
[11325]81      orienteeringSolutionView.Content.StartingPoint.Value = Content.StartingPoint;
[11267]82    }
[12721]83
[11319]84    private void TerminalPointParameter_ValueChanged(object sender, EventArgs e) {
[11325]85      orienteeringSolutionView.Content.TerminalPoint.Value = Content.TerminalPoint;
[11267]86    }
[12721]87
[11245]88    private void ScoresParameter_ValueChanged(object sender, EventArgs e) {
89      orienteeringSolutionView.Content.Scores = Content.Scores;
90    }
[12721]91
[11245]92    private void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
93      orienteeringSolutionView.Content.Quality = Content.BestKnownQuality;
94    }
[12721]95
[11245]96    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
97      orienteeringSolutionView.Content.IntegerVector = Content.BestKnownSolution;
[11327]98      if (Content.BestKnownSolution != null)
99        EvaluateBestSolution();
100      else {
101        var solution = orienteeringSolutionView.Content;
102        solution.Penalty = null;
103        solution.Distance = null;
104      }
[11245]105    }
[11327]106
107    private void EvaluateBestSolution() {
108      var evaluation = Content.Evaluator.Evaluate(Content.BestKnownSolution, Content.Scores, Content.DistanceMatrix,
109        Content.MaximumDistance, Content.PointVisitingCosts);
110      orienteeringSolutionView.Content.Quality = evaluation.Quality;
111      orienteeringSolutionView.Content.Penalty = evaluation.Penalty;
112      orienteeringSolutionView.Content.Distance = evaluation.Distance;
113    }
[11189]114  }
115}
Note: See TracBrowser for help on using the repository browser.