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).

Location:
trunk/sources/HeuristicLab.Optimization/3.3
Files:
1 added
8 edited

Legend:

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

    r3275 r3280  
    6464    }
    6565
     66    [Storable]
    6667    private IProblem problem;
    67     [Storable]
    68     private IProblem ProblemPersistence {
    69       get { return problem; }
    70       set {
    71         if (problem != null) DeregisterProblemEvents();
    72         problem = value;
    73         if (problem != null) RegisterProblemEvents();
    74       }
    75     }
    7668    public IProblem Problem {
    7769      get { return problem; }
     
    9183
    9284    [Storable]
     85    protected int runsCounter;
     86
     87    [Storable]
    9388    private RunCollection runs;
    9489    public RunCollection Runs {
     
    10095      executionState = ExecutionState.Stopped;
    10196      executionTime = TimeSpan.Zero;
     97      runsCounter = 0;
    10298      runs = new RunCollection();
    10399    }
     
    106102      executionState = ExecutionState.Stopped;
    107103      executionTime = TimeSpan.Zero;
     104      runsCounter = 0;
    108105      runs = new RunCollection();
    109106    }
     
    112109      executionState = ExecutionState.Stopped;
    113110      executionTime = TimeSpan.Zero;
     111      runsCounter = 0;
    114112      runs = new RunCollection();
    115113    }
     
    118116      executionState = ExecutionState.Stopped;
    119117      executionTime = TimeSpan.Zero;
     118      runsCounter = 0;
    120119      runs = new RunCollection();
    121120    }
     
    124123      executionState = ExecutionState.Stopped;
    125124      executionTime = TimeSpan.Zero;
    126       runs = new RunCollection();
     125      runsCounter = 0;
     126      runs = new RunCollection();
     127    }
     128    internal Algorithm(Algorithm algorithm, Cloner cloner)
     129      : base(algorithm.Name, algorithm.Description, (ParameterCollection)cloner.Clone(algorithm.Parameters)) {
     130      executionState = algorithm.executionState;
     131      executionTime = algorithm.executionTime;
     132      problem = (IProblem)cloner.Clone(algorithm.problem);
     133      runsCounter = algorithm.runsCounter;
     134      runs = (RunCollection)cloner.Clone(algorithm.runs);
     135      Initialize();
     136    }
     137    [StorableConstructor]
     138    protected Algorithm(bool deserializing) : base(deserializing) { }
     139
     140    [StorableHook(HookType.AfterDeserialization)]
     141    private void Initialize() {
     142      if (problem != null) RegisterProblemEvents();
    127143    }
    128144
    129145    public override IDeepCloneable Clone(Cloner cloner) {
     146      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
    130147      Algorithm clone = (Algorithm)base.Clone(cloner);
    131148      clone.executionState = executionState;
    132149      clone.executionTime = executionTime;
    133       clone.Problem = (IProblem)cloner.Clone(problem);
     150      clone.problem = (IProblem)cloner.Clone(problem);
     151      clone.runsCounter = runsCounter;
    134152      clone.runs = (RunCollection)cloner.Clone(runs);
     153      clone.Initialize();
    135154      return clone;
    136155    }
     
    143162      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    144163        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    145       if (clearRuns) runs.Clear();
     164      if (clearRuns) {
     165        runsCounter = 0;
     166        runs.Clear();
     167      }
    146168      Prepare();
    147169    }
     
    165187    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
    166188      foreach (IResult result in Results)
    167         values.Add(result.Name, result.Value != null ? (IItem)result.Value.Clone() : null);
     189        values.Add(result.Name, result.Value);
    168190    }
    169191
     
    205227    public event EventHandler Stopped;
    206228    protected virtual void OnStopped() {
    207       Run run = new Run("Run (" + ExecutionTime.ToString() + ")");
    208       CollectParameterValues(run.Parameters);
    209       CollectResultValues(run.Results);
    210       runs.Add(run);
    211229      ExecutionState = ExecutionState.Stopped;
     230      runsCounter++;
     231      runs.Add(new Run(string.Format("{0} Run {1} ({2})", Name, runsCounter, ExecutionTime), this));
    212232      EventHandler handler = Stopped;
    213233      if (handler != null) handler(this, EventArgs.Empty);
  • trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs

    r3276 r3280  
    6666    }
    6767
     68    [Storable]
    6869    private IAlgorithm algorithm;
    69     [Storable]
    70     private IAlgorithm AlgorithmPersistence {
    71       get { return algorithm; }
    72       set {
    73         if (algorithm != null) DeregisterAlgorithmEvents();
    74         algorithm = value;
    75         if (algorithm != null) RegisterAlgorithmEvents();
    76       }
    77     }
    7870    public IAlgorithm Algorithm {
    7971      get { return algorithm; }
     
    113105    public BatchRun()
    114106      : base() {
     107      name = ItemName;
     108      description = ItemDescription;
    115109      executionState = ExecutionState.Stopped;
    116110      executionTime = TimeSpan.Zero;
     
    119113      stopPending = false;
    120114    }
    121     public BatchRun(string name) : base(name) {
     115    public BatchRun(string name)
     116      : base(name) {
     117      description = ItemDescription;
    122118      executionState = ExecutionState.Stopped;
    123119      executionTime = TimeSpan.Zero;
     
    126122      stopPending = false;
    127123    }
    128     public BatchRun(string name, string description) : base(name, description) {
     124    public BatchRun(string name, string description)
     125      : base(name, description) {
    129126      executionState = ExecutionState.Stopped;
    130127      executionTime = TimeSpan.Zero;
     
    133130      stopPending = false;
    134131    }
     132    [StorableConstructor]
     133    private BatchRun(bool deserializing)
     134      : base(deserializing) {
     135      stopPending = false;
     136    }
     137
     138    [StorableHook(HookType.AfterDeserialization)]
     139    private void Initialize() {
     140      if (algorithm != null) RegisterAlgorithmEvents();
     141    }
    135142
    136143    public override IDeepCloneable Clone(Cloner cloner) {
     144      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
    137145      BatchRun clone = (BatchRun)base.Clone(cloner);
    138146      clone.executionState = executionState;
    139147      clone.executionTime = executionTime;
    140       clone.Algorithm = (IAlgorithm)cloner.Clone(algorithm);
     148      clone.algorithm = (IAlgorithm)cloner.Clone(algorithm);
    141149      clone.repetitions = repetitions;
    142150      clone.runs = (RunCollection)cloner.Clone(runs);
    143151      clone.stopPending = stopPending;
     152      clone.Initialize();
    144153      return clone;
    145154    }
     
    234243      algorithm.Started += new EventHandler(Algorithm_Started);
    235244      algorithm.Stopped += new EventHandler(Algorithm_Stopped);
    236       algorithm.Runs.CollectionReset += new CollectionItemsChangedEventHandler<Run>(Algorithm_Runs_CollectionReset);
    237       algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<Run>(Algorithm_Runs_ItemsAdded);
    238       algorithm.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<Run>(Algorithm_Runs_ItemsRemoved);
     245      algorithm.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_CollectionReset);
     246      algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded);
     247      algorithm.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsRemoved);
    239248    }
    240249    private void DeregisterAlgorithmEvents() {
     
    245254      algorithm.Started -= new EventHandler(Algorithm_Started);
    246255      algorithm.Stopped -= new EventHandler(Algorithm_Stopped);
    247       algorithm.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<Run>(Algorithm_Runs_CollectionReset);
    248       algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<Run>(Algorithm_Runs_ItemsAdded);
    249       algorithm.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<Run>(Algorithm_Runs_ItemsRemoved);
     256      algorithm.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_CollectionReset);
     257      algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded);
     258      algorithm.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsRemoved);
    250259    }
    251260    private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     
    277286      }
    278287    }
    279     private void Algorithm_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<Run> e) {
     288    private void Algorithm_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    280289      Runs.RemoveRange(e.OldItems);
    281290      Runs.AddRange(e.Items);
    282291    }
    283     private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<Run> e) {
     292    private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    284293      Runs.AddRange(e.Items);
    285294    }
    286     private void Algorithm_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<Run> e) {
     295    private void Algorithm_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    287296      Runs.RemoveRange(e.Items);
    288297    }
  • trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs

    r3275 r3280  
    3434  [StorableClass]
    3535  public abstract class EngineAlgorithm : Algorithm {
     36    [Storable]
    3637    private OperatorGraph operatorGraph;
    37     [Storable]
    38     private OperatorGraph OperatorGraphPersistence {
    39       get { return operatorGraph; }
    40       set {
    41         if (operatorGraph != null) operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged);
    42         operatorGraph = value;
    43         if (operatorGraph != null) operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);
    44       }
    45     }
    4638    protected OperatorGraph OperatorGraph {
    4739      get { return operatorGraph; }
     
    4941        if (value == null) throw new ArgumentNullException();
    5042        if (value != operatorGraph) {
    51           if (operatorGraph != null) operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged);
     43          operatorGraph.InitialOperatorChanged -= new EventHandler(OperatorGraph_InitialOperatorChanged);
    5244          operatorGraph = value;
    53           if (operatorGraph != null) operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);
     45          operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);
    5446          OnOperatorGraphChanged();
    5547          Prepare();
     
    6456    }
    6557
     58    [Storable]
    6659    private IEngine engine;
    67     [Storable]
    68     private IEngine EnginePersistence {
    69       get { return engine; }
    70       set {
    71         if (engine != null) DeregisterEngineEvents();
    72         engine = value;
    73         if (engine != null) RegisterEngineEvents();
    74       }
    75     }
    7660    public IEngine Engine {
    7761      get { return engine; }
     
    9781      globalScope = new Scope("Global Scope");
    9882      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    99       OperatorGraph = new OperatorGraph();
    100       InitializeEngine();
     83      operatorGraph = new OperatorGraph();
     84      Initialize();
    10185    }
    10286    protected EngineAlgorithm(string name)
     
    10488      globalScope = new Scope("Global Scope");
    10589      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    106       OperatorGraph = new OperatorGraph();
    107       InitializeEngine();
     90      operatorGraph = new OperatorGraph();
     91      Initialize();
    10892    }
    10993    protected EngineAlgorithm(string name, ParameterCollection parameters)
     
    11195      globalScope = new Scope("Global Scope");
    11296      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    113       OperatorGraph = new OperatorGraph();
    114       InitializeEngine();
     97      operatorGraph = new OperatorGraph();
     98      Initialize();
    11599    }
    116100    protected EngineAlgorithm(string name, string description)
     
    118102      globalScope = new Scope("Global Scope");
    119103      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    120       OperatorGraph = new OperatorGraph();
    121       InitializeEngine();
     104      operatorGraph = new OperatorGraph();
     105      Initialize();
    122106    }
    123107    protected EngineAlgorithm(string name, string description, ParameterCollection parameters)
     
    125109      globalScope = new Scope("Global Scope");
    126110      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    127       OperatorGraph = new OperatorGraph();
    128       InitializeEngine();
    129     }
    130 
    131     private void InitializeEngine() {
    132       if (ApplicationManager.Manager != null) {
     111      operatorGraph = new OperatorGraph();
     112      Initialize();
     113    }
     114    internal EngineAlgorithm(EngineAlgorithm algorithm, Cloner cloner)
     115      : base(algorithm, cloner) {
     116      globalScope = (IScope)cloner.Clone(algorithm.globalScope);
     117      operatorGraph = (OperatorGraph)cloner.Clone(algorithm.operatorGraph);
     118      engine = (IEngine)cloner.Clone(algorithm.engine);
     119      Initialize();
     120    }
     121    [StorableConstructor]
     122    protected EngineAlgorithm(bool deserializing) : base(deserializing) { }
     123
     124    [StorableHook(HookType.AfterDeserialization)]
     125    private void Initialize() {
     126      operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);
     127      if ((engine == null) && (ApplicationManager.Manager != null)) {
    133128        var types = ApplicationManager.Manager.GetTypes(typeof(IEngine));
    134129        Type t = types.FirstOrDefault(x => x.Name.Equals("SequentialEngine"));
    135130        if (t == null) t = types.FirstOrDefault();
    136         if (t != null) Engine = (IEngine)Activator.CreateInstance(t);
    137       }
     131        if (t != null) engine = (IEngine)Activator.CreateInstance(t);
     132      }
     133      if (engine != null) RegisterEngineEvents();
    138134    }
    139135
     
    141137      EngineAlgorithm clone = (EngineAlgorithm)base.Clone(cloner);
    142138      clone.globalScope = (IScope)cloner.Clone(globalScope);
    143       clone.Engine = (IEngine)cloner.Clone(engine);
    144       clone.OperatorGraph = (OperatorGraph)cloner.Clone(operatorGraph);
     139      clone.engine = (IEngine)cloner.Clone(engine);
     140      clone.operatorGraph = (OperatorGraph)cloner.Clone(operatorGraph);
     141      clone.Initialize();
    145142      return clone;
    146143    }
    147144
    148145    public UserDefinedAlgorithm CreateUserDefinedAlgorithm() {
    149       UserDefinedAlgorithm algorithm = new UserDefinedAlgorithm(Name, Description);
    150       Cloner cloner = new Cloner();
    151       foreach (IParameter param in Parameters)
    152         algorithm.Parameters.Add((IParameter)cloner.Clone(param));
    153       algorithm.Problem = (IProblem)cloner.Clone(Problem);
    154       algorithm.Engine = (IEngine)cloner.Clone(engine);
    155       algorithm.OperatorGraph = (OperatorGraph)cloner.Clone(operatorGraph);
    156       return algorithm;
     146      return new UserDefinedAlgorithm(this, new Cloner());
    157147    }
    158148
  • trunk/sources/HeuristicLab.Optimization/3.3/Experiment.cs

    r3276 r3280  
    6262    }
    6363
     64    [Storable]
    6465    private OptimizerList optimizers;
    65     [Storable]
    6666    public OptimizerList Optimizers {
    6767      get { return optimizers; }
    68       private set {
    69         if (optimizers != value) {
    70           if (optimizers != null) DeregisterOptimizersEvents();
    71           optimizers = value;
    72           if (optimizers != null) RegisterOptimizersEvents();
    73           foreach (IOptimizer optimizer in optimizers)
    74             RegisterOptimizerEvents(optimizer);
    75         }
    76       }
    7768    }
    7869
     
    8778    public Experiment()
    8879      : base() {
     80      name = ItemName;
     81      description = ItemDescription;
    8982      executionState = ExecutionState.Stopped;
    9083      executionTime = TimeSpan.Zero;
    91       Optimizers = new OptimizerList();
     84      optimizers = new OptimizerList();
    9285      runs = new RunCollection();
    9386      stopPending = false;
    94     }
    95     public Experiment(string name) : base(name) {
     87      Initialize();
     88    }
     89    public Experiment(string name)
     90      : base(name) {
     91      description = ItemDescription;
    9692      executionState = ExecutionState.Stopped;
    9793      executionTime = TimeSpan.Zero;
    98       Optimizers = new OptimizerList();
     94      optimizers = new OptimizerList();
    9995      runs = new RunCollection();
    10096      stopPending = false;
    101     }
    102     public Experiment(string name, string description) : base(name, description) {
     97      Initialize();
     98    }
     99    public Experiment(string name, string description)
     100      : base(name, description) {
    103101      executionState = ExecutionState.Stopped;
    104102      executionTime = TimeSpan.Zero;
    105       Optimizers = new OptimizerList();
     103      optimizers = new OptimizerList();
    106104      runs = new RunCollection();
    107105      stopPending = false;
     106      Initialize();
     107    }
     108    [StorableConstructor]
     109    private Experiment(bool deserializing)
     110      : base(deserializing) {
     111      stopPending = false;
     112    }
     113
     114    [StorableHook(HookType.AfterDeserialization)]
     115    private void Initialize() {
     116      RegisterOptimizersEvents();
     117      foreach (IOptimizer optimizer in optimizers)
     118        RegisterOptimizerEvents(optimizer);
    108119    }
    109120
    110121    public override IDeepCloneable Clone(Cloner cloner) {
     122      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
    111123      Experiment clone = (Experiment)base.Clone(cloner);
    112124      clone.executionState = executionState;
    113125      clone.executionTime = executionTime;
    114       clone.Optimizers = (OptimizerList)cloner.Clone(optimizers);
     126      clone.optimizers = (OptimizerList)cloner.Clone(optimizers);
    115127      clone.runs = (RunCollection)cloner.Clone(runs);
    116128      clone.stopPending = stopPending;
     129      clone.Initialize();
    117130      return clone;
    118131    }
     
    244257      optimizer.Started += new EventHandler(optimizer_Started);
    245258      optimizer.Stopped += new EventHandler(optimizer_Stopped);
    246       optimizer.Runs.CollectionReset += new CollectionItemsChangedEventHandler<Run>(optimizer_Runs_CollectionReset);
    247       optimizer.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<Run>(optimizer_Runs_ItemsAdded);
    248       optimizer.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<Run>(optimizer_Runs_ItemsRemoved);
     259      optimizer.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_CollectionReset);
     260      optimizer.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsAdded);
     261      optimizer.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved);
    249262    }
    250263    private void DeregisterOptimizerEvents(IOptimizer optimizer) {
     
    255268      optimizer.Started -= new EventHandler(optimizer_Started);
    256269      optimizer.Stopped -= new EventHandler(optimizer_Stopped);
    257       optimizer.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<Run>(optimizer_Runs_CollectionReset);
    258       optimizer.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<Run>(optimizer_Runs_ItemsAdded);
    259       optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<Run>(optimizer_Runs_ItemsRemoved);
     270      optimizer.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_CollectionReset);
     271      optimizer.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsAdded);
     272      optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved);
    260273    }
    261274    private void optimizer_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     
    287300      }
    288301    }
    289     private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<Run> e) {
     302    private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    290303      Runs.RemoveRange(e.OldItems);
    291304      Runs.AddRange(e.Items);
    292305    }
    293     private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<Run> e) {
     306    private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    294307      Runs.AddRange(e.Items);
    295308    }
    296     private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<Run> e) {
     309    private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    297310      Runs.RemoveRange(e.Items);
    298311    }
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3274 r3280  
    8787    <Compile Include="Algorithm.cs" />
    8888    <Compile Include="BatchRun.cs" />
     89    <Compile Include="Interfaces\IRun.cs" />
    8990    <Compile Include="OptimizerList.cs" />
    9091    <Compile Include="Experiment.cs" />
  • 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]));
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r3274 r3280  
    2828  [StorableClass]
    2929  [Item("RunCollection", "Represents a collection of runs.")]
    30   public class RunCollection : ItemCollection<Run> {
     30  public class RunCollection : ItemCollection<IRun> {
    3131    public RunCollection() : base() { }
    3232    public RunCollection(int capacity) : base(capacity) { }
    33     public RunCollection(IEnumerable<Run> collection) : base(collection) { }
     33    public RunCollection(IEnumerable<IRun> collection) : base(collection) { }
    3434
    3535    public override IDeepCloneable Clone(Cloner cloner) {
    36       RunCollection clone = new RunCollection(this.Select(x => (Run)cloner.Clone(x)));
     36      RunCollection clone = new RunCollection(this.Select(x => (IRun)cloner.Clone(x)));
    3737      cloner.RegisterClonedObject(this, clone);
    3838      return clone;
  • trunk/sources/HeuristicLab.Optimization/3.3/UserDefinedAlgorithm.cs

    r3262 r3280  
    5252    public UserDefinedAlgorithm(string name) : base(name) { }
    5353    public UserDefinedAlgorithm(string name, string description) : base(name, description) { }
     54    internal UserDefinedAlgorithm(EngineAlgorithm algorithm, Cloner cloner) : base(algorithm, cloner) { }
     55    [StorableConstructor]
     56    private UserDefinedAlgorithm(bool deserializing) : base(deserializing) { }
    5457
    5558    public event EventHandler OperatorGraphChanged;
Note: See TracChangeset for help on using the changeset viewer.