Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/13/16 10:51:56 (8 years ago)
Author:
abeham
Message:

#2431: Refactored ResultsParameter

Location:
branches/PerformanceComparison
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/Optimizers/IteratedAlgorithm.cs

    r13738 r14058  
    475475        }
    476476      }
    477       if (Algorithm.Results.TryGetValue(perClockAnalyzer.QualityPerClockParameter.ResultName, out result)) UpdateQualityPerClockResult((IndexedDataTable<double>)result.Value, restarts.Value);
    478       if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.QualityPerEvaluationsParameter.ResultName, out result)) UpdateQualityPerEvaluationsResult((IndexedDataTable<double>)result.Value, restarts.Value);
     477      if (Algorithm.Results.TryGetValue(perClockAnalyzer.QualityPerClockParameter.ActualName, out result)) UpdateQualityPerClockResult((IndexedDataTable<double>)result.Value, restarts.Value);
     478      if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.QualityPerEvaluationsParameter.ActualName, out result)) UpdateQualityPerEvaluationsResult((IndexedDataTable<double>)result.Value, restarts.Value);
    479479      if (StoreSolutionInRun) {
    480480        foreach (var r in Algorithm.Results) {
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/QualityPerClockAnalyzer.cs

    r12834 r14058  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    7676    public override IOperation Apply() {
    7777      var bestQuality = BestQualityParameter.ActualValue.Value;
    78       var dataTable = QualityPerClockParameter.ResultValue;
     78      var dataTable = QualityPerClockParameter.ActualValue;
    7979      var values = dataTable.Rows["First-hit Graph"].Values;
    8080
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/QualityPerEvaluationsAnalyzer.cs

    r12834 r14058  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    8888      if (evalMoves != null) evaluations += evalMoves.Value * MoveCostPerSolutionParameter.ActualValue.Value;
    8989
    90       var dataTable = QualityPerEvaluationsParameter.ResultValue;
     90      var dataTable = QualityPerEvaluationsParameter.ActualValue;
    9191      var values = dataTable.Rows["First-hit Graph"].Values;
    9292      if (evaluations == 0 || values.Count > 0 && evaluations < values.Last().Item1) evaluations = 1;
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/ResultParameterView.Designer.cs

    r12764 r14058  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (components != null) components.Dispose();
    36       }
    37       base.Dispose(disposing);
    38     }
    39 
     28   
    4029    #region Component Designer generated code
    4130
     
    4534    /// </summary>
    4635    private void InitializeComponent() {
    47       this.resultNameTextBox = new System.Windows.Forms.TextBox();
    48       this.resultNameLabel = new System.Windows.Forms.Label();
     36      this.resultCollectionNameTextBox = new System.Windows.Forms.TextBox();
     37      this.resultCollectionNameLabel = new System.Windows.Forms.Label();
     38      this.defaultValueGroupBox = new System.Windows.Forms.GroupBox();
     39      this.removeDefaultValueButton = new System.Windows.Forms.Button();
     40      this.setDefaultValueButton = new System.Windows.Forms.Button();
     41      this.defaultValueViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    4942      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     43      this.defaultValueGroupBox.SuspendLayout();
    5044      this.SuspendLayout();
    5145      //
    52       // dataTypeLabel
     46      // actualNameTextBox
    5347      //
    54       this.dataTypeLabel.Location = new System.Drawing.Point(3, 55);
    55       this.dataTypeLabel.TabIndex = 5;
     48      this.actualNameTextBox.Location = new System.Drawing.Point(98, 26);
     49      this.actualNameTextBox.Size = new System.Drawing.Size(288, 20);
    5650      //
    5751      // dataTypeTextBox
    5852      //
    59       this.dataTypeTextBox.Location = new System.Drawing.Point(80, 52);
    60       this.dataTypeTextBox.Size = new System.Drawing.Size(306, 20);
    61       this.dataTypeTextBox.TabIndex = 6;
     53      this.dataTypeTextBox.Location = new System.Drawing.Point(98, 52);
     54      this.dataTypeTextBox.Size = new System.Drawing.Size(288, 20);
    6255      //
    6356      // nameTextBox
     
    6558      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    6659      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    67       this.nameTextBox.Location = new System.Drawing.Point(80, 0);
    68       this.nameTextBox.Size = new System.Drawing.Size(281, 20);
     60      this.nameTextBox.Location = new System.Drawing.Point(98, 0);
     61      this.nameTextBox.Size = new System.Drawing.Size(263, 20);
    6962      //
    70       // infoLabel
     63      // resultCollectionNameTextBox
    7164      //
    72       this.infoLabel.Location = new System.Drawing.Point(367, 3);
     65      this.resultCollectionNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     66            | System.Windows.Forms.AnchorStyles.Right)));
     67      this.resultCollectionNameTextBox.Location = new System.Drawing.Point(98, 78);
     68      this.resultCollectionNameTextBox.Name = "resultCollectionNameTextBox";
     69      this.resultCollectionNameTextBox.Size = new System.Drawing.Size(288, 20);
     70      this.resultCollectionNameTextBox.TabIndex = 6;
     71      this.resultCollectionNameTextBox.Validated += new System.EventHandler(this.resultNameTextBox_Validated);
    7372      //
    74       // actualNameTextBox
     73      // resultCollectionNameLabel
    7574      //
    76       this.actualNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    77                   | System.Windows.Forms.AnchorStyles.Right)));
    78       this.actualNameTextBox.Location = new System.Drawing.Point(80, 26);
    79       this.actualNameTextBox.Name = "actualNameTextBox";
    80       this.actualNameTextBox.Size = new System.Drawing.Size(306, 20);
    81       this.actualNameTextBox.TabIndex = 4;
    82       this.actualNameTextBox.Validated += new System.EventHandler(this.actualNameTextBox_Validated);
     75      this.resultCollectionNameLabel.AutoSize = true;
     76      this.resultCollectionNameLabel.Location = new System.Drawing.Point(3, 81);
     77      this.resultCollectionNameLabel.Name = "resultCollectionNameLabel";
     78      this.resultCollectionNameLabel.Size = new System.Drawing.Size(89, 13);
     79      this.resultCollectionNameLabel.TabIndex = 5;
     80      this.resultCollectionNameLabel.Text = "&Result Collection:";
    8381      //
    84       // actualNameLabel
     82      // defaultValueGroupBox
    8583      //
    86       this.actualNameLabel.AutoSize = true;
    87       this.actualNameLabel.Location = new System.Drawing.Point(3, 29);
    88       this.actualNameLabel.Name = "actualNameLabel";
    89       this.actualNameLabel.Size = new System.Drawing.Size(71, 13);
    90       this.actualNameLabel.TabIndex = 3;
    91       this.actualNameLabel.Text = "&Actual Name:";
     84      this.defaultValueGroupBox.AllowDrop = true;
     85      this.defaultValueGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     86            | System.Windows.Forms.AnchorStyles.Left)
     87            | System.Windows.Forms.AnchorStyles.Right)));
     88      this.defaultValueGroupBox.Controls.Add(this.removeDefaultValueButton);
     89      this.defaultValueGroupBox.Controls.Add(this.setDefaultValueButton);
     90      this.defaultValueGroupBox.Controls.Add(this.defaultValueViewHost);
     91      this.defaultValueGroupBox.Location = new System.Drawing.Point(0, 104);
     92      this.defaultValueGroupBox.Name = "defaultValueGroupBox";
     93      this.defaultValueGroupBox.Size = new System.Drawing.Size(386, 222);
     94      this.defaultValueGroupBox.TabIndex = 7;
     95      this.defaultValueGroupBox.TabStop = false;
     96      this.defaultValueGroupBox.Text = "Default Value";
     97      this.defaultValueGroupBox.DragDrop += new System.Windows.Forms.DragEventHandler(this.defaultValueGroupBox_DragDrop);
     98      this.defaultValueGroupBox.DragEnter += new System.Windows.Forms.DragEventHandler(this.defaultValueGroupBox_DragEnterOver);
     99      this.defaultValueGroupBox.DragOver += new System.Windows.Forms.DragEventHandler(this.defaultValueGroupBox_DragEnterOver);
    92100      //
    93       // resultNameTextBox
     101      // removeDefaultValueButton
    94102      //
    95       this.resultNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    96                   | System.Windows.Forms.AnchorStyles.Right)));
    97       this.resultNameTextBox.Location = new System.Drawing.Point(80, 78);
    98       this.resultNameTextBox.Name = "resultNameTextBox";
    99       this.resultNameTextBox.Size = new System.Drawing.Size(306, 20);
    100       this.resultNameTextBox.TabIndex = 6;
    101       this.resultNameTextBox.Validated += new System.EventHandler(this.resultNameTextBox_Validated);
     103      this.removeDefaultValueButton.Location = new System.Drawing.Point(38, 19);
     104      this.removeDefaultValueButton.Name = "removeDefaultValueButton";
     105      this.removeDefaultValueButton.Size = new System.Drawing.Size(26, 23);
     106      this.removeDefaultValueButton.TabIndex = 1;
     107      this.removeDefaultValueButton.Text = "Remove";
     108      this.removeDefaultValueButton.UseVisualStyleBackColor = true;
     109      this.removeDefaultValueButton.Click += new System.EventHandler(this.removeDefaultValueButton_Click);
    102110      //
    103       // resultNameLabel
     111      // setDefaultValueButton
    104112      //
    105       this.resultNameLabel.AutoSize = true;
    106       this.resultNameLabel.Location = new System.Drawing.Point(3, 81);
    107       this.resultNameLabel.Name = "resultNameLabel";
    108       this.resultNameLabel.Size = new System.Drawing.Size(71, 13);
    109       this.resultNameLabel.TabIndex = 5;
    110       this.resultNameLabel.Text = "&Result Name:";
     113      this.setDefaultValueButton.Location = new System.Drawing.Point(6, 19);
     114      this.setDefaultValueButton.Name = "setDefaultValueButton";
     115      this.setDefaultValueButton.Size = new System.Drawing.Size(26, 23);
     116      this.setDefaultValueButton.TabIndex = 1;
     117      this.setDefaultValueButton.Text = "Set";
     118      this.setDefaultValueButton.UseVisualStyleBackColor = true;
     119      this.setDefaultValueButton.Click += new System.EventHandler(this.setDefaultValueButton_Click);
    111120      //
    112       // LookupParameterView
     121      // defaultValueViewHost
    113122      //
    114       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     123      this.defaultValueViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     124            | System.Windows.Forms.AnchorStyles.Left)
     125            | System.Windows.Forms.AnchorStyles.Right)));
     126      this.defaultValueViewHost.Caption = "View";
     127      this.defaultValueViewHost.Content = null;
     128      this.defaultValueViewHost.Enabled = false;
     129      this.defaultValueViewHost.Location = new System.Drawing.Point(6, 48);
     130      this.defaultValueViewHost.Name = "defaultValueViewHost";
     131      this.defaultValueViewHost.ReadOnly = false;
     132      this.defaultValueViewHost.Size = new System.Drawing.Size(374, 168);
     133      this.defaultValueViewHost.TabIndex = 0;
     134      this.defaultValueViewHost.ViewsLabelVisible = true;
     135      this.defaultValueViewHost.ViewType = null;
     136      //
     137      // ResultParameterView
     138      //
    115139      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    116       this.Controls.Add(this.resultNameTextBox);
    117       this.Controls.Add(this.resultNameLabel);
     140      this.Controls.Add(this.defaultValueGroupBox);
     141      this.Controls.Add(this.resultCollectionNameTextBox);
     142      this.Controls.Add(this.resultCollectionNameLabel);
    118143      this.Name = "ResultParameterView";
    119       this.Size = new System.Drawing.Size(386, 76);
     144      this.Size = new System.Drawing.Size(386, 326);
    120145      this.Controls.SetChildIndex(this.dataTypeLabel, 0);
    121146      this.Controls.SetChildIndex(this.dataTypeTextBox, 0);
     
    125150      this.Controls.SetChildIndex(this.actualNameTextBox, 0);
    126151      this.Controls.SetChildIndex(this.nameLabel, 0);
    127       this.Controls.SetChildIndex(this.resultNameLabel, 0);
    128       this.Controls.SetChildIndex(this.resultNameTextBox, 0);
     152      this.Controls.SetChildIndex(this.resultCollectionNameLabel, 0);
     153      this.Controls.SetChildIndex(this.resultCollectionNameTextBox, 0);
     154      this.Controls.SetChildIndex(this.defaultValueGroupBox, 0);
    129155      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
     156      this.defaultValueGroupBox.ResumeLayout(false);
    130157      this.ResumeLayout(false);
    131158      this.PerformLayout();
     
    135162    #endregion
    136163
    137     protected System.Windows.Forms.TextBox resultNameTextBox;
    138     protected System.Windows.Forms.Label resultNameLabel;
     164    protected System.Windows.Forms.TextBox resultCollectionNameTextBox;
     165    protected System.Windows.Forms.Label resultCollectionNameLabel;
     166    private System.Windows.Forms.GroupBox defaultValueGroupBox;
     167    private MainForm.WindowsForms.ViewHost defaultValueViewHost;
     168    private System.Windows.Forms.Button removeDefaultValueButton;
     169    private System.Windows.Forms.Button setDefaultValueButton;
    139170  }
    140171}
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/ResultParameterView.cs

    r12764 r14058  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
     23using System.Windows.Forms;
     24using HeuristicLab.Common.Resources;
    2325using HeuristicLab.Core;
     26using HeuristicLab.Core.Views;
    2427using HeuristicLab.MainForm;
    2528using HeuristicLab.Parameters.Views;
     29using HeuristicLab.PluginInfrastructure;
    2630
    2731namespace HeuristicLab.Optimization.Views {
     
    2933  [Content(typeof(ResultParameter<>), true)]
    3034  [Content(typeof(IResultParameter<>), false)]
    31   public partial class ResultParameterView<T> : LookupParameterView<ResultCollection> where T : class, IItem, new() {
     35  public partial class ResultParameterView<T> : LookupParameterView<T> where T : class, IItem {
     36    protected TypeSelectorDialog typeSelectorDialog;
    3237
    3338    public new IResultParameter<T> Content {
     
    3843    public ResultParameterView() {
    3944      InitializeComponent();
     45      setDefaultValueButton.Text = string.Empty;
     46      setDefaultValueButton.Image = VSImageLibrary.Edit;
     47      removeDefaultValueButton.Text = string.Empty;
     48      removeDefaultValueButton.Image = VSImageLibrary.Remove;
     49    }
     50
     51    /// <summary>
     52    /// Clean up any resources being used.
     53    /// </summary>
     54    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
     55    protected override void Dispose(bool disposing) {
     56      if (disposing) {
     57        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     58        if (components != null) components.Dispose();
     59      }
     60      base.Dispose(disposing);
    4061    }
    4162
    4263    protected override void DeregisterContentEvents() {
    43       Content.ResultNameChanged -= new EventHandler(Content_ResultNameChanged);
     64      Content.ResultCollectionNameChanged -= ContentOnResultCollectionNameChanged;
     65      Content.DefaultValueChanged -= ContentOnDefaultValueChanged;
    4466      base.DeregisterContentEvents();
    4567    }
     
    4769    protected override void RegisterContentEvents() {
    4870      base.RegisterContentEvents();
    49       Content.ResultNameChanged += new EventHandler(Content_ResultNameChanged);
     71      Content.ResultCollectionNameChanged += ContentOnResultCollectionNameChanged;
     72      Content.DefaultValueChanged += ContentOnDefaultValueChanged;
    5073    }
    5174
    5275    protected override void OnContentChanged() {
    5376      base.OnContentChanged();
    54       if (Content == null)
    55         resultNameTextBox.Text = "-";
    56       else
    57         resultNameTextBox.Text = Content.ResultName;
     77      if (Content == null) {
     78        resultCollectionNameTextBox.Text = "-";
     79        defaultValueViewHost.Content = null;
     80      } else {
     81        resultCollectionNameTextBox.Text = Content.ResultCollectionName;
     82        defaultValueViewHost.Content = Content.DefaultValue;
     83      }
    5884    }
    5985
    6086    protected override void SetEnabledStateOfControls() {
    6187      base.SetEnabledStateOfControls();
    62       resultNameTextBox.Enabled = Content != null;
    63       resultNameTextBox.ReadOnly = ReadOnly;
     88      resultCollectionNameTextBox.Enabled = Content != null;
     89      resultCollectionNameTextBox.ReadOnly = ReadOnly;
    6490    }
    6591
    66     private void Content_ResultNameChanged(object sender, EventArgs e) {
    67       if (InvokeRequired)
    68         Invoke(new EventHandler(Content_ResultNameChanged), sender, e);
    69       else
    70         resultNameTextBox.Text = Content.ResultName;
     92    private void ContentOnDefaultValueChanged(object sender, EventArgs e) {
     93      if (InvokeRequired) Invoke((Action<object, EventArgs>)ContentOnDefaultValueChanged, sender, e);
     94      else defaultValueViewHost.Content = Content.DefaultValue;
     95    }
     96
     97    private void ContentOnResultCollectionNameChanged(object sender, EventArgs e) {
     98      if (InvokeRequired) Invoke((Action<object, EventArgs>)ContentOnResultCollectionNameChanged, sender, e);
     99      else resultCollectionNameTextBox.Text = Content.ResultCollectionName;
    71100    }
    72101
    73102    private void resultNameTextBox_Validated(object sender, EventArgs e) {
    74       Content.ResultName = resultNameTextBox.Text;
     103      if (InvokeRequired) Invoke((Action<object, EventArgs>)resultNameTextBox_Validated, sender, e);
     104      else Content.ResultCollectionName = resultCollectionNameTextBox.Text;
     105    }
     106
     107    private void setDefaultValueButton_Click(object sender, EventArgs e) {
     108      if (typeSelectorDialog == null) {
     109        typeSelectorDialog = new TypeSelectorDialog();
     110        typeSelectorDialog.Caption = "Select Value";
     111        typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);
     112      }
     113      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
     114        try {
     115          Content.DefaultValue = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     116        } catch (Exception ex) {
     117          ErrorHandling.ShowErrorDialog(this, ex);
     118        }
     119      }
     120    }
     121
     122    private void removeDefaultValueButton_Click(object sender, EventArgs e) {
     123      Content.DefaultValue = null;
     124    }
     125
     126    protected virtual void defaultValueGroupBox_DragEnterOver(object sender, DragEventArgs e) {
     127      e.Effect = DragDropEffects.None;
     128      if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) != null) && Content.DataType.IsAssignableFrom(e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat).GetType())) {
     129        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
     130        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
     131        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     132        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     133        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
     134      }
     135    }
     136    protected virtual void defaultValueGroupBox_DragDrop(object sender, DragEventArgs e) {
     137      if (e.Effect != DragDropEffects.None) {
     138        T value = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as T;
     139        if (e.Effect.HasFlag(DragDropEffects.Copy)) value = (T)value.Clone();
     140        Content.DefaultValue = value;
     141      }
    75142    }
    76143  }
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Results/IResultParameter.cs

    r12764 r14058  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525namespace HeuristicLab.Optimization {
    2626  public interface IResultParameter : ILookupParameter {
    27     string ResultName { get; set; }
    28     event EventHandler ResultNameChanged;
     27    string ResultCollectionName { get; set; }
     28    event EventHandler ResultCollectionNameChanged;
    2929  }
    3030
    31   public interface IResultParameter<T> : ILookupParameter<ResultCollection>, IResultParameter where T : class, IItem, new() {
     31  public interface IResultParameter<T> : ILookupParameter<T>, IResultParameter where T : class, IItem {
    3232    T DefaultValue { get; set; }
    33     T ResultValue { get; set; }
     33    event EventHandler DefaultValueChanged;
    3434  }
    3535}
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Results/ResultParameter.cs

    r12764 r14058  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
     23using System.Drawing;
    2324using HeuristicLab.Common;
     25using HeuristicLab.Common.Resources;
    2426using HeuristicLab.Core;
    2527using HeuristicLab.Parameters;
     
    3133  [StorableClass]
    3234  [NonDiscoverableType]
    33   public sealed class ResultParameter<T> : LookupParameter<ResultCollection>, IResultParameter<T> where T : class, IItem, new() {
     35  public sealed class ResultParameter<T> : LookupParameter<T>, IResultParameter<T> where T : class, IItem {
     36    public override Image ItemImage { get { return VSImageLibrary.Exception; } }
    3437
    3538    [Storable]
    36     private string resultName;
    37     public string ResultName {
    38       get { return resultName; }
     39    private string resultCollectionName;
     40    public string ResultCollectionName {
     41      get { return resultCollectionName; }
    3942      set {
    4043        if (value == null) throw new ArgumentNullException();
    41         if (string.IsNullOrWhiteSpace(value)) {
    42           resultName = Name;
    43           OnResultNameChanged();
    44         } else if (!resultName.Equals(value)) {
    45           resultName = value;
    46           OnResultNameChanged();
     44        if (string.IsNullOrWhiteSpace(value)) throw new ArgumentNullException();
     45        else if (!resultCollectionName.Equals(value)) {
     46          resultCollectionName = value;
     47          OnResultCollectionNameChanged();
    4748        }
    4849      }
     
    6162    }
    6263
    63     public T ResultValue {
    64       get { return GetResultValue(); }
    65       set { SetResultValue(value); }
    66     }
    67 
    6864    [StorableConstructor]
    6965    private ResultParameter(bool deserializing) : base(deserializing) { }
    7066    private ResultParameter(ResultParameter<T> original, Cloner cloner)
    7167      : base(original, cloner) {
    72       resultName = original.resultName;
     68      resultCollectionName = original.resultCollectionName;
    7369      defaultValue = cloner.Clone(original.defaultValue);
    7470    }
     
    7672      return new ResultParameter<T>(this, cloner);
    7773    }
    78     public ResultParameter() : this("Anonymous") { }
    79     public ResultParameter(string name)
    80       : base(name, string.Empty, "Results") {
    81       resultName = Name;
    82       defaultValue = new T();
    83     }
    84     public ResultParameter(string name, string description) : this(name, description, new T()) { }
    85     public ResultParameter(string name, string description, T defaultValue)
    86       : base(name, description, "Results") {
     74    public ResultParameter() : this("Anonymous", string.Empty, "Results") { }
     75    public ResultParameter(string name) : this(name, string.Empty, "Results") { }
     76    public ResultParameter(string name, string description) : this(name, description, "Results") { }
     77    public ResultParameter(string name, string description, string resultCollectionName)
     78      : base(name, description, string.Empty) {
     79      if (string.IsNullOrEmpty(resultCollectionName)) throw new ArgumentException("resultCollectionName");
     80      this.resultCollectionName = resultCollectionName;
     81    }
     82    public ResultParameter(string name, string description, string resultCollectionName, T defaultValue)
     83      : base(name, description, string.Empty) {
     84      if (string.IsNullOrEmpty(resultCollectionName)) throw new ArgumentException("resultCollectionName");
    8785      if (defaultValue == null) throw new ArgumentNullException("defaultValue");
    88       resultName = Name;
     86      this.resultCollectionName = resultCollectionName;
    8987      this.defaultValue = defaultValue;
    9088    }
    91     public ResultParameter(string name, string description, string resultName) : this(name, description, new T(), resultName) { }
    92     public ResultParameter(string name, string description, T defaultValue, string resultName)
    93       : base(name, description, "Results") {
    94       if (defaultValue == null) throw new ArgumentNullException("defaultValue");
    95       this.resultName = string.IsNullOrWhiteSpace(resultName) ? Name : resultName;
    96       this.defaultValue = defaultValue;
    97     }
     89   
     90    protected override IItem GetActualValue() {
     91      ResultCollection results;
     92      if (CachedActualValue != null) {
     93        results = CachedActualValue as ResultCollection;
     94        if (results == null) throw new InvalidOperationException("ResultParameter (" + ActualName + "): ResultCollection not found.");
     95      } else {
     96        var tmp = ResultCollectionName;
     97        // verifyType has to be disabled, because the ResultCollection may not be identical to the generic type of the parameter
     98        results = GetValue(ExecutionContext, ref tmp) as ResultCollection;
     99        if (results == null) throw new InvalidOperationException("ResultParameter (" + ActualName + "): ResultCollection with name " + tmp + " not found.");
     100        CachedActualValue = results;
     101      }
    98102
    99     public override string ToString() {
    100       if (Name.Equals(ResultName)) return Name;
    101       return Name + ": " + ResultName;
    102     }
     103      IResult result;
     104      if (!results.TryGetValue(ActualName, out result)) {
     105        if (DefaultValue == null) throw new InvalidOperationException("ResultParameter (" + ActualName + "): Result not found and no default value specified.");
     106        result = new Result(ActualName, (T)DefaultValue.Clone());
     107        results.Add(result);
     108      }
    103109
    104     private T GetResultValue() {
    105       var results = ActualValue;
    106       if (results == null)
    107         throw new InvalidOperationException("ResultParameter (" + ResultName + "): ResultCollection " + ActualName + " not found.");
    108 
    109       if (!results.ContainsKey(ResultName)) results.Add(new Result(ResultName, (T)DefaultValue.Clone()));
    110       var resultValue = results[ResultName].Value as T;
     110      var resultValue = result.Value as T;
    111111      if (resultValue == null)
    112         throw new InvalidOperationException(string.Format("Type mismatch. Result \"{0}\" does not contain a \"{1}\".", ResultName, typeof(T).GetPrettyName()));
     112        throw new InvalidOperationException(string.Format("Type mismatch. Result \"{0}\" does not contain a \"{1}\".", ActualName, typeof(T).GetPrettyName()));
    113113
    114114      return resultValue;
    115115    }
    116116
    117     private void SetResultValue(T value) {
    118       var results = ActualValue;
    119       if (results == null)
    120         throw new InvalidOperationException("ResultParameter (" + ResultName + "): ResultCollection " + ActualName + " not found.");
     117    protected override void SetActualValue(IItem value) {
     118      ResultCollection results;
     119      if (CachedActualValue != null) {
     120        results = CachedActualValue as ResultCollection;
     121        if (results == null) throw new InvalidOperationException("ResultParameter (" + ActualName + "): ResultCollection not found.");
     122      } else {
     123        var tmp = ResultCollectionName;
     124        results = GetValue(ExecutionContext, ref tmp) as ResultCollection;
     125        if (results == null) throw new InvalidOperationException("ResultParameter (" + ActualName + "): ResultCollection with name " + tmp + " not found.");
     126        CachedActualValue = results;
     127      }
    121128
    122       if (!results.ContainsKey(ResultName))
    123         results.Add(new Result(ResultName, value));
    124       else results[ResultName].Value = value;
     129      IResult result;
     130      if (!results.TryGetValue(ActualName, out result)) {
     131        result = new Result(ActualName, value);
     132        results.Add(result);
     133      } else result.Value = value;
    125134    }
    126135
    127     public event EventHandler ResultNameChanged;
    128     private void OnResultNameChanged() {
    129       var handler = ResultNameChanged;
     136
     137    public event EventHandler ResultCollectionNameChanged;
     138    private void OnResultCollectionNameChanged() {
     139      var handler = ResultCollectionNameChanged;
    130140      if (handler != null) handler(this, EventArgs.Empty);
    131141      OnToStringChanged();
Note: See TracChangeset for help on using the changeset viewer.