#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using HeuristicLab.Collections;
using HeuristicLab.Core.Views;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
[View("GQAPAssignmentArchiveView")]
[Content(typeof(GQAPAssignmentArchive), IsDefaultView = true)]
public partial class GQAPAssignmentArchiveView : ItemView {
public new GQAPAssignmentArchive Content {
get { return (GQAPAssignmentArchive)base.Content; }
set { base.Content = value; }
}
public GQAPAssignmentArchiveView() {
InitializeComponent();
}
#region Register Content Events
protected override void DeregisterContentEvents() {
Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
Content.Solutions.CollectionReset -= new CollectionItemsChangedEventHandler>(ContentSolutions_Changed);
Content.Solutions.ItemsAdded -= new CollectionItemsChangedEventHandler>(ContentSolutions_Changed);
Content.Solutions.ItemsRemoved -= new CollectionItemsChangedEventHandler>(ContentSolutions_Changed);
base.DeregisterContentEvents();
}
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
Content.Solutions.CollectionReset += new CollectionItemsChangedEventHandler>(ContentSolutions_Changed);
Content.Solutions.ItemsAdded += new CollectionItemsChangedEventHandler>(ContentSolutions_Changed);
Content.Solutions.ItemsRemoved += new CollectionItemsChangedEventHandler>(ContentSolutions_Changed);
}
private void ContentSolutions_Changed(object sender, CollectionItemsChangedEventArgs> e) {
UpdateParetoFront();
}
private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
UpdateParetoFront();
}
#endregion
protected override void OnContentChanged() {
base.OnContentChanged();
UpdateParetoFront();
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
}
private void UpdateParetoFront() {
if (InvokeRequired) Invoke((Action)UpdateParetoFront);
else {
paretoFrontChart.Series[0].Points.SuspendUpdates();
try {
paretoFrontChart.Series[0].Points.Clear();
if (Content == null) return;
foreach (var solution in Content.Solutions) {
if (solution.OverbookedCapacity.Value <= 0.0) {
paretoFrontChart.Series[0].Points.AddXY(solution.FlowDistanceQuality.Value, solution.InstallationQuality.Value);
paretoFrontChart.Series[0].Points.Last().Tag = solution;
}
}
} finally {
paretoFrontChart.Series[0].Points.ResumeUpdates();
messageLabel.Visible = paretoFrontChart.Series[0].Points.Count == 0;
}
}
}
private void paretoFrontChart_MouseDoubleClick(object sender, MouseEventArgs e) {
HitTestResult h = paretoFrontChart.HitTest(e.X, e.Y, ChartElementType.DataPoint);
if (h.ChartElementType == ChartElementType.DataPoint) {
var solution = (GQAPSolution)((DataPoint)h.Object).Tag;
var assignment = new GQAPAssignment(solution.Assignment, solution.Quality, solution.FlowDistanceQuality, solution.InstallationQuality, solution.OverbookedCapacity, Content.EquipmentNames, Content.LocationNames, Content.Distances, Content.Weights, Content.InstallationCosts, Content.Demands, Content.Capacities, Content.TransportationCosts, Content.ExpectedRandomQuality, Content.Evaluator);
var view = MainFormManager.MainForm.ShowContent(assignment);
if (view != null) {
view.ReadOnly = this.ReadOnly;
view.Locked = this.Locked;
}
}
}
}
}