#!/usr/bin/python3
import random
HUMAN_DNA_ELEMENTS = ["A","C","G","T"]

class SimpleGene:

    @staticmethod
    def clone_gene(g):
        return SimpleGene(g.dna, g.elements, g.name)

    # SimpleGene - is a Gene with only one DNA.
    # dna - an object.
    # elements - a set of element which is the basic component of dna.
    def __init__(self, dna, elements=HUMAN_DNA_ELEMENTS, name=""):
        assert dna is not None
        assert type(elements) == list
        self.__elements = elements
        self.__name = name
        self.dna = dna

    @property
    def dna(self):
        return self.__dna

    @dna.setter
    def dna(self, dna):
        assert dna is not None
        self.__dna = dna

    @property
    def dna_in_kernel(self):
        return self._elements.index(self.dna)

    @property
    def length(self):
        return 1

    @property
    def name(self):
        return self.__name

    @property
    def elements(self):
        return self.__elements

    @property
    def elements_in_kernel(self):
        return list(range(0, len(self.__elements)))

    @property
    def kernel_file(self):
        return "simple_gene.c"

    @property
    def elements_length(self):
        return len(self.__elements)

    @property
    def mutate_func_name(self):
        # Chromosome can use this function to execute built-in mutate function which choose an
        # excluded elments randomly.
        return "simple_gene_mutate"

    @property
    def elements_in_kernel_str(self):
        # Chromosome can use this function to declare elements array
        elements_str = ", ".join([str(v) for v in self.elements_in_kernel])
        return "{" + elements_str + "}\n"

    def from_kernel_value(self, v):
        assert v > -1 and v < len(self.__elements)
        return SimpleGene(self.__elements[v], self.__elements, self.__name)

@@ -126,16 +126,80 @@
 ene(g):%0A
+        # Clone a new gene containing the same dna symbol in g.%0A
         
@@ -290,16 +290,24 @@
  one DNA
+ element
 .%0A    # 
@@ -317,16 +317,44 @@
  - a
-n object
+ single element picked from elements
 .%0A  
@@ -919,32 +919,98 @@
 f length(self):%0A
+        # SimpleGene is designed to be only 1 dna element inside.%0A
         return 1
@@ -1037,32 +1037,70 @@
 def name(self):%0A
+        # The name of this SimpleGene%0A
         return s
@@ -1141,32 +1141,68 @@
 elements(self):%0A
+        # The list of dna elements.%0A
         return s
@@ -1371,76 +1371,324 @@
     
-return %22simple_gene.c%22%0A%0A    @property%0A    def elements_length(self):
+# Kernel file which contains related operating functions for SimpleGene,%0A        # i.e. simple_gene_mutate()%0A        return %22simple_gene.c%22%0A%0A    @property%0A    def elements_length(self):%0A        # The elements size of this SimpleGene.%0A        # Could be considered as the problem space represented by this SimpleGene.
 %0A   
@@ -2224,25 +2224,157 @@
     
-assert v %3E -1 and
+# Construct a SimpleGene object on system memory according to%0A        # the calculated index values 'v' on opencl(device) memory.%0A        assert 0 %3C=
  v %3C

Add more comments in simple_gene.py