Skip to content

Commit

Permalink
Merge branch 'master' into keszybz-doc-build
Browse files Browse the repository at this point in the history
  • Loading branch information
fmder committed Jul 23, 2023
2 parents 8320b2a + 6b63e7a commit 9e0095c
Show file tree
Hide file tree
Showing 53 changed files with 1,639 additions and 881 deletions.
34 changes: 0 additions & 34 deletions azure-pipelines.yml → .azure-pipelines/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,6 @@ jobs:
twine upload -r pypi -u $(twineUsername) -p $(twinePassword) --skip-existing --disable-progress-bar dist/*
displayName: 'Publish wheel to PyPi'
- job: macOS10_15Build
pool:
vmImage: 'macOS-10.15'
strategy:
matrix:
Python36:
python.version: '3.6'
Python37:
python.version: '3.7'
Python38:
python.version: '3.8'
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'
- script: |
python -m pip install --upgrade pip
pip install numpy
displayName: 'Install dependencies'
- script: |
pip install wheel twine
displayName: 'Install build tools'
- script: |
python setup.py sdist bdist_wheel
displayName: 'Build wheel'
- script: |
twine upload -r pypi -u $(twineUsername) -p $(twinePassword) --skip-existing --disable-progress-bar dist/*
displayName: 'Publish wheel to PyPi'
- job: macOS11Build
pool:
vmImage: 'macOS-11'
Expand Down
48 changes: 48 additions & 0 deletions .azure-pipelines/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
trigger:
- master
- dev

jobs:
- job: 'Tests'
pool:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
python -m pip install --upgrade pip wheel
displayName: 'Install build tools'
- script: |
pip install .
displayName: 'Install library'
- script: |
pip install pytest pytest-azurepipelines pytest-cov
pytest .
displayName: 'Run tests'
# - job: 'Lint'
# pool:
# vmImage: 'ubuntu-latest'
# steps:
# - task: UsePythonVersion@0
# inputs:
# versionSpec: '3.9'

# - script: |
# pip install flake8
# flake8 .
# displayName: 'Run linting'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ doc/_build/
.pytest_cache/
__pycache__/
env/
venv/
*.egg-info/

# files to ignore
Expand Down
56 changes: 0 additions & 56 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include *.md
recursive-include deap *.cpp *.c *.hpp *.h
recursive-include examples *.py *.csv *.json *.txt *.cpp *.hpp *.h
recursive-include doc *
recursive-include tests *
prune doc/_build
global-exclude .DS_Store
global-exclude *.pyc
4 changes: 2 additions & 2 deletions deap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# You should have received a copy of the GNU Lesser General Public
# License along with DEAP. If not, see <http://www.gnu.org/licenses/>.
__author__ = "DEAP Team"
__version__ = "1.3"
__revision__ = "1.3.3"
__version__ = "1.4"
__revision__ = "1.4.1"
98 changes: 93 additions & 5 deletions deap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ def setValues(self, values):
except TypeError:
_, _, traceback = sys.exc_info()
raise TypeError("Both weights and assigned values must be a "
"sequence of numbers when assigning to values of "
"%r. Currently assigning value(s) %r of %r to a "
"fitness with weights %s."
% (self.__class__, values, type(values),
self.weights)).with_traceback(traceback)
"sequence of numbers when assigning to values of "
"%r. Currently assigning value(s) %r of %r to a "
"fitness with weights %s."
% (self.__class__, values, type(values),
self.weights)).with_traceback(traceback)

def delValues(self):
self.wvalues = ()
Expand Down Expand Up @@ -268,3 +268,91 @@ def __repr__(self):
"""Return the Python code to build a copy of the object."""
return "%s.%s(%r)" % (self.__module__, self.__class__.__name__,
self.values if self.valid else tuple())


def _violates_constraint(fitness):
return not fitness.valid \
and fitness.constraint_violation is not None \
and sum(fitness.constraint_violation) > 0


class ConstrainedFitness(Fitness):
def __init__(self, values=(), constraint_violation=None):
super(ConstrainedFitness, self).__init__(values)
self.constraint_violation = constraint_violation

@Fitness.values.deleter
def values(self):
self.wvalues = ()
self.constraint_violation = None

def __gt__(self, other):
return not self.__le__(other)

def __ge__(self, other):
return not self.__lt__(other)

def __le__(self, other):
self_violates_constraints = _violates_constraint(self)
other_violates_constraints = _violates_constraint(other)

if self_violates_constraints and other_violates_constraints:
return True
elif self_violates_constraints:
return True
elif other_violates_constraints:
return False

return self.wvalues <= other.wvalues

def __lt__(self, other):
self_violates_constraints = _violates_constraint(self)
other_violates_constraints = _violates_constraint(other)

if self_violates_constraints and other_violates_constraints:
return False
elif self_violates_constraints:
return True
elif other_violates_constraints:
return False

return self.wvalues < other.wvalues

def __eq__(self, other):
self_violates_constraints = _violates_constraint(self)
other_violates_constraints = _violates_constraint(other)

if self_violates_constraints and other_violates_constraints:
return True
elif self_violates_constraints:
return False
elif other_violates_constraints:
return False

return self.wvalues == other.wvalues

def __ne__(self, other):
return not self.__eq__(other)

def dominates(self, other):
self_violates_constraints = _violates_constraint(self)
other_violates_constraints = _violates_constraint(other)

if self_violates_constraints and other_violates_constraints:
return False
elif self_violates_constraints:
return False
elif other_violates_constraints:
return True

return super(ConstrainedFitness, self).dominates(other)

def __str__(self):
"""Return the values of the Fitness object."""
return str((self.values if self.valid else tuple(), self.constraint_violation))

def __repr__(self):
"""Return the Python code to build a copy of the object."""
return "%s.%s(%r, %r)" % (self.__module__, self.__class__.__name__,
self.values if self.valid else tuple(),
self.constraint_violation)
Loading

0 comments on commit 9e0095c

Please sign in to comment.