Ignore:
Timestamp:
08/14/18 12:01:42 (16 months ago)
Author:
abeham
Message:

#2936: Added integration branch

Location:
branches/2936_GQAPIntegration
Files:
1 added
1 edited
1 copied

Legend:

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

    r15510 r16077  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4545    public GQAPAssignmentView() {
    4646      InitializeComponent();
     47      recalculateButton.Text = string.Empty;
    4748      recalculateButton.Image = VSImageLibrary.Refresh;
    4849    }
     
    5051    #region Register Content Events
    5152    protected override void DeregisterContentEvents() {
    52       Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
     53      DeregisterSolutionEvents();
     54      Content.PropertyChanged -= Content_PropertyChanged;
    5355      base.DeregisterContentEvents();
    5456    }
    5557    protected override void RegisterContentEvents() {
    5658      base.RegisterContentEvents();
    57       Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
     59      Content.PropertyChanged += Content_PropertyChanged;
     60      RegisterSolutionEvents();
     61    }
     62
     63    private void DeregisterSolutionEvents() {
     64      if (Content.Solution != null) Content.Solution.PropertyChanged -= Content_SolutionPropertyChanged;
     65    }
     66    private void RegisterSolutionEvents() {
     67      if (Content.Solution != null) Content.Solution.PropertyChanged += Content_SolutionPropertyChanged;
    5868    }
    5969    #endregion
     
    6373      UpdateEvaluation();
    6474      UpdateAssignment();
    65       if (Content != null) assignmentView.Content = Content.Assignment;
     75      if (Content != null && Content.Solution != null) assignmentView.Content = Content.Solution.Assignment;
    6676      else assignmentView.Content = null;
    6777    }
     
    6979    protected override void SetEnabledStateOfControls() {
    7080      base.SetEnabledStateOfControls();
     81      recalculateButton.Enabled = Content != null && Content.Solution != null && !Locked && !ReadOnly;
    7182    }
    7283
     
    7485    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    7586      switch (e.PropertyName) {
    76         case nameof(Content.Evaluation): UpdateEvaluation(); break;
    77         case nameof(Content.Assignment): UpdateAssignment(); break;
     87        case nameof(Content.Solution): RegisterSolutionEvents(); UpdateEvaluation(); UpdateAssignment(); break;
    7888        case nameof(Content.ProblemInstance): UpdateEvaluation(); UpdateAssignment(); break;
    7989        default: break;
    8090      }
     91      SetEnabledStateOfControls();
     92    }
     93
     94    private void Content_SolutionPropertyChanged(object sender, PropertyChangedEventArgs e) {
     95      switch (e.PropertyName) {
     96        case nameof(Content.Solution.Assignment): UpdateAssignment(); break;
     97        case nameof(Content.Solution.Evaluation): UpdateEvaluation(); break;
     98        default: break;
     99      }
    81100    }
    82101
     
    88107    #region Event Handlers
    89108    private void assignmentTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
    90       if (Content != null) {
     109      if (Content != null && Content.Solution != null) {
    91110        assignmentTreeView.BeginUpdate();
    92111        try {
     
    120139      if (InvokeRequired) Invoke((Action)UpdateEvaluation);
    121140      else {
    122         if (Content == null) {
     141        if (Content == null || Content.Solution == null) {
    123142          qualityLabel.Text = "-";
    124143          flowDistanceQualityLabel.Text = "-";
     
    126145          overbookedCapacityLabel.Text = "-";
    127146        } else {
    128           qualityLabel.Text = Content.ProblemInstance.ToSingleObjective(Content.Evaluation).ToString();
    129           flowDistanceQualityLabel.Text = Content.Evaluation.FlowCosts.ToString();
    130           installationQualityLabel.Text = Content.Evaluation.InstallationCosts.ToString();
    131           overbookedCapacityLabel.Text = Content.Evaluation.ExcessDemand.ToString();
     147          qualityLabel.Text = Content.ProblemInstance.ToSingleObjective(Content.Solution.Evaluation).ToString();
     148          flowDistanceQualityLabel.Text = Content.Solution.Evaluation.FlowCosts.ToString();
     149          installationQualityLabel.Text = Content.Solution.Evaluation.InstallationCosts.ToString();
     150          overbookedCapacityLabel.Text = Content.Solution.Evaluation.ExcessDemand.ToString();
    132151        }
    133152      }
     
    138157      else {
    139158        assignmentTreeView.Nodes.Clear();
    140         if (Content != null) {
    141           IntegerVector assignment = Content.Assignment;
     159        if (Content != null && Content.Solution != null) {
     160          IntegerVector assignment = Content.Solution.Assignment;
    142161          Dictionary<int, TreeNode> locationNodes = new Dictionary<int, TreeNode>();
    143162          for (int i = 0; i < assignment.Length; i++) {
     
    169188      var installationCosts = new Dictionary<EquipmentNode, double>();
    170189      foreach (var node in GetAllSubNodes(assignmentTreeView.Nodes).OfType<EquipmentNode>()) {
    171         int location = Content.Assignment[node.Equipment];
     190        int location = Content.Solution.Assignment[node.Equipment];
    172191        installationCosts[node] = Content.ProblemInstance.InstallationCosts[node.Equipment, location];
    173192      }
     
    216235
    217236    private void ColorByWeight(LocationNode selectedNode) {
    218       var equipments = new HashSet<int>(Content.Assignment.Select((v, i) => new { Index = i, Value = v })
     237      var equipments = new HashSet<int>(Content.Solution.Assignment.Select((v, i) => new { Index = i, Value = v })
    219238        .Where(x => x.Value == selectedNode.Location).Select(x => x.Index));
    220239      var rowSums = new Dictionary<int, double>(equipments.Count);
     
    279298
    280299    private void recalculateButton_Click(object sender, EventArgs e) {
    281       Content.Evaluation = Content.ProblemInstance.Evaluate(Content.Assignment);
     300      Content.Solution.Evaluation = Content.ProblemInstance.Evaluate(Content.Solution.Assignment);
    282301    }
    283302  }
Note: See TracChangeset for help on using the changeset viewer.