source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.cs @ 7523

Last change on this file since 7523 was 7523, checked in by abeham, 8 years ago

#1614

  • sorted operators
  • added crossover defined by Cordeau et al.
  • fixed a few bugs
File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Collections.Generic;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29using HeuristicLab.Optimization;
30using HeuristicLab.PluginInfrastructure;
31using HeuristicLab.Problems.Instances;
32
33namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
34  [View("ProblemView")]
35  [Content(typeof(Problem), IsDefaultView = true)]
36  public partial class ProblemView : ParameterizedNamedItemView {
37
38    public new Problem Content {
39      get { return (Problem)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public ProblemView() {
44      InitializeComponent();
45    }
46
47    protected override void OnContentChanged() {
48      base.OnContentChanged();
49      if (Content == null) {
50        problemInstanceProviderComboBox.DataSource = null;
51      } else {
52        problemInstanceProviderComboBox.DisplayMember = "Name";
53        problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().ToList();
54      }
55    }
56
57    protected override void SetEnabledStateOfControls() {
58      base.SetEnabledStateOfControls();
59      problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null;
60    }
61
62    private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
63      if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
64        var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
65        provider.SetConsumer((IProblemInstanceConsumer)Content);
66        problemInstanceProviderViewHost.Content = provider;
67      }
68    }
69
70    private void comboBox_DataSourceChanged(object sender, EventArgs e) {
71      var comboBox = (ComboBox)sender;
72      if (comboBox.DataSource == null)
73        comboBox.Items.Clear();
74    }
75
76    protected virtual IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() {
77      var consumerTypes = Content.GetType().GetInterfaces()
78        .Where(x => x.IsGenericType
79          && typeof(IProblemInstanceConsumer).IsAssignableFrom(x));
80
81      if (consumerTypes.Any()) {
82        var instanceTypes = consumerTypes
83          .Select(x => x.GetGenericArguments().First())
84          .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x));
85
86        foreach (var type in instanceTypes) {
87          foreach (var provider in ApplicationManager.Manager.GetInstances(type))
88            yield return (IProblemInstanceProvider)provider;
89        }
90      }
91    }
92
93    protected virtual string GetProviderToolTip(IProblemInstanceProvider provider) {
94      if (provider.WebLink != null) {
95        return provider.Name
96            + Environment.NewLine
97            + provider.WebLink.ToString()
98            + Environment.NewLine + Environment.NewLine
99            + provider.ReferencePublication;
100      } else {
101        return provider.Name
102            + Environment.NewLine + Environment.NewLine
103            + provider.ReferencePublication;
104      }
105    }
106
107    private void problemInstanceProviderComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) {
108      e.ToolTip = GetProviderToolTip((IProblemInstanceProvider)e.Item);
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.