Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization/3.3/Run.cs @ 3300

Last change on this file since 3300 was 3300, checked in by swagner, 12 years ago

Continued work on algorithm batch processing (#947).

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Collections.Generic;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.Optimization {
28  /// <summary>
29  /// Represents the parameters and results of an algorithm run.
30  /// </summary>
31  [Item("Run", "The parameters and results of an algorithm run.")]
32  [StorableClass]
33  public sealed class Run : NamedItem, IRun {
34    [Storable]
35    private IAlgorithm algorithm;
36    public IAlgorithm Algorithm {
37      get { return algorithm; }
38    }
39    [Storable]
40    private Dictionary<string, IItem> parameters;
41    public IDictionary<string, IItem> Parameters {
42      get { return parameters; }
43    }
44    [Storable]
45    private Dictionary<string, IItem> results;
46    public IDictionary<string, IItem> Results {
47      get { return results; }
48    }
49
50    public Run()
51      : base() {
52      name = ItemName;
53      description = ItemDescription;
54      algorithm = null;
55      parameters = new Dictionary<string, IItem>();
56      results = new Dictionary<string, IItem>();
57    }
58    public Run(IAlgorithm algorithm)
59      : base() {
60      if (algorithm == null) throw new ArgumentNullException();
61      name = algorithm.Name + " Run (" + algorithm.ExecutionTime.ToString() + ")";
62      description = ItemDescription;
63      Initialize((IAlgorithm)algorithm.Clone());
64    }
65    public Run(string name, IAlgorithm algorithm)
66      : base(name) {
67      if (algorithm == null) throw new ArgumentNullException();
68      description = ItemDescription;
69      Initialize((IAlgorithm)algorithm.Clone());
70    }
71    public Run(string name, string description, IAlgorithm algorithm)
72      : base(name, description) {
73      if (algorithm == null) throw new ArgumentNullException();
74      Initialize((IAlgorithm)algorithm.Clone());
75    }
76
77    private void Initialize(IAlgorithm algorithm) {
78      this.algorithm = algorithm;
79      this.algorithm.Runs.Clear();
80      parameters = new Dictionary<string, IItem>();
81      results = new Dictionary<string, IItem>();
82      this.algorithm.CollectParameterValues(parameters);
83      this.algorithm.CollectResultValues(results);
84    }
85
86    public override IDeepCloneable Clone(Cloner cloner) {
87      Run clone = (Run)base.Clone(cloner);
88      clone.algorithm = (IAlgorithm)cloner.Clone(algorithm);
89      foreach (string key in parameters.Keys)
90        clone.parameters.Add(key, (IItem)cloner.Clone(parameters[key]));
91      foreach (string key in results.Keys)
92        clone.results.Add(key, (IItem)cloner.Clone(results[key]));
93      return clone;
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.