def __init__(self, size=10, cloning=False): """ The initializator of G1DList representation, size parameter must be specified """ GenomeBase.__init__(self) G1DBase.__init__(self, size) if not cloning: self.initializator.set(Consts.CDefG1DListInit) self.mutator.set(Consts.CDefG1DListMutator) self.crossover.set(Consts.CDefG1DListCrossover)
def __init__(self, length=10): """ The initializator of G1DList representation """ GenomeBase.__init__(self) G1DBase.__init__(self, length) self.genomeList = [] self.stringLength = length self.initializator.set(Consts.CDefG1DBinaryStringInit) self.mutator.set(Consts.CDefG1DBinaryStringMutator) self.crossover.set(Consts.CDefG1DBinaryStringCrossover)
def copy(self, g): """ Copy genome to 'g' Example: >>> genome_origin.copy(genome_destination) :param g: the destination G1DList instance """ GenomeBase.copy(self, g) G1DBase.copy(self, g)
def append(self, value): """ Appends an item to the list Example: >>> g = G1DBinaryString(2) >>> g.append(0) :param value: value to be added, 0 or 1 """ if value not in [0, 1]: Util.raiseException("The value must be 0 or 1", ValueError) G1DBase.append(self, value)
def __setitem__(self, key, value): """ Set the specified value for an gene of List >>> g = G1DBinaryString(5) >>> for i in xrange(len(g)): ... g.append(1) >>> g[4] = 0 >>> g[4] 0 """ if value not in (0, 1): Util.raiseException("The value must be zero (0) or one (1), used (%s)" % value, ValueError) G1DBase.__setitem__(self, key, value)
def copy(self, g): """ Copy genome to 'g' Example: >>> g1 = G1DBinaryString(2) >>> g1.append(0) >>> g1.append(1) >>> g2 = G1DBinaryString(2) >>> g1.copy(g2) >>> g2[1] 1 :param g: the destination genome """ GenomeBase.copy(self, g) G1DBase.copy(self, g)