From 77c115e4c76d3cae6949e7b477c68041aff57639 Mon Sep 17 00:00:00 2001 From: yushikmr Date: Sat, 12 Dec 2020 21:55:43 +0900 Subject: [PATCH 1/7] add a crossover function, 'cxBlendBounded' --- deap/tools/crossover.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/deap/tools/crossover.py b/deap/tools/crossover.py index e64d02deb..859803164 100644 --- a/deap/tools/crossover.py +++ b/deap/tools/crossover.py @@ -259,6 +259,45 @@ def cxBlend(ind1, ind2, alpha): return ind1, ind2 +def cxBlendBounded(ind1, ind2, low, up, alpha): + """Executes a blend crossover that modify in-place the input individuals. + The blend crossover expects :term:`sequence` individuals of floating point + numbers. + + :param ind1: The first individual participating in the crossover. + :param ind2: The second individual participating in the crossover. + :param low: A value or a :term:`python:sequence` of values that is the lower + bound of the search space. + :param up: A value or a :term:`python:sequence` of values that is the upper + bound of the search space. + :param alpha: Extent of the interval in which the new values can be drawn + for each attribute on both side of the parents' attributes. + :returns: A tuple of two individuals. + + This function uses the :func:`~random.random` function from the python base + :mod:`random` module. + """ + + size = min(len(ind1), len(ind2)) + if not isinstance(low, Sequence): + low = repeat(low, size) + elif len(low) < size: + raise IndexError("low must be at least the size of the shorter individual: %d < %d" % (len(low), size)) + if not isinstance(up, Sequence): + up = repeat(up, size) + elif len(up) < size: + raise IndexError("up must be at least the size of the shorter individual: %d < %d" % (len(up), size)) + + for i, (x1, x2, xl, xu) in enumerate(zip(ind1, ind2, low, up)): + gamma = (1. + 2. * alpha) * random.random() - alpha + c1 = (1. - gamma) * x1 + gamma * x2 + c2 = gamma * x1 + (1. - gamma) * x2 + + ind1[i] = min(max(c1, xl), xu) + ind2[i] = min(max(c2, xl), xu) + + return ind1, ind2 + def cxSimulatedBinary(ind1, ind2, eta): """Executes a simulated binary crossover that modify in-place the input @@ -455,7 +494,7 @@ def cxESTwoPoints(ind1, ind2): # List of exported function names. __all__ = ['cxOnePoint', 'cxTwoPoint', 'cxUniform', 'cxPartialyMatched', - 'cxUniformPartialyMatched', 'cxOrdered', 'cxBlend', + 'cxUniformPartialyMatched', 'cxOrdered', 'cxBlend', "cxBlendBounded", 'cxSimulatedBinary', 'cxSimulatedBinaryBounded', 'cxMessyOnePoint', 'cxESBlend', 'cxESTwoPoint'] From e0d5cf0a037dee7af5f09f75e8fead7919ddd296 Mon Sep 17 00:00:00 2001 From: yushikmr Date: Sat, 12 Dec 2020 22:47:08 +0900 Subject: [PATCH 2/7] =?UTF-8?q?add=20cxBlendBounded=20docstring=20to=20Ope?= =?UTF-8?q?rators=C2=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/api/tools.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/api/tools.rst b/doc/api/tools.rst index 9bca2db62..b72ced981 100644 --- a/doc/api/tools.rst +++ b/doc/api/tools.rst @@ -27,6 +27,7 @@ Here is a list of the implemented operators in DEAP, .. :func:`cxUniformPartialyMatched` :func:`mutUniformInt` :func:`selSPEA2` .. .. :func:`cxOrdered` :func:`mutESLogNormal` :func:`selRandom` .. .. :func:`cxBlend` .. :func:`selBest` .. + .. :func:`cxBlendBounded` .. .. :func:`cxESBlend` .. :func:`selWorst` .. .. :func:`cxESTwoPoint` .. :func:`selTournamentDCD` .. .. :func:`cxSimulatedBinary` .. :func:`selDoubleTournament` .. @@ -86,6 +87,8 @@ Crossover .. autofunction:: deap.tools.cxBlend +.. autofunction:: deap.tools.cxBlendBounded + .. autofunction:: deap.tools.cxESBlend .. autofunction:: deap.tools.cxESTwoPoint From 077e1b86d36f1e0dea31a1828533eacc209397a5 Mon Sep 17 00:00:00 2001 From: yushikmr Date: Sun, 13 Dec 2020 00:44:31 +0900 Subject: [PATCH 3/7] add python3.8 to travis ci --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 10514ea0f..2c11dff18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,9 @@ matrix: - python: "3.7" dist: xenial env: NUMPY=numpy - - python: "pypy" - env: NUMPY="git+https://bitbucket.org/pypy/numpy.git" + - python: "3.8" + dist: xenial + env: NUMPY=numpy addons: apt: packages: @@ -46,7 +47,7 @@ install: - pip install $NUMPY # command to run tests script: - - python setup.py nosetests --verbosity=3 --with-doctest + - pytest notifications: webhooks: urls: From 690b4d39b4a8a7bb1673dc19a6fe0af6356ef723 Mon Sep 17 00:00:00 2001 From: yushikmr Date: Sun, 13 Dec 2020 00:57:00 +0900 Subject: [PATCH 4/7] Revert "add python3.8 to travis ci" This reverts commit 077e1b86d36f1e0dea31a1828533eacc209397a5. --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2c11dff18..10514ea0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,8 @@ matrix: - python: "3.7" dist: xenial env: NUMPY=numpy - - python: "3.8" - dist: xenial - env: NUMPY=numpy + - python: "pypy" + env: NUMPY="git+https://bitbucket.org/pypy/numpy.git" addons: apt: packages: @@ -47,7 +46,7 @@ install: - pip install $NUMPY # command to run tests script: - - pytest + - python setup.py nosetests --verbosity=3 --with-doctest notifications: webhooks: urls: From 225e802c4b0621eb16ddc76030920049fa15d01e Mon Sep 17 00:00:00 2001 From: yushikmr Date: Sun, 13 Dec 2020 01:01:10 +0900 Subject: [PATCH 5/7] Abolition of pypy and addition of python3.8 --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 10514ea0f..9a18663f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,9 @@ matrix: - python: "3.7" dist: xenial env: NUMPY=numpy - - python: "pypy" - env: NUMPY="git+https://bitbucket.org/pypy/numpy.git" + - python: "3.8" + dist: xenial + env: NUMPY=numpy addons: apt: packages: @@ -46,7 +47,7 @@ install: - pip install $NUMPY # command to run tests script: - - python setup.py nosetests --verbosity=3 --with-doctest + - pytest notifications: webhooks: urls: From 8439263f0c8d7f87b9fd67023764781f85fc0d70 Mon Sep 17 00:00:00 2001 From: yushikmr Date: Sun, 13 Dec 2020 01:48:51 +0900 Subject: [PATCH 6/7] Revert "Abolition of pypy and addition of python3.8" This reverts commit 225e802c4b0621eb16ddc76030920049fa15d01e. --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9a18663f6..10514ea0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,8 @@ matrix: - python: "3.7" dist: xenial env: NUMPY=numpy - - python: "3.8" - dist: xenial - env: NUMPY=numpy + - python: "pypy" + env: NUMPY="git+https://bitbucket.org/pypy/numpy.git" addons: apt: packages: @@ -47,7 +46,7 @@ install: - pip install $NUMPY # command to run tests script: - - pytest + - python setup.py nosetests --verbosity=3 --with-doctest notifications: webhooks: urls: From b6f2d13354d9e6b1a29f8732688258dbf464a63b Mon Sep 17 00:00:00 2001 From: yushikmr Date: Sun, 13 Dec 2020 01:50:19 +0900 Subject: [PATCH 7/7] Abolition of pypy and addition of python3.8 --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 10514ea0f..ec6e95156 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,9 @@ matrix: - python: "3.7" dist: xenial env: NUMPY=numpy - - python: "pypy" - env: NUMPY="git+https://bitbucket.org/pypy/numpy.git" + - python: "3.8" + dist: xenial + env: NUMPY=numpy addons: apt: packages: