Skip to content

Commit

Permalink
Merge branch 'fmder-azure-pipelines' into fmder-metacreator
Browse files Browse the repository at this point in the history
  • Loading branch information
fmder committed Jul 19, 2023
2 parents 5802673 + f04bfcb commit ef5be77
Show file tree
Hide file tree
Showing 26 changed files with 1,147 additions and 414 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.

2 changes: 1 addition & 1 deletion INSTALL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Options
Prefix
++++++

You might want to install this software somewhere else by addind the prefix options to the installation.
You might want to install this software somewhere else by adding the prefix options to the installation.

$ python setup.py install --prefix=somewhere/else

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ DEAP build status is available on Travis-CI https://travis-ci.org/DEAP/deap.
## Requirements
The most basic features of DEAP requires Python2.6. In order to combine the toolbox and the multiprocessing module Python2.7 is needed for its support to pickle partial functions. CMA-ES requires Numpy, and we recommend matplotlib for visualization of results as it is fully compatible with DEAP's API.

Since version 0.8, DEAP is compatible out of the box with Python 3.
Since version 0.8, DEAP is compatible out of the box with Python 3. The installation procedure automatically translates the source to Python 3 with 2to3, however this requires having `setuptools<=58`. It is recommended to use `pip install setuptools==57.5.0` to address this issue.

## Example

Expand Down
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 ef5be77

Please sign in to comment.