Changeset 14058
- Timestamp:
- 07/13/16 10:51:56 (8 years ago)
- Location:
- branches/PerformanceComparison
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Analysis/3.3/Optimizers/IteratedAlgorithm.cs
r13738 r14058 475 475 } 476 476 } 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); 479 479 if (StoreSolutionInRun) { 480 480 foreach (var r in Algorithm.Results) { -
branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/QualityPerClockAnalyzer.cs
r12834 r14058 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 76 76 public override IOperation Apply() { 77 77 var bestQuality = BestQualityParameter.ActualValue.Value; 78 var dataTable = QualityPerClockParameter. ResultValue;78 var dataTable = QualityPerClockParameter.ActualValue; 79 79 var values = dataTable.Rows["First-hit Graph"].Values; 80 80 -
branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/QualityPerEvaluationsAnalyzer.cs
r12834 r14058 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 88 88 if (evalMoves != null) evaluations += evalMoves.Value * MoveCostPerSolutionParameter.ActualValue.Value; 89 89 90 var dataTable = QualityPerEvaluationsParameter. ResultValue;90 var dataTable = QualityPerEvaluationsParameter.ActualValue; 91 91 var values = dataTable.Rows["First-hit Graph"].Values; 92 92 if (evaluations == 0 || values.Count > 0 && evaluations < values.Last().Item1) evaluations = 1; -
branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/ResultParameterView.Designer.cs
r12764 r14058 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 26 26 /// </summary> 27 27 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 40 29 #region Component Designer generated code 41 30 … … 45 34 /// </summary> 46 35 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(); 49 42 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 43 this.defaultValueGroupBox.SuspendLayout(); 50 44 this.SuspendLayout(); 51 45 // 52 // dataTypeLabel46 // actualNameTextBox 53 47 // 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); 56 50 // 57 51 // dataTypeTextBox 58 52 // 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); 62 55 // 63 56 // nameTextBox … … 65 58 this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 66 59 this.errorProvider.SetIconPadding(this.nameTextBox, 2); 67 this.nameTextBox.Location = new System.Drawing.Point( 80, 0);68 this.nameTextBox.Size = new System.Drawing.Size(2 81, 20);60 this.nameTextBox.Location = new System.Drawing.Point(98, 0); 61 this.nameTextBox.Size = new System.Drawing.Size(263, 20); 69 62 // 70 // infoLabel63 // resultCollectionNameTextBox 71 64 // 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); 73 72 // 74 // actualNameTextBox73 // resultCollectionNameLabel 75 74 // 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:"; 83 81 // 84 // actualNameLabel82 // defaultValueGroupBox 85 83 // 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); 92 100 // 93 // re sultNameTextBox101 // removeDefaultValueButton 94 102 // 95 this.re sultNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)96 | System.Windows.Forms.AnchorStyles.Right)));97 this.re sultNameTextBox.Location = new System.Drawing.Point(80, 78);98 this.re sultNameTextBox.Name = "resultNameTextBox";99 this.re sultNameTextBox.Size = new System.Drawing.Size(306, 20);100 this.re sultNameTextBox.TabIndex = 6;101 this.re sultNameTextBox.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); 102 110 // 103 // resultNameLabel111 // setDefaultValueButton 104 112 // 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); 111 120 // 112 // LookupParameterView121 // defaultValueViewHost 113 122 // 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 // 115 139 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); 118 143 this.Name = "ResultParameterView"; 119 this.Size = new System.Drawing.Size(386, 76);144 this.Size = new System.Drawing.Size(386, 326); 120 145 this.Controls.SetChildIndex(this.dataTypeLabel, 0); 121 146 this.Controls.SetChildIndex(this.dataTypeTextBox, 0); … … 125 150 this.Controls.SetChildIndex(this.actualNameTextBox, 0); 126 151 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); 129 155 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 156 this.defaultValueGroupBox.ResumeLayout(false); 130 157 this.ResumeLayout(false); 131 158 this.PerformLayout(); … … 135 162 #endregion 136 163 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; 139 170 } 140 171 } -
branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/ResultParameterView.cs
r12764 r14058 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Windows.Forms; 24 using HeuristicLab.Common.Resources; 23 25 using HeuristicLab.Core; 26 using HeuristicLab.Core.Views; 24 27 using HeuristicLab.MainForm; 25 28 using HeuristicLab.Parameters.Views; 29 using HeuristicLab.PluginInfrastructure; 26 30 27 31 namespace HeuristicLab.Optimization.Views { … … 29 33 [Content(typeof(ResultParameter<>), true)] 30 34 [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; 32 37 33 38 public new IResultParameter<T> Content { … … 38 43 public ResultParameterView() { 39 44 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); 40 61 } 41 62 42 63 protected override void DeregisterContentEvents() { 43 Content.ResultNameChanged -= new EventHandler(Content_ResultNameChanged); 64 Content.ResultCollectionNameChanged -= ContentOnResultCollectionNameChanged; 65 Content.DefaultValueChanged -= ContentOnDefaultValueChanged; 44 66 base.DeregisterContentEvents(); 45 67 } … … 47 69 protected override void RegisterContentEvents() { 48 70 base.RegisterContentEvents(); 49 Content.ResultNameChanged += new EventHandler(Content_ResultNameChanged); 71 Content.ResultCollectionNameChanged += ContentOnResultCollectionNameChanged; 72 Content.DefaultValueChanged += ContentOnDefaultValueChanged; 50 73 } 51 74 52 75 protected override void OnContentChanged() { 53 76 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 } 58 84 } 59 85 60 86 protected override void SetEnabledStateOfControls() { 61 87 base.SetEnabledStateOfControls(); 62 result NameTextBox.Enabled = Content != null;63 result NameTextBox.ReadOnly = ReadOnly;88 resultCollectionNameTextBox.Enabled = Content != null; 89 resultCollectionNameTextBox.ReadOnly = ReadOnly; 64 90 } 65 91 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; 71 100 } 72 101 73 102 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 } 75 142 } 76 143 } -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Results/IResultParameter.cs
r12764 r14058 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 namespace HeuristicLab.Optimization { 26 26 public interface IResultParameter : ILookupParameter { 27 string Result Name { get; set; }28 event EventHandler Result NameChanged;27 string ResultCollectionName { get; set; } 28 event EventHandler ResultCollectionNameChanged; 29 29 } 30 30 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 { 32 32 T DefaultValue { get; set; } 33 T ResultValue { get; set; }33 event EventHandler DefaultValueChanged; 34 34 } 35 35 } -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Results/ResultParameter.cs
r12764 r14058 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Drawing; 23 24 using HeuristicLab.Common; 25 using HeuristicLab.Common.Resources; 24 26 using HeuristicLab.Core; 25 27 using HeuristicLab.Parameters; … … 31 33 [StorableClass] 32 34 [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; } } 34 37 35 38 [Storable] 36 private string result Name;37 public string Result Name {38 get { return result Name; }39 private string resultCollectionName; 40 public string ResultCollectionName { 41 get { return resultCollectionName; } 39 42 set { 40 43 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(); 47 48 } 48 49 } … … 61 62 } 62 63 63 public T ResultValue {64 get { return GetResultValue(); }65 set { SetResultValue(value); }66 }67 68 64 [StorableConstructor] 69 65 private ResultParameter(bool deserializing) : base(deserializing) { } 70 66 private ResultParameter(ResultParameter<T> original, Cloner cloner) 71 67 : base(original, cloner) { 72 result Name = original.resultName;68 resultCollectionName = original.resultCollectionName; 73 69 defaultValue = cloner.Clone(original.defaultValue); 74 70 } … … 76 72 return new ResultParameter<T>(this, cloner); 77 73 } 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"); 87 85 if (defaultValue == null) throw new ArgumentNullException("defaultValue"); 88 resultName =Name;86 this.resultCollectionName = resultCollectionName; 89 87 this.defaultValue = defaultValue; 90 88 } 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 } 98 102 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 } 103 109 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; 111 111 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())); 113 113 114 114 return resultValue; 115 115 } 116 116 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 } 121 128 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; 125 134 } 126 135 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; 130 140 if (handler != null) handler(this, EventArgs.Empty); 131 141 OnToStringChanged();
Note: See TracChangeset
for help on using the changeset viewer.