Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2205_OptimizationNetworks/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs @ 17021

Last change on this file since 17021 was 14677, checked in by abeham, 8 years ago

#2205: added results tab to solution view to analyze vrp solution in more detail

  • reorganized insertion infos and adapted some evaluators and instances
File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 System.Linq;
24using System.Text;
25using System.Windows.Forms;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Problems.VehicleRouting.Views {
29  [View("VRPSolution View")]
30  [Content(typeof(VRPSolution), true)]
31  public partial class VRPSolutionView : HeuristicLab.Core.Views.ItemView {
32    public new VRPSolution Content {
33      get { return (VRPSolution)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public VRPSolutionView() {
38      InitializeComponent();
39      problemInstanceView.ViewsLabelVisible = false;
40    }
41
42    protected override void DeregisterContentEvents() {
43      Content.SolutionChanged -= new EventHandler(Content_SolutionChanged);
44      base.DeregisterContentEvents();
45    }
46    protected override void RegisterContentEvents() {
47      base.RegisterContentEvents();
48      Content.SolutionChanged += new EventHandler(Content_SolutionChanged);
49    }
50
51    private void UpdateContent() {
52      var view = problemInstanceView.ActiveView as VRPProblemInstanceView;
53      if (view != null) view.Solution = null;
54
55      problemInstanceView.Content = Content.ProblemInstance;
56
57      view = problemInstanceView.ActiveView as VRPProblemInstanceView;
58      if (view != null) view.Solution = Content.Solution;
59
60      UpdateTourView();
61      UpdateResultsView();
62    }
63
64    protected override void OnContentChanged() {
65      base.OnContentChanged();
66      if (Content == null) {
67        problemInstanceView.Content = null;
68      } else {
69        UpdateContent();
70      }
71    }
72
73    private void Content_SolutionChanged(object sender, EventArgs e) {
74      if (InvokeRequired)
75        Invoke(new EventHandler(Content_SolutionChanged), sender, e);
76      else {
77        UpdateContent();
78      }
79    }
80
81    protected override void OnReadOnlyChanged() {
82      base.OnReadOnlyChanged();
83      SetEnabledStateOfControls();
84    }
85
86    protected override void SetEnabledStateOfControls() {
87      base.SetEnabledStateOfControls();
88      tabControl1.Enabled = Content != null;
89      problemInstanceView.Enabled = Content != null;
90    }
91
92    private void UpdateTourView() {
93      var sb = new StringBuilder();
94
95      if (Content != null && Content.Solution != null) {
96        foreach (var tour in Content.Solution.GetTours()) {
97          foreach (var city in tour.Stops) {
98            sb.Append(city);
99            sb.Append(" ");
100          }
101          sb.AppendLine();
102        }
103      }
104
105      valueTextBox.Text = sb.ToString();
106    }
107   
108    private void UpdateResultsView() {
109      var builder = new StringBuilder();
110      if (Content != null && Content.Solution != null) {
111        var evaluationInfo = Content.ProblemInstance.Evaluate(Content.Solution);
112        evaluationInfo.GetReport(builder);
113      }
114      resultsTextBox.Text = builder.ToString();
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.