Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 12335 was 11327, checked in by pfleck, 10 years ago

#2208

  • Added distance and penalty visualization for orienteering solution.
  • Added Evaluate method in IOrienteeringEvaluator for evaluation of new best solutions (still need some design improvements).
File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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
28  [View("Orienteering Problem View")]
29  [Content(typeof(OrienteeringProblem), true)]
30  public partial class OrienteeringProblemView : ProblemView {
31    public new OrienteeringProblem Content {
32      get { return (OrienteeringProblem)base.Content; }
33      set { base.Content = value; }
34    }
35
36    public OrienteeringProblemView() {
37      InitializeComponent();
38    }
39
40    protected override void DeregisterContentEvents() {
41      Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
42      Content.StartingPointParameter.ValueChanged -= new EventHandler(StartingPointParameter_ValueChanged);
43      Content.TerminalPointParameter.ValueChanged -= new EventHandler(TerminalPointParameter_ValueChanged);
44      Content.ScoresParameter.ValueChanged -= new EventHandler(ScoresParameter_ValueChanged);
45      Content.BestKnownQualityParameter.ValueChanged -= new EventHandler(BestKnownQualityParameter_ValueChanged);
46      Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
47      base.DeregisterContentEvents();
48    }
49    protected override void RegisterContentEvents() {
50      base.RegisterContentEvents();
51      Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
52      Content.StartingPointParameter.ValueChanged += new EventHandler(StartingPointParameter_ValueChanged);
53      Content.TerminalPointParameter.ValueChanged += new EventHandler(TerminalPointParameter_ValueChanged);
54      Content.ScoresParameter.ValueChanged += new EventHandler(ScoresParameter_ValueChanged);
55      Content.BestKnownQualityParameter.ValueChanged += new EventHandler(BestKnownQualityParameter_ValueChanged);
56      Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
57    }
58
59    protected override void OnContentChanged() {
60      base.OnContentChanged();
61      if (Content == null) {
62        orienteeringSolutionView.Content = null;
63      } else {
64        orienteeringSolutionView.Content = new OrienteeringSolution(Content.BestKnownSolution,
65          Content.Coordinates, Content.StartingPointParameter.Value, Content.TerminalPointParameter.Value, Content.Scores);
66        if (Content.BestKnownSolution != null) {
67          EvaluateBestSolution();
68        }
69      }
70    }
71
72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
74      orienteeringSolutionView.Enabled = Content != null;
75    }
76
77    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
78      orienteeringSolutionView.Content.Coordinates = Content.Coordinates;
79    }
80    private void StartingPointParameter_ValueChanged(object sender, EventArgs e) {
81      orienteeringSolutionView.Content.StartingPoint.Value = Content.StartingPoint;
82    }
83    private void TerminalPointParameter_ValueChanged(object sender, EventArgs e) {
84      orienteeringSolutionView.Content.TerminalPoint.Value = Content.TerminalPoint;
85    }
86    private void ScoresParameter_ValueChanged(object sender, EventArgs e) {
87      orienteeringSolutionView.Content.Scores = Content.Scores;
88    }
89    private void BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) {
90      orienteeringSolutionView.Content.Quality = Content.BestKnownQuality;
91    }
92    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
93      orienteeringSolutionView.Content.IntegerVector = Content.BestKnownSolution;
94      if (Content.BestKnownSolution != null)
95        EvaluateBestSolution();
96      else {
97        var solution = orienteeringSolutionView.Content;
98        solution.Penalty = null;
99        solution.Distance = null;
100      }
101    }
102
103    private void EvaluateBestSolution() {
104      var evaluation = Content.Evaluator.Evaluate(Content.BestKnownSolution, Content.Scores, Content.DistanceMatrix,
105        Content.MaximumDistance, Content.PointVisitingCosts);
106      orienteeringSolutionView.Content.Quality = evaluation.Quality;
107      orienteeringSolutionView.Content.Penalty = evaluation.Penalty;
108      orienteeringSolutionView.Content.Distance = evaluation.Distance;
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.