Last change
on this file since 5664 was
5653,
checked in by cneumuel, 14 years ago
|
#1215
- evaluation operator returns operatorgraph which creates a scope and an operation for each algorithm execution (each repetition and problem)
- split ValueConfiguration into ParameterizedValueConfiguration and RangeValueConfiguration
|
File size:
1.2 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Threading;
|
---|
3 | using HeuristicLab.Optimization;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
6 |
|
---|
7 | public static class AlgorithmExtensions {
|
---|
8 | public static void StartSync(this IAlgorithm algorithm) {
|
---|
9 | var executor = new AlgorithmExecutor(algorithm);
|
---|
10 | executor.StartSync();
|
---|
11 | }
|
---|
12 | }
|
---|
13 |
|
---|
14 | /// <summary>
|
---|
15 | /// Can execute an algorithm synchronously
|
---|
16 | /// </summary>
|
---|
17 | internal class AlgorithmExecutor {
|
---|
18 | private IAlgorithm algorithm;
|
---|
19 | private AutoResetEvent waitHandle = new AutoResetEvent(false);
|
---|
20 |
|
---|
21 | public AlgorithmExecutor(IAlgorithm algorithm) {
|
---|
22 | this.algorithm = algorithm;
|
---|
23 | }
|
---|
24 |
|
---|
25 | public void StartSync() {
|
---|
26 | algorithm.Stopped += new EventHandler(algorithm_Stopped);
|
---|
27 | algorithm.Paused += new EventHandler(algorithm_Paused);
|
---|
28 | algorithm.Start();
|
---|
29 | waitHandle.WaitOne();
|
---|
30 | waitHandle.Dispose();
|
---|
31 | algorithm.Stopped -= new EventHandler(algorithm_Stopped);
|
---|
32 | algorithm.Paused -= new EventHandler(algorithm_Paused);
|
---|
33 | }
|
---|
34 |
|
---|
35 | void algorithm_Paused(object sender, EventArgs e) {
|
---|
36 | waitHandle.Set();
|
---|
37 | }
|
---|
38 |
|
---|
39 | void algorithm_Stopped(object sender, EventArgs e) {
|
---|
40 | waitHandle.Set();
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.