Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/26/12 14:50:56 (12 years ago)
Author:
abeham
Message:

#1614: improved results output of GQAP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs

    r7412 r7415  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    4445    #region Register Content Events
    4546    protected override void DeregisterContentEvents() {
    46       // TODO: Deregister your event handlers on the Content here
     47      Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
    4748      base.DeregisterContentEvents();
    4849    }
    4950    protected override void RegisterContentEvents() {
    5051      base.RegisterContentEvents();
    51       // TODO: Register your event handlers on the Content here
     52      Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
    5253    }
    5354    #endregion
     
    5556    protected override void OnContentChanged() {
    5657      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       }
     58      UpdateQuality();
     59      UpdateAssignment();
    6460    }
    6561
    6662    protected override void SetEnabledStateOfControls() {
    6763      base.SetEnabledStateOfControls();
    68       qualityTextBox.Enabled = false;
    69       assignmentTreeView.Enabled = true;
    7064    }
    7165
    7266    #region Event Handlers
    73     // TODO: Put event handlers here
     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    }
    7479    #endregion
    7580
    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));
     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();
    8588        }
    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);
    9089      }
     90    }
    9191
    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();
     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();
    9799        }
    98       } finally { assignmentTreeView.EndUpdate(); }
     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      }
    99154    }
    100155  }
Note: See TracChangeset for help on using the changeset viewer.