#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Drawing; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Optimization { /// /// Represents the parameters and results of an algorithm run. /// [Item("Run", "The parameters and results of an algorithm run.")] [StorableClass] public sealed class Run : NamedItem, IRun, IStorableContent { public string Filename { get; set; } [StorableConstructor] private Run(bool deserializing) : base(deserializing) { } public Run() : base() { name = ItemName; description = ItemDescription; color = Color.Black; algorithm = null; parameters = new Dictionary(); results = new Dictionary(); } public Run(IAlgorithm algorithm) : base() { if (algorithm == null) throw new ArgumentNullException(); name = algorithm.Name + " Run (" + algorithm.ExecutionTime.ToString() + ")"; description = ItemDescription; color = Color.Black; Initialize(algorithm); } public Run(string name, IAlgorithm algorithm) : base(name) { if (algorithm == null) throw new ArgumentNullException(); color = Color.Black; description = ItemDescription; Initialize(algorithm); } public Run(string name, string description, IAlgorithm algorithm) : base(name, description) { if (algorithm == null) throw new ArgumentNullException(); color = Color.Black; Initialize(algorithm); } private void Initialize(IAlgorithm algorithm) { IAlgorithm clone = (IAlgorithm)algorithm.Clone(); parameters = new Dictionary(); results = new Dictionary(); clone.CollectParameterValues(parameters); clone.CollectResultValues(results); if (clone.StoreAlgorithmInEachRun) { clone.Prepare(true); this.algorithm = clone; } } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserializationHook() { if (color == Color.Empty) color = Color.Black; } [Storable] private IAlgorithm algorithm; public IAlgorithm Algorithm { get { return algorithm; } } [Storable] private Dictionary parameters; public IDictionary Parameters { get { return parameters; } } [Storable] private Dictionary results; public IDictionary Results { get { return results; } } [Storable] private Color color; public Color Color { get { return this.color; } set { if (color != value) { this.color = value; this.OnChanged(); } } } private bool visible = true; public bool Visible { get { return this.visible; } set { if (visible != value) { this.visible = value; this.OnChanged(); } } } public event EventHandler Changed; private void OnChanged() { EventHandler handler = Changed; if (handler != null) handler(this, EventArgs.Empty); } public override IDeepCloneable Clone(Cloner cloner) { Run clone = (Run)base.Clone(cloner); clone.color = this.color; clone.algorithm = (IAlgorithm)cloner.Clone(algorithm); foreach (string key in parameters.Keys) clone.parameters.Add(key, (IItem)cloner.Clone(parameters[key])); foreach (string key in results.Keys) clone.results.Add(key, (IItem)cloner.Clone(results[key])); return clone; } } }