0

I have just started to use the DEAP package in python. Following the tutorial, I can't understand this statement:

toolbox.register("cross",tools.cxTwoPoint)

I understand that tools.cxTwoPoint is to call the cxTwoPoint function. However, I checked the source code, the cxTwoPoint function is not within tools module, and it is a defined function within crossover.py. Also, I didn't find any statement in tools.py which may relate to crossover.py or cxTwoPoint.

Can someone help me? Many many thanks!!!

Zhida Deng
  • 189
  • 2
  • 12
  • It is in deap.tools.mutation. Which gets importet into the deap.tools namespace. (https://github.com/DEAP/deap/blob/master/deap/tools/mutation.py) – Ohjeah Jun 16 '17 at 20:27
  • Thanks for your information. And I also wonder there is a `tools.py` in benchmark folder. – Zhida Deng Jun 17 '17 at 20:55

1 Answers1

0

The tools.py is used for benchmarking the algorithm. As we can seen from __init__.py, there is a statement from .crossover import * which means import all of the functions in the crossover module where located same directory as __init__.py. This gives you a easy way to access these functions in other files. And __init__.py are required to make Python trent the directories as containing packages as answered in:What is __init__.py for?.

Zhida Deng
  • 189
  • 2
  • 12