Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/07/10 05:22:33 (14 years ago)
Author:
swagner
Message:

Continued work on algorithm batch processing (#947).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/Run.cs

    r3275 r3280  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Core;
     
    3031  [Item("Run", "The parameters and results of an algorithm run.")]
    3132  [StorableClass]
    32   public sealed class Run : NamedItem {
    33     public override bool CanChangeName {
    34       get { return false; }
     33  public sealed class Run : NamedItem, IRun {
     34    [Storable]
     35    private IAlgorithm algorithm;
     36    public IAlgorithm Algorithm {
     37      get { return algorithm; }
    3538    }
    36     public override bool CanChangeDescription {
    37       get { return false; }
    38     }
    39 
    4039    [Storable]
    4140    private Dictionary<string, IItem> parameters;
     
    5049
    5150    public Run()
    52       : base("Anonymous") {
     51      : base() {
     52      name = ItemName;
     53      description = ItemDescription;
     54      algorithm = null;
    5355      parameters = new Dictionary<string, IItem>();
    5456      results = new Dictionary<string, IItem>();
    5557    }
    56     public Run(string name)
     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)
    5766      : base(name) {
     67      if (algorithm == null) throw new ArgumentNullException();
     68      description = ItemDescription;
     69      Initialize((IAlgorithm)algorithm.Clone());
     70    }
     71    public Run(string name, string description, IAlgorithm algorithm)
     72      : base(name, description) {
     73      if (algorithm == null) throw new ArgumentNullException();
     74      Initialize((IAlgorithm)algorithm.Clone());
     75    }
     76
     77    private void Initialize(IAlgorithm algorithm) {
     78      this.algorithm = algorithm;
    5879      parameters = new Dictionary<string, IItem>();
    5980      results = new Dictionary<string, IItem>();
    60     }
    61     public Run(string name, string description)
    62       : base(name, description) {
    63       parameters = new Dictionary<string, IItem>();
    64       results = new Dictionary<string, IItem>();
     81      this.algorithm.CollectParameterValues(parameters);
     82      this.algorithm.CollectResultValues(results);
    6583    }
    6684
    6785    public override IDeepCloneable Clone(Cloner cloner) {
    68       Run clone = new Run(Name, Description);
    69       cloner.RegisterClonedObject(this, clone);
     86      Run clone = (Run)base.Clone(cloner);
     87      clone.algorithm = (IAlgorithm)cloner.Clone(algorithm);
    7088      foreach (string key in parameters.Keys)
    7189        clone.parameters.Add(key, (IItem)cloner.Clone(parameters[key]));
Note: See TracChangeset for help on using the changeset viewer.