def mutate(self):
        m = random.randint(0,7)
        i = random.randint(0,len(self.elements)-1)
        if m==0:
            #Change value of one component
            m = random.randint(0,1)
            if m==0:
                #New value
                self.elements[i] = mutate_value(self.elements[i],self.parts_list)
            else:
                #Slight change
                self.elements[i] = mutate_value(self.elements[i],self.parts_list,rel_amount=0.1)
        elif m==1:
            #Add one component if not already maximum number of components
            if len(self.elements)<self.max_parts:
                #self.elements.append(random_element(self.parts_list,self.nodes))
                self.elements.append(random_element(self.parts_list,self.nodes,fixed_node=self.get_connected_node()))
        elif m==2 and len(self.elements)>1:
            #Replace one component with open circuit
            del self.elements[i]
        elif m==3 and len(self.elements)>1:
            #Replace one component with open circuit
            nodes = self.elements[i].nodes
            random.shuffle(nodes)
            try:
                n1 = nodes[0]
                n2 = nodes[1]
            except __HOLE__:
                return None#Device doesn't have two nodes
            del self.elements[i]
            for element in self.elements:
                element.nodes = [(n1 if i==n2 else i) for i in element.nodes]
        elif m==4:
            #Replace one component keeping one node connected
            fixed_node = random.choice(self.elements[i].nodes)
            del self.elements[i]
            self.elements.append(random_element(self.parts_list,self.nodes,fixed_node=fixed_node))
        elif m==5:
            #Shuffle list of elements(better crossovers)
            random.shuffle(self.elements)
        elif m==6:
            #Change the extra_value
            if self.extra_range!=None:
                i = random.randint(0,len(self.extra_value)-1)
                self.extra_value[i] = random.uniform(*self.extra_range[i])
            else:
                self.mutate()
        elif m==7:
            #Relabel nodes
            l = len(self.elements)-1
            n1 = random.choice(self.elements[random.randint(0,l)].nodes)
            n2 = random.choice(self.elements[random.randint(0,l)].nodes)
            tries = 0
            while tries<10 or n1!=n2:
                n2 = random.choice(self.elements[random.randint(0,l)].nodes)
                tries+=1
            for element in self.elements:
                element.nodes = [(n1 if i==n2 else (n2 if i==n1 else i)) for i in element.nodes]
dataset/ETHPy150Open Ttl/evolutionary-circuits/evolutionary/chromosomes/netlist.py/Chromosome.mutate