[7418] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16077] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7418] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.ComponentModel;
|
---|
[7437] | 24 | using System.Linq;
|
---|
[7418] | 25 | using System.Windows.Forms;
|
---|
[7437] | 26 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
[7418] | 27 | using HeuristicLab.Collections;
|
---|
| 28 | using HeuristicLab.Core.Views;
|
---|
| 29 | using HeuristicLab.MainForm;
|
---|
| 30 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 31 |
|
---|
| 32 | namespace 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) {
|
---|
[15504] | 87 | if (solution.Evaluation.ExcessDemand <= 0.0) {
|
---|
| 88 | paretoFrontChart.Series[0].Points.AddXY(solution.Evaluation.FlowCosts, solution.Evaluation.InstallationCosts);
|
---|
[7437] | 89 | paretoFrontChart.Series[0].Points.Last().Tag = solution;
|
---|
| 90 | }
|
---|
[7418] | 91 | }
|
---|
| 92 | } finally {
|
---|
| 93 | paretoFrontChart.Series[0].Points.ResumeUpdates();
|
---|
| 94 | messageLabel.Visible = paretoFrontChart.Series[0].Points.Count == 0;
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
[7437] | 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;
|
---|
[15504] | 103 | var assignment = new GQAPAssignment(solution.Assignment, Content.ProblemInstance, solution.Evaluation);
|
---|
[7437] | 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 | }
|
---|
[7418] | 112 | }
|
---|
| 113 | }
|
---|