예제 #1
0
    def generate_genes_from_array_with_mut(self, array, rate):
        """
        Transform DNA sequence into a list of genes,
        plus a mutation.

        Args:
            array: DNA sequence.
            rate: mutation rate.
        """
        new_array = zip(*[iter(array)]*6)
        self.genes = []
        for chunk in new_array:
            g = gene()
            if random.uniform(0, 1) > rate:
                g.pos_1 = chunk[0]
                g.pos_2 = chunk[1]
                g.pos_3 = chunk[2]
                g.color['r'] = chunk[3]
                g.color['g'] = chunk[4]
                g.color['b'] = chunk[5]
            self.genes.append(g)
예제 #2
0
    def generate_genes_from_array_with_mut(self, array, rate):
        """
        Transform DNA sequence into a list of genes,
        plus a mutation.

        Args:
            array: DNA sequence.
            rate: mutation rate.
        """
        new_array = zip(*[iter(array)] * 6)
        self.genes = []
        for chunk in new_array:
            g = gene()
            if random.uniform(0, 1) > rate:
                g.pos_1 = chunk[0]
                g.pos_2 = chunk[1]
                g.pos_3 = chunk[2]
                g.color['r'] = chunk[3]
                g.color['g'] = chunk[4]
                g.color['b'] = chunk[5]
            self.genes.append(g)
예제 #3
0
    def __init__(self, parent_1=None, parent_2=None):
        """
        Inits an individual.
        If it has parents, generate its genes via crossover operation.
        If not, generate its genes randomly.

        Args:
            parent_1: a parent.
            parent_2: another parent.
        """
        self.genes = []
        op = genetic()
        if parent_1 and parent_2:
            array = op.crossover3(parent_1, parent_2, TRI_NUM)
            self.generate_genes_from_array_with_mut(array, MUT_RATE)
        else:
            for i in xrange(TRI_NUM):
                self.genes.append(gene())
        # set actual image
        self.im = self.get_current_img()
        # calculate fitness
        self.fitness = self.get_fitness(TARGET)
예제 #4
0
    def __init__(self, parent_1=None, parent_2=None):
        """
        Inits an individual.
        If it has parents, generate its genes via crossover operation.
        If not, generate its genes randomly.

        Args:
            parent_1: a parent.
            parent_2: another parent.
        """
        self.genes = []
        op = genetic()
        if parent_1 and parent_2:
            array = op.crossover3(parent_1, parent_2, TRI_NUM)
            self.generate_genes_from_array_with_mut(array, MUT_RATE)
        else:
            for i in xrange(TRI_NUM):
                self.genes.append(gene())
        # set actual image
        self.im = self.get_current_img()
        # calculate fitness
        self.fitness = self.get_fitness(TARGET)
예제 #5
0
파일: LENAJUNO.py 프로젝트: iljabek/genetic
def getBeam():
	"Genome prototype"
	beam = []
	#Date Scan Chunk Stat PEnergy PowOpt Pow Mat TarDiam TarLen TarDist Cur1 Cur2 TunRad TunLen PosFoc BinN BinMin BinMax Fitness
	beam.append( genetic.gene("PEnergy", [     1,   100,  1.0    ]        ) )#0 GeV
	beam.append( genetic.gene("Pow",     [   0.2,     5,  0.2    ]        ) )#1 MW
	beam.append( genetic.gene("Mat",     ("myGraphite","myBeryllium","Water","quartz","Tungsten")) )
	beam.append( genetic.gene("TarDiam", [     1,    10,  0.5    ]        ) )#5 mm
	beam.append( genetic.gene("TarLen",  [    20,   200,  1.0    ]        ) )#4 cm
	beam.append( genetic.gene("TarDist", [ 13963, 14063,  1.0    ]        ) )#6 cm
	beam.append( genetic.gene("Cur1",    [ 100e3, 350e3, 10.e3   ]        ) )#7 A
	beam.append( genetic.gene("Cur2",    [ 100e3, 350e3, 10.e3   ]        ) )#8 A
	beam.append( genetic.gene("TunRad",  [    50,   500, 10.0    ]        ) )#3 cm
	beam.append( genetic.gene("TunLen",  [    10,   500, 10.0    ]        ) )#2 m
	beam.append( genetic.gene("PosFoc",  [     1,     9,  1      ]        ) )#9 y
	return beam