#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 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 {
[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; }
}
public Run()
: base() {
name = ItemName;
description = ItemDescription;
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;
Initialize((IAlgorithm)algorithm.Clone());
}
public Run(string name, IAlgorithm algorithm)
: base(name) {
if (algorithm == null) throw new ArgumentNullException();
description = ItemDescription;
Initialize((IAlgorithm)algorithm.Clone());
}
public Run(string name, string description, IAlgorithm algorithm)
: base(name, description) {
if (algorithm == null) throw new ArgumentNullException();
Initialize((IAlgorithm)algorithm.Clone());
}
private void Initialize(IAlgorithm algorithm) {
this.algorithm = algorithm;
this.algorithm.Runs.Clear();
parameters = new Dictionary();
results = new Dictionary();
this.algorithm.CollectParameterValues(parameters);
this.algorithm.CollectResultValues(results);
}
public override IDeepCloneable Clone(Cloner cloner) {
Run clone = (Run)base.Clone(cloner);
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;
}
}
}