[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;
|
---|
[3376] | 24 | using HeuristicLab.Common;
|
---|
[3260] | 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[3428] | 27 | using System.Drawing;
|
---|
[3260] | 28 |
|
---|
| 29 | namespace HeuristicLab.Optimization {
|
---|
| 30 | /// <summary>
|
---|
| 31 | /// Represents the parameters and results of an algorithm run.
|
---|
| 32 | /// </summary>
|
---|
| 33 | [Item("Run", "The parameters and results of an algorithm run.")]
|
---|
| 34 | [StorableClass]
|
---|
[3280] | 35 | public sealed class Run : NamedItem, IRun {
|
---|
| 36 | [Storable]
|
---|
| 37 | private IAlgorithm algorithm;
|
---|
| 38 | public IAlgorithm Algorithm {
|
---|
| 39 | get { return algorithm; }
|
---|
[3260] | 40 | }
|
---|
| 41 | [Storable]
|
---|
| 42 | private Dictionary<string, IItem> parameters;
|
---|
| 43 | public IDictionary<string, IItem> Parameters {
|
---|
| 44 | get { return parameters; }
|
---|
| 45 | }
|
---|
| 46 | [Storable]
|
---|
| 47 | private Dictionary<string, IItem> results;
|
---|
| 48 | public IDictionary<string, IItem> Results {
|
---|
| 49 | get { return results; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[3428] | 52 | private Color color = Color.Black;
|
---|
| 53 | public Color Color {
|
---|
| 54 | get { return this.color; }
|
---|
| 55 | set {
|
---|
| 56 | if (color != value) {
|
---|
| 57 | this.color = value;
|
---|
| 58 | this.OnChanged();
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | private bool visible = true;
|
---|
| 63 | public bool Visible {
|
---|
| 64 | get { return this.visible; }
|
---|
| 65 | set {
|
---|
| 66 | if (visible != value) {
|
---|
| 67 | this.visible = value;
|
---|
| 68 | this.OnChanged();
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | public event EventHandler Changed;
|
---|
| 73 | private void OnChanged() {
|
---|
| 74 | EventHandler handler = Changed;
|
---|
| 75 | if (handler != null)
|
---|
| 76 | handler(this, EventArgs.Empty);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[3260] | 79 | public Run()
|
---|
[3280] | 80 | : base() {
|
---|
| 81 | name = ItemName;
|
---|
| 82 | description = ItemDescription;
|
---|
| 83 | algorithm = null;
|
---|
[3260] | 84 | parameters = new Dictionary<string, IItem>();
|
---|
| 85 | results = new Dictionary<string, IItem>();
|
---|
| 86 | }
|
---|
[3280] | 87 | public Run(IAlgorithm algorithm)
|
---|
| 88 | : base() {
|
---|
| 89 | if (algorithm == null) throw new ArgumentNullException();
|
---|
| 90 | name = algorithm.Name + " Run (" + algorithm.ExecutionTime.ToString() + ")";
|
---|
| 91 | description = ItemDescription;
|
---|
| 92 | Initialize((IAlgorithm)algorithm.Clone());
|
---|
| 93 | }
|
---|
| 94 | public Run(string name, IAlgorithm algorithm)
|
---|
[3260] | 95 | : base(name) {
|
---|
[3280] | 96 | if (algorithm == null) throw new ArgumentNullException();
|
---|
| 97 | description = ItemDescription;
|
---|
| 98 | Initialize((IAlgorithm)algorithm.Clone());
|
---|
[3260] | 99 | }
|
---|
[3280] | 100 | public Run(string name, string description, IAlgorithm algorithm)
|
---|
[3260] | 101 | : base(name, description) {
|
---|
[3280] | 102 | if (algorithm == null) throw new ArgumentNullException();
|
---|
| 103 | Initialize((IAlgorithm)algorithm.Clone());
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | private void Initialize(IAlgorithm algorithm) {
|
---|
| 107 | this.algorithm = algorithm;
|
---|
[3300] | 108 | this.algorithm.Runs.Clear();
|
---|
[3260] | 109 | parameters = new Dictionary<string, IItem>();
|
---|
| 110 | results = new Dictionary<string, IItem>();
|
---|
[3280] | 111 | this.algorithm.CollectParameterValues(parameters);
|
---|
| 112 | this.algorithm.CollectResultValues(results);
|
---|
[3260] | 113 | }
|
---|
| 114 |
|
---|
| 115 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[3280] | 116 | Run clone = (Run)base.Clone(cloner);
|
---|
| 117 | clone.algorithm = (IAlgorithm)cloner.Clone(algorithm);
|
---|
[3260] | 118 | foreach (string key in parameters.Keys)
|
---|
| 119 | clone.parameters.Add(key, (IItem)cloner.Clone(parameters[key]));
|
---|
| 120 | foreach (string key in results.Keys)
|
---|
| 121 | clone.results.Add(key, (IItem)cloner.Clone(results[key]));
|
---|
| 122 | return clone;
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|