[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;
|
---|
[4068] | 24 | using System.Drawing;
|
---|
[3376] | 25 | using HeuristicLab.Common;
|
---|
[3260] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 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 {
|
---|
[4156] | 36 | [StorableConstructor]
|
---|
| 37 | private Run(bool deserializing) : base(deserializing) { }
|
---|
[3260] | 38 | public Run()
|
---|
[3280] | 39 | : base() {
|
---|
| 40 | name = ItemName;
|
---|
| 41 | description = ItemDescription;
|
---|
[4156] | 42 | color = Color.Black;
|
---|
[3280] | 43 | algorithm = null;
|
---|
[3260] | 44 | parameters = new Dictionary<string, IItem>();
|
---|
| 45 | results = new Dictionary<string, IItem>();
|
---|
| 46 | }
|
---|
[3280] | 47 | public Run(IAlgorithm algorithm)
|
---|
| 48 | : base() {
|
---|
| 49 | if (algorithm == null) throw new ArgumentNullException();
|
---|
| 50 | name = algorithm.Name + " Run (" + algorithm.ExecutionTime.ToString() + ")";
|
---|
| 51 | description = ItemDescription;
|
---|
[4156] | 52 | color = Color.Black;
|
---|
[4102] | 53 | Initialize(algorithm);
|
---|
[3280] | 54 | }
|
---|
| 55 | public Run(string name, IAlgorithm algorithm)
|
---|
[3260] | 56 | : base(name) {
|
---|
[3280] | 57 | if (algorithm == null) throw new ArgumentNullException();
|
---|
[4156] | 58 | color = Color.Black;
|
---|
[3280] | 59 | description = ItemDescription;
|
---|
[4102] | 60 | Initialize(algorithm);
|
---|
[3260] | 61 | }
|
---|
[3280] | 62 | public Run(string name, string description, IAlgorithm algorithm)
|
---|
[3260] | 63 | : base(name, description) {
|
---|
[3280] | 64 | if (algorithm == null) throw new ArgumentNullException();
|
---|
[4156] | 65 | color = Color.Black;
|
---|
[4102] | 66 | Initialize(algorithm);
|
---|
[3280] | 67 | }
|
---|
| 68 |
|
---|
| 69 | private void Initialize(IAlgorithm algorithm) {
|
---|
[4102] | 70 | IAlgorithm clone = (IAlgorithm)algorithm.Clone();
|
---|
[3260] | 71 | parameters = new Dictionary<string, IItem>();
|
---|
| 72 | results = new Dictionary<string, IItem>();
|
---|
[4102] | 73 | clone.CollectParameterValues(parameters);
|
---|
| 74 | clone.CollectResultValues(results);
|
---|
| 75 | if (clone.StoreAlgorithmInEachRun) {
|
---|
| 76 | clone.Prepare(true);
|
---|
| 77 | this.algorithm = clone;
|
---|
| 78 | }
|
---|
[3260] | 79 | }
|
---|
[4156] | 80 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 81 | private void AfterDeserializationHook() {
|
---|
| 82 | if (color == Color.Empty) color = Color.Black;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[4200] | 85 | [Storable]
|
---|
| 86 | private IAlgorithm algorithm;
|
---|
| 87 | public IAlgorithm Algorithm {
|
---|
| 88 | get { return algorithm; }
|
---|
| 89 | }
|
---|
| 90 | [Storable]
|
---|
| 91 | private Dictionary<string, IItem> parameters;
|
---|
| 92 | public IDictionary<string, IItem> Parameters {
|
---|
| 93 | get { return parameters; }
|
---|
| 94 | }
|
---|
| 95 | [Storable]
|
---|
| 96 | private Dictionary<string, IItem> results;
|
---|
| 97 | public IDictionary<string, IItem> Results {
|
---|
| 98 | get { return results; }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | [Storable]
|
---|
| 102 | private Color color;
|
---|
| 103 | public Color Color {
|
---|
| 104 | get { return this.color; }
|
---|
| 105 | set {
|
---|
| 106 | if (color != value) {
|
---|
| 107 | this.color = value;
|
---|
| 108 | this.OnChanged();
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | private bool visible = true;
|
---|
| 113 | public bool Visible {
|
---|
| 114 | get { return this.visible; }
|
---|
| 115 | set {
|
---|
| 116 | if (visible != value) {
|
---|
| 117 | this.visible = value;
|
---|
| 118 | this.OnChanged();
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | public event EventHandler Changed;
|
---|
| 123 | private void OnChanged() {
|
---|
| 124 | EventHandler handler = Changed;
|
---|
| 125 | if (handler != null)
|
---|
| 126 | handler(this, EventArgs.Empty);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[3260] | 129 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[3280] | 130 | Run clone = (Run)base.Clone(cloner);
|
---|
[4161] | 131 | clone.color = this.color;
|
---|
[3280] | 132 | clone.algorithm = (IAlgorithm)cloner.Clone(algorithm);
|
---|
[3260] | 133 | foreach (string key in parameters.Keys)
|
---|
| 134 | clone.parameters.Add(key, (IItem)cloner.Clone(parameters[key]));
|
---|
| 135 | foreach (string key in results.Keys)
|
---|
| 136 | clone.results.Add(key, (IItem)cloner.Clone(results[key]));
|
---|
| 137 | return clone;
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|