Exemple #1
0
    def execute(self, input_registers):
        """
        Execute code for each input
        """
        if len(self.instructions_without_introns_) == 0:
            self.instructions_without_introns_ = Program.remove_introns(self.instructions)
            self.inputs_list_ = self._inputs_list()
        instructions = self.instructions_without_introns_
        
        general_registers = [0] * Config.RESTRICTIONS['genotype_options']['total_registers']
        if_instruction = None
        skip_next = False
        for instruction in instructions:
            if if_instruction and not Operation.execute_if(if_instruction.op, if_instruction.target, if_instruction.source):
                if_instruction = None
                if instruction.op in Config.RESTRICTIONS['genotype_options']['if-instructions']:
                    skip_next = True
            elif skip_next:
                if instruction.op in Config.RESTRICTIONS['genotype_options']['if-instructions']:
                    skip_next = True
                else:
                    skip_next = False
            elif instruction.op in Config.RESTRICTIONS['genotype_options']['if-instructions']:
                if_instruction = instruction
            elif instruction.op in Config.RESTRICTIONS['genotype_options']['one-operand-instructions']:
                general_registers[instruction.target] = Operation.execute(instruction.op, general_registers[instruction.target])
            else:
                if instruction.mode == 'read-register':
                    source =  general_registers[instruction.source]
                else:
                    source =  input_registers[instruction.source]
                general_registers[instruction.target] = Operation.execute(instruction.op, general_registers[instruction.target], source)

        return general_registers[0] # get bid output
Exemple #2
0
    def execute(self, input_registers, force_reset=False):
        """
        Execute code for each input
        """
        if len(self.instructions_without_introns_) == 0:
            self.instructions_without_introns_ = Program.remove_introns(
                self.instructions)
            self.inputs_list_ = self._inputs_list()
        instructions = self.instructions_without_introns_
        if Config.USER['task'] == 'classification' or force_reset:
            self.reset_registers()

        if_instruction = None
        skip_next = False
        for instruction in instructions:
            if if_instruction and not Operation.execute_if(
                    if_instruction.op, if_instruction.target,
                    if_instruction.source):
                if_instruction = None
                if instruction.op in Config.RESTRICTIONS['genotype_options'][
                        'if-instructions']:
                    skip_next = True
            elif skip_next:
                if instruction.op in Config.RESTRICTIONS['genotype_options'][
                        'if-instructions']:
                    skip_next = True
                else:
                    skip_next = False
            elif instruction.op in Config.RESTRICTIONS['genotype_options'][
                    'if-instructions']:
                if_instruction = instruction
            elif instruction.op in Config.RESTRICTIONS['genotype_options'][
                    'one-operand-instructions']:
                self.general_registers_[
                    instruction.target] = Operation.execute(
                        instruction.op,
                        self.general_registers_[instruction.target])
            else:
                if instruction.mode == 'read-register':
                    source = self.general_registers_[instruction.source]
                else:
                    source = input_registers[instruction.source]
                self.general_registers_[
                    instruction.target] = Operation.execute(
                        instruction.op,
                        self.general_registers_[instruction.target], source)

        return self.general_registers_[0]  # get bid output
    def execute(self, input_registers, force_reset = False):
        """
        Execute code for each input
        """
        if len(self.instructions_without_introns_) == 0:
            self.instructions_without_introns_ = Program.remove_introns(self.instructions)
            self.inputs_list_ = self._inputs_list()
        instructions = self.instructions_without_introns_
        if Config.USER['task'] == 'classification' or force_reset:
            self.reset_registers()
        
        if_instruction = None
        skip_next = False
        for instruction in instructions:
            if if_instruction and not Operation.execute_if(if_instruction.op, if_instruction.target, 
                    if_instruction.source):
                if_instruction = None
                if instruction.op in Config.RESTRICTIONS['genotype_options']['if-instructions']:
                    skip_next = True
            elif skip_next:
                if instruction.op in Config.RESTRICTIONS['genotype_options']['if-instructions']:
                    skip_next = True
                else:
                    skip_next = False
            elif instruction.op in Config.RESTRICTIONS['genotype_options']['if-instructions']:
                if_instruction = instruction
            elif instruction.op in Config.RESTRICTIONS['genotype_options']['one-operand-instructions']:
                self.general_registers_[instruction.target] = Operation.execute(instruction.op, 
                    self.general_registers_[instruction.target])
            else:
                if instruction.mode == 'read-register':
                    source =  self.general_registers_[instruction.source]
                else:
                    source =  input_registers[instruction.source]
                self.general_registers_[instruction.target] = Operation.execute(instruction.op, 
                    self.general_registers_[instruction.target], source)

        return self.general_registers_[0] # get bid output