Skip to content

Logging for debug purposes

supix edited this page May 1, 2017 · 2 revisions

NaturalShift is capable of printing log messages during genetic algoritm execution. Logging is managed through log4net library. The library is dynamically loaded when it is found on program startup, gracefully giving up when the library is not found (thanks to this project for the dynamic-library-loading).

Then, in order to enable logging, you have to deploy log4net assembly together with library and configure log4net according to the official documentation.

An an example, a simple console logging can be done by directly using the following line of code on program startup:

  log4net.Config.BasicConfigurator.Configure();

If you want to enable more sophisticated logging (e.g. on file, database, network, ecc.) with different logging levels, keep in mind that NaturalShift logging is always performed by classes living in the NaturalShift namespace.

Sample logging output

The following log trace has been captured by a computation using 4 threads and lasting 4 minutes.

167 [11] DEBUG NaturalShift.SolvingEnvironment.TheWorld (null) - Starting population.
168 [10] DEBUG NaturalShift.SolvingEnvironment.TheWorld (null) - Starting population.
168 [12] DEBUG NaturalShift.SolvingEnvironment.TheWorld (null) - Starting population.
167 [13] DEBUG NaturalShift.SolvingEnvironment.TheWorld (null) - Starting population.
726 [12] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.945733726024628. Average: 0.941992871761322
746 [13] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.946387767791748. Average: 0.942091158628464
1093 [10] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.946401596069336. Average: 0.94279080092907
1273 [12] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.946464240550995. Average: 0.943644763827324
1295 [13] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.947465658187866. Average: 0.943374216556549
1817 [12] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.947593629360199. Average: 0.9443956553936
2926 [12] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.947726666927338. Average: 0.946347246170044
[...]
29323 [13] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max epochs without fitness improvement reached. Evolution terminated.
29323 [13] DEBUG NaturalShift.SolvingEnvironment.SolutionBuilder (null) - Solution built in 0 ms
29323 [13] DEBUG NaturalShift.SolvingEnvironment.TheWorld (null) - Starting population.
29666 [12] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.952440083026886. Average: 0.952229953408241
30182 [12] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.952492535114288. Average: 0.952425566315651
30932 [12] DEBUG NaturalShift.SolvingEnvironment.MultiThreadedSolvingEnvironment (null) - Best fitness found: 0.952549397945404. Average: 0.952347710132599
31269 [11] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max epochs without fitness improvement reached. Evolution terminated.
31285 [11] DEBUG NaturalShift.SolvingEnvironment.SolutionBuilder (null) - Solution built in 0 ms
[...]
240156 [11] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max computation time reached. Evolution terminated.
240156 [11] DEBUG NaturalShift.SolvingEnvironment.SolutionBuilder (null) - Solution built in 0 ms
240171 [11] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max computation time reached. Evolution terminated.
240235 [10] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max computation time reached. Evolution terminated.
240251 [10] DEBUG NaturalShift.SolvingEnvironment.SolutionBuilder (null) - Solution built in 0 ms
240251 [10] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max computation time reached. Evolution terminated.
240298 [12] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max computation time reached. Evolution terminated.
240298 [13] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max computation time reached. Evolution terminated.
240298 [12] DEBUG NaturalShift.SolvingEnvironment.SolutionBuilder (null) - Solution built in 0 ms
240298 [12] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max computation time reached. Evolution terminated.
240298 [13] DEBUG NaturalShift.SolvingEnvironment.SolutionBuilder (null) - Solution built in 0 ms
240298 [13] DEBUG NaturalShift.SolvingEnvironment.ComputationTerminationManager (null) - Max computation time reached. Evolution terminated.

The log gives information about convergence trend of the genetic algoritm towards the solution. For example, you can see how much time is needed, on average, in order to have a good solution, preventing the engine to work longer uselessly.

Clone this wiki locally