#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 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 HeuristicLab.MainForm;
using HeuristicLab.OptimizationExpertSystem.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms.DataVisualization.Charting;
namespace HeuristicLab.OptimizationExpertSystem {
[View("Understanding Problem Instance")]
[Content(typeof(KnowledgeCenter), IsDefaultView = false)]
public partial class UnderstandingProblemInstanceView : KnowledgeCenterViewBase {
public UnderstandingProblemInstanceView() {
InitializeComponent();
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
problemInstancesView.Content = null;
instanceMapChart.Series["InstancesSeries"].Points.Clear();
instanceMapChart.Series["CurrentInstanceSeries"].Points.Clear();
} else {
problemInstancesView.Content = Content.ProblemInstances;
UpdateProjectionComboBox();
}
}
#region Content Event Handlers
protected override void OnProblemChanged() {
base.OnProblemChanged();
SetEnabledStateOfControls();
}
protected override void OnProblemInstancesChanged() {
base.OnProblemInstancesChanged();
if (Content.ProblemInstances.UpdateOfRunsInProgress) return;
UpdateProjectionComboBox();
}
protected override void OnDownloadEnded() {
base.OnDownloadEnded();
UpdateProjectionComboBox();
}
#endregion
public IEnumerable GetProjections() {
return Content.ProblemInstances
.SelectMany(x => x.Results.Where(y => Regex.IsMatch(y.Key, "^Projection[.].*[.][XY]$")))
.Select(x => Regex.Match(x.Key, "Projection[.](?.*)[.][XY]").Groups["g"].Value)
.Distinct();
}
public void ProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection) {
instancesSeries.Points.Clear();
currentInstanceSeries.Points.Clear();
foreach (var run in Content.ProblemInstances) {
var xKey = "Projection." + projection + ".X";
var yKey = "Projection." + projection + ".Y";
if (!run.Results.ContainsKey(xKey) || !run.Results.ContainsKey(yKey)
|| !(run.Results[xKey] is Data.DoubleValue) || !(run.Results[yKey] is Data.DoubleValue)) continue;
var x = ((Data.DoubleValue)run.Results[xKey]).Value;
var y = ((Data.DoubleValue)run.Results[yKey]).Value;
var dataPoint = new DataPoint(x, y) {
Label = run.Name
};
instancesSeries.Points.Add(dataPoint);
}
var curPoint = Content.ProjectCurrentInstance(projection);
if (curPoint != null) {
var dp = new DataPoint(curPoint.Item1, curPoint.Item2) {
Label = Content.Problem.Problem.Name
};
currentInstanceSeries.Points.Add(dp);
}
}
private void ProjectionComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
if (InvokeRequired) { Invoke((Action