Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs @ 10207

Last change on this file since 10207 was 7861, checked in by svonolfe, 13 years ago

Fixed issues related to display of VRP solution (#1177)

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