Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DEAP/deap
Browse files Browse the repository at this point in the history
  • Loading branch information
fmder committed Jul 20, 2023
2 parents 318f00f + a224b5d commit 3f8f09f
Show file tree
Hide file tree
Showing 27 changed files with 1,205 additions and 499 deletions.
File renamed without changes.
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'
56 changes: 0 additions & 56 deletions .travis.yml

This file was deleted.

88 changes: 88 additions & 0 deletions deap/base.py
Original file line number Diff line number Diff line change
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 3f8f09f

Please sign in to comment.