Free cookie consent management tool by TermsFeed Policy Generator

Ticket #2281: resultparameter2.patch

File resultparameter2.patch, 66.4 KB (added by abeham, 9 years ago)

Improved patch (deriving result parameter from lookup parameter)

  • HeuristicLab.Analysis/3.3/QualityAnalysis/QualityDistributionAnalyzer.cs

     
    3737    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
    3838      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    3939    }
    40     public IValueLookupParameter<ResultCollection> ResultsParameter {
    41       get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     40    public IResultParameter<DataTable> QualityDistributionParameter {
     41      get { return (IResultParameter<DataTable>)Parameters["Quality Distribution"]; }
    4242    }
    43     private ValueParameter<StringValue> HistogramNameParameter {
    44       get { return (ValueParameter<StringValue>)Parameters["HistogramName"]; }
     43    public IResultParameter<DataTableHistory> QualityDistributionHistoryParameter {
     44      get { return (IResultParameter<DataTableHistory>)Parameters["Quality Distribution History"]; }
    4545    }
    46     private ValueParameter<BoolValue> StoreHistoryParameter {
    47       get { return (ValueParameter<BoolValue>)Parameters["StoreHistory"]; }
    48     }
    4946    public ILookupParameter<IntValue> IterationsParameter {
    5047      get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; }
    5148    }
     
    5249    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
    5350      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    5451    }
     52    private ValueParameter<BoolValue> StoreHistoryParameter {
     53      get { return (ValueParameter<BoolValue>)Parameters["StoreHistory"]; }
     54    }
    5555    #endregion
    5656
    5757    public virtual bool EnabledByDefault {
     
    5858      get { return true; }
    5959    }
    6060
    61     public string HistogramName {
    62       get { return HistogramNameParameter.Value.Value; }
    63       set { HistogramNameParameter.Value.Value = value; }
    64     }
    65 
    6661    public bool StoreHistory {
    6762      get { return StoreHistoryParameter.Value.Value; }
    6863      set { StoreHistoryParameter.Value.Value = value; }
     
    7671    public QualityDistributionAnalyzer()
    7772      : base() {
    7873      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    79       Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection where the analysis values should be stored."));
    80       Parameters.Add(new FixedValueParameter<StringValue>("HistogramName", "The name of the histogram that gets injected in to the results collection.", new StringValue("Quality Distribution")));
     74      Parameters.Add(new ResultParameter<DataTable>("Quality Distribution", "Shows the quality distributions in the current population."));
     75      Parameters.Add(new ResultParameter<DataTableHistory>("Quality Distribution History", "Maintains the history of the quality distributions of each iteration."));
    8176      Parameters.Add(new FixedValueParameter<BoolValue>("StoreHistory", "True if the history should be stored in addition to the current distribution", new BoolValue(false)));
    8277      Parameters.Add(new LookupParameter<IntValue>("Iterations", "Optional: A value indicating the current iteration."));
    8378      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "Unused", new IntValue(-1)));
    8479
    8580      QualityParameter.Hidden = true;
    86       ResultsParameter.Hidden = true;
    8781      IterationsParameter.Hidden = true;
    8882      MaximumIterationsParameter.Hidden = true;
     83
     84      var table = new DataTable("Population Quality Distribution", QualityDistributionParameter.Description) {
     85        VisualProperties = { XAxisTitle = "Quality", YAxisTitle = "Frequency" }
     86      };
     87      var row = new DataRow("QualityDistribution") {
     88        VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Histogram }
     89      };
     90      table.Rows.Add(row);
     91      QualityDistributionParameter.DefaultValue = table;
     92
     93      QualityDistributionHistoryParameter.DefaultValue = new DataTableHistory();
    8994    }
    9095
    9196    public override IDeepCloneable Clone(Cloner cloner) {
     
    9398    }
    9499
    95100    public override IOperation Apply() {
    96       DataTable qualityDistribution = null;
    97       ResultCollection results = ResultsParameter.ActualValue;
    98       string description = "Shows the quality distributions in the current population.";
    99       if (results.ContainsKey(HistogramName)) {
    100         qualityDistribution = results[HistogramName].Value as DataTable;
    101       } else {
    102         qualityDistribution = new DataTable("Population Quality Distribution", description);
    103         qualityDistribution.VisualProperties.XAxisTitle = QualityParameter.ActualName;
    104         qualityDistribution.VisualProperties.YAxisTitle = "Frequency";
    105         results.Add(new Result(HistogramName, description, qualityDistribution));
    106       }
    107       DataRow row;
    108       if (!qualityDistribution.Rows.TryGetValue("QualityDistribution", out row)) {
    109         row = new DataRow("QualityDistribution");
    110         row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    111         qualityDistribution.Rows.Add(row);
    112       }
     101      var qualityDistribution = QualityDistributionParameter.ResultValue;
     102      var row = qualityDistribution.Rows.First();
     103
    113104      var qualities = QualityParameter.ActualValue;
    114105      row.Values.Replace(qualities.Select(x => x.Value));
    115106
    116107      if (StoreHistory) {
    117         string historyResultName = HistogramName + " History";
    118         DataTableHistory qdHistory = null;
    119         if (results.ContainsKey(historyResultName)) {
    120           qdHistory = results[historyResultName].Value as DataTableHistory;
    121         } else {
    122           qdHistory = new DataTableHistory();
    123           results.Add(new Result(historyResultName, qdHistory));
    124         }
    125         DataTable table = (DataTable)qualityDistribution.Clone();
    126         IntValue iteration = IterationsParameter.ActualValue;
     108        var qdHistory = QualityDistributionHistoryParameter.ResultValue;
     109        var table = (DataTable)qualityDistribution.Clone();
     110        var iteration = IterationsParameter.ActualValue;
    127111        if (iteration != null) {
    128           string iterationName = IterationsParameter.ActualName;
     112          var iterationName = IterationsParameter.ActualName;
    129113          if (iterationName.EndsWith("s")) iterationName = iterationName.Remove(iterationName.Length - 1);
    130           string appendix = " at " + iterationName + " " + iteration.Value.ToString();
     114          var appendix = " at " + iterationName + " " + iteration.Value;
    131115          table.Name += appendix;
    132           table.Rows["QualityDistribution"].VisualProperties.DisplayName += appendix;
     116          table.Rows.First().VisualProperties.DisplayName += appendix;
    133117        }
    134118        qdHistory.Add(table);
    135119      }
  • HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

     
    159159    <Compile Include="ExperimentListView.Designer.cs">
    160160      <DependentUpon>ExperimentListView.cs</DependentUpon>
    161161    </Compile>
     162    <Compile Include="ResultParameterView.cs">
     163      <SubType>UserControl</SubType>
     164    </Compile>
     165    <Compile Include="ResultParameterView.Designer.cs">
     166      <DependentUpon>ResultParameterView.cs</DependentUpon>
     167    </Compile>
    162168    <Compile Include="MultiEncodingView.cs">
    163169      <SubType>UserControl</SubType>
    164170    </Compile>
     
    383389      <Name>HeuristicLab.Optimization-3.3</Name>
    384390      <Private>False</Private>
    385391    </ProjectReference>
     392    <ProjectReference Include="..\..\HeuristicLab.Parameters.Views\3.3\HeuristicLab.Parameters.Views-3.3.csproj">
     393      <Project>{ae5b1ce5-9862-4d6f-a700-d72cd9aea295}</Project>
     394      <Name>HeuristicLab.Parameters.Views-3.3</Name>
     395      <Private>False</Private>
     396    </ProjectReference>
     397    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
     398      <Project>{56f9106a-079f-4c61-92f6-86a84c2d84b7}</Project>
     399      <Name>HeuristicLab.Parameters-3.3</Name>
     400      <Private>False</Private>
     401    </ProjectReference>
    386402    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    387403      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    388404      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
  • HeuristicLab.Optimization.Views/3.3/ResultParameterView.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using HeuristicLab.Core;
     24using HeuristicLab.MainForm;
     25using HeuristicLab.Parameters.Views;
     26
     27namespace HeuristicLab.Optimization.Views {
     28  [View("ResultParameter View")]
     29  [Content(typeof(ResultParameter<>), true)]
     30  [Content(typeof(IResultParameter<>), false)]
     31  public partial class ResultParameterView<T> : LookupParameterView<ResultCollection> where T : class, IItem, new() {
     32
     33    public new IResultParameter<T> Content {
     34      get { return (IResultParameter<T>)base.Content; }
     35      set { base.Content = value; }
     36    }
     37
     38    public ResultParameterView() {
     39      InitializeComponent();
     40    }
     41
     42    protected override void DeregisterContentEvents() {
     43      Content.ResultNameChanged -= new EventHandler(Content_ResultNameChanged);
     44      base.DeregisterContentEvents();
     45    }
     46
     47    protected override void RegisterContentEvents() {
     48      base.RegisterContentEvents();
     49      Content.ResultNameChanged += new EventHandler(Content_ResultNameChanged);
     50    }
     51
     52    protected override void OnContentChanged() {
     53      base.OnContentChanged();
     54      if (Content == null)
     55        resultNameTextBox.Text = "-";
     56      else
     57        resultNameTextBox.Text = Content.ResultName;
     58    }
     59
     60    protected override void SetEnabledStateOfControls() {
     61      base.SetEnabledStateOfControls();
     62      resultNameTextBox.Enabled = Content != null;
     63      resultNameTextBox.ReadOnly = ReadOnly;
     64    }
     65
     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;
     71    }
     72
     73    private void resultNameTextBox_Validated(object sender, EventArgs e) {
     74      Content.ResultName = resultNameTextBox.Text;
     75    }
     76  }
     77}
  • HeuristicLab.Optimization.Views/3.3/ResultParameterView.Designer.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22namespace HeuristicLab.Optimization.Views {
     23  partial class ResultParameterView<T> {
     24    /// <summary>
     25    /// Required designer variable.
     26    /// </summary>
     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
     40    #region Component Designer generated code
     41
     42    /// <summary>
     43    /// Required method for Designer support - do not modify
     44    /// the contents of this method with the code editor.
     45    /// </summary>
     46    private void InitializeComponent() {
     47      this.resultNameTextBox = new System.Windows.Forms.TextBox();
     48      this.resultNameLabel = new System.Windows.Forms.Label();
     49      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     50      this.SuspendLayout();
     51      //
     52      // dataTypeLabel
     53      //
     54      this.dataTypeLabel.Location = new System.Drawing.Point(3, 55);
     55      this.dataTypeLabel.TabIndex = 5;
     56      //
     57      // dataTypeTextBox
     58      //
     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;
     62      //
     63      // nameTextBox
     64      //
     65      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
     66      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);
     69      //
     70      // infoLabel
     71      //
     72      this.infoLabel.Location = new System.Drawing.Point(367, 3);
     73      //
     74      // actualNameTextBox
     75      //
     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);
     83      //
     84      // actualNameLabel
     85      //
     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:";
     92      //
     93      // resultNameTextBox
     94      //
     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);
     102      //
     103      // resultNameLabel
     104      //
     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:";
     111      //
     112      // LookupParameterView
     113      //
     114      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     115      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     116      this.Controls.Add(this.resultNameTextBox);
     117      this.Controls.Add(this.resultNameLabel);
     118      this.Name = "ResultParameterView";
     119      this.Size = new System.Drawing.Size(386, 76);
     120      this.Controls.SetChildIndex(this.dataTypeLabel, 0);
     121      this.Controls.SetChildIndex(this.dataTypeTextBox, 0);
     122      this.Controls.SetChildIndex(this.infoLabel, 0);
     123      this.Controls.SetChildIndex(this.actualNameLabel, 0);
     124      this.Controls.SetChildIndex(this.nameTextBox, 0);
     125      this.Controls.SetChildIndex(this.actualNameTextBox, 0);
     126      this.Controls.SetChildIndex(this.nameLabel, 0);
     127      this.Controls.SetChildIndex(this.resultNameLabel, 0);
     128      this.Controls.SetChildIndex(this.resultNameTextBox, 0);
     129      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
     130      this.ResumeLayout(false);
     131      this.PerformLayout();
     132
     133    }
     134
     135    #endregion
     136
     137    protected System.Windows.Forms.TextBox resultNameTextBox;
     138    protected System.Windows.Forms.Label resultNameLabel;
     139  }
     140}
  • HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

     
    154154    <Compile Include="BasicProblems\SingleObjectiveBasicProblem.cs" />
    155155    <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" />
    156156    <Compile Include="Interfaces\IMultiObjectiveOperator.cs" />
     157    <Compile Include="Results\IResultParameter.cs" />
    157158    <Compile Include="Interfaces\ISingleObjectiveOperator.cs" />
    158159    <Compile Include="Interfaces\ISingleObjectivePathRelinker.cs" />
    159160    <Compile Include="Interfaces\ISingleObjectiveImprovementOperator.cs" />
     
    164165    <Compile Include="Interfaces\ISolutionSimilarityCalculator.cs" />
    165166    <Compile Include="MetaOptimizers\BatchRun.cs" />
    166167    <Compile Include="MetaOptimizers\Experiment.cs" />
     168    <Compile Include="Results\ResultParameter.cs" />
    167169    <Compile Include="RunCollectionModification\RunCollectionRunRemover.cs" />
    168170    <Compile Include="Plugin.cs" />
    169171    <Compile Include="RunCollectionModification\RunCollectionDiscretizer.cs" />
     
    218220    <Compile Include="Interfaces\IOptimizer.cs" />
    219221    <Compile Include="RunCollection.cs" />
    220222    <Compile Include="Run.cs" />
    221     <Compile Include="Interfaces\IResult.cs" />
     223    <Compile Include="Results\IResult.cs" />
    222224    <Compile Include="Interfaces\IDiscreteDoubleValueModifier.cs" />
    223225    <Compile Include="Interfaces\IExhaustiveMoveGenerator.cs" />
    224226    <Compile Include="Interfaces\IMoveOperator.cs" />
     
    242244    <Compile Include="Interfaces\IStochasticOperator.cs" />
    243245    <Compile Include="Interfaces\ITabuChecker.cs" />
    244246    <Compile Include="Interfaces\ITabuMaker.cs" />
    245     <Compile Include="Result.cs" />
     247    <Compile Include="Results\Result.cs" />
    246248    <Compile Include="Algorithms\UserDefinedAlgorithm.cs" />
    247249    <Compile Include="Algorithms\EngineAlgorithm.cs" />
    248250    <Compile Include="Properties\AssemblyInfo.cs" />
    249     <Compile Include="ResultCollection.cs" />
     251    <Compile Include="Results\ResultCollection.cs" />
    250252    <Compile Include="Problems\UserDefinedProblem.cs" />
    251253  </ItemGroup>
    252254  <ItemGroup>
  • HeuristicLab.Optimization/3.3/Interfaces/IResult.cs

     
    1 #region License Information
    2 /* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    4  *
    5  * This file is part of HeuristicLab.
    6  *
    7  * HeuristicLab is free software: you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation, either version 3 of the License, or
    10  * (at your option) any later version.
    11  *
    12  * HeuristicLab is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    19  */
    20 #endregion
    21 
    22 using System;
    23 using HeuristicLab.Core;
    24 
    25 namespace HeuristicLab.Optimization {
    26   /// <summary>
    27   /// Represents a result which has a name and a data type and holds an IItem.
    28   /// </summary>
    29   public interface IResult : INamedItem {
    30     Type DataType { get; }
    31     IItem Value { get; set; }
    32 
    33     /// <inheritdoc/>
    34     event EventHandler ValueChanged;
    35   }
    36 }
  • HeuristicLab.Optimization/3.3/Result.cs

     
    1 #region License Information
    2 /* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    4  *
    5  * This file is part of HeuristicLab.
    6  *
    7  * HeuristicLab is free software: you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation, either version 3 of the License, or
    10  * (at your option) any later version.
    11  *
    12  * HeuristicLab is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    19  */
    20 #endregion
    21 
    22 using System;
    23 using System.Drawing;
    24 using HeuristicLab.Common;
    25 using HeuristicLab.Core;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 
    28 namespace HeuristicLab.Optimization {
    29   /// <summary>
    30   /// Represents a result which has a name and a data type and holds an IItem.
    31   /// </summary>
    32   [Item("Result", "A result which has a name and a data type and holds an IItem.")]
    33   [StorableClass]
    34   public sealed class Result : NamedItem, IResult, IStorableContent {
    35     public string Filename { get; set; }
    36 
    37     public override Image ItemImage {
    38       get {
    39         if (value != null) return value.ItemImage;
    40         else return base.ItemImage;
    41       }
    42     }
    43 
    44     public override bool CanChangeName {
    45       get { return false; }
    46     }
    47     public override bool CanChangeDescription {
    48       get { return false; }
    49     }
    50 
    51     [Storable]
    52     private Type dataType;
    53     public Type DataType {
    54       get { return dataType; }
    55     }
    56 
    57     [Storable]
    58     private IItem value;
    59     public IItem Value {
    60       get { return value; }
    61       set {
    62         if (this.value != value) {
    63           if ((value != null) && (!dataType.IsInstanceOfType(value)))
    64             throw new ArgumentException(
    65               string.Format("Type mismatch. Value is not a \"{0}\".",
    66                             dataType.GetPrettyName())
    67             );
    68 
    69           DeregisterValueEvents();
    70           this.value = value;
    71           RegisterValueEvents();
    72           OnValueChanged();
    73         }
    74       }
    75     }
    76 
    77     [StorableConstructor]
    78     private Result(bool deserializing) : base(deserializing) { }
    79     private Result(Result original, Cloner cloner)
    80       : base(original, cloner) {
    81       dataType = original.dataType;
    82       value = cloner.Clone(original.value);
    83       Initialize();
    84     }
    85     public Result()
    86       : base("Anonymous") {
    87       this.dataType = typeof(IItem);
    88       this.value = null;
    89     }
    90     public Result(string name, Type dataType)
    91       : base(name) {
    92       this.dataType = dataType;
    93       this.value = null;
    94     }
    95     public Result(string name, string description, Type dataType)
    96       : base(name, description) {
    97       this.dataType = dataType;
    98       this.value = null;
    99     }
    100     public Result(string name, IItem value)
    101       : base(name) {
    102       this.dataType = value == null ? typeof(IItem) : value.GetType();
    103       this.value = value;
    104       Initialize();
    105     }
    106     public Result(string name, string description, IItem value)
    107       : base(name, description) {
    108       this.dataType = value == null ? typeof(IItem) : value.GetType();
    109       this.value = value;
    110       Initialize();
    111     }
    112 
    113     [StorableHook(HookType.AfterDeserialization)]
    114     private void AfterDeserialization() {
    115       Initialize();
    116     }
    117 
    118     public override IDeepCloneable Clone(Cloner cloner) {
    119       return new Result(this, cloner);
    120     }
    121 
    122     private void Initialize() {
    123       RegisterValueEvents();
    124     }
    125 
    126     public override string ToString() {
    127       return string.Format("{0}: {1}", Name, Value == null ? "null" : Value.ToString());
    128     }
    129 
    130     public event EventHandler ValueChanged;
    131     private void OnValueChanged() {
    132       var handler = ValueChanged;
    133       if (handler != null) handler(this, EventArgs.Empty);
    134       OnItemImageChanged();
    135       OnToStringChanged();
    136     }
    137 
    138     private void RegisterValueEvents() {
    139       if (value != null) {
    140         value.ItemImageChanged += new EventHandler(Value_ItemImageChanged);
    141         value.ToStringChanged += new EventHandler(Value_ToStringChanged);
    142       }
    143     }
    144     private void DeregisterValueEvents() {
    145       if (value != null) {
    146         value.ItemImageChanged -= new EventHandler(Value_ItemImageChanged);
    147         value.ToStringChanged -= new EventHandler(Value_ToStringChanged);
    148       }
    149     }
    150     private void Value_ItemImageChanged(object sender, EventArgs e) {
    151       OnItemImageChanged();
    152     }
    153     private void Value_ToStringChanged(object sender, EventArgs e) {
    154       OnToStringChanged();
    155     }
    156   }
    157 }
  • HeuristicLab.Optimization/3.3/ResultCollection.cs

     
    1 #region License Information
    2 /* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    4  *
    5  * This file is part of HeuristicLab.
    6  *
    7  * HeuristicLab is free software: you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation, either version 3 of the License, or
    10  * (at your option) any later version.
    11  *
    12  * HeuristicLab is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    19  */
    20 #endregion
    21 
    22 using System.Collections.Generic;
    23 using HeuristicLab.Common;
    24 using HeuristicLab.Core;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 
    27 namespace HeuristicLab.Optimization {
    28   [StorableClass]
    29   [Item("ResultCollection", "Represents a collection of results.")]
    30   public class ResultCollection : NamedItemCollection<IResult> {
    31     public ResultCollection() : base() { }
    32     public ResultCollection(int capacity) : base(capacity) { }
    33     public ResultCollection(IEnumerable<IResult> collection) : base(collection) { }
    34     [StorableConstructor]
    35     protected ResultCollection(bool deserializing) : base(deserializing) { }
    36     protected ResultCollection(ResultCollection original, Cloner cloner)
    37       : base(original, cloner) {
    38     }
    39     public override IDeepCloneable Clone(Cloner cloner) {
    40       return new ResultCollection(this, cloner);
    41     }
    42 
    43     public static new System.Drawing.Image StaticItemImage {
    44       get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
    45     }
    46 
    47     public virtual void CollectResultValues(IDictionary<string, IItem> values) {
    48       CollectResultValues(values, string.Empty);
    49     }
    50 
    51     public virtual void CollectResultValues(IDictionary<string, IItem> values, string rootPath) {
    52       foreach (IResult result in this) {
    53         var children = GetCollectedResults(result);
    54         string path = string.Empty;
    55         if (!string.IsNullOrWhiteSpace(rootPath))
    56           path = rootPath + ".";
    57         foreach (var c in children) {
    58           if (string.IsNullOrEmpty(c.Key))
    59             values.Add(path + result.Name, c.Value);
    60           else values.Add(path + result.Name + "." + c.Key, c.Value);
    61         }
    62       }
    63     }
    64 
    65     protected virtual IEnumerable<KeyValuePair<string, IItem>> GetCollectedResults(IResult result) {
    66       if (result.Value == null) yield break;
    67       yield return new KeyValuePair<string, IItem>(string.Empty, result.Value);
    68 
    69       var resultCollection = result.Value as ResultCollection;
    70       if (resultCollection != null) {
    71         var children = new Dictionary<string, IItem>();
    72         resultCollection.CollectResultValues(children);
    73         foreach (var child in children) yield return child;
    74       }
    75     }
    76 
    77   }
    78 }
  • HeuristicLab.Optimization/3.3/Results/IResult.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using HeuristicLab.Core;
     24
     25namespace HeuristicLab.Optimization {
     26  /// <summary>
     27  /// Represents a result which has a name and a data type and holds an IItem.
     28  /// </summary>
     29  public interface IResult : INamedItem {
     30    Type DataType { get; }
     31    IItem Value { get; set; }
     32
     33    /// <inheritdoc/>
     34    event EventHandler ValueChanged;
     35  }
     36}
  • HeuristicLab.Optimization/3.3/Results/IResultParameter.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using HeuristicLab.Core;
     24
     25namespace HeuristicLab.Optimization {
     26  public interface IResultParameter : ILookupParameter {
     27    string ResultName { get; set; }
     28    event EventHandler ResultNameChanged;
     29  }
     30
     31  public interface IResultParameter<T> : ILookupParameter<ResultCollection>, IResultParameter where T : class, IItem, new() {
     32    T DefaultValue { get; set; }
     33    T ResultValue { get; set; }
     34  }
     35}
  • HeuristicLab.Optimization/3.3/Results/Result.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using System.Drawing;
     24using HeuristicLab.Common;
     25using HeuristicLab.Core;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27
     28namespace HeuristicLab.Optimization {
     29  /// <summary>
     30  /// Represents a result which has a name and a data type and holds an IItem.
     31  /// </summary>
     32  [Item("Result", "A result which has a name and a data type and holds an IItem.")]
     33  [StorableClass]
     34  public sealed class Result : NamedItem, IResult, IStorableContent {
     35    public string Filename { get; set; }
     36
     37    public override Image ItemImage {
     38      get {
     39        if (value != null) return value.ItemImage;
     40        else return base.ItemImage;
     41      }
     42    }
     43
     44    public override bool CanChangeName {
     45      get { return false; }
     46    }
     47    public override bool CanChangeDescription {
     48      get { return false; }
     49    }
     50
     51    [Storable]
     52    private Type dataType;
     53    public Type DataType {
     54      get { return dataType; }
     55    }
     56
     57    [Storable]
     58    private IItem value;
     59    public IItem Value {
     60      get { return value; }
     61      set {
     62        if (this.value != value) {
     63          if ((value != null) && (!dataType.IsInstanceOfType(value)))
     64            throw new ArgumentException(
     65              string.Format("Type mismatch. Value is not a \"{0}\".",
     66                            dataType.GetPrettyName())
     67            );
     68
     69          DeregisterValueEvents();
     70          this.value = value;
     71          RegisterValueEvents();
     72          OnValueChanged();
     73        }
     74      }
     75    }
     76
     77    [StorableConstructor]
     78    private Result(bool deserializing) : base(deserializing) { }
     79    private Result(Result original, Cloner cloner)
     80      : base(original, cloner) {
     81      dataType = original.dataType;
     82      value = cloner.Clone(original.value);
     83      Initialize();
     84    }
     85    public Result()
     86      : base("Anonymous") {
     87      this.dataType = typeof(IItem);
     88      this.value = null;
     89    }
     90    public Result(string name, Type dataType)
     91      : base(name) {
     92      this.dataType = dataType;
     93      this.value = null;
     94    }
     95    public Result(string name, string description, Type dataType)
     96      : base(name, description) {
     97      this.dataType = dataType;
     98      this.value = null;
     99    }
     100    public Result(string name, IItem value)
     101      : base(name) {
     102      this.dataType = value == null ? typeof(IItem) : value.GetType();
     103      this.value = value;
     104      Initialize();
     105    }
     106    public Result(string name, string description, IItem value)
     107      : base(name, description) {
     108      this.dataType = value == null ? typeof(IItem) : value.GetType();
     109      this.value = value;
     110      Initialize();
     111    }
     112
     113    [StorableHook(HookType.AfterDeserialization)]
     114    private void AfterDeserialization() {
     115      Initialize();
     116    }
     117
     118    public override IDeepCloneable Clone(Cloner cloner) {
     119      return new Result(this, cloner);
     120    }
     121
     122    private void Initialize() {
     123      RegisterValueEvents();
     124    }
     125
     126    public override string ToString() {
     127      return string.Format("{0}: {1}", Name, Value == null ? "null" : Value.ToString());
     128    }
     129
     130    public event EventHandler ValueChanged;
     131    private void OnValueChanged() {
     132      var handler = ValueChanged;
     133      if (handler != null) handler(this, EventArgs.Empty);
     134      OnItemImageChanged();
     135      OnToStringChanged();
     136    }
     137
     138    private void RegisterValueEvents() {
     139      if (value != null) {
     140        value.ItemImageChanged += new EventHandler(Value_ItemImageChanged);
     141        value.ToStringChanged += new EventHandler(Value_ToStringChanged);
     142      }
     143    }
     144    private void DeregisterValueEvents() {
     145      if (value != null) {
     146        value.ItemImageChanged -= new EventHandler(Value_ItemImageChanged);
     147        value.ToStringChanged -= new EventHandler(Value_ToStringChanged);
     148      }
     149    }
     150    private void Value_ItemImageChanged(object sender, EventArgs e) {
     151      OnItemImageChanged();
     152    }
     153    private void Value_ToStringChanged(object sender, EventArgs e) {
     154      OnToStringChanged();
     155    }
     156  }
     157}
  • HeuristicLab.Optimization/3.3/Results/ResultCollection.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Collections.Generic;
     23using HeuristicLab.Common;
     24using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26
     27namespace HeuristicLab.Optimization {
     28  [StorableClass]
     29  [Item("ResultCollection", "Represents a collection of results.")]
     30  public class ResultCollection : NamedItemCollection<IResult> {
     31    public ResultCollection() : base() { }
     32    public ResultCollection(int capacity) : base(capacity) { }
     33    public ResultCollection(IEnumerable<IResult> collection) : base(collection) { }
     34    [StorableConstructor]
     35    protected ResultCollection(bool deserializing) : base(deserializing) { }
     36    protected ResultCollection(ResultCollection original, Cloner cloner)
     37      : base(original, cloner) {
     38    }
     39    public override IDeepCloneable Clone(Cloner cloner) {
     40      return new ResultCollection(this, cloner);
     41    }
     42
     43    public static new System.Drawing.Image StaticItemImage {
     44      get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
     45    }
     46
     47    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
     48      CollectResultValues(values, string.Empty);
     49    }
     50
     51    public virtual void CollectResultValues(IDictionary<string, IItem> values, string rootPath) {
     52      foreach (IResult result in this) {
     53        var children = GetCollectedResults(result);
     54        string path = string.Empty;
     55        if (!string.IsNullOrWhiteSpace(rootPath))
     56          path = rootPath + ".";
     57        foreach (var c in children) {
     58          if (string.IsNullOrEmpty(c.Key))
     59            values.Add(path + result.Name, c.Value);
     60          else values.Add(path + result.Name + "." + c.Key, c.Value);
     61        }
     62      }
     63    }
     64
     65    protected virtual IEnumerable<KeyValuePair<string, IItem>> GetCollectedResults(IResult result) {
     66      if (result.Value == null) yield break;
     67      yield return new KeyValuePair<string, IItem>(string.Empty, result.Value);
     68
     69      var resultCollection = result.Value as ResultCollection;
     70      if (resultCollection != null) {
     71        var children = new Dictionary<string, IItem>();
     72        resultCollection.CollectResultValues(children);
     73        foreach (var child in children) yield return child;
     74      }
     75    }
     76
     77  }
     78}
  • HeuristicLab.Optimization/3.3/Results/ResultParameter.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using HeuristicLab.Common;
     24using HeuristicLab.Core;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27
     28namespace HeuristicLab.Optimization {
     29  [Item("ResultParameter", "A parameter whose value is written to a result collection.")]
     30  [StorableClass]
     31  public sealed class ResultParameter<T> : LookupParameter<ResultCollection>, IResultParameter<T> where T : class, IItem, new() {
     32
     33    [Storable]
     34    private string resultName;
     35    public string ResultName {
     36      get { return resultName; }
     37      set {
     38        if (value == null) throw new ArgumentNullException();
     39        if (string.IsNullOrWhiteSpace(value)) {
     40          resultName = Name;
     41          OnResultNameChanged();
     42        } else if (!resultName.Equals(value)) {
     43          resultName = value;
     44          OnResultNameChanged();
     45        }
     46      }
     47    }
     48
     49    [Storable]
     50    private T defaultValue;
     51    public T DefaultValue {
     52      get { return defaultValue; }
     53      set {
     54        if (value != defaultValue) {
     55          defaultValue = value;
     56          OnDefaultValueChanged();
     57        }
     58      }
     59    }
     60
     61    public T ResultValue {
     62      get { return GetResultValue(); }
     63      set { SetResultValue(value); }
     64    }
     65
     66    [StorableConstructor]
     67    private ResultParameter(bool deserializing) : base(deserializing) { }
     68    private ResultParameter(ResultParameter<T> original, Cloner cloner)
     69      : base(original, cloner) {
     70      resultName = original.resultName;
     71      defaultValue = cloner.Clone(original.defaultValue);
     72    }
     73    public override IDeepCloneable Clone(Cloner cloner) {
     74      return new ResultParameter<T>(this, cloner);
     75    }
     76    public ResultParameter() : this("Anonymous") { }
     77    public ResultParameter(string name)
     78      : base(name, string.Empty, "Results") {
     79      resultName = Name;
     80      defaultValue = new T();
     81    }
     82    public ResultParameter(string name, string description) : this(name, description, new T()) { }
     83    public ResultParameter(string name, string description, T defaultValue)
     84      : base(name, description, "Results") {
     85      if (defaultValue == null) throw new ArgumentNullException("defaultValue");
     86      resultName = Name;
     87      this.defaultValue = defaultValue;
     88    }
     89    public ResultParameter(string name, string description, string resultName) : this(name, description, new T(), resultName) { }
     90    public ResultParameter(string name, string description, T defaultValue, string resultName)
     91      : base(name, description, "Results") {
     92      if (defaultValue == null) throw new ArgumentNullException("defaultValue");
     93      this.resultName = string.IsNullOrWhiteSpace(resultName) ? Name : resultName;
     94      this.defaultValue = defaultValue;
     95    }
     96
     97    public override string ToString() {
     98      if (Name.Equals(ResultName)) return Name;
     99      return Name + ": " + ResultName;
     100    }
     101
     102    private T GetResultValue() {
     103      var results = ActualValue;
     104      if (results == null)
     105        throw new InvalidOperationException("ResultParameter (" + ResultName + "): ResultCollection " + ActualName + " not found.");
     106
     107      if (!results.ContainsKey(ResultName)) results.Add(new Result(ResultName, (T)DefaultValue.Clone()));
     108      var resultValue = results[ResultName].Value as T;
     109      if (resultValue == null)
     110        throw new InvalidOperationException(string.Format("Type mismatch. Result \"{0}\" does not contain a \"{1}\".", ResultName, typeof(T).GetPrettyName()));
     111
     112      return resultValue;
     113    }
     114
     115    private void SetResultValue(T value) {
     116      var results = ActualValue;
     117      if (results == null)
     118        throw new InvalidOperationException("ResultParameter (" + ResultName + "): ResultCollection " + ActualName + " not found.");
     119
     120      if (!results.ContainsKey(ResultName))
     121        results.Add(new Result(ResultName, value));
     122      else results[ResultName].Value = value;
     123    }
     124
     125    public event EventHandler ResultNameChanged;
     126    private void OnResultNameChanged() {
     127      var handler = ResultNameChanged;
     128      if (handler != null) handler(this, EventArgs.Empty);
     129      OnToStringChanged();
     130    }
     131
     132    public event EventHandler DefaultValueChanged;
     133    private void OnDefaultValueChanged() {
     134      EventHandler handler = DefaultValueChanged;
     135      if (handler != null) handler(this, EventArgs.Empty);
     136      OnItemImageChanged();
     137    }
     138  }
     139}
  • HeuristicLab.Optimization/3.3/Results/IResult.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using HeuristicLab.Core;
     24
     25namespace HeuristicLab.Optimization {
     26  /// <summary>
     27  /// Represents a result which has a name and a data type and holds an IItem.
     28  /// </summary>
     29  public interface IResult : INamedItem {
     30    Type DataType { get; }
     31    IItem Value { get; set; }
     32
     33    /// <inheritdoc/>
     34    event EventHandler ValueChanged;
     35  }
     36}
  • HeuristicLab.Optimization/3.3/Results/IResultParameter.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using HeuristicLab.Core;
     24
     25namespace HeuristicLab.Optimization {
     26  public interface IResultParameter : ILookupParameter {
     27    string ResultName { get; set; }
     28    event EventHandler ResultNameChanged;
     29  }
     30
     31  public interface IResultParameter<T> : ILookupParameter<ResultCollection>, IResultParameter where T : class, IItem, new() {
     32    T DefaultValue { get; set; }
     33    T ResultValue { get; set; }
     34  }
     35}
  • HeuristicLab.Optimization/3.3/Results/Result.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using System.Drawing;
     24using HeuristicLab.Common;
     25using HeuristicLab.Core;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27
     28namespace HeuristicLab.Optimization {
     29  /// <summary>
     30  /// Represents a result which has a name and a data type and holds an IItem.
     31  /// </summary>
     32  [Item("Result", "A result which has a name and a data type and holds an IItem.")]
     33  [StorableClass]
     34  public sealed class Result : NamedItem, IResult, IStorableContent {
     35    public string Filename { get; set; }
     36
     37    public override Image ItemImage {
     38      get {
     39        if (value != null) return value.ItemImage;
     40        else return base.ItemImage;
     41      }
     42    }
     43
     44    public override bool CanChangeName {
     45      get { return false; }
     46    }
     47    public override bool CanChangeDescription {
     48      get { return false; }
     49    }
     50
     51    [Storable]
     52    private Type dataType;
     53    public Type DataType {
     54      get { return dataType; }
     55    }
     56
     57    [Storable]
     58    private IItem value;
     59    public IItem Value {
     60      get { return value; }
     61      set {
     62        if (this.value != value) {
     63          if ((value != null) && (!dataType.IsInstanceOfType(value)))
     64            throw new ArgumentException(
     65              string.Format("Type mismatch. Value is not a \"{0}\".",
     66                            dataType.GetPrettyName())
     67            );
     68
     69          DeregisterValueEvents();
     70          this.value = value;
     71          RegisterValueEvents();
     72          OnValueChanged();
     73        }
     74      }
     75    }
     76
     77    [StorableConstructor]
     78    private Result(bool deserializing) : base(deserializing) { }
     79    private Result(Result original, Cloner cloner)
     80      : base(original, cloner) {
     81      dataType = original.dataType;
     82      value = cloner.Clone(original.value);
     83      Initialize();
     84    }
     85    public Result()
     86      : base("Anonymous") {
     87      this.dataType = typeof(IItem);
     88      this.value = null;
     89    }
     90    public Result(string name, Type dataType)
     91      : base(name) {
     92      this.dataType = dataType;
     93      this.value = null;
     94    }
     95    public Result(string name, string description, Type dataType)
     96      : base(name, description) {
     97      this.dataType = dataType;
     98      this.value = null;
     99    }
     100    public Result(string name, IItem value)
     101      : base(name) {
     102      this.dataType = value == null ? typeof(IItem) : value.GetType();
     103      this.value = value;
     104      Initialize();
     105    }
     106    public Result(string name, string description, IItem value)
     107      : base(name, description) {
     108      this.dataType = value == null ? typeof(IItem) : value.GetType();
     109      this.value = value;
     110      Initialize();
     111    }
     112
     113    [StorableHook(HookType.AfterDeserialization)]
     114    private void AfterDeserialization() {
     115      Initialize();
     116    }
     117
     118    public override IDeepCloneable Clone(Cloner cloner) {
     119      return new Result(this, cloner);
     120    }
     121
     122    private void Initialize() {
     123      RegisterValueEvents();
     124    }
     125
     126    public override string ToString() {
     127      return string.Format("{0}: {1}", Name, Value == null ? "null" : Value.ToString());
     128    }
     129
     130    public event EventHandler ValueChanged;
     131    private void OnValueChanged() {
     132      var handler = ValueChanged;
     133      if (handler != null) handler(this, EventArgs.Empty);
     134      OnItemImageChanged();
     135      OnToStringChanged();
     136    }
     137
     138    private void RegisterValueEvents() {
     139      if (value != null) {
     140        value.ItemImageChanged += new EventHandler(Value_ItemImageChanged);
     141        value.ToStringChanged += new EventHandler(Value_ToStringChanged);
     142      }
     143    }
     144    private void DeregisterValueEvents() {
     145      if (value != null) {
     146        value.ItemImageChanged -= new EventHandler(Value_ItemImageChanged);
     147        value.ToStringChanged -= new EventHandler(Value_ToStringChanged);
     148      }
     149    }
     150    private void Value_ItemImageChanged(object sender, EventArgs e) {
     151      OnItemImageChanged();
     152    }
     153    private void Value_ToStringChanged(object sender, EventArgs e) {
     154      OnToStringChanged();
     155    }
     156  }
     157}
  • HeuristicLab.Optimization/3.3/Results/ResultCollection.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Collections.Generic;
     23using HeuristicLab.Common;
     24using HeuristicLab.Core;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26
     27namespace HeuristicLab.Optimization {
     28  [StorableClass]
     29  [Item("ResultCollection", "Represents a collection of results.")]
     30  public class ResultCollection : NamedItemCollection<IResult> {
     31    public ResultCollection() : base() { }
     32    public ResultCollection(int capacity) : base(capacity) { }
     33    public ResultCollection(IEnumerable<IResult> collection) : base(collection) { }
     34    [StorableConstructor]
     35    protected ResultCollection(bool deserializing) : base(deserializing) { }
     36    protected ResultCollection(ResultCollection original, Cloner cloner)
     37      : base(original, cloner) {
     38    }
     39    public override IDeepCloneable Clone(Cloner cloner) {
     40      return new ResultCollection(this, cloner);
     41    }
     42
     43    public static new System.Drawing.Image StaticItemImage {
     44      get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
     45    }
     46
     47    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
     48      CollectResultValues(values, string.Empty);
     49    }
     50
     51    public virtual void CollectResultValues(IDictionary<string, IItem> values, string rootPath) {
     52      foreach (IResult result in this) {
     53        var children = GetCollectedResults(result);
     54        string path = string.Empty;
     55        if (!string.IsNullOrWhiteSpace(rootPath))
     56          path = rootPath + ".";
     57        foreach (var c in children) {
     58          if (string.IsNullOrEmpty(c.Key))
     59            values.Add(path + result.Name, c.Value);
     60          else values.Add(path + result.Name + "." + c.Key, c.Value);
     61        }
     62      }
     63    }
     64
     65    protected virtual IEnumerable<KeyValuePair<string, IItem>> GetCollectedResults(IResult result) {
     66      if (result.Value == null) yield break;
     67      yield return new KeyValuePair<string, IItem>(string.Empty, result.Value);
     68
     69      var resultCollection = result.Value as ResultCollection;
     70      if (resultCollection != null) {
     71        var children = new Dictionary<string, IItem>();
     72        resultCollection.CollectResultValues(children);
     73        foreach (var child in children) yield return child;
     74      }
     75    }
     76
     77  }
     78}
  • HeuristicLab.Optimization/3.3/Results/ResultParameter.cs

     
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
     23using HeuristicLab.Common;
     24using HeuristicLab.Core;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27
     28namespace HeuristicLab.Optimization {
     29  [Item("ResultParameter", "A parameter whose value is written to a result collection.")]
     30  [StorableClass]
     31  public sealed class ResultParameter<T> : LookupParameter<ResultCollection>, IResultParameter<T> where T : class, IItem, new() {
     32
     33    [Storable]
     34    private string resultName;
     35    public string ResultName {
     36      get { return resultName; }
     37      set {
     38        if (value == null) throw new ArgumentNullException();
     39        if (string.IsNullOrWhiteSpace(value)) {
     40          resultName = Name;
     41          OnResultNameChanged();
     42        } else if (!resultName.Equals(value)) {
     43          resultName = value;
     44          OnResultNameChanged();
     45        }
     46      }
     47    }
     48
     49    [Storable]
     50    private T defaultValue;
     51    public T DefaultValue {
     52      get { return defaultValue; }
     53      set {
     54        if (value != defaultValue) {
     55          defaultValue = value;
     56          OnDefaultValueChanged();
     57        }
     58      }
     59    }
     60
     61    public T ResultValue {
     62      get { return GetResultValue(); }
     63      set { SetResultValue(value); }
     64    }
     65
     66    [StorableConstructor]
     67    private ResultParameter(bool deserializing) : base(deserializing) { }
     68    private ResultParameter(ResultParameter<T> original, Cloner cloner)
     69      : base(original, cloner) {
     70      resultName = original.resultName;
     71      defaultValue = cloner.Clone(original.defaultValue);
     72    }
     73    public override IDeepCloneable Clone(Cloner cloner) {
     74      return new ResultParameter<T>(this, cloner);
     75    }
     76    public ResultParameter() : this("Anonymous") { }
     77    public ResultParameter(string name)
     78      : base(name, string.Empty, "Results") {
     79      resultName = Name;
     80      defaultValue = new T();
     81    }
     82    public ResultParameter(string name, string description) : this(name, description, new T()) { }
     83    public ResultParameter(string name, string description, T defaultValue)
     84      : base(name, description, "Results") {
     85      if (defaultValue == null) throw new ArgumentNullException("defaultValue");
     86      resultName = Name;
     87      this.defaultValue = defaultValue;
     88    }
     89    public ResultParameter(string name, string description, string resultName) : this(name, description, new T(), resultName) { }
     90    public ResultParameter(string name, string description, T defaultValue, string resultName)
     91      : base(name, description, "Results") {
     92      if (defaultValue == null) throw new ArgumentNullException("defaultValue");
     93      this.resultName = string.IsNullOrWhiteSpace(resultName) ? Name : resultName;
     94      this.defaultValue = defaultValue;
     95    }
     96
     97    public override string ToString() {
     98      if (Name.Equals(ResultName)) return Name;
     99      return Name + ": " + ResultName;
     100    }
     101
     102    private T GetResultValue() {
     103      var results = ActualValue;
     104      if (results == null)
     105        throw new InvalidOperationException("ResultParameter (" + ResultName + "): ResultCollection " + ActualName + " not found.");
     106
     107      if (!results.ContainsKey(ResultName)) results.Add(new Result(ResultName, (T)DefaultValue.Clone()));
     108      var resultValue = results[ResultName].Value as T;
     109      if (resultValue == null)
     110        throw new InvalidOperationException(string.Format("Type mismatch. Result \"{0}\" does not contain a \"{1}\".", ResultName, typeof(T).GetPrettyName()));
     111
     112      return resultValue;
     113    }
     114
     115    private void SetResultValue(T value) {
     116      var results = ActualValue;
     117      if (results == null)
     118        throw new InvalidOperationException("ResultParameter (" + ResultName + "): ResultCollection " + ActualName + " not found.");
     119
     120      if (!results.ContainsKey(ResultName))
     121        results.Add(new Result(ResultName, value));
     122      else results[ResultName].Value = value;
     123    }
     124
     125    public event EventHandler ResultNameChanged;
     126    private void OnResultNameChanged() {
     127      var handler = ResultNameChanged;
     128      if (handler != null) handler(this, EventArgs.Empty);
     129      OnToStringChanged();
     130    }
     131
     132    public event EventHandler DefaultValueChanged;
     133    private void OnDefaultValueChanged() {
     134      EventHandler handler = DefaultValueChanged;
     135      if (handler != null) handler(this, EventArgs.Empty);
     136      OnItemImageChanged();
     137    }
     138  }
     139}
  • HeuristicLab.Parameters.Views/3.3/HeuristicLab.Parameters.Views-3.3.csproj

     
    216216      <Name>HeuristicLab.MainForm-3.3</Name>
    217217      <Private>False</Private>
    218218    </ProjectReference>
    219     <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj">
    220       <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project>
    221       <Name>HeuristicLab.Optimization.Views-3.3</Name>
    222       <Private>False</Private>
    223     </ProjectReference>
    224     <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    225       <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
    226       <Name>HeuristicLab.Optimization-3.3</Name>
    227       <Private>False</Private>
    228     </ProjectReference>
    229219    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
    230220      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
    231221      <Name>HeuristicLab.Parameters-3.3</Name>