Changes between Version 8 and Version 9 of Documentation/DevelopmentCenter/IntegrateHeuristicLab
- Timestamp:
- 08/29/18 13:02:24 (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Documentation/DevelopmentCenter/IntegrateHeuristicLab
v8 v9 23 23 24 24 {{{#!csharp 25 private static void LoadingCompleted(IStorableContent content, Exception error) {25 private static void LoadingCompleted(IStorableContent content, Exception error) { 26 26 if (error != null) throw error; 27 27 Console.WriteLine("Loading completed!"); … … 41 41 RegisterAlgorithmEventHandlers(algorithm); 42 42 algorithm.Start(); 43 // Since HeuristicLab 3.3.15 Start() is blocking 44 Console.WriteLine("Run is finished! Results are: "); 45 46 foreach (var s in algorithm.Results) { 47 Console.WriteLine(s.Name + ": " + s.Value); 48 } 49 DeregisterAlgorithmEventHandlers(algorithm); 43 50 } else { 44 51 Console.WriteLine("Unknown content in file: " + content.ToString()); … … 67 74 68 75 {{{#!csharp 69 private static void RegisterAlgorithmEventHandlers(EngineAlgorithm alg) {76 private static void RegisterAlgorithmEventHandlers(EngineAlgorithm alg) { 70 77 alg.ExecutionStateChanged += new EventHandler(alg_ExecutionStateChanged); 71 78 alg.ExecutionTimeChanged += new EventHandler(alg_ExecutionTimeChanged); 72 alg.Stopped += new EventHandler(alg_Stopped); 73 } 79 } 74 80 75 81 private static void DeregisterAlgorithmEventHandlers(EngineAlgorithm alg) { 76 82 alg.ExecutionStateChanged -= new EventHandler(alg_ExecutionStateChanged); 77 83 alg.ExecutionTimeChanged -= new EventHandler(alg_ExecutionTimeChanged); 78 alg.Stopped -= new EventHandler(alg_Stopped); 79 } 84 } 80 85 }}} 81 86 82 The stopped event is called when the algorithm has finished it's execution. In the event handler the results of the algorithm are queried and printed to the console. 87 Note that, before HeuristicLab 3.3.15 you had to additionally register the Stopped event to display the results as the Start() method was non-blocking. 83 88 84 89 {{{#!csharp 85 static void alg_Stopped(object sender, EventArgs e) {86 EngineAlgorithm alg = sender as EngineAlgorithm;87 Console.WriteLine("Run is finished! Results are: ");88 89 foreach (var s in alg.Results) {90 Console.WriteLine(s.Name + ": " + s.Value);91 }92 DeregisterAlgorithmEventHandlers(alg);93 }94 95 90 static void alg_ExecutionTimeChanged(object sender, EventArgs e) { 96 91 EngineAlgorithm alg = sender as EngineAlgorithm; … … 121 116 }}} 122 117 123 Note that in HeuristicLab 3.3 the Start() method is non-blocking. Thus, if there is no Console to wait for user input and delay the length of the execution, a WaitHandle such as an [https://msdn.microsoft.com/en-us/library/system.threading.autoresetevent(v=vs.110).aspx AutoResetEvent] has to be used.118 Note that in HeuristicLab 3.3.14 and earlier the Start() method was non-blocking and you have to use a WaitHandle such as an [https://msdn.microsoft.com/en-us/library/system.threading.autoresetevent(v=vs.110).aspx AutoResetEvent] to avoid terminating the application prematurely. 124 119 125 120