Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Async/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemView.cs @ 14618

Last change on this file since 14618 was 12721, checked in by abeham, 9 years ago

#2208:

  • Added missing license headers
  • Updates copyright year
  • Renamed analyzer (us spelling)
  • Removed script
  • Implemented samples unit test
  • Changed solution view to use horizontal splitting, removed viewhosts
  • Updated instance provider to use .NET45 zip compression
  • Restructuring and reformatting
File size: 4.9 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 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    }
38
39    protected override void DeregisterContentEvents() {
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;
46      base.DeregisterContentEvents();
47    }
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
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;
56    }
57
58    protected override void OnContentChanged() {
59      base.OnContentChanged();
60      if (Content == null) {
61        orienteeringSolutionView.Content = null;
62      } else {
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        }
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    }
79
80    private void StartingPointParameter_ValueChanged(object sender, EventArgs e) {
81      orienteeringSolutionView.Content.StartingPoint.Value = Content.StartingPoint;
82    }
83
84    private void TerminalPointParameter_ValueChanged(object sender, EventArgs e) {
85      orienteeringSolutionView.Content.TerminalPoint.Value = Content.TerminalPoint;
86    }
87
88    private void ScoresParameter_ValueChanged(object sender, EventArgs e) {
89      orienteeringSolutionView.Content.Scores = Content.Scores;
90    }
91
92    private void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
93      orienteeringSolutionView.Content.Quality = Content.BestKnownQuality;
94    }
95
96    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
97      orienteeringSolutionView.Content.IntegerVector = Content.BestKnownSolution;
98      if (Content.BestKnownSolution != null)
99        EvaluateBestSolution();
100      else {
101        var solution = orienteeringSolutionView.Content;
102        solution.Penalty = null;
103        solution.Distance = null;
104      }
105    }
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    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.