Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added generic GP with value types support #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyevolve/Consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@
# Util Consts
CDefBroadcastAddress = "255.255.255.255"
nodeType = {"TERMINAL" : 0, "NONTERMINAL": 1}
nodeValueType = [ "", "i", "b", "f", "s" ]
# [ default, int, bool, float, string ]
CDefValueType = 0

CDefGPGenomes = [GTreeGP]

Expand Down
5 changes: 4 additions & 1 deletion pyevolve/Crossovers.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,10 @@ def GTreeGPCrossoverSinglePoint(genome, **args):
if dadRandom.getType() == Consts.nodeType["TERMINAL"]:
momRandom = gMom.getRandomNode(1)
elif dadRandom.getType() == Consts.nodeType["NONTERMINAL"]:
momRandom = gMom.getRandomNode(2)
momRandom = gMom.getRandomNode(2, dadRandom.getOutType(), dadRandom.getInType())

if momRandom is None:
continue

mD = gMom.getNodeDepth(momRandom)
dD = gDad.getNodeDepth(dadRandom)
Expand Down
14 changes: 7 additions & 7 deletions pyevolve/DBAdapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import Statistics


class DBBaseAdapter:
class DBBaseAdapter(object):
""" DBBaseAdapter Class - The base class for all DB Adapters

If you want to create your own DB Adapter, you must subclass this
Expand Down Expand Up @@ -121,7 +121,7 @@ def __init__(self, filename=Consts.CDefCSVFileName, identify=None,
frequency = Consts.CDefCSVFileStatsGenFreq, reset=True):
""" The creator of DBFileCSV Class """

DBBaseAdapter.__init__(self, frequency, identify)
super(DBFileCSV, self).__init__(frequency, identify)

self.csvmod = None

Expand Down Expand Up @@ -211,7 +211,7 @@ def __init__(self, url, identify=None,
frequency = Consts.CDefURLPostStatsGenFreq, post=True):
""" The creator of the DBURLPost Class. """

DBBaseAdapter.__init__(self, frequency, identify)
super(DBURLPost, self).__init__(frequency, identify)
self.urllibmod = None

self.url = url
Expand Down Expand Up @@ -286,7 +286,7 @@ def __init__(self, dbname=Consts.CDefSQLiteDBName, identify=None, resetDB=False,
commit_freq=Consts.CDefSQLiteStatsCommitFreq):
""" The creator of the DBSQLite Class """

DBBaseAdapter.__init__(self, frequency, identify)
super(DBSQLite, self).__init__(frequency, identify)

self.sqlite3mod = None
self.connection = None
Expand Down Expand Up @@ -476,7 +476,7 @@ def insert(l):
def __init__(self, url, identify=None, frequency = Consts.CDefXMLRPCStatsGenFreq):
""" The creator of DBXMLRPC Class """

DBBaseAdapter.__init__(self, frequency, identify)
super(DBXMLRPC, self).__init__(frequency, identify)
self.xmlrpclibmod = None

self.url = url
Expand Down Expand Up @@ -538,7 +538,7 @@ class DBVPythonGraph(DBBaseAdapter):
"""

def __init__(self, identify=None, frequency = 20, genmax=False):
DBBaseAdapter.__init__(self, frequency, identify)
super(DBVPythonGraph, self).__init__(frequency, identify)
self.genmax = genmax
self.vtkGraph = None
self.curveMin = None
Expand Down Expand Up @@ -638,7 +638,7 @@ def __init__(self, user, passwd, host=Consts.CDefMySQLDBHost, port=Consts.CDefMy
frequency=Consts.CDefMySQLStatsGenFreq, commit_freq=Consts.CDefMySQLStatsCommitFreq):
""" The creator of the DBSQLite Class """

DBBaseAdapter.__init__(self, frequency, identify)
super(DBMySQLAdapter, self).__init__(frequency, identify)

self.mysqldbmod = None
self.connection = None
Expand Down
2 changes: 1 addition & 1 deletion pyevolve/FunctionSlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import Util

class FunctionSlot:
class FunctionSlot(object):
""" FunctionSlot Class - The function slot

Example:
Expand Down
42 changes: 4 additions & 38 deletions pyevolve/G1DBinaryString.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,26 @@
import Consts
import Util

class G1DBinaryString(GenomeBase, G1DBase):
class G1DBinaryString(G1DBase):
""" G1DBinaryString Class - The 1D Binary String chromosome

Inheritance diagram for :class:`G1DBinaryString.G1DBinaryString`:

.. inheritance-diagram:: G1DBinaryString.G1DBinaryString

This chromosome class extends the :class:`GenomeBase.GenomeBase`
and :class:`GenomeBase.G1DBase` classes.
This chromosome class extends the :class:`GenomeBase.G1DBase` class.

Example:
>>> genome = G1DBinaryString.G1DBinaryString(5)

:param length: the 1D Binary String size

"""

evaluator = None
""" This is the :term:`evaluation function` slot, you can add
a function with the *set* method: ::

genome.evaluator.set(eval_func)
"""

initializator = None
""" This is the initialization function of the genome, you
can change the default initializator using the function slot: ::

genome.initializator.set(Initializators.G1DBinaryStringInitializator)

In this example, the initializator :func:`Initializators.G1DBinaryStringInitializator`
will be used to create the initial population.
"""

mutator = None
""" This is the mutator function slot, you can change the default
mutator using the slot *set* function: ::

genome.mutator.set(Mutators.G1DBinaryStringMutatorSwap)

"""

crossover = None
""" This is the reproduction function slot, the crossover. You
can change the default crossover method using: ::

genome.crossover.set(Crossovers.G1DBinaryStringXUniform)
"""

__slots__ = [ "stringLength" ]

def __init__(self, length=10):
""" The initializator of G1DList representation """
GenomeBase.__init__(self)
G1DBase.__init__(self, length)
super(G1DBinaryString, self).__init__(length)
self.genomeList = []
self.stringLength = length
self.initializator.set(Consts.CDefG1DBinaryStringInit)
Expand Down
40 changes: 3 additions & 37 deletions pyevolve/G1DList.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
from GenomeBase import GenomeBase, G1DBase
import Consts

class G1DList(GenomeBase, G1DBase):
class G1DList(G1DBase):
""" G1DList Class - The 1D List chromosome representation

Inheritance diagram for :class:`G1DList.G1DList`:

.. inheritance-diagram:: G1DList.G1DList

This chromosome class extends the :class:`GenomeBase.GenomeBase`
and :class:`GenomeBase.G1DBase` classes.
This chromosome class extends the :class:`GenomeBase.G1DBase` classes.

**Examples**

Expand Down Expand Up @@ -104,43 +103,10 @@ class G1DList(GenomeBase, G1DBase):

"""

evaluator = None
""" This is the :term:`evaluation function` slot, you can add
a function with the *set* method: ::

genome.evaluator.set(eval_func)
"""

initializator = None
""" This is the initialization function of the genome, you
can change the default initializator using the function slot: ::

genome.initializator.set(Initializators.G1DListInitializatorAllele)

In this example, the initializator :func:`Initializators.G1DListInitializatorAllele`
will be used to create the initial population.
"""

mutator = None
""" This is the mutator function slot, you can change the default
mutator using the slot *set* function: ::

genome.mutator.set(Mutators.G1DListMutatorSwap)

"""

crossover = None
""" This is the reproduction function slot, the crossover. You
can change the default crossover method using: ::

genome.crossover.set(Crossovers.G1DListCrossoverUniform)
"""

def __init__(self, size=10, cloning=False):
""" The initializator of G1DList representation,
size parameter must be specified """
GenomeBase.__init__(self)
G1DBase.__init__(self, size)
super(G1DList, self).__init__(size)
if not cloning:
self.initializator.set(Consts.CDefG1DListInit)
self.mutator.set(Consts.CDefG1DListMutator)
Expand Down
36 changes: 2 additions & 34 deletions pyevolve/G2DBinaryString.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,12 @@ class G2DBinaryString(GenomeBase):
:param width: the number of columns

"""

evaluator = None
""" This is the :term:`evaluation function` slot, you can add
a function with the *set* method: ::

genome.evaluator.set(eval_func)
"""

initializator = None
""" This is the initialization function of the genome, you
can change the default initializator using the function slot: ::

genome.initializator.set(Initializators.G2DBinaryStringInitializator)

In this example, the initializator :func:`Initializators.G1DBinaryStringInitializator`
will be used to create the initial population.
"""

mutator = None
""" This is the mutator function slot, you can change the default
mutator using the slot *set* function: ::

genome.mutator.set(Mutators.G2DBinaryStringMutatorSwap)

"""

crossover = None
""" This is the reproduction function slot, the crossover. You
can change the default crossover method using: ::

genome.crossover.set(Crossovers.G2DBinaryStringXUniform)
"""

__slots__ = [ "height", "width", "genomeString" ]

def __init__(self, height, width):
""" The initializator of G2DBinaryString representation,
height and width must be specified """
GenomeBase.__init__(self)
super(G2DBinaryString ,self).__init__()
self.height = height
self.width = width

Expand Down
35 changes: 2 additions & 33 deletions pyevolve/G2DList.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,43 +85,12 @@ class G2DList(GenomeBase):
:param width: the number of columns

"""

evaluator = None
""" This is the :term:`evaluation function` slot, you can add
a function with the *set* method: ::

genome.evaluator.set(eval_func)
"""

initializator = None
""" This is the initialization function of the genome, you
can change the default initializator using the function slot: ::

genome.initializator.set(Initializators.G2DListInitializatorAllele)

In this example, the initializator :func:`Initializators.G2DListInitializatorAllele`
will be used to create the initial population.
"""

mutator = None
""" This is the mutator function slot, you can change the default
mutator using the slot *set* function: ::

genome.mutator.set(Mutators.G2DListMutatorIntegerGaussian)

"""

crossover = None
""" This is the reproduction function slot, the crossover. You
can change the default crossover method using: ::

genome.crossover.set(Crossovers.G2DListCrossoverSingleHPoint)
"""
__slots__ = [ "height", "width", "genomeList" ]

def __init__(self, height, width, cloning=False):
""" The initializator of G2DList representation,
height and width must be specified """
GenomeBase.__init__(self)
super(G2DList, self).__init__()
self.height = height
self.width = width

Expand Down
6 changes: 3 additions & 3 deletions pyevolve/GAllele.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class that holds the allele types) and all the
import Consts
import Util

class GAlleles:
class GAlleles(object):
""" GAlleles Class - The set of alleles

Example:
Expand Down Expand Up @@ -101,7 +101,7 @@ def __repr__(self):
return ret


class GAlleleList:
class GAlleleList(object):
""" GAlleleList Class - The list allele type

Example:
Expand Down Expand Up @@ -171,7 +171,7 @@ def __repr__(self):
ret += "\tAllele Options:\t %s\n\n" % (self.options,)
return ret

class GAlleleRange:
class GAlleleRange(object):
""" GAlleleRange Class - The range allele type

Example:
Expand Down
2 changes: 1 addition & 1 deletion pyevolve/GPopulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def multiprocessing_eval_full(ind):
return ind


class GPopulation:
class GPopulation(object):
""" GPopulation Class - The container for the population

**Examples**
Expand Down
Loading