[3260] | 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 |
|
---|
[3280] | 22 | using System;
|
---|
[3260] | 23 | using System.Collections.Generic;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 26 |
|
---|
| 27 | namespace 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]
|
---|
[3280] | 33 | public sealed class Run : NamedItem, IRun {
|
---|
| 34 | [Storable]
|
---|
| 35 | private IAlgorithm algorithm;
|
---|
| 36 | public IAlgorithm Algorithm {
|
---|
| 37 | get { return algorithm; }
|
---|
[3260] | 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()
|
---|
[3280] | 51 | : base() {
|
---|
| 52 | name = ItemName;
|
---|
| 53 | description = ItemDescription;
|
---|
| 54 | algorithm = null;
|
---|
[3260] | 55 | parameters = new Dictionary<string, IItem>();
|
---|
| 56 | results = new Dictionary<string, IItem>();
|
---|
| 57 | }
|
---|
[3280] | 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)
|
---|
[3260] | 66 | : base(name) {
|
---|
[3280] | 67 | if (algorithm == null) throw new ArgumentNullException();
|
---|
| 68 | description = ItemDescription;
|
---|
| 69 | Initialize((IAlgorithm)algorithm.Clone());
|
---|
[3260] | 70 | }
|
---|
[3280] | 71 | public Run(string name, string description, IAlgorithm algorithm)
|
---|
[3260] | 72 | : base(name, description) {
|
---|
[3280] | 73 | if (algorithm == null) throw new ArgumentNullException();
|
---|
| 74 | Initialize((IAlgorithm)algorithm.Clone());
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | private void Initialize(IAlgorithm algorithm) {
|
---|
| 78 | this.algorithm = algorithm;
|
---|
[3300] | 79 | this.algorithm.Runs.Clear();
|
---|
[3260] | 80 | parameters = new Dictionary<string, IItem>();
|
---|
| 81 | results = new Dictionary<string, IItem>();
|
---|
[3280] | 82 | this.algorithm.CollectParameterValues(parameters);
|
---|
| 83 | this.algorithm.CollectResultValues(results);
|
---|
[3260] | 84 | }
|
---|
| 85 |
|
---|
| 86 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[3280] | 87 | Run clone = (Run)base.Clone(cloner);
|
---|
| 88 | clone.algorithm = (IAlgorithm)cloner.Clone(algorithm);
|
---|
[3260] | 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 | }
|
---|