Changeset 6024 for branches/HeuristicLab.MetaOptimization
- Timestamp:
- 04/18/11 23:27:42 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r6018 r6024 48 48 49 49 private static int metaAlgorithmPopulationSize = 10; 50 private static int metaAlgorithmMaxGenerations = 10;50 private static int metaAlgorithmMaxGenerations = 20; 51 51 private static int metaProblemRepetitions = 2; 52 private static int baseAlgorithmMaxGenerations = 10;52 private static int baseAlgorithmMaxGenerations = 50; 53 53 private static double mutationProbability = 0.10; 54 54 … … 80 80 MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem(); 81 81 metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions); 82 GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);83 //GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);82 //GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem); 83 GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem); 84 84 //GeneticAlgorithm metaLevelAlgorithm = GetHiveParallelMetaGA(metaOptimizationProblem); 85 85 … … 353 353 tasks[i] = new Task<TimeSpan>((alg) => { 354 354 Console.WriteLine("Task {0} started.", Task.CurrentId); 355 var cancellationTokenSource = new CancellationTokenSource(); 355 356 356 357 Stopwatch swx = new Stopwatch(); 357 358 swx.Start(); 358 359 ((EngineAlgorithm)alg).ExecutionTimeChanged += new EventHandler(Program_ExecutionTimeChanged); 359 ((EngineAlgorithm)alg).StartSync( );360 ((EngineAlgorithm)alg).StartSync(cancellationTokenSource.Token); 360 361 ((EngineAlgorithm)alg).ExecutionTimeChanged -= new EventHandler(Program_ExecutionTimeChanged); 361 362 swx.Stop(); … … 467 468 algs.Enqueue(clonedGa); 468 469 470 var cancellationTokenSource = new CancellationTokenSource(); 469 471 //if (algs.Count > 24) 470 472 // algs.Dequeue(); 471 clonedGa.StartSync( );473 clonedGa.StartSync(cancellationTokenSource.Token); 472 474 sw.Stop(); 473 475 latestExecutionTimes.Enqueue(sw.Elapsed); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/AlgorithmExecutor.cs
r6018 r6024 6 6 7 7 public static class AlgorithmExtensions { 8 public static void StartSync(this IAlgorithm algorithm) {9 var executor = new AlgorithmExecutor(algorithm);10 executor.StartSync();11 }12 8 public static void StartSync(this IAlgorithm algorithm, CancellationToken cancellationToken) { 13 9 var executor = new AlgorithmExecutor(algorithm, cancellationToken); … … 23 19 private AutoResetEvent waitHandle = new AutoResetEvent(false); 24 20 private CancellationToken cancellationToken; 25 private bool useCancellationToken = false;26 27 public AlgorithmExecutor(IAlgorithm algorithm) {28 this.algorithm = algorithm;29 }30 21 31 22 public AlgorithmExecutor(IAlgorithm algorithm, CancellationToken cancellationToken) { 32 23 this.algorithm = algorithm; 33 24 this.cancellationToken = cancellationToken; 34 this.useCancellationToken = true;35 25 } 36 26 … … 38 28 algorithm.Stopped += new EventHandler(algorithm_Stopped); 39 29 algorithm.Paused += new EventHandler(algorithm_Paused); 40 41 if(useCancellationToken && algorithm is EngineAlgorithm && ((EngineAlgorithm)algorithm).Engine is SequentialEngine.SequentialEngine) { 42 ((SequentialEngine.SequentialEngine)((EngineAlgorithm)algorithm).Engine).Start(cancellationToken); 43 } else { 30 31 using (CancellationTokenRegistration registration = cancellationToken.Register(new Action(cancellationToken_Canceled))) { 44 32 algorithm.Start(); 33 waitHandle.WaitOne(); 34 waitHandle.Dispose(); 45 35 } 46 36 47 waitHandle.WaitOne();48 waitHandle.Dispose();49 37 algorithm.Stopped -= new EventHandler(algorithm_Stopped); 50 38 algorithm.Paused -= new EventHandler(algorithm_Paused); 39 if (algorithm.ExecutionState == Core.ExecutionState.Started) { 40 algorithm.Pause(); 41 } 42 cancellationToken.ThrowIfCancellationRequested(); 51 43 } 52 44 53 void algorithm_Paused(object sender, EventArgs e) {45 private void algorithm_Paused(object sender, EventArgs e) { 54 46 waitHandle.Set(); 55 47 } 56 48 57 void algorithm_Stopped(object sender, EventArgs e) { 49 private void algorithm_Stopped(object sender, EventArgs e) { 50 waitHandle.Set(); 51 } 52 53 private void cancellationToken_Canceled() { 58 54 waitHandle.Set(); 59 55 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmEvaluator.cs
r6018 r6024 64 64 var sw = new Stopwatch(); 65 65 sw.Start(); 66 //// prepare and clear is needed, if the algorithm has been started and stopped before (this happens when meta level algorithm is paused) 67 //algorithm.Prepare(); // <--- SHOULD NOT HAPPEN! 68 //algorithm.Runs.Clear(); 69 66 70 algorithm.StartSync(CancellationToken); 67 71 sw.Stop();
Note: See TracChangeset
for help on using the changeset viewer.