Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPProblemView.cs @ 7445

Last change on this file since 7445 was 7445, checked in by abeham, 13 years ago

#1614

  • updated problem instance provider
File size: 4.3 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.PluginInfrastructure;
30using HeuristicLab.Problems.Instances;
31
32namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
33  [View("GeneralizedQuadraticAssignmentProblemView")]
34  [Content(typeof(GeneralizedQuadraticAssignmentProblem), IsDefaultView = true)]
35  public partial class GeneralizedQuadraticAssignmentProblemView : ParameterizedNamedItemView {
36
37    public new GeneralizedQuadraticAssignmentProblem Content {
38      get { return (GeneralizedQuadraticAssignmentProblem)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public GeneralizedQuadraticAssignmentProblemView() {
43      InitializeComponent();
44      problemInstanceProviderComboBox.DisplayMember = "Name";
45      instancesComboBox.DisplayMember = "Name";
46      problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().ToList();
47    }
48
49    #region Register Content Events
50    protected override void DeregisterContentEvents() {
51      base.DeregisterContentEvents();
52    }
53    protected override void RegisterContentEvents() {
54      base.RegisterContentEvents();
55    }
56    #endregion
57
58    protected override void OnContentChanged() {
59      base.OnContentChanged();
60      problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().ToList();
61    }
62
63    protected override void SetEnabledStateOfControls() {
64      base.SetEnabledStateOfControls();
65    }
66
67    #region Content Event Handlers
68    #endregion
69
70    #region Event Handlers
71    private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
72      var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
73      instancesComboBox.DataSource = provider.GetInstanceDescriptors().ToList();
74    }
75
76    private void comboBox_DataSourceChanged(object sender, EventArgs e) {
77      var comboBox = (ComboBox)sender;
78      if (comboBox.DataSource == null)
79        comboBox.Items.Clear();
80    }
81
82    private void loadButton_Click(object sender, EventArgs e) {
83      var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
84      var descriptor = (IInstanceDescriptor)instancesComboBox.SelectedItem;
85      OnLoadProblemInstanceButtonClicked(provider, descriptor);
86    }
87    #endregion
88
89    #region Helpers
90    #endregion
91
92    protected virtual IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() {
93      var qapProviders = ApplicationManager.Manager.GetInstances<IProblemInstanceProvider<IQAPInstance>>().Cast<IProblemInstanceProvider>();
94      var ctapProviders = ApplicationManager.Manager.GetInstances<IProblemInstanceProvider<ICTAPInstance>>().Cast<IProblemInstanceProvider>();
95      return qapProviders.Concat(ctapProviders);
96    }
97
98    protected virtual void OnLoadProblemInstanceButtonClicked(IProblemInstanceProvider provider, IInstanceDescriptor descriptor) {
99      if (provider is IProblemInstanceProvider<IQAPInstance>) {
100        Content.LoadFrom(((IProblemInstanceProvider<IQAPInstance>)provider).GetInstance(descriptor));
101      } else if (provider is IProblemInstanceProvider<ICTAPInstance>) {
102        Content.LoadFrom(((IProblemInstanceProvider<ICTAPInstance>)provider).GetInstance(descriptor));
103      }
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.