Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/03/10 06:04:49 (15 years ago)
Author:
swagner
Message:

Continued work on algorithm batch processing (#947).

Location:
trunk/sources/HeuristicLab.Optimization/3.3
Files:
2 added
5 edited

Legend:

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

    r3226 r3260  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Drawing;
    24 using HeuristicLab.Collections;
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     
    120120    }
    121121
     122    public override void CollectParameterValues(IDictionary<string, IItem> values) {
     123      base.CollectParameterValues(values);
     124      Problem.CollectParameterValues(values);
     125    }
     126    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
     127      foreach (IResult result in Results)
     128        values.Add(result.Name, result.Value != null ? (IItem)result.Value.Clone() : null);
     129    }
     130
    122131    #region Events
    123132    public event EventHandler ProblemChanged;
  • TabularUnified trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs

    r3246 r3260  
    2222using System;
    2323using System.Drawing;
    24 using HeuristicLab.Collections;
    2524using HeuristicLab.Core;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    7473
    7574    [Storable]
    76     private ResultCollection results;
    77     public ResultCollection Results {
    78       get { return results; }
     75    private RunCollection runs;
     76    public RunCollection Runs {
     77      get { return runs; }
    7978    }
    8079
     
    103102
    104103    public bool Finished {
    105       get { return ((Algorithm == null) || (Algorithm.Finished && (results.Count >= repetitions))); }
     104      get { return ((Algorithm == null) || (Algorithm.Finished && (runs.Count >= repetitions))); }
    106105    }
    107106
     
    111110      : base() {
    112111      repetitions = 10;
    113       results = new ResultCollection();
     112      runs = new RunCollection();
    114113      executionTime = TimeSpan.Zero;
    115114    }
    116115    public BatchRun(string name) : base(name) {
    117116      repetitions = 10;
    118       results = new ResultCollection();
     117      runs = new RunCollection();
    119118      executionTime = TimeSpan.Zero;
    120119    }
    121120    public BatchRun(string name, string description) : base(name, description) {
    122121      repetitions = 10;
    123       results = new ResultCollection();
     122      runs = new RunCollection();
    124123      executionTime = TimeSpan.Zero;
    125124    }
     
    129128      clone.Algorithm = (IAlgorithm)cloner.Clone(algorithm);
    130129      clone.repetitions = repetitions;
    131       clone.results = (ResultCollection)cloner.Clone(results);
     130      clone.runs = (RunCollection)cloner.Clone(runs);
    132131      clone.executionTime = executionTime;
    133132      clone.running = running;
     
    137136
    138137    public void Prepare() {
    139       results.Clear();
     138      executionTime = TimeSpan.Zero;
     139      runs.Clear();
    140140      if (Algorithm != null) Algorithm.Prepare();
    141141      OnPrepared();
     
    196196
    197197    private void DeregisterAlgorithmEvents() {
    198       algorithm.Prepared -= new EventHandler(Algorithm_Prepared);
    199198      algorithm.RunningChanged -= new EventHandler(Algorithm_RunningChanged);
    200199      algorithm.ExceptionOccurred -= new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
     
    202201
    203202    private void RegisterAlgorithmEvents() {
    204       algorithm.Prepared += new EventHandler(Algorithm_Prepared);
    205203      algorithm.RunningChanged += new EventHandler(Algorithm_RunningChanged);
    206204      algorithm.ExceptionOccurred += new EventHandler<HeuristicLab.Common.EventArgs<Exception>>(Algorithm_ExceptionOccurred);
    207205    }
    208206
    209     private void Algorithm_Prepared(object sender, EventArgs e) {
    210       results.Add(new Result("Run " + DateTime.Now.ToString(), Algorithm.Results));
    211     }
    212207    private void Algorithm_RunningChanged(object sender, EventArgs e) {
    213208      if (Algorithm.Running) {
     
    215210        OnStarted();
    216211      } else {
    217         if (!canceled && (results.Count < repetitions)) {
     212        if (!canceled) {
    218213          ExecutionTime += Algorithm.ExecutionTime;
     214          runs.Add(new Run("Run " + Algorithm.ExecutionTime.ToString(), Algorithm));
    219215          Algorithm.Prepare();
    220           Algorithm.Start();
     216          if (runs.Count < repetitions) Algorithm.Start();
     217          else OnStopped();
    221218        } else {
    222           if (Algorithm.Finished) ExecutionTime += Algorithm.ExecutionTime;
    223219          OnStopped();
    224220        }
  • TabularUnified trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs

    r3226 r3260  
    216216      Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
    217217      Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged);
    218       Engine.Stopped += new EventHandler(Engine_Stopped);
     218      Engine.RunningChanged += new EventHandler(Engine_RunningChanged);
    219219    }
    220220    private void DeregisterEngineEvents() {
    221221      Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
    222222      Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged);
    223       Engine.Stopped -= new EventHandler(Engine_Stopped);
     223      Engine.RunningChanged -= new EventHandler(Engine_RunningChanged);
    224224    }
    225225
     
    230230      OnExecutionTimeChanged();
    231231    }
    232     private void Engine_Stopped(object sender, EventArgs e) {
    233       OnStopped();
     232    private void Engine_RunningChanged(object sender, EventArgs e) {
     233      if (!Engine.Running) OnStopped();
    234234    }
    235235  }
  • TabularUnified trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3246 r3260  
    8787    <Compile Include="Algorithm.cs" />
    8888    <Compile Include="BatchRun.cs" />
     89    <Compile Include="RunCollection.cs" />
     90    <Compile Include="Run.cs" />
    8991    <Compile Include="Interfaces\IMultiObjectiveSolutionsVisualizer.cs" />
    9092    <Compile Include="Interfaces\IResult.cs" />
  • TabularUnified trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IAlgorithm.cs

    r3226 r3260  
    2121
    2222using System;
    23 using HeuristicLab.Collections;
     23using System.Collections.Generic;
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     
    4141    void Stop();
    4242
     43    void CollectResultValues(IDictionary<string, IItem> values);
     44
    4345    event EventHandler ProblemChanged;
    4446    event EventHandler ExecutionTimeChanged;
Note: See TracChangeset for help on using the changeset viewer.