Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs @ 7415

Last change on this file since 7415 was 7415, checked in by abeham, 12 years ago

#1614: improved results output of GQAP

File size: 5.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Linq;
26using System.Windows.Forms;
27using HeuristicLab.Core.Views;
28using HeuristicLab.Encodings.IntegerVectorEncoding;
29using HeuristicLab.MainForm;
30using HeuristicLab.MainForm.WindowsForms;
31
32namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
33  [View("GQAPAssignmentView")]
34  [Content(typeof(GQAPAssignment), IsDefaultView = true)]
35  public partial class GQAPAssignmentView : ItemView {
36    public new GQAPAssignment Content {
37      get { return (GQAPAssignment)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public GQAPAssignmentView() {
42      InitializeComponent();
43    }
44
45    #region Register Content Events
46    protected override void DeregisterContentEvents() {
47      Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
48      base.DeregisterContentEvents();
49    }
50    protected override void RegisterContentEvents() {
51      base.RegisterContentEvents();
52      Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
53    }
54    #endregion
55
56    protected override void OnContentChanged() {
57      base.OnContentChanged();
58      UpdateQuality();
59      UpdateAssignment();
60    }
61
62    protected override void SetEnabledStateOfControls() {
63      base.SetEnabledStateOfControls();
64    }
65
66    #region Event Handlers
67    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
68      switch (e.PropertyName) {
69        case "Quality": UpdateQuality(); break;
70        case "FlowDistanceQuality": UpdateFlowDistanceQuality(); break;
71        case "InstallationQuality": UpdateInstallationQuality(); break;
72        case "OverbookedCapacity": UpdateOverbookedCapacity(); break;
73        case "Assignment": UpdateAssignment(); break;
74        case "EquipmentNames": UpdateAssignment(); break;
75        case "LocationNames": UpdateAssignment(); break;
76        default: break;
77      }
78    }
79    #endregion
80
81    private void UpdateQuality() {
82      if (InvokeRequired) Invoke((Action)UpdateQuality);
83      else {
84        if (Content == null) {
85          qualityLabel.Text = "-";
86        } else {
87          qualityLabel.Text = Content.Quality.ToString();
88        }
89      }
90    }
91
92    private void UpdateFlowDistanceQuality() {
93      if (InvokeRequired) Invoke((Action)UpdateFlowDistanceQuality);
94      else {
95        if (Content == null || Content.FlowDistanceQuality == null) {
96          flowDistanceQualityLabel.Text = "-";
97        } else {
98          flowDistanceQualityLabel.Text = Content.FlowDistanceQuality.ToString();
99        }
100      }
101    }
102
103    private void UpdateInstallationQuality() {
104      if (InvokeRequired) Invoke((Action)UpdateInstallationQuality);
105      else {
106        if (Content == null || Content.InstallationQuality == null) {
107          installationQualityLabel.Text = "-";
108        } else {
109          installationQualityLabel.Text = Content.InstallationQuality.ToString();
110        }
111      }
112    }
113
114    private void UpdateOverbookedCapacity() {
115      if (InvokeRequired) Invoke((Action)UpdateOverbookedCapacity);
116      else {
117        if (Content == null || Content.OverbookedCapacity == null) {
118          overbookedCapacityLabel.Text = "-";
119        } else {
120          overbookedCapacityLabel.Text = Content.OverbookedCapacity.ToString();
121        }
122      }
123    }
124
125    private void UpdateAssignment() {
126      if (InvokeRequired) Invoke((Action)UpdateAssignment);
127      else {
128        assignmentTreeView.Nodes.Clear();
129        if (Content != null) {
130          IntegerVector assignment = Content.Assignment;
131          Dictionary<int, TreeNode> locationNodes = new Dictionary<int, TreeNode>();
132          for (int i = 0; i < assignment.Length; i++) {
133            if (!locationNodes.ContainsKey(assignment[i])) {
134              string locationName = assignment[i].ToString();
135              if (Content.LocationNames != null && Content.LocationNames.Length > assignment[i])
136                locationName = Content.LocationNames[assignment[i]];
137              locationNodes.Add(assignment[i], new TreeNode(locationName));
138            }
139            string equipmentName = i.ToString();
140            if (Content.EquipmentNames != null && Content.EquipmentNames.Length > i)
141              equipmentName = Content.EquipmentNames[i];
142            locationNodes[assignment[i]].Nodes.Add(equipmentName);
143          }
144
145          assignmentTreeView.BeginUpdate();
146          try {
147            foreach (var node in locationNodes.OrderBy(x => x.Key).Select(x => x.Value)) {
148              assignmentTreeView.Nodes.Add(node);
149              node.Expand();
150            }
151          } finally { assignmentTreeView.EndUpdate(); }
152        }
153      }
154    }
155  }
156}
Note: See TracBrowser for help on using the repository browser.