Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1614: worked on GQAP (added operators, assignment view)

File size: 3.7 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.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Core.Views;
27using HeuristicLab.Encodings.IntegerVectorEncoding;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
30
31namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
32  [View("GQAPAssignmentView")]
33  [Content(typeof(GQAPAssignment), IsDefaultView = true)]
34  public partial class GQAPAssignmentView : ItemView {
35    public new GQAPAssignment Content {
36      get { return (GQAPAssignment)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public GQAPAssignmentView() {
41      InitializeComponent();
42    }
43
44    #region Register Content Events
45    protected override void DeregisterContentEvents() {
46      // TODO: Deregister your event handlers on the Content here
47      base.DeregisterContentEvents();
48    }
49    protected override void RegisterContentEvents() {
50      base.RegisterContentEvents();
51      // TODO: Register your event handlers on the Content here
52    }
53    #endregion
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      assignmentTreeView.Nodes.Clear();
58      if (Content == null) {
59        qualityTextBox.Text = String.Empty;
60      } else {
61        qualityTextBox.Text = Content.Quality.Value.ToString();
62        BuildAssignmentTree();
63      }
64    }
65
66    protected override void SetEnabledStateOfControls() {
67      base.SetEnabledStateOfControls();
68      qualityTextBox.Enabled = !ReadOnly && !Locked && Content != null;
69      assignmentTreeView.Enabled = !ReadOnly && !Locked && Content != null;
70    }
71
72    #region Event Handlers
73    // TODO: Put event handlers here
74    #endregion
75
76    private void BuildAssignmentTree() {
77      IntegerVector assignment = Content.Assignment;
78      Dictionary<int, TreeNode> locationNodes = new Dictionary<int, TreeNode>();
79      for (int i = 0; i < assignment.Length; i++) {
80        if (!locationNodes.ContainsKey(assignment[i])) {
81          string locationName = assignment[i].ToString();
82          if (Content.LocationNames != null && Content.LocationNames.Length > 0)
83            locationName = Content.LocationNames[assignment[i] % Content.LocationNames.Length];
84          locationNodes.Add(assignment[i], new TreeNode(locationName));
85        }
86        string equipmentName = i.ToString();
87        if (Content.EquipmentNames != null && Content.EquipmentNames.Length > 0)
88          equipmentName = Content.EquipmentNames[i % Content.EquipmentNames.Length];
89        locationNodes[assignment[i]].Nodes.Add(equipmentName);
90      }
91
92      assignmentTreeView.BeginUpdate();
93      try {
94        foreach (var node in locationNodes.OrderBy(x => x.Key).Select(x => x.Value)) {
95          assignmentTreeView.Nodes.Add(node);
96          node.Expand();
97        }
98      } finally { assignmentTreeView.EndUpdate(); }
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.