Example #1
0
 def test_load_from_file(self):
     data.load_from_file("data_2.0.xml")
     self.assertEqual(
             data.get_callback("googleKeyboard", "keyboard", "A_DOWN"),
             ["touch", "DOWN_AND_UP", "300", "680"])
     self.assertEqual(
             data.get_callback("default", "alias", "click"),
             [["touch", "DOWN", ["arg", "1"], ["arg", "2"]],
                 ["sleep", "0.1"],
                 ["touch", "UP", ["arg", "1"], ["arg", "2"]]
                 ])
Example #2
0
def generate_data(path, tokenizer, char_vcb, word_vcb, is_training=False):
    '''
    Generate data
    '''
    global root_path
    qp_pairs = data.load_from_file(path=path, is_training=is_training)

    tokenized_sent = 0
    # qp_pairs = qp_pairs[:1000]1
    for qp_pair in qp_pairs:
        tokenized_sent += 1
        data.tokenize(qp_pair, tokenizer, is_training)
        for word in qp_pair['question_tokens']:
            word_vcb.add(word['word'])
            for char in word['word']:
                char_vcb.add(char)
        for word in qp_pair['passage_tokens']:
            word_vcb.add(word['word'])
            for char in word['word']:
                char_vcb.add(char)

    max_query_length = max(len(x['question_tokens']) for x in qp_pairs)
    max_passage_length = max(len(x['passage_tokens']) for x in qp_pairs)
    #min_passage_length = min(len(x['passage_tokens']) for x in qp_pairs)
    cfg.max_query_length = max_query_length
    cfg.max_passage_length = max_passage_length

    return qp_pairs
Example #3
0
def multifit(file=None, taxrate=10, verbose=False):
    """ Executa todas Heurísticas com a lista de objetos definidos, utilizando o
    valor da taxa definida, e retorna o melhor variante do algorítimo
    """
    my_items = load_from_file(file)

    if verbose:  #imprime alguns detalhes, caso verboso
        totalitemvalue, totalitemsize = 0, 0
        for i in my_items:
            totalitemvalue += i.value
            totalitemsize += i.size
        print("Itens: Valor: " + str(totalitemvalue) + " Tamanho:" +
              str(totalitemsize) + " Taxa: " + str(taxrate))

    fit_option = ['first', 'best', 'worst',
                  'avoidtaxes']  #todas as opções de heuristicas do fit
    sort_option = [True, False, 'cheapest',
                   'expensive']  #todas as opções de ordenação do fit

    results = []  #lista dos resultados

    for f in fit_option:  #para cada heuristica
        for s in sort_option:  #para cada ordenação
            mybox = fit(my_items, fit=f, sortedlist=s,
                        verbose=False)  #executa a heuristica
            res = Result(list_of_boxes=mybox, fit_order=f,sort_order=s, \
                         profit=calc_profit(mybox,taxrate),box_amount=len(mybox)) #salva o resultado em um objeto Result
            results.append(res)  # e coloca na lista de resultados

    results = sorted(
        results, key=attrgetter('profit'),
        reverse=True)  #as melhores resultados são colocadas no topo da lista
    finalresult = results[0]  #o melhor resultado é o primeiro
    if verbose:
        for x in results:
            x.print_result_h()  #se verboso, imprime o resultado
    return finalresult  #retorna o melhor resultado
Example #4
0
def stresstest(itemgen=None, file=None, taxrate=False):

    if itemgen == 'normal':
        my_items = generate_item_list(amount=100, max_size=1000, max_value=100)
    elif itemgen == 'pareto':
        my_items = generate_pareto_list(amount=100,
                                        medium_size=400,
                                        medium_value=50,
                                        max_size=1000,
                                        max_value=100)
    else:
        my_items = load_from_file(file)
    totalitemvalue, totalitemsize = 0, 0
    for i in my_items:
        totalitemvalue += i.value
        totalitemsize += i.size
    print(str(totalitemsize) + ' ' + str(totalitemvalue))

    testtaxrate = taxrate if taxrate else [0, 10, 20, 30, 40, 50, 60]
    fit_option = ['first', 'best', 'worst', 'avoidtaxes']
    sort_option = [True, False, 'cheapest', 'expensive']

    for t in testtaxrate:
        results = {}
        print("TAX RATE: " + str(t), end=' ')
        for f in fit_option:
            for s in sort_option:
                mybox = fit(my_items, fit=f, sortedlist=s, verbose=False)
                l = len(mybox)
                # n = fit_option.index(f) + (sort_option.index(s)*10)
                # mysum = 0
                # for x in mybox: mysum += x.used_size # rint(x.used_size, end=' ')

                results[f, s, l] = calc_profit(mybox, t)
        for k, v in sorted(results.items(), key=itemgetter(1), reverse=True):
            print(str(k), str(v))
            break