Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13540 for trunk


Ignore:
Timestamp:
01/18/16 15:03:52 (9 years ago)
Author:
abeham
Message:

#2560: added loading of characteristic calculators into OKB problem view

Location:
trunk/sources
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.Designer.cs

    r13534 r13540  
    5151      this.tabControl = new System.Windows.Forms.TabControl();
    5252      this.parametersTabPage = new System.Windows.Forms.TabPage();
     53      this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
    5354      this.characteristicsTabPage = new System.Windows.Forms.TabPage();
    54       this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
     55      this.characteristicSplitContainer = new System.Windows.Forms.SplitContainer();
     56      this.calculatorListView = new System.Windows.Forms.ListView();
     57      this.characteristicColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
     58      this.calculateButton = new System.Windows.Forms.Button();
     59      this.characteristicsMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
     60      this.uploadCharacteristicsButton = new System.Windows.Forms.Button();
    5561      this.downloadCharacteristicsButton = new System.Windows.Forms.Button();
    56       this.uploadCharacteristicsButton = new System.Windows.Forms.Button();
    57       this.characteristicsMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
    5862      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5963      this.tabControl.SuspendLayout();
    6064      this.parametersTabPage.SuspendLayout();
    6165      this.characteristicsTabPage.SuspendLayout();
     66      ((System.ComponentModel.ISupportInitialize)(this.characteristicSplitContainer)).BeginInit();
     67      this.characteristicSplitContainer.Panel1.SuspendLayout();
     68      this.characteristicSplitContainer.Panel2.SuspendLayout();
     69      this.characteristicSplitContainer.SuspendLayout();
    6270      this.SuspendLayout();
    6371      //
     
    8290      // problemComboBox
    8391      //
    84       this.problemComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     92      this.problemComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    8593            | System.Windows.Forms.AnchorStyles.Right)));
    8694      this.problemComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     
    104112      //
    105113      this.refreshButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    106       this.refreshButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Refresh;
    107114      this.refreshButton.Location = new System.Drawing.Point(682, -1);
    108115      this.refreshButton.Name = "refreshButton";
     
    116123      //
    117124      this.cloneProblemButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    118       this.cloneProblemButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Clone;
    119125      this.cloneProblemButton.Location = new System.Drawing.Point(652, -1);
    120126      this.cloneProblemButton.Name = "cloneProblemButton";
     
    127133      // tabControl
    128134      //
    129       this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    130             | System.Windows.Forms.AnchorStyles.Left)
     135      this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     136            | System.Windows.Forms.AnchorStyles.Left) 
    131137            | System.Windows.Forms.AnchorStyles.Right)));
    132138      this.tabControl.Controls.Add(this.parametersTabPage);
     
    148154      this.parametersTabPage.Text = "Parameters";
    149155      this.parametersTabPage.UseVisualStyleBackColor = true;
    150       //
    151       // characteristicsTabPage
    152       //
    153       this.characteristicsTabPage.Controls.Add(this.characteristicsMatrixView);
    154       this.characteristicsTabPage.Controls.Add(this.uploadCharacteristicsButton);
    155       this.characteristicsTabPage.Controls.Add(this.downloadCharacteristicsButton);
    156       this.characteristicsTabPage.Location = new System.Drawing.Point(4, 22);
    157       this.characteristicsTabPage.Name = "characteristicsTabPage";
    158       this.characteristicsTabPage.Padding = new System.Windows.Forms.Padding(3);
    159       this.characteristicsTabPage.Size = new System.Drawing.Size(692, 314);
    160       this.characteristicsTabPage.TabIndex = 1;
    161       this.characteristicsTabPage.Text = "Characteristics";
    162       this.characteristicsTabPage.UseVisualStyleBackColor = true;
    163156      //
    164157      // parameterCollectionView
     
    175168      this.parameterCollectionView.TabIndex = 8;
    176169      //
     170      // characteristicsTabPage
     171      //
     172      this.characteristicsTabPage.Controls.Add(this.characteristicSplitContainer);
     173      this.characteristicsTabPage.Controls.Add(this.uploadCharacteristicsButton);
     174      this.characteristicsTabPage.Controls.Add(this.downloadCharacteristicsButton);
     175      this.characteristicsTabPage.Location = new System.Drawing.Point(4, 22);
     176      this.characteristicsTabPage.Name = "characteristicsTabPage";
     177      this.characteristicsTabPage.Padding = new System.Windows.Forms.Padding(3);
     178      this.characteristicsTabPage.Size = new System.Drawing.Size(692, 314);
     179      this.characteristicsTabPage.TabIndex = 1;
     180      this.characteristicsTabPage.Text = "Characteristics";
     181      this.characteristicsTabPage.UseVisualStyleBackColor = true;
     182      //
     183      // characteristicSplitContainer
     184      //
     185      this.characteristicSplitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     186            | System.Windows.Forms.AnchorStyles.Left)
     187            | System.Windows.Forms.AnchorStyles.Right)));
     188      this.characteristicSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
     189      this.characteristicSplitContainer.Location = new System.Drawing.Point(0, 35);
     190      this.characteristicSplitContainer.Name = "characteristicSplitContainer";
     191      //
     192      // characteristicSplitContainer.Panel1
     193      //
     194      this.characteristicSplitContainer.Panel1.Controls.Add(this.calculatorListView);
     195      this.characteristicSplitContainer.Panel1.Controls.Add(this.calculateButton);
     196      //
     197      // characteristicSplitContainer.Panel2
     198      //
     199      this.characteristicSplitContainer.Panel2.Controls.Add(this.characteristicsMatrixView);
     200      this.characteristicSplitContainer.Size = new System.Drawing.Size(692, 279);
     201      this.characteristicSplitContainer.SplitterDistance = 221;
     202      this.characteristicSplitContainer.TabIndex = 2;
     203      //
     204      // calculatorListView
     205      //
     206      this.calculatorListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     207            | System.Windows.Forms.AnchorStyles.Left)
     208            | System.Windows.Forms.AnchorStyles.Right)));
     209      this.calculatorListView.CheckBoxes = true;
     210      this.calculatorListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
     211            this.characteristicColumnHeader});
     212      this.calculatorListView.Location = new System.Drawing.Point(3, 0);
     213      this.calculatorListView.Name = "calculatorListView";
     214      this.calculatorListView.Size = new System.Drawing.Size(215, 244);
     215      this.calculatorListView.TabIndex = 0;
     216      this.calculatorListView.UseCompatibleStateImageBehavior = false;
     217      this.calculatorListView.View = System.Windows.Forms.View.Details;
     218      //
     219      // characteristicColumnHeader
     220      //
     221      this.characteristicColumnHeader.Text = "Characteristic";
     222      this.characteristicColumnHeader.Width = 211;
     223      //
     224      // calculateButton
     225      //
     226      this.calculateButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
     227            | System.Windows.Forms.AnchorStyles.Right)));
     228      this.calculateButton.Location = new System.Drawing.Point(6, 250);
     229      this.calculateButton.Name = "calculateButton";
     230      this.calculateButton.Size = new System.Drawing.Size(212, 23);
     231      this.calculateButton.TabIndex = 0;
     232      this.calculateButton.Text = "Calculate";
     233      this.calculateButton.UseVisualStyleBackColor = true;
     234      this.calculateButton.Click += new System.EventHandler(this.calculateButton_Click);
     235      //
     236      // characteristicsMatrixView
     237      //
     238      this.characteristicsMatrixView.Caption = "StringConvertibleMatrix View";
     239      this.characteristicsMatrixView.Content = null;
     240      this.characteristicsMatrixView.Dock = System.Windows.Forms.DockStyle.Fill;
     241      this.characteristicsMatrixView.Location = new System.Drawing.Point(0, 0);
     242      this.characteristicsMatrixView.Name = "characteristicsMatrixView";
     243      this.characteristicsMatrixView.ReadOnly = false;
     244      this.characteristicsMatrixView.ShowRowsAndColumnsTextBox = false;
     245      this.characteristicsMatrixView.ShowStatisticalInformation = false;
     246      this.characteristicsMatrixView.Size = new System.Drawing.Size(467, 279);
     247      this.characteristicsMatrixView.TabIndex = 1;
     248      //
     249      // uploadCharacteristicsButton
     250      //
     251      this.uploadCharacteristicsButton.Location = new System.Drawing.Point(38, 6);
     252      this.uploadCharacteristicsButton.Name = "uploadCharacteristicsButton";
     253      this.uploadCharacteristicsButton.Size = new System.Drawing.Size(26, 23);
     254      this.uploadCharacteristicsButton.TabIndex = 0;
     255      this.uploadCharacteristicsButton.Text = "Upload";
     256      this.uploadCharacteristicsButton.UseVisualStyleBackColor = true;
     257      this.uploadCharacteristicsButton.Click += new System.EventHandler(this.uploadCharacteristicsButton_Click);
     258      //
    177259      // downloadCharacteristicsButton
    178260      //
     
    184266      this.downloadCharacteristicsButton.UseVisualStyleBackColor = true;
    185267      this.downloadCharacteristicsButton.Click += new System.EventHandler(this.downloadCharacteristicsButton_Click);
    186       //
    187       // uploadCharacteristicsButton
    188       //
    189       this.uploadCharacteristicsButton.Location = new System.Drawing.Point(38, 6);
    190       this.uploadCharacteristicsButton.Name = "uploadCharacteristicsButton";
    191       this.uploadCharacteristicsButton.Size = new System.Drawing.Size(26, 23);
    192       this.uploadCharacteristicsButton.TabIndex = 0;
    193       this.uploadCharacteristicsButton.Text = "Upload";
    194       this.uploadCharacteristicsButton.UseVisualStyleBackColor = true;
    195       this.uploadCharacteristicsButton.Click += new System.EventHandler(this.uploadCharacteristicsButton_Click);
    196       //
    197       // characteristicsMatrixView
    198       //
    199       this.characteristicsMatrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    200             | System.Windows.Forms.AnchorStyles.Left)
    201             | System.Windows.Forms.AnchorStyles.Right)));
    202       this.characteristicsMatrixView.Caption = "StringConvertibleMatrix View";
    203       this.characteristicsMatrixView.Content = null;
    204       this.characteristicsMatrixView.Location = new System.Drawing.Point(6, 35);
    205       this.characteristicsMatrixView.Name = "characteristicsMatrixView";
    206       this.characteristicsMatrixView.ReadOnly = false;
    207       this.characteristicsMatrixView.ShowRowsAndColumnsTextBox = false;
    208       this.characteristicsMatrixView.ShowStatisticalInformation = false;
    209       this.characteristicsMatrixView.Size = new System.Drawing.Size(680, 273);
    210       this.characteristicsMatrixView.TabIndex = 1;
    211268      //
    212269      // OKBProblemView
     
    233290      this.parametersTabPage.ResumeLayout(false);
    234291      this.characteristicsTabPage.ResumeLayout(false);
     292      this.characteristicSplitContainer.Panel1.ResumeLayout(false);
     293      this.characteristicSplitContainer.Panel2.ResumeLayout(false);
     294      ((System.ComponentModel.ISupportInitialize)(this.characteristicSplitContainer)).EndInit();
     295      this.characteristicSplitContainer.ResumeLayout(false);
    235296      this.ResumeLayout(false);
    236297      this.PerformLayout();
     
    251312    private System.Windows.Forms.Button uploadCharacteristicsButton;
    252313    private System.Windows.Forms.Button downloadCharacteristicsButton;
     314    private System.Windows.Forms.SplitContainer characteristicSplitContainer;
     315    private System.Windows.Forms.ListView calculatorListView;
     316    private System.Windows.Forms.ColumnHeader characteristicColumnHeader;
     317    private System.Windows.Forms.Button calculateButton;
    253318
    254319
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs

    r13534 r13540  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Globalization;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    2829using HeuristicLab.Data;
    2930using HeuristicLab.MainForm;
     31using HeuristicLab.Optimization;
     32using HeuristicLab.PluginInfrastructure;
    3033
    3134namespace HeuristicLab.Clients.OKB.RunCreation {
     
    4144    public OKBProblemView() {
    4245      InitializeComponent();
     46      refreshButton.Text = string.Empty;
     47      refreshButton.Image = VSImageLibrary.Refresh;
     48      cloneProblemButton.Text = string.Empty;
     49      cloneProblemButton.Image = VSImageLibrary.Clone;
    4350      downloadCharacteristicsButton.Text = string.Empty;
    4451      downloadCharacteristicsButton.Image = VSImageLibrary.Refresh;
     
    7279        parameterCollectionView.Content = Content.Parameters;
    7380      }
     81      UpdateCharacteristicCalculators();
    7482    }
    7583
     
    92100    }
    93101
     102    private void UpdateCharacteristicCalculators() {
     103      calculatorListView.Items.Clear();
     104      calculatorListView.Groups.Clear();
     105      if (Content == null || Content.ProblemId == -1) return;
     106      var problem = Content.CloneProblem();
     107      var calculators = ApplicationManager.Manager.GetInstances<ICharacteristicCalculator>().Where(x => x.CanCalculate(problem)).ToList();
     108      try {
     109        calculatorListView.BeginUpdate();
     110        foreach (var calc in calculators) {
     111          var group = calculatorListView.Groups.Add(calc.Name, calc.Name);
     112          group.Tag = calc;
     113          foreach (var c in calc.Characteristics) {
     114            var item = calculatorListView.Items.Add(c, c);
     115            item.Group = group;
     116          }
     117        }
     118      } finally { calculatorListView.EndUpdate(); }
     119    }
     120
    94121    private void RunCreationClient_Refreshing(object sender, EventArgs e) {
    95122      if (InvokeRequired) {
     
    161188      } catch (Exception ex) { PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex); }
    162189    }
     190    private void calculateButton_Click(object sender, EventArgs e) {
     191      var problem = Content.CloneProblem();
     192      var characteristics = calculatorListView.CheckedItems.OfType<ListViewItem>().GroupBy(x => x.Group);
     193      var results = new Dictionary<string, double>();
     194      foreach (var c in characteristics) {
     195        var calc = (ICharacteristicCalculator)c.Key.Tag;
     196        foreach (var result in calc.Calculate(problem, c.Select(x => x.Text).ToArray()))
     197          results[result.Key] = result.Value;
     198      }
     199      var matrix = characteristicsMatrixView.Content as StringMatrix;
     200      if (matrix == null) matrix = new StringMatrix(results.Count, 3);
     201      for (var i = 0; i < matrix.Rows; i++) {
     202        double r;
     203        if (results.TryGetValue(matrix[i, 0], out r)) {
     204          matrix[i, 1] = r.ToString(CultureInfo.CurrentCulture.NumberFormat);
     205          matrix[i, 2] = "DoubleValue";
     206          results.Remove(matrix[i, 0]);
     207        }
     208      }
     209      if (results.Count == 0) return;
     210      var resultsList = results.ToList();
     211      var counter = resultsList.Count - 1;
     212      for (var i = 0; i < matrix.Rows; i++) {
     213        if (string.IsNullOrEmpty(matrix[i, 0])) {
     214          matrix[i, 0] = resultsList[counter].Key;
     215          matrix[i, 1] = resultsList[counter].Value.ToString(CultureInfo.CurrentCulture.NumberFormat);
     216          matrix[i, 2] = "DoubleValue";
     217          resultsList.RemoveAt(counter);
     218          counter--;
     219          if (counter < 0) return;
     220        }
     221      }
     222      if (counter >= 0) {
     223        ((IStringConvertibleMatrix)matrix).Rows += counter + 1;
     224        for (var i = matrix.Rows - 1; counter >= 0; i--) {
     225          matrix[i, 0] = resultsList[0].Key;
     226          matrix[i, 1] = resultsList[0].Value.ToString(CultureInfo.CurrentCulture.NumberFormat);
     227          matrix[i, 2] = "DoubleValue";
     228          counter--;
     229        }
     230      }
     231    }
    163232    #endregion
    164233
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r12975 r13540  
    153153    <Compile Include="BasicProblems\Operators\SingleObjectiveMoveMaker.cs" />
    154154    <Compile Include="BasicProblems\SingleObjectiveBasicProblem.cs" />
     155    <Compile Include="Interfaces\ICharacteristicCalculator.cs" />
    155156    <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" />
    156157    <Compile Include="Interfaces\IMultiObjectiveOperator.cs" />
Note: See TracChangeset for help on using the changeset viewer.