Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/17/10 10:26:55 (14 years ago)
Author:
cneumuel
Message:
  • Refactored HL.Hive.Experiment. JobItems are not called HiveJobs and OptimizerJobs do not contain a hierarchy anymore.
  • Dynamic generation of jobs on a slave are not reflected on the client user interface.
  • Optimizer-Trees are now strictly synchronized with the HiveJob-Trees (also the ComputeInParallel property is taken into account when the Child HiveJobs are created)
  • Improved the way a class can report progress and lock the UI (IProgressReporter, IProgress, Progress, ProgressView)
  • Changes were made to the config-files, so that server and clients work with blade12.hpc.fh-hagenberg.at
  • Lots of small changes and bugfixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/Jobs/OptimizerJob.cs

    r4368 r4423  
    11using System;
     2using System.Linq;
    23using System.Collections.Generic;
    34using HeuristicLab.Core;
     
    56using HeuristicLab.Optimization;
    67using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     8using HeuristicLab.Common;
     9using HeuristicLab.Hive.Contracts.BusinessObjects;
    710
    811namespace HeuristicLab.Hive.Experiment.Jobs {
    912  [StorableClass]
    1013  public class OptimizerJob : IJob {
    11     [Storable]
    12     protected Guid internalId;
    13     public Guid InternalId {
    14       get { return internalId; }
    15     }
    16    
    1714    [Storable]
    1815    protected IOptimizer optimizer;
     
    2017      get { return optimizer; }
    2118      set {
    22         if (optimizer != null && value != optimizer) {
    23           DeregisterEvents();
    24         }
    25         optimizer = value;
    26         if (optimizer != null) {
    27           RegisterEvents();
     19        if (value != optimizer) {
     20          if (optimizer != null) {
     21            DeregisterEvents();
     22          }
     23          optimizer = value;
     24          if (optimizer != null) {
     25            RegisterEvents();
     26          }
     27          OnOptimizerChanged();
    2828        }
    2929      }
    3030    }
    31 
    32     [Storable]
    33     protected double progress = 0.0;
    3431
    3532    [Storable]
     
    4037
    4138    [Storable]
    42     protected ICollection<IJob> childJobs;
    43     public IEnumerable<IJob> ChildJobs {
    44       get { return childJobs; }
    45     }
    46 
    47     [Storable]
    4839    protected bool computeInParallel;
    4940    public bool ComputeInParallel {
    5041      get { return computeInParallel; }
    51       set { computeInParallel = value; }
    52     }
    53 
    54     [Storable]
    55     protected int coresNeeded;
    56     public int CoresNeeded {
    57       get { return coresNeeded; }
    58       set { coresNeeded = value; }
    59     }
    60 
    61     [Storable]
    62     protected int memoryNeeded;
    63     public int MemoryNeeded {
    64       get { return memoryNeeded; }
    65       set { memoryNeeded = value; }
     42      set {
     43        if (computeInParallel != value) {
     44          computeInParallel = value;
     45          OnComputeInParallelChanged();
     46        }
     47      }
     48    }
     49
     50    [Storable]
     51    private int indexInParentOptimizerList = -1;
     52    public int IndexInParentOptimizerList {
     53      get { return indexInParentOptimizerList; }
     54      set { this.indexInParentOptimizerList = value; }
     55    }
     56
     57
     58    [Storable]
     59    private bool collectChildJobs;
     60    public bool CollectChildJobs {
     61      get { return collectChildJobs; }
     62      set { collectChildJobs = value; }
    6663    }
    6764
    6865    public OptimizerJob() {
    69       this.internalId = Guid.NewGuid();
    7066      this.log = new Log();
    71       this.childJobs = new List<IJob>();
    72       this.ComputeInParallel = false;
    73       this.CoresNeeded = 1;
    74       this.MemoryNeeded = 0;
    7567    }
    7668
     
    7870      : this() {
    7971      this.optimizer = optimizer;
     72
     73      if (optimizer is Optimization.Experiment) {
     74        this.ComputeInParallel = true;
     75      } else if (optimizer is Optimization.BatchRun) {
     76        this.ComputeInParallel = false;
     77      } else {
     78        this.ComputeInParallel = false;
     79      }
    8080    }
    8181
     
    8585    }
    8686
     87    /// <summary>
     88    /// Casts the Optimizer to an Experiment. Returns null if cast was not successfull.
     89    /// </summary>
     90    public Optimization.Experiment OptimizerAsExperiment {
     91      get { return Optimizer as Optimization.Experiment; }
     92    }
     93
     94    /// <summary>
     95    /// Casts the Optimizer to an BatchRun. Returns null if cast was not successfull.
     96    /// </summary>
     97    public Optimization.BatchRun OptimizerAsBatchRun {
     98      get { return Optimizer as Optimization.BatchRun; }
     99    }
     100
    87101    #region IJob Members
    88    
    89     public double Progress {
    90       get { return optimizer.ExecutionState == ExecutionState.Stopped ? 1.0 : this.progress; }
    91     }
    92102
    93103    public virtual ExecutionState ExecutionState {
     
    95105    }
    96106
     107    public TimeSpan ExecutionTime {
     108      get { return optimizer.ExecutionTime; }
     109    }
     110
    97111    public virtual void Run() {
    98112      throw new NotSupportedException();
     
    104118
    105119    public virtual void Start() {
    106       optimizer.Start();
     120      if ((optimizer is Optimization.Experiment && OptimizerAsExperiment.Optimizers.Count == 0) || // experiment would not fire OnStopped if it has 0 optimizers
     121          (optimizer is Optimization.BatchRun && OptimizerAsBatchRun.Algorithm == null)) { // batchrun would not fire OnStopped if algorithm == null
     122        OnJobStopped();
     123      } else {
     124        optimizer.Start();
     125      }
    107126    }
    108127
     
    112131
    113132    public virtual void Resume(IEnumerable<IJob> childJobs) {
    114       throw new NotSupportedException();
     133      OnJobStopped();
    115134    }
    116135
     
    122141
    123142    public event EventHandler JobFailed;
    124     protected virtual void OnJobFailed(Common.EventArgs<Exception> e) {
     143    protected virtual void OnJobFailed(EventArgs<Exception> e) {
    125144      EventHandler handler = JobFailed;
    126145      if (handler != null) handler(this, e);
    127146    }
    128147
    129     public event EventHandler<Common.EventArgs<IJob>> NewChildJob;
     148    public event EventHandler<EventArgs<IJob>> NewChildJob;
    130149    protected virtual void OnNewChildJob(IJob job) {
    131150      EventHandler<Common.EventArgs<IJob>> handler = NewChildJob;
    132       if (handler != null) handler(this, new Common.EventArgs<IJob>(job));
     151      if (handler != null) handler(this, new EventArgs<IJob>(job));
    133152    }
    134153
     
    139158    }
    140159
     160    public event EventHandler DeleteChildJobs;
     161    protected virtual void OnDeleteChildJobs() {
     162      EventHandler handler = DeleteChildJobs;
     163      if (handler != null) handler(this, EventArgs.Empty);
     164    }
     165
     166    public event EventHandler ComputeInParallelChanged;
     167    protected virtual void OnComputeInParallelChanged() {
     168      EventHandler handler = ComputeInParallelChanged;
     169      if (handler != null) handler(this, EventArgs.Empty);
     170    }
     171
     172    public event EventHandler OptimizerChanged;
     173    protected virtual void OnOptimizerChanged() {
     174      EventHandler handler = OptimizerChanged;
     175      if (handler != null) handler(this, EventArgs.Empty);
     176    }
    141177    #endregion
    142178
     
    165201
    166202    protected virtual void optimizer_ExceptionOccurred(object sender, Common.EventArgs<Exception> e) {
    167       if (optimizer.ExecutionState != ExecutionState.Stopped) this.progress = 0.0;
    168       else this.progress = 1.0;
    169203      OnJobFailed(e);
    170204    }
    171205
    172206    protected virtual void optimizer_Stopped(object sender, EventArgs e) {
    173       if (optimizer.ExecutionState != ExecutionState.Stopped) this.progress = 0.0;
    174       else this.progress = 1.0;
    175207      OnJobStopped();
    176208    }
     
    237269    #region IDeepCloneable Members
    238270
    239     public Common.IDeepCloneable Clone(Common.Cloner cloner) {
    240       throw new NotImplementedException();
     271    public Common.IDeepCloneable Clone(Cloner cloner) {
     272      OptimizerJob clone = (OptimizerJob)Activator.CreateInstance(this.GetType());
     273      cloner.RegisterClonedObject(this, clone);
     274      clone.Optimizer = (IOptimizer)cloner.Clone(this.Optimizer);
     275      clone.log = (ILog)cloner.Clone(this.Log);
     276      clone.ComputeInParallel = this.ComputeInParallel;
     277      clone.IndexInParentOptimizerList = this.IndexInParentOptimizerList;
     278      clone.CollectChildJobs = this.CollectChildJobs;
     279      clone.RegisterEvents();
     280      return clone;
    241281    }
    242282
     
    246286
    247287    public object Clone() {
    248       throw new NotImplementedException();
     288      return Clone(new Cloner());
    249289    }
    250290
     
    258298      return Name;
    259299    }
    260    
     300
    261301    public virtual bool IsParallelizable {
    262       get { return false; }
    263     }
     302      get { return this.Optimizer is Optimization.Experiment || this.Optimizer is BatchRun; }
     303    }
     304
    264305  }
    265306}
Note: See TracChangeset for help on using the changeset viewer.