Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7841


Ignore:
Timestamp:
05/16/12 16:10:55 (13 years ago)
Author:
abeham
Message:

#1851: Updated CreateExperimentDialog to discover and display available problem instances...

Location:
trunk/sources/HeuristicLab.Optimizer/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.Designer.cs

    r7259 r7841  
    4646    private void InitializeComponent() {
    4747      this.components = new System.ComponentModel.Container();
     48      System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("QAPLIB", System.Windows.Forms.HorizontalAlignment.Left);
     49      System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("TSPLIB", System.Windows.Forms.HorizontalAlignment.Left);
     50      System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("bur26a");
     51      System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("esc32a");
     52      System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("berlin52");
     53      System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("ch130");
    4854      this.okButton = new System.Windows.Forms.Button();
    4955      this.cancelButton = new System.Windows.Forms.Button();
     
    5359      this.repetitionsNumericUpDown = new System.Windows.Forms.NumericUpDown();
    5460      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     61      this.instancesLabel = new System.Windows.Forms.Label();
     62      this.instancesListView = new System.Windows.Forms.ListView();
     63      this.columnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
    5564      ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).BeginInit();
    5665      this.SuspendLayout();
     
    6170      this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
    6271      this.okButton.Enabled = false;
    63       this.okButton.Location = new System.Drawing.Point(113, 58);
     72      this.okButton.Location = new System.Drawing.Point(113, 259);
    6473      this.okButton.Name = "okButton";
    6574      this.okButton.Size = new System.Drawing.Size(75, 23);
     
    7382      this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    7483      this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    75       this.cancelButton.Location = new System.Drawing.Point(194, 58);
     84      this.cancelButton.Location = new System.Drawing.Point(194, 259);
    7685      this.cancelButton.Name = "cancelButton";
    7786      this.cancelButton.Size = new System.Drawing.Size(75, 23);
     
    105114      //
    106115      this.repetitionsLabel.AutoSize = true;
    107       this.repetitionsLabel.Location = new System.Drawing.Point(12, 30);
     116      this.repetitionsLabel.Location = new System.Drawing.Point(12, 31);
    108117      this.repetitionsLabel.Name = "repetitionsLabel";
    109118      this.repetitionsLabel.Size = new System.Drawing.Size(63, 13);
     
    113122      // repetitionsNumericUpDown
    114123      //
    115       this.repetitionsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    116                   | System.Windows.Forms.AnchorStyles.Right)));
     124      this.repetitionsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     125            | System.Windows.Forms.AnchorStyles.Right)));
    117126      this.repetitionsNumericUpDown.Location = new System.Drawing.Point(113, 28);
    118127      this.repetitionsNumericUpDown.Maximum = new decimal(new int[] {
     
    138147      this.repetitionsNumericUpDown.Validated += new System.EventHandler(this.repetitionsNumericUpDown_Validated);
    139148      //
     149      // instancesLabel
     150      //
     151      this.instancesLabel.AutoSize = true;
     152      this.instancesLabel.Location = new System.Drawing.Point(12, 54);
     153      this.instancesLabel.Name = "instancesLabel";
     154      this.instancesLabel.Size = new System.Drawing.Size(56, 13);
     155      this.instancesLabel.TabIndex = 2;
     156      this.instancesLabel.Text = "&Instances:";
     157      //
     158      // instancesListView
     159      //
     160      this.instancesListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     161            | System.Windows.Forms.AnchorStyles.Left)
     162            | System.Windows.Forms.AnchorStyles.Right)));
     163      this.instancesListView.CheckBoxes = true;
     164      this.instancesListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
     165            this.columnHeader});
     166      listViewGroup1.Header = "QAPLIB";
     167      listViewGroup1.Name = "QAPLIBHeader";
     168      listViewGroup2.Header = "TSPLIB";
     169      listViewGroup2.Name = "TSPLIBHeader";
     170      listViewGroup2.Tag = "";
     171      this.instancesListView.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] {
     172            listViewGroup1,
     173            listViewGroup2});
     174      this.instancesListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
     175      listViewItem1.Checked = true;
     176      listViewItem1.Group = listViewGroup1;
     177      listViewItem1.StateImageIndex = 1;
     178      listViewItem2.Checked = true;
     179      listViewItem2.Group = listViewGroup1;
     180      listViewItem2.StateImageIndex = 1;
     181      listViewItem3.Group = listViewGroup2;
     182      listViewItem3.StateImageIndex = 0;
     183      listViewItem4.Group = listViewGroup2;
     184      listViewItem4.StateImageIndex = 0;
     185      this.instancesListView.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
     186            listViewItem1,
     187            listViewItem2,
     188            listViewItem3,
     189            listViewItem4});
     190      this.instancesListView.Location = new System.Drawing.Point(113, 54);
     191      this.instancesListView.Name = "instancesListView";
     192      this.instancesListView.Size = new System.Drawing.Size(156, 199);
     193      this.instancesListView.TabIndex = 6;
     194      this.instancesListView.UseCompatibleStateImageBehavior = false;
     195      this.instancesListView.View = System.Windows.Forms.View.Details;
     196      //
     197      // columnHeader
     198      //
     199      this.columnHeader.Width = 150;
     200      //
    140201      // CreateExperimentDialog
    141202      //
     
    144205      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    145206      this.CancelButton = this.cancelButton;
    146       this.ClientSize = new System.Drawing.Size(281, 93);
     207      this.ClientSize = new System.Drawing.Size(281, 294);
     208      this.Controls.Add(this.instancesListView);
    147209      this.Controls.Add(this.repetitionsNumericUpDown);
     210      this.Controls.Add(this.instancesLabel);
    148211      this.Controls.Add(this.repetitionsLabel);
    149212      this.Controls.Add(this.createBatchRunLabel);
     
    173236    private System.Windows.Forms.NumericUpDown repetitionsNumericUpDown;
    174237    private System.Windows.Forms.ToolTip toolTip;
     238    private System.Windows.Forms.Label instancesLabel;
     239    private System.Windows.Forms.ListView instancesListView;
     240    private System.Windows.Forms.ColumnHeader columnHeader;
    175241
    176242  }
  • trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs

    r7259 r7841  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2325using System.Windows.Forms;
    2426using HeuristicLab.Optimization;
     27using HeuristicLab.PluginInfrastructure;
     28using HeuristicLab.Problems.Instances;
    2529
    2630namespace HeuristicLab.Optimizer {
     
    4145    }
    4246
    43     public CreateExperimentDialog() {
     47    public CreateExperimentDialog() : this(null) { }
     48    public CreateExperimentDialog(IOptimizer optimizer) {
     49      InitializeComponent();
     50      Optimizer = optimizer;
    4451      experiment = null;
    45       optimizer = null;
    46       InitializeComponent();
     52      instancesListView.Items.Clear();
     53      instancesListView.Groups.Clear();
     54      FillOrHideInstanceListView();
    4755    }
    48     public CreateExperimentDialog(IOptimizer optimizer)
    49       : this() {
    50       Optimizer = optimizer;
     56
     57    private void FillOrHideInstanceListView() {
     58      if (Optimizer != null && optimizer is IAlgorithm) {
     59        var algorithm = (IAlgorithm)Optimizer;
     60        if (algorithm.Problem != null) {
     61          var instanceProviders = GetProblemInstanceProviders(algorithm.Problem);
     62          if (instanceProviders.Any()) {
     63            foreach (var provider in instanceProviders) {
     64              var group = new ListViewGroup(provider.Name, provider.Name);
     65              group.Tag = provider;
     66              instancesListView.Groups.Add(group);
     67              IEnumerable<IDataDescriptor> descriptors = ((dynamic)provider).GetDataDescriptors();
     68              foreach (var d in descriptors) {
     69                var item = new ListViewItem(d.Name, group);
     70                item.Checked = true;
     71                item.Tag = d;
     72                instancesListView.Items.Add(item);
     73              }
     74            }
     75            instancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
     76            if (instancesListView.Items.Count > 0) return;
     77          }
     78        }
     79      }
     80      instancesLabel.Visible = false;
     81      instancesListView.Visible = false;
     82      Height = 130;
     83    }
     84
     85    private IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders(IProblem problem) {
     86      var consumerTypes = problem.GetType().GetInterfaces()
     87        .Where(x => x.IsGenericType
     88          && x.GetGenericTypeDefinition() == typeof(IProblemInstanceConsumer<>));
     89
     90      if (consumerTypes.Any()) {
     91        var instanceTypes = consumerTypes
     92          .Select(x => x.GetGenericArguments().First())
     93          .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x));
     94
     95        foreach (var type in instanceTypes) {
     96          foreach (var provider in ApplicationManager.Manager.GetInstances(type))
     97            yield return (IProblemInstanceProvider)provider;
     98        }
     99      }
    51100    }
    52101
     
    60109    private void okButton_Click(object sender, EventArgs e) {
    61110      experiment = new Experiment();
    62       if (createBatchRunCheckBox.Checked) {
    63         BatchRun batchRun = new BatchRun();
    64         batchRun.Repetitions = (int)repetitionsNumericUpDown.Value;
    65         batchRun.Optimizer = (IOptimizer)Optimizer.Clone();
    66         Experiment.Optimizers.Add(batchRun);
     111      if (instancesListView.CheckedItems.Count == 0) {
     112        AddOptimizer((IOptimizer)Optimizer.Clone());
    67113      } else {
    68         Experiment.Optimizers.Add((IOptimizer)Optimizer.Clone());
     114        foreach (var item in instancesListView.CheckedItems.OfType<ListViewItem>()) {
     115          var descriptor = (IDataDescriptor)item.Tag;
     116          var provider = (IProblemInstanceProvider)item.Group.Tag;
     117          var algorithm = (IAlgorithm)Optimizer.Clone();
     118          ((dynamic)algorithm.Problem).Load(((dynamic)provider).LoadData(descriptor));
     119          AddOptimizer(algorithm);
     120        }
    69121      }
    70122      Experiment.Prepare(true);
    71123    }
     124
     125    private void AddOptimizer(IOptimizer optimizer) {
     126      if (createBatchRunCheckBox.Checked) {
     127        var batchRun = new BatchRun();
     128        batchRun.Repetitions = (int)repetitionsNumericUpDown.Value;
     129        batchRun.Optimizer = optimizer;
     130        experiment.Optimizers.Add(batchRun);
     131      } else {
     132        experiment.Optimizers.Add(optimizer);
     133      }
     134    }
    72135  }
    73136}
  • trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj

    r7013 r7841  
    9999  </PropertyGroup>
    100100  <ItemGroup>
     101    <Reference Include="Microsoft.CSharp" />
    101102    <Reference Include="System" />
    102103    <Reference Include="System.Core">
     
    259260      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    260261      <Private>False</Private>
     262    </ProjectReference>
     263    <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj">
     264      <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project>
     265      <Name>HeuristicLab.Problems.Instances-3.3</Name>
    261266    </ProjectReference>
    262267  </ItemGroup>
  • trunk/sources/HeuristicLab.Optimizer/3.3/Plugin.cs.frame

    r7260 r7841  
    3737  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3838  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     39  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    3940  public class HeuristicLabOptimizerPlugin : PluginBase {
    4041  }
Note: See TracChangeset for help on using the changeset viewer.