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

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

#1614

  • added instances of Cordeau et al. as given by L. Moccia
  • added operators for tabu search
File size: 4.2 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        toolTip.SetToolTip(problemInstanceProviderComboBox, GetProviderToolTip(provider));
68      }
69    }
70
71    private void comboBox_DataSourceChanged(object sender, EventArgs e) {
72      var comboBox = (ComboBox)sender;
73      if (comboBox.DataSource == null)
74        comboBox.Items.Clear();
75    }
76
77    protected virtual IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() {
78      var consumerTypes = Content.GetType().GetInterfaces()
79        .Where(x => x.IsGenericType
80          && typeof(IProblemInstanceConsumer).IsAssignableFrom(x));
81
82      if (consumerTypes.Any()) {
83        var instanceTypes = consumerTypes
84          .Select(x => x.GetGenericArguments().First())
85          .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x));
86
87        foreach (var type in instanceTypes) {
88          foreach (var provider in ApplicationManager.Manager.GetInstances(type))
89            yield return (IProblemInstanceProvider)provider;
90        }
91      }
92    }
93
94    protected virtual string GetProviderToolTip(IProblemInstanceProvider provider) {
95      if (provider.WebLink != null) {
96        return provider.Name
97            + Environment.NewLine
98            + provider.WebLink.ToString()
99            + Environment.NewLine + Environment.NewLine
100            + provider.ReferencePublication;
101      } else {
102        return provider.Name
103            + Environment.NewLine + Environment.NewLine
104            + provider.ReferencePublication;
105      }
106    }
107
108    private void problemInstanceProviderComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) {
109      e.ToolTip = GetProviderToolTip((IProblemInstanceProvider)e.Item);
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.