- Timestamp:
- 12/30/11 01:54:44 (13 years ago)
- 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 3 3 obj 4 4 *.vs10x 5 *.user
-
- Property svn:ignore
-
trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3/BenchmarkAlgorithm.cs
r7245 r7246 36 36 37 37 namespace 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.).")] 42 39 [Creatable("Algorithms")] 43 40 [StorableClass] 44 public class Benchmark: IAlgorithm {41 public sealed class BenchmarkAlgorithm : IAlgorithm { 45 42 private Random random = new Random(); 43 private CancellationTokenSource cancellationTokenSource; 46 44 47 45 [Storable] … … 49 47 50 48 [Storable] 51 private IBenchmark benchmark Algorithm;52 public IBenchmark Benchmark Algorithm{53 get { return benchmark Algorithm; }49 private IBenchmark benchmark; 50 public IBenchmark Benchmark { 51 get { return benchmark; } 54 52 set { 55 53 if (value == null) throw new ArgumentNullException(); 56 benchmarkAlgorithm = value; 57 } 58 } 59 60 private CancellationTokenSource cancellationTokenSource; 54 benchmark = value; 55 } 56 } 61 57 62 58 [Storable] … … 77 73 public TimeSpan ExecutionTime { 78 74 get { return executionTime; } 79 pr otectedset {75 private set { 80 76 executionTime = value; 81 77 OnExecutionTimeChanged(); … … 96 92 97 93 [Storable] 98 pr otectedint runsCounter;94 private int runsCounter; 99 95 100 96 [Storable] … … 102 98 public RunCollection Runs { 103 99 get { return runs; } 104 pr otectedset {100 private set { 105 101 if (value == null) throw new ArgumentNullException(); 106 102 if (runs != value) { … … 116 112 public ResultCollection Results { 117 113 get { return results; } 114 } 115 116 public Type ProblemType { 117 get { return typeof(IProblem); } 118 118 } 119 119 … … 134 134 } 135 135 136 public Type ProblemType { 137 get { return typeof(IProblem); } 138 } 139 140 [Storable] 141 protected string name; 142 136 [Storable] 137 private string name; 143 138 public string Name { 144 139 get { return name; } … … 161 156 162 157 [Storable] 163 pr otectedstring description;158 private string description; 164 159 public string Description { 165 160 get { return description; } … … 224 219 #region Parameter Properties 225 220 226 public ConstrainedValueParameter<IBenchmark> Benchmark AlgorithmParameter {227 get { return (ConstrainedValueParameter<IBenchmark>)Parameters["Benchmark Algorithm"]; }221 public ConstrainedValueParameter<IBenchmark> BenchmarkParameter { 222 get { return (ConstrainedValueParameter<IBenchmark>)Parameters["Benchmark"]; } 228 223 } 229 224 … … 241 236 242 237 [StorableConstructor] 243 public Benchmark (bool deserializing) { }244 245 public Benchmark () {238 public BenchmarkAlgorithm(bool deserializing) { } 239 240 public BenchmarkAlgorithm() { 246 241 name = ItemName; 247 242 description = ItemDescription; … … 259 254 } 260 255 261 public Benchmark (Benchmarkoriginal, Cloner cloner) {256 public BenchmarkAlgorithm(BenchmarkAlgorithm original, Cloner cloner) { 262 257 cloner.RegisterClonedObject(original, this); 263 258 name = original.name; … … 293 288 values.Add(b); 294 289 } 295 string paramName = "Benchmark Algorithm";290 string paramName = "Benchmark"; 296 291 if (!Parameters.ContainsKey(paramName)) { 297 292 if (values.Count > 0) { … … 308 303 } 309 304 310 public v irtual void Prepare() {305 public void Prepare() { 311 306 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) 312 307 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); … … 322 317 } 323 318 324 public v irtual void Pause() {319 public void Pause() { 325 320 if (ExecutionState != ExecutionState.Started) 326 321 throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); 327 322 } 328 public v irtual void Stop() {323 public void Stop() { 329 324 if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) 330 325 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); … … 332 327 } 333 328 334 public v irtual void Start() {329 public void Start() { 335 330 cancellationTokenSource = new CancellationTokenSource(); 336 331 OnStarted(); … … 356 351 } 357 352 358 pr otected virtualvoid Run(object state) {353 private void Run(object state) { 359 354 CancellationToken cancellationToken = (CancellationToken)state; 360 355 lastUpdateTime = DateTime.Now; … … 364 359 timer.Start(); 365 360 try { 366 Benchmark Algorithm = (IBenchmark)BenchmarkAlgorithmParameter.ActualValue;361 Benchmark = (IBenchmark)BenchmarkParameter.ActualValue; 367 362 int chunkSize = ((IntValue)ChunkSizeParameter.ActualValue).Value; 368 363 if (chunkSize > 0) { 369 Benchmark Algorithm.ChunkData = CreateDataChuck(chunkSize);364 Benchmark.ChunkData = CreateDataChuck(chunkSize); 370 365 } else if (chunkSize < 0) { 371 366 throw new ArgumentException("ChunkSize must not be negativ."); … … 375 370 throw new ArgumentException("TimeLimit must not be negativ. "); 376 371 } 377 Benchmark Algorithm.TimeLimit = timelimit;378 Benchmark Algorithm.Run(cancellationToken, results);372 Benchmark.TimeLimit = timelimit; 373 Benchmark.Run(cancellationToken, results); 379 374 } 380 375 catch (OperationCanceledException) { … … 396 391 } 397 392 398 public v irtual void CollectResultValues(IDictionary<string, IItem> values) {393 public void CollectResultValues(IDictionary<string, IItem> values) { 399 394 values.Add("Execution Time", new TimeSpanValue(ExecutionTime)); 400 395 CollectResultsRecursively("", Results, values); … … 411 406 } 412 407 413 public v irtual void CollectParameterValues(IDictionary<string, IItem> values) {408 public void CollectParameterValues(IDictionary<string, IItem> values) { 414 409 foreach (IValueParameter param in parameters.OfType<IValueParameter>()) { 415 410 if (param.GetsCollected && param.Value != null) values.Add(param.Name, param.Value); … … 438 433 439 434 public event EventHandler ExecutionStateChanged; 440 pr otected virtualvoid OnExecutionStateChanged() {435 private void OnExecutionStateChanged() { 441 436 EventHandler handler = ExecutionStateChanged; 442 437 if (handler != null) handler(this, EventArgs.Empty); 443 438 } 444 439 public event EventHandler ExecutionTimeChanged; 445 pr otected virtualvoid OnExecutionTimeChanged() {440 private void OnExecutionTimeChanged() { 446 441 EventHandler handler = ExecutionTimeChanged; 447 442 if (handler != null) handler(this, EventArgs.Empty); 448 443 } 449 444 public event EventHandler ProblemChanged; 450 pr otected virtualvoid OnProblemChanged() {445 private void OnProblemChanged() { 451 446 EventHandler handler = ProblemChanged; 452 447 if (handler != null) handler(this, EventArgs.Empty); 453 448 } 454 449 public event EventHandler StoreAlgorithmInEachRunChanged; 455 pr otected virtualvoid OnStoreAlgorithmInEachRunChanged() {450 private void OnStoreAlgorithmInEachRunChanged() { 456 451 EventHandler handler = StoreAlgorithmInEachRunChanged; 457 452 if (handler != null) handler(this, EventArgs.Empty); 458 453 } 459 454 public event EventHandler Prepared; 460 pr otected virtualvoid OnPrepared() {455 private void OnPrepared() { 461 456 ExecutionState = ExecutionState.Prepared; 462 457 ExecutionTime = TimeSpan.Zero; … … 468 463 } 469 464 public event EventHandler Started; 470 pr otected virtualvoid OnStarted() {465 private void OnStarted() { 471 466 ExecutionState = ExecutionState.Started; 472 467 EventHandler handler = Started; … … 474 469 } 475 470 public event EventHandler Paused; 476 pr otected virtualvoid OnPaused() {471 private void OnPaused() { 477 472 ExecutionState = ExecutionState.Paused; 478 473 EventHandler handler = Paused; … … 480 475 } 481 476 public event EventHandler Stopped; 482 pr otected virtualvoid OnStopped() {477 private void OnStopped() { 483 478 ExecutionState = ExecutionState.Stopped; 484 479 foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects().OfType<IStatefulItem>()) { … … 491 486 } 492 487 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 493 pr otected virtualvoid OnExceptionOccurred(Exception exception) {488 private void OnExceptionOccurred(Exception exception) { 494 489 EventHandler<EventArgs<Exception>> handler = ExceptionOccurred; 495 490 if (handler != null) handler(this, new EventArgs<Exception>(exception)); … … 497 492 498 493 public event EventHandler<CancelEventArgs<string>> NameChanging; 499 pr otected virtualvoid OnNameChanging(CancelEventArgs<string> e) {494 private void OnNameChanging(CancelEventArgs<string> e) { 500 495 var handler = NameChanging; 501 496 if (handler != null) handler(this, e); … … 503 498 504 499 public event EventHandler NameChanged; 505 pr otected virtualvoid OnNameChanged() {500 private void OnNameChanged() { 506 501 var handler = NameChanged; 507 502 if (handler != null) handler(this, EventArgs.Empty); … … 510 505 511 506 public event EventHandler DescriptionChanged; 512 pr otected virtualvoid OnDescriptionChanged() {507 private void OnDescriptionChanged() { 513 508 var handler = DescriptionChanged; 514 509 if (handler != null) handler(this, EventArgs.Empty); … … 516 511 517 512 public event EventHandler ItemImageChanged; 518 pr otected virtualvoid OnItemImageChanged() {513 private void OnItemImageChanged() { 519 514 EventHandler handler = ItemImageChanged; 520 515 if (handler != null) handler(this, EventArgs.Empty); 521 516 } 522 517 public event EventHandler ToStringChanged; 523 pr otected virtualvoid OnToStringChanged() {518 private void OnToStringChanged() { 524 519 EventHandler handler = ToStringChanged; 525 520 if (handler != null) handler(this, EventArgs.Empty); 526 521 } 527 522 528 pr otected virtualvoid DeregisterProblemEvents() {523 private void DeregisterProblemEvents() { 529 524 problem.OperatorsChanged -= new EventHandler(Problem_OperatorsChanged); 530 525 problem.Reset -= new EventHandler(Problem_Reset); 531 526 } 532 pr otected virtualvoid RegisterProblemEvents() {527 private void RegisterProblemEvents() { 533 528 problem.OperatorsChanged += new EventHandler(Problem_OperatorsChanged); 534 529 problem.Reset += new EventHandler(Problem_Reset); 535 530 } 536 pr otected virtualvoid Problem_OperatorsChanged(object sender, EventArgs e) { }537 pr otected virtualvoid Problem_Reset(object sender, EventArgs e) {531 private void Problem_OperatorsChanged(object sender, EventArgs e) { } 532 private void Problem_Reset(object sender, EventArgs e) { 538 533 Prepare(); 539 534 } 540 535 541 pr otected virtualvoid DeregisterRunsEvents() {536 private void DeregisterRunsEvents() { 542 537 runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset); 543 538 } 544 pr otected virtualvoid RegisterRunsEvents() {539 private void RegisterRunsEvents() { 545 540 runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset); 546 541 } 547 pr otected virtualvoid Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {542 private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 548 543 runsCounter = runs.Count; 549 544 } … … 554 549 555 550 public IDeepCloneable Clone(Cloner cloner) { 556 return new Benchmark (this, cloner);551 return new BenchmarkAlgorithm(this, cloner); 557 552 } 558 553
Note: See TracChangeset
for help on using the changeset viewer.