#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.Analysis;
using HeuristicLab.Analysis.QualityAnalysis;
using HeuristicLab.Clients.OKB.RunCreation;
using HeuristicLab.Common;
using HeuristicLab.Common.Resources;
using HeuristicLab.Core;
using HeuristicLab.Core.Views;
using HeuristicLab.Data;
using HeuristicLab.Data.Views;
using HeuristicLab.MainForm;
using HeuristicLab.Optimization;
using HeuristicLab.Optimization.Views;
using HeuristicLab.OptimizationExpertSystem.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace HeuristicLab.OptimizationExpertSystem {
[View("Knowledge Center (all-in-one view)")]
[Content(typeof(ExpertSystem), IsDefaultView = true)]
public partial class ExpertSystemView : ItemView {
private EnumValueView seedingStrategyView;
private CheckedItemListView seedingSolutionsView;
protected virtual bool SuppressEvents { get; set; }
private bool okbDownloadInProgress;
public new ExpertSystem Content {
get { return (ExpertSystem)base.Content; }
set { base.Content = value; }
}
public ExpertSystemView() {
InitializeComponent();
// brings progress panel to front (it is not visible by default, but obstructs other elements in designer)
this.Controls.SetChildIndex(this.progressPanel, 0);
algorithmStartButton.Text = string.Empty;
algorithmStartButton.Image = VSImageLibrary.Play;
algorithmCloneButton.Text = string.Empty;
algorithmCloneButton.Image = VSImageLibrary.Clone;
refreshMapButton.Text = string.Empty;
refreshMapButton.Image = VSImageLibrary.Refresh;
seedingStrategyView = new EnumValueView() {
Dock = DockStyle.Fill
};
seedingSolutionsView = new CheckedItemListView() {
Dock = DockStyle.Fill
};
seedingStrategyPanel.Controls.Add(seedingStrategyView);
solutionSeedingTabPage.Controls.Add(seedingSolutionsView);
}
#region Event Registration
protected override void DeregisterContentEvents() {
Content.PropertyChanged -= ContentOnPropertyChanged;
Content.SuggestedInstances.CollectionReset -= SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsAdded -= SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsMoved -= SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsRemoved -= SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsReplaced -= SuggestedInstancesOnChanged;
Content.SolutionSeedingPool.CollectionReset -= SeedingPoolOnChanged;
Content.SolutionSeedingPool.ItemsAdded -= SeedingPoolOnChanged;
Content.SolutionSeedingPool.ItemsRemoved -= SeedingPoolOnChanged;
Content.SolutionSeedingPool.ItemsReplaced -= SeedingPoolOnChanged;
Content.SolutionSeedingPool.CheckedItemsChanged -= SeedingPoolOnChanged;
DeregisterProblemEvents(Content.Problem);
base.DeregisterContentEvents();
}
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.PropertyChanged += ContentOnPropertyChanged;
Content.SuggestedInstances.CollectionReset += SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsAdded += SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsMoved += SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsRemoved += SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsReplaced += SuggestedInstancesOnChanged;
Content.SolutionSeedingPool.CollectionReset += SeedingPoolOnChanged;
Content.SolutionSeedingPool.ItemsAdded += SeedingPoolOnChanged;
Content.SolutionSeedingPool.ItemsRemoved += SeedingPoolOnChanged;
Content.SolutionSeedingPool.ItemsReplaced += SeedingPoolOnChanged;
Content.SolutionSeedingPool.CheckedItemsChanged += SeedingPoolOnChanged;
RegisterProblemEvents(Content.Problem);
}
private void DeregisterProblemEvents(OKBProblem problem) {
if (problem == null) return;
problem.Solutions.ItemsAdded -= SolutionsOnChanged;
problem.Solutions.ItemsRemoved -= SolutionsOnChanged;
problem.Solutions.ItemsReplaced -= SolutionsOnChanged;
problem.Solutions.CollectionReset -= SolutionsOnChanged;
problem.ProblemChanged -= ContentOnProblemChanged;
}
private void RegisterProblemEvents(OKBProblem problem) {
if (problem == null) return;
problem.Solutions.ItemsAdded += SolutionsOnChanged;
problem.Solutions.ItemsRemoved += SolutionsOnChanged;
problem.Solutions.ItemsReplaced += SolutionsOnChanged;
problem.Solutions.CollectionReset += SolutionsOnChanged;
problem.ProblemChanged += ContentOnProblemChanged;
}
#endregion
protected override void OnContentChanged() {
base.OnContentChanged();
SuppressEvents = true;
okbDownloadInProgress = false;
try {
if (Content == null) {
maxEvaluationsTextBox.Text = String.Empty;
problemViewHost.Content = null;
solverParametersView.Content = null;
solverResultsView.Content = null;
runsView.Content = null;
kbViewHost.Content = null;
problemInstancesView.Content = null;
seedingStrategyView.Content = null;
seedingSolutionsView.Content = null;
} else {
maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString();
problemViewHost.Content = Content.Problem;
runsView.Content = Content.Runs;
kbViewHost.ViewType = typeof(RunCollectionRLDView);
kbViewHost.Content = Content.KnowledgeBase;
problemInstancesView.Content = Content.ProblemInstances;
solverResultsView.Content = Content.CurrentResult;
seedingStrategyView.Content = Content.SeedingStrategy;
seedingSolutionsView.Content = Content.SolutionSeedingPool;
}
} finally { SuppressEvents = false; }
UpdateSuggestedInstancesCombobox();
UpdateSimilarityCalculators();
UpdateNamesComboboxes();
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
maxEvaluationsTextBox.Enabled = Content != null && !ReadOnly && !Locked;
problemViewHost.Enabled = Content != null && !ReadOnly && !Locked && !okbDownloadInProgress;
suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked && !okbDownloadInProgress;
algorithmStartButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
algorithmCloneButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0;
runsView.Enabled = Content != null;
kbViewHost.Enabled = Content != null && !okbDownloadInProgress;
problemInstancesView.Enabled = Content != null && !okbDownloadInProgress;
refreshMapButton.Enabled = Content != null;
okbDownloadButton.Enabled = Content != null && Content.Problem != null && Content.Problem.ProblemId >= 0 && !ReadOnly && !Locked && !okbDownloadInProgress;
}
#region Event Handlers
#region Content events
private void ContentOnProblemChanged(object sender, EventArgs eventArgs) {
UpdateSuggestedInstancesCombobox();
UpdateSimilarityCalculators();
SetEnabledStateOfControls();
}
private void ContentOnPropertyChanged(object sender, PropertyChangedEventArgs e) {
if (InvokeRequired) {
Invoke((Action