Exemplo n.º 1
0
    def __init__(self,
                 dimension,
                 population,
                 passes_filename,
                 goals,
                 compiler,
                 benchmarks_directory,
                 working_set,
                 times,
                 tool,
                 verify_output):
        """Initialize the arguments.

        Arguments
        ----------
        dimension : int
            The length of a sequence.

        population : int

        passes_filename : str
            The file that describes the passes to use.

        goals : dict

        compiler : str

        benchmarks_directory : str

        working_set : int
            The dataset to execute the benchmark.

        times: int
            Execution times

        tool: str
            Execution tool

        verify_output: bool
            The goal is valid only if the execution status is OK.
        """
        first_key, last_key, passes_dict = IO.load_passes(passes_filename)

        # When the goal is obtained during compile time
        # and the dataset is not defined during compilation,
        # we do not need the dataset.
        self.__flags = self.PygmoFlags(first_key,
                                       last_key,
                                       passes_dict,
                                       dimension,
                                       population,
                                       goals,
                                       compiler,
                                       benchmarks_directory,
                                       working_set,
                                       times,
                                       tool,
                                       verify_output)
    def create_random_sequences(nof_sequences, minimum, maximum, factor, ssa,
                                shuffle, update_, repetition, original,
                                passes_filename):
        """Create N random sequences.

        Arguments
        ----------
        nof_sequences : int
            The number of sequences.

        minimum : int
            The minimum and maximum length of the sequence.

        maximum : int
            The maximum length of the sequence.

        factor : int
            The times to appy to nof_sequences. (nof_sequences *= factor)

        ssa : bool
            Enable ssa?

        shuffle : bool
            Enable shuffle?

        update : bool
            Enable update?

        repetition : bool
            Enable repetition?

        original : bool
            Insert the orginal?

        passes_filename : str
            The yaml filename which describes the available passes.

        Return
        ------
        sequences : dict
            A dictionary which contains N random sequences.
        """
        if (not repetition) and (maximum > (maximum * 0.7)):
            lg.error('adjust MAXIMUM lenght. MAXIMUM \
            should be less than 70% of |PASSES|')
            sys.exit(1)
        if not (original or update_ or shuffle):
            lg.error('Error: it is necessary to use at \
            least one argument (-original, -update, -shuffle)')
            sys.exit(1)

        # Load the passes
        first_key, last_key, passes = IO.load_passes(passes_filename)
        counter = 0
        sequences = {}
        nof_sequences *= factor

        while True:
            # generate a sequence
            seq = Sequence.create_random_sequence(first_key, last_key, passes,
                                                  minimum, maximum, repetition)
            seq = Sequence.sanitize(seq)

            if ssa:
                seq = Sequence.mem2reg_first(seq)

            if original:
                if not Sequence.exist(seq, sequences):
                    sequences[counter] = {'seq': seq}
                    counter += 1
                    if counter >= nof_sequences:
                        break
                if shuffle:
                    sseq = seq[:]
                    rn.shuffle(sseq)
                    sseq = Sequence.sanitize(sseq)
                    if not Sequence.exist(sseq, sequences):
                        sequences[counter] = {'seq': sseq}
                        counter += 1
                        if counter >= nof_sequences:
                            break
            if update_:
                seq = Sequence.update(seq)
                seq = Sequence.sanitize(seq)

                if not Sequence.exist(seq, sequences):
                    sequences[counter] = {'seq': seq}
                    counter += 1
                    if counter >= nof_sequences:
                        break

                if shuffle:
                    seq = Sequence.update(seq)
                    seq = Sequence.sanitize(seq)
                    if not Sequence.exist(seq, sequences):
                        sequences[counter] = {'seq': seq}
                        counter += 1
                        if counter >= nof_sequences:
                            break

        return sequences