Free cookie consent management tool by TermsFeed Policy Generator

Changes between Version 8 and Version 9 of Documentation/DevelopmentCenter/IntegrateHeuristicLab


Ignore:
Timestamp:
08/29/18 13:02:24 (6 years ago)
Author:
abeham
Comment:

Adapted because 3.3.15 provides non-blocking Start method

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/DevelopmentCenter/IntegrateHeuristicLab

    v8 v9  
    2323
    2424{{{#!csharp
    25 private static void LoadingCompleted(IStorableContent content, Exception error) {
     25    private static void LoadingCompleted(IStorableContent content, Exception error) {
    2626      if (error != null) throw error;
    2727      Console.WriteLine("Loading completed!");
     
    4141        RegisterAlgorithmEventHandlers(algorithm);
    4242        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);
    4350      } else {
    4451        Console.WriteLine("Unknown content in file: " + content.ToString());
     
    6774
    6875{{{#!csharp
    69 private static void RegisterAlgorithmEventHandlers(EngineAlgorithm alg) {
     76    private static void RegisterAlgorithmEventHandlers(EngineAlgorithm alg) {
    7077      alg.ExecutionStateChanged += new EventHandler(alg_ExecutionStateChanged);
    7178      alg.ExecutionTimeChanged += new EventHandler(alg_ExecutionTimeChanged);
    72       alg.Stopped += new EventHandler(alg_Stopped);
    73 }
     79    }
    7480
    7581    private static void DeregisterAlgorithmEventHandlers(EngineAlgorithm alg) {
    7682      alg.ExecutionStateChanged -= new EventHandler(alg_ExecutionStateChanged);
    7783      alg.ExecutionTimeChanged -= new EventHandler(alg_ExecutionTimeChanged);
    78       alg.Stopped -= new EventHandler(alg_Stopped);
    79 }
     84    }
    8085}}}
    8186
    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.
     87Note 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.
    8388
    8489{{{#!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 
    9590    static void alg_ExecutionTimeChanged(object sender, EventArgs e) {
    9691      EngineAlgorithm alg = sender as EngineAlgorithm;
     
    121116}}}
    122117
    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.
     118Note 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.
    124119
    125120