Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/30/11 01:54:44 (12 years ago)
Author:
swagner
Message:

Changes due to review of benchmark algorithms (#1659):

  • renamed Benchmark to BenchmarkAlgorithm and BenchmarkView to BenchmarkAlgorithmView
  • removed unnecessary assembly references
  • removed IBenchmarkView as the user should be informed that there is no specific view for benchmarks
  • adapted descriptions of plugins and assemblies
  • adapted assembly Guids
  • sealed BenchmarkAlgorithm
  • adapted item names and item descriptions
  • adapted code formatting
Location:
trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3

    • Property svn:ignore
      •  

        old new  
        33obj
        44*.vs10x
         5*.user
  • trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3/BenchmarkAlgorithm.cs

    r7245 r7246  
    3636
    3737namespace HeuristicLab.Algorithms.Benchmarks {
    38   /// <summary>
    39   /// A base class for benchmarks.
    40   /// </summary>
    41   [Item("Benchmark", "A wrapper for benchmark algorithms.")]
     38  [Item("Benchmark Algorithm", "An algorithm to execute performance benchmarks (Linpack, Dhrystone, Whetstone, etc.).")]
    4239  [Creatable("Algorithms")]
    4340  [StorableClass]
    44   public class Benchmark : IAlgorithm {
     41  public sealed class BenchmarkAlgorithm : IAlgorithm {
    4542    private Random random = new Random();
     43    private CancellationTokenSource cancellationTokenSource;
    4644
    4745    [Storable]
     
    4947
    5048    [Storable]
    51     private IBenchmark benchmarkAlgorithm;
    52     public IBenchmark BenchmarkAlgorithm {
    53       get { return benchmarkAlgorithm; }
     49    private IBenchmark benchmark;
     50    public IBenchmark Benchmark {
     51      get { return benchmark; }
    5452      set {
    5553        if (value == null) throw new ArgumentNullException();
    56         benchmarkAlgorithm = value;
    57       }
    58     }
    59 
    60     private CancellationTokenSource cancellationTokenSource;
     54        benchmark = value;
     55      }
     56    }
    6157
    6258    [Storable]
     
    7773    public TimeSpan ExecutionTime {
    7874      get { return executionTime; }
    79       protected set {
     75      private set {
    8076        executionTime = value;
    8177        OnExecutionTimeChanged();
     
    9692
    9793    [Storable]
    98     protected int runsCounter;
     94    private int runsCounter;
    9995
    10096    [Storable]
     
    10298    public RunCollection Runs {
    10399      get { return runs; }
    104       protected set {
     100      private set {
    105101        if (value == null) throw new ArgumentNullException();
    106102        if (runs != value) {
     
    116112    public ResultCollection Results {
    117113      get { return results; }
     114    }
     115
     116    public Type ProblemType {
     117      get { return typeof(IProblem); }
    118118    }
    119119
     
    134134    }
    135135
    136     public Type ProblemType {
    137       get { return typeof(IProblem); }
    138     }
    139 
    140     [Storable]
    141     protected string name;
    142 
     136    [Storable]
     137    private string name;
    143138    public string Name {
    144139      get { return name; }
     
    161156
    162157    [Storable]
    163     protected string description;
     158    private string description;
    164159    public string Description {
    165160      get { return description; }
     
    224219    #region Parameter Properties
    225220
    226     public ConstrainedValueParameter<IBenchmark> BenchmarkAlgorithmParameter {
    227       get { return (ConstrainedValueParameter<IBenchmark>)Parameters["BenchmarkAlgorithm"]; }
     221    public ConstrainedValueParameter<IBenchmark> BenchmarkParameter {
     222      get { return (ConstrainedValueParameter<IBenchmark>)Parameters["Benchmark"]; }
    228223    }
    229224
     
    241236
    242237    [StorableConstructor]
    243     public Benchmark(bool deserializing) { }
    244 
    245     public Benchmark() {
     238    public BenchmarkAlgorithm(bool deserializing) { }
     239
     240    public BenchmarkAlgorithm() {
    246241      name = ItemName;
    247242      description = ItemDescription;
     
    259254    }
    260255
    261     public Benchmark(Benchmark original, Cloner cloner) {
     256    public BenchmarkAlgorithm(BenchmarkAlgorithm original, Cloner cloner) {
    262257      cloner.RegisterClonedObject(original, this);
    263258      name = original.name;
     
    293288        values.Add(b);
    294289      }
    295       string paramName = "BenchmarkAlgorithm";
     290      string paramName = "Benchmark";
    296291      if (!Parameters.ContainsKey(paramName)) {
    297292        if (values.Count > 0) {
     
    308303    }
    309304
    310     public virtual void Prepare() {
     305    public void Prepare() {
    311306      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    312307        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
     
    322317    }
    323318
    324     public virtual void Pause() {
     319    public void Pause() {
    325320      if (ExecutionState != ExecutionState.Started)
    326321        throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
    327322    }
    328     public virtual void Stop() {
     323    public void Stop() {
    329324      if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
    330325        throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
     
    332327    }
    333328
    334     public virtual void Start() {
     329    public void Start() {
    335330      cancellationTokenSource = new CancellationTokenSource();
    336331      OnStarted();
     
    356351    }
    357352
    358     protected virtual void Run(object state) {
     353    private void Run(object state) {
    359354      CancellationToken cancellationToken = (CancellationToken)state;
    360355      lastUpdateTime = DateTime.Now;
     
    364359      timer.Start();
    365360      try {
    366         BenchmarkAlgorithm = (IBenchmark)BenchmarkAlgorithmParameter.ActualValue;
     361        Benchmark = (IBenchmark)BenchmarkParameter.ActualValue;
    367362        int chunkSize = ((IntValue)ChunkSizeParameter.ActualValue).Value;
    368363        if (chunkSize > 0) {
    369           BenchmarkAlgorithm.ChunkData = CreateDataChuck(chunkSize);
     364          Benchmark.ChunkData = CreateDataChuck(chunkSize);
    370365        } else if (chunkSize < 0) {
    371366          throw new ArgumentException("ChunkSize must not be negativ.");
     
    375370          throw new ArgumentException("TimeLimit must not be negativ. ");
    376371        }
    377         BenchmarkAlgorithm.TimeLimit = timelimit;
    378         BenchmarkAlgorithm.Run(cancellationToken, results);
     372        Benchmark.TimeLimit = timelimit;
     373        Benchmark.Run(cancellationToken, results);
    379374      }
    380375      catch (OperationCanceledException) {
     
    396391    }
    397392
    398     public virtual void CollectResultValues(IDictionary<string, IItem> values) {
     393    public void CollectResultValues(IDictionary<string, IItem> values) {
    399394      values.Add("Execution Time", new TimeSpanValue(ExecutionTime));
    400395      CollectResultsRecursively("", Results, values);
     
    411406    }
    412407
    413     public virtual void CollectParameterValues(IDictionary<string, IItem> values) {
     408    public void CollectParameterValues(IDictionary<string, IItem> values) {
    414409      foreach (IValueParameter param in parameters.OfType<IValueParameter>()) {
    415410        if (param.GetsCollected && param.Value != null) values.Add(param.Name, param.Value);
     
    438433
    439434    public event EventHandler ExecutionStateChanged;
    440     protected virtual void OnExecutionStateChanged() {
     435    private void OnExecutionStateChanged() {
    441436      EventHandler handler = ExecutionStateChanged;
    442437      if (handler != null) handler(this, EventArgs.Empty);
    443438    }
    444439    public event EventHandler ExecutionTimeChanged;
    445     protected virtual void OnExecutionTimeChanged() {
     440    private void OnExecutionTimeChanged() {
    446441      EventHandler handler = ExecutionTimeChanged;
    447442      if (handler != null) handler(this, EventArgs.Empty);
    448443    }
    449444    public event EventHandler ProblemChanged;
    450     protected virtual void OnProblemChanged() {
     445    private void OnProblemChanged() {
    451446      EventHandler handler = ProblemChanged;
    452447      if (handler != null) handler(this, EventArgs.Empty);
    453448    }
    454449    public event EventHandler StoreAlgorithmInEachRunChanged;
    455     protected virtual void OnStoreAlgorithmInEachRunChanged() {
     450    private void OnStoreAlgorithmInEachRunChanged() {
    456451      EventHandler handler = StoreAlgorithmInEachRunChanged;
    457452      if (handler != null) handler(this, EventArgs.Empty);
    458453    }
    459454    public event EventHandler Prepared;
    460     protected virtual void OnPrepared() {
     455    private void OnPrepared() {
    461456      ExecutionState = ExecutionState.Prepared;
    462457      ExecutionTime = TimeSpan.Zero;
     
    468463    }
    469464    public event EventHandler Started;
    470     protected virtual void OnStarted() {
     465    private void OnStarted() {
    471466      ExecutionState = ExecutionState.Started;
    472467      EventHandler handler = Started;
     
    474469    }
    475470    public event EventHandler Paused;
    476     protected virtual void OnPaused() {
     471    private void OnPaused() {
    477472      ExecutionState = ExecutionState.Paused;
    478473      EventHandler handler = Paused;
     
    480475    }
    481476    public event EventHandler Stopped;
    482     protected virtual void OnStopped() {
     477    private void OnStopped() {
    483478      ExecutionState = ExecutionState.Stopped;
    484479      foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects().OfType<IStatefulItem>()) {
     
    491486    }
    492487    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    493     protected virtual void OnExceptionOccurred(Exception exception) {
     488    private void OnExceptionOccurred(Exception exception) {
    494489      EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
    495490      if (handler != null) handler(this, new EventArgs<Exception>(exception));
     
    497492
    498493    public event EventHandler<CancelEventArgs<string>> NameChanging;
    499     protected virtual void OnNameChanging(CancelEventArgs<string> e) {
     494    private void OnNameChanging(CancelEventArgs<string> e) {
    500495      var handler = NameChanging;
    501496      if (handler != null) handler(this, e);
     
    503498
    504499    public event EventHandler NameChanged;
    505     protected virtual void OnNameChanged() {
     500    private void OnNameChanged() {
    506501      var handler = NameChanged;
    507502      if (handler != null) handler(this, EventArgs.Empty);
     
    510505
    511506    public event EventHandler DescriptionChanged;
    512     protected virtual void OnDescriptionChanged() {
     507    private void OnDescriptionChanged() {
    513508      var handler = DescriptionChanged;
    514509      if (handler != null) handler(this, EventArgs.Empty);
     
    516511
    517512    public event EventHandler ItemImageChanged;
    518     protected virtual void OnItemImageChanged() {
     513    private void OnItemImageChanged() {
    519514      EventHandler handler = ItemImageChanged;
    520515      if (handler != null) handler(this, EventArgs.Empty);
    521516    }
    522517    public event EventHandler ToStringChanged;
    523     protected virtual void OnToStringChanged() {
     518    private void OnToStringChanged() {
    524519      EventHandler handler = ToStringChanged;
    525520      if (handler != null) handler(this, EventArgs.Empty);
    526521    }
    527522
    528     protected virtual void DeregisterProblemEvents() {
     523    private void DeregisterProblemEvents() {
    529524      problem.OperatorsChanged -= new EventHandler(Problem_OperatorsChanged);
    530525      problem.Reset -= new EventHandler(Problem_Reset);
    531526    }
    532     protected virtual void RegisterProblemEvents() {
     527    private void RegisterProblemEvents() {
    533528      problem.OperatorsChanged += new EventHandler(Problem_OperatorsChanged);
    534529      problem.Reset += new EventHandler(Problem_Reset);
    535530    }
    536     protected virtual void Problem_OperatorsChanged(object sender, EventArgs e) { }
    537     protected virtual void Problem_Reset(object sender, EventArgs e) {
     531    private void Problem_OperatorsChanged(object sender, EventArgs e) { }
     532    private void Problem_Reset(object sender, EventArgs e) {
    538533      Prepare();
    539534    }
    540535
    541     protected virtual void DeregisterRunsEvents() {
     536    private void DeregisterRunsEvents() {
    542537      runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
    543538    }
    544     protected virtual void RegisterRunsEvents() {
     539    private void RegisterRunsEvents() {
    545540      runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
    546541    }
    547     protected virtual void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     542    private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    548543      runsCounter = runs.Count;
    549544    }
     
    554549
    555550    public IDeepCloneable Clone(Cloner cloner) {
    556       return new Benchmark(this, cloner);
     551      return new BenchmarkAlgorithm(this, cloner);
    557552    }
    558553
Note: See TracChangeset for help on using the changeset viewer.