Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2936_GQAPIntegration/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentArchiveView.cs @ 17456

Last change on this file since 17456 was 16077, checked in by abeham, 6 years ago

#2936: Added integration branch

File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.ComponentModel;
24using System.Linq;
25using System.Windows.Forms;
26using System.Windows.Forms.DataVisualization.Charting;
27using HeuristicLab.Collections;
28using HeuristicLab.Core.Views;
29using HeuristicLab.MainForm;
30using HeuristicLab.MainForm.WindowsForms;
31
32namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
33  [View("GQAPAssignmentArchiveView")]
34  [Content(typeof(GQAPAssignmentArchive), IsDefaultView = true)]
35  public partial class GQAPAssignmentArchiveView : ItemView {
36    public new GQAPAssignmentArchive Content {
37      get { return (GQAPAssignmentArchive)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public GQAPAssignmentArchiveView() {
42      InitializeComponent();
43    }
44
45    #region Register Content Events
46    protected override void DeregisterContentEvents() {
47      Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
48      Content.Solutions.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<GQAPSolution>>(ContentSolutions_Changed);
49      Content.Solutions.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<GQAPSolution>>(ContentSolutions_Changed);
50      Content.Solutions.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<GQAPSolution>>(ContentSolutions_Changed);
51      base.DeregisterContentEvents();
52    }
53    protected override void RegisterContentEvents() {
54      base.RegisterContentEvents();
55      Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
56      Content.Solutions.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<GQAPSolution>>(ContentSolutions_Changed);
57      Content.Solutions.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<GQAPSolution>>(ContentSolutions_Changed);
58      Content.Solutions.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<GQAPSolution>>(ContentSolutions_Changed);
59    }
60
61    private void ContentSolutions_Changed(object sender, CollectionItemsChangedEventArgs<IndexedItem<GQAPSolution>> e) {
62      UpdateParetoFront();
63    }
64
65    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
66      UpdateParetoFront();
67    }
68    #endregion
69
70    protected override void OnContentChanged() {
71      base.OnContentChanged();
72      UpdateParetoFront();
73    }
74
75    protected override void SetEnabledStateOfControls() {
76      base.SetEnabledStateOfControls();
77    }
78
79    private void UpdateParetoFront() {
80      if (InvokeRequired) Invoke((Action)UpdateParetoFront);
81      else {
82        paretoFrontChart.Series[0].Points.SuspendUpdates();
83        try {
84          paretoFrontChart.Series[0].Points.Clear();
85          if (Content == null) return;
86          foreach (var solution in Content.Solutions) {
87            if (solution.Evaluation.ExcessDemand <= 0.0) {
88              paretoFrontChart.Series[0].Points.AddXY(solution.Evaluation.FlowCosts, solution.Evaluation.InstallationCosts);
89              paretoFrontChart.Series[0].Points.Last().Tag = solution;
90            }
91          }
92        } finally {
93          paretoFrontChart.Series[0].Points.ResumeUpdates();
94          messageLabel.Visible = paretoFrontChart.Series[0].Points.Count == 0;
95        }
96      }
97    }
98
99    private void paretoFrontChart_MouseDoubleClick(object sender, MouseEventArgs e) {
100      HitTestResult h = paretoFrontChart.HitTest(e.X, e.Y, ChartElementType.DataPoint);
101      if (h.ChartElementType == ChartElementType.DataPoint) {
102        var solution = (GQAPSolution)((DataPoint)h.Object).Tag;
103        var assignment = new GQAPAssignment(solution.Assignment, Content.ProblemInstance, solution.Evaluation);
104
105        var view = MainFormManager.MainForm.ShowContent(assignment);
106        if (view != null) {
107          view.ReadOnly = this.ReadOnly;
108          view.Locked = this.Locked;
109        }
110      }
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.