Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/22/12 11:11:38 (12 years ago)
Author:
jkarder
Message:

#1331:

  • synced branch with trunk
  • added custom interface (ISimilarityBasedOperator) to mark operators that conduct similarity calculation
  • similarity calculators are now parameterized by the algorithm
  • deleted SolutionPool2TierUpdateMethod
  • deleted KnapsackMultipleGuidesPathRelinker
  • moved IImprovementOperator, IPathRelinker and ISimilarityCalculator to HeuristicLab.Optimization
  • added parameter descriptions
  • fixed plugin references
  • fixed count of EvaluatedSolutions
  • fixed check for duplicate solutions
  • minor code improvements
Location:
branches/ScatterSearch (trunk integration)
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)

  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Views/3.3/ProblemView.cs

    r7641 r8086  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Diagnostics;
    2524using System.Linq;
    2625using System.Windows.Forms;
    27 using HeuristicLab.Common.Resources;
    2826using HeuristicLab.Core.Views;
    2927using HeuristicLab.MainForm;
    30 using HeuristicLab.PluginInfrastructure;
    3128using HeuristicLab.Problems.Instances;
     29using HeuristicLab.Problems.Instances.Views;
    3230
    3331namespace HeuristicLab.Optimization.Views {
     
    3836  [Content(typeof(IProblem), true)]
    3937  public partial class ProblemView : ParameterizedNamedItemView {
     38
     39    private static Type neededViewType = typeof(ProblemInstanceConsumerView);
     40
    4041    public new IProblem Content {
    4142      get { return (IProblem)base.Content; }
    4243      set { base.Content = value; }
    43     }
    44 
    45     protected IProblemInstanceProvider SelectedProvider {
    46       get { return (problemInstanceProviderComboBox.SelectedIndex >= 0 ? (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem : null); }
    4744    }
    4845
     
    5249    public ProblemView() {
    5350      InitializeComponent();
    54       libraryInfoButton.Text = String.Empty;
    55       libraryInfoButton.Image = VSImageLibrary.Internet;
    5651    }
    5752
    5853    protected override void OnContentChanged() {
    5954      base.OnContentChanged();
    60       if (Content == null) {
    61         problemInstanceProviderComboBox.DataSource = null;
     55      IProblemInstanceConsumer consumer = Content as IProblemInstanceConsumer;
     56      if (consumer != null) {
     57        IEnumerable<Type> viewTypes = MainFormManager.GetViewTypes(consumer.GetType(), true);
     58        Type genericView = viewTypes.Where(x => x.IsSubclassOf(neededViewType)).First();
     59        ProblemInstanceConsumerViewHost.ViewType = genericView;
     60        ProblemInstanceConsumerViewHost.Content = consumer;
     61        ProblemInstanceConsumerView view = (ProblemInstanceConsumerView)ProblemInstanceConsumerViewHost.ActiveView;
     62        problemInstanceSplitContainer.Panel1Collapsed = !view.ProblemInstanceProviders.Any();
    6263      } else {
    63         problemInstanceProviderComboBox.DisplayMember = "Name";
    64         problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().ToList();
    65         problemInstanceSplitContainer.Panel1Collapsed = problemInstanceProviderComboBox.Items.Count <= 0;
    66 
     64        problemInstanceSplitContainer.Panel1Collapsed = true;
    6765      }
    6866      SetEnabledStateOfControls();
    6967    }
    7068
    71     protected override void SetEnabledStateOfControls() {
    72       base.SetEnabledStateOfControls();
    73       problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null && problemInstanceProviderComboBox.Items.Count > 0;
    74       libraryInfoButton.Enabled = SelectedProvider != null && SelectedProvider.WebLink != null;
    75     }
    76 
    77     protected virtual void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
    78       if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
    79         dynamic provider = SelectedProvider;
    80         dynamic consumer = Content;
    81         provider.Consumer = consumer;
    82         problemInstanceProviderViewHost.Content = SelectedProvider;
    83         SetTooltip();
    84       }
    85       SetEnabledStateOfControls();
    86     }
    87 
    88     private void comboBox_DataSourceChanged(object sender, EventArgs e) {
    89       var comboBox = (ComboBox)sender;
    90       if (comboBox.DataSource == null)
    91         comboBox.Items.Clear();
    92     }
    93 
    94     protected virtual void libraryInfoButton_Click(object sender, EventArgs e) {
    95       if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
    96         if (SelectedProvider != null && SelectedProvider.WebLink != null)
    97           Process.Start(SelectedProvider.WebLink.ToString());
    98       }
    99     }
    100 
    101     protected virtual IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() {
    102       var consumerTypes = Content.GetType().GetInterfaces()
    103         .Where(x => x.IsGenericType
    104           && x.GetGenericTypeDefinition() == typeof(IProblemInstanceConsumer<>));
    105 
    106       if (consumerTypes.Any()) {
    107         var instanceTypes = consumerTypes
    108           .Select(x => x.GetGenericArguments().First())
    109           .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x));
    110 
    111         foreach (var type in instanceTypes) {
    112           foreach (var provider in ApplicationManager.Manager.GetInstances(type))
    113             yield return (IProblemInstanceProvider)provider;
    114         }
    115       }
    116     }
    117 
    118     protected virtual void SetTooltip() {
    119       toolTip.SetToolTip(problemInstanceProviderComboBox, GetProviderToolTip());
    120       if (SelectedProvider.WebLink != null)
    121         toolTip.SetToolTip(libraryInfoButton, "Browse to " + SelectedProvider.WebLink.ToString());
    122       else toolTip.SetToolTip(libraryInfoButton, "Library does not have a web reference.");
    123     }
    124 
    125     protected virtual string GetProviderToolTip() {
    126       var provider = SelectedProvider;
    127       string toolTip = provider.Name;
    128 
    129       if (!String.IsNullOrEmpty(provider.ReferencePublication)) {
    130         toolTip = toolTip
    131             + Environment.NewLine + Environment.NewLine
    132             + provider.ReferencePublication;
    133       }
    134       if (provider.WebLink != null) {
    135         toolTip = toolTip
    136             + Environment.NewLine
    137             + provider.WebLink.ToString();
    138       }
    139 
    140       return toolTip;
    141     }
    14269  }
    14370}
Note: See TracChangeset for help on using the changeset viewer.