Exemplo n.º 1
0
def search(b: board):
    stack = []
    stack.append([b])
    explored = set()

    while True:
        if len(stack) == 0:
            print(-1, len(explored))
            return
        else:
            level_nodes = stack.pop()
            for current_node in level_nodes:
                moves = current_node.getPossibleMoves()
                current_node.fboxes = frozenset(current_node.boxes)
                explored.add(hash(current_node))

                deep_level = []

                for move in moves:
                    child = deepcopy(current_node)
                    child.move(move)
                    if hash(child) not in explored:
                        if child.is_win():
                            utils.print_output(child.path, len(explored),
                                               child.box_moves,
                                               "Iterative Deepening")
                            return
                        deep_level.append(child)

                stack.append(deep_level)
Exemplo n.º 2
0
 def run(self):
     """
     :return:
     """
     i = 0
     while i < self.count:
         line = self.queue.get(True)
         if line:
             print '[%d]' % (i + 1, ),
             utils.print_output(line)
             i += 1
         self.queue.task_done()
Exemplo n.º 3
0
def main(args):
    # Read configuration file
    conf = configreader.parse(args.config)
    if not conf:
        sys.exit(1)
    
    # Get list of fields
    if args.fields:
        fields = args.fields.split(',')
    else:
        try:
            fields = conf['default']['fields'].split(',')
        except Exception as e:
            logger.error(f'Config missing `fields` in [default] section!')
            logger.exception(e)
            sys.exit(2)
    
    # Get github config for auth
    try:
        if conf['github']['token']:
            headers = {
                'Authorization': f'token {conf["github"]["token"]}',
                'Accept': 'application/json'
            }
    except Exception as e:
        logger.error(f'Config missing `token` in [github] section')
        logger.exception(e)
        sys.exit(2)
    
    # Assemble the data
    org = args.repository
    data = []
    if args.repository:
        data = [handle_repository(args.repository, headers, fields, args.nolanguages)]
    elif args.organization:
        org = args.organization
        data = handle_organization(args.organization, headers, fields, args.nolanguages)
    elif args.user:
        org = args.user
        data = handle_organization(args.user, headers, fields, args.nolanguages, user_repos=True)
    else:
        print("Yay.... No work to do!")
        print("To exercise me specify either repository or organization to scan.")
        return
    
    if data:
        # Output the data
        print_output(data, fields, args.mode, org)
    
        # Analyze the data
        print(json.dumps(get_stats(get_csv_data_as_file(data, fields), org), indent=4))
Exemplo n.º 4
0
def printer(r_name, r_count, r_queue, lock):
    """

    :param r_name:
    :param r_count:
    :param r_queue:
    :return:
    """
    i = 0
    while i < r_count:
        line = r_queue.get(True)
        if line:
            lock.acquire()
            print '[%d]' % (i + 1,),
            utils.print_output(line)
            lock.release()
            i += 1
        r_queue.task_done()
Exemplo n.º 5
0
def search(b: board):
    q = Queue()
    q.put(b)
    explored = set()

    while True:
        if q.empty():
            print(-1, len(explored))
            return
        else:
            current_node = q.get()
            moves = current_node.getPossibleMoves()
            current_node.fboxes = frozenset(current_node.boxes)
            explored.add(hash(current_node))

            for move in moves:
                child = deepcopy(current_node)
                child.move(move)
                if hash(child) not in explored:
                    if child.is_win():
                        utils.print_output(child.path, len(explored),
                                           child.box_moves, "BFS")
                        return
                    q.put(child)
Exemplo n.º 6
0
def search(b: board):
    board_list = [b]
    explored = set()
    while True:
        if len(board_list) == 0:
            print(-1, len(explored))
            return
        else:
            board_list.sort(key=lambda b: len(b.path))
            current_node = board_list[0]
            del board_list[0]

            moves = current_node.getPossibleMoves()
            current_node.fboxes = frozenset(current_node.boxes)
            explored.add(hash(current_node))

            for move in moves:
                child = deepcopy(current_node)
                child.move(move)
                if hash(child) not in explored:
                    if child.is_win():
                        utils.print_output(child.path, len(explored), child.box_moves, "UCS")
                        return
                    board_list.append(child)
Exemplo n.º 7
0
def search(b: board):
    stack = []
    stack.append(b)
    explored = set()

    while True:
        if len(stack) == 0:
            print(-1, len(explored))
            return
        else:
            current_node = stack.pop()
            moves = current_node.getPossibleMoves()
            current_node.fboxes = frozenset(current_node.boxes)
            explored.add(hash(current_node))

            for move in moves:
                child = deepcopy(current_node)
                child.move(move)
                if hash(child) not in explored:
                    if child.is_win():
                        utils.print_output(child.path, len(explored),
                                           child.box_moves, "DFS")
                        return
                    stack.append(child)
Exemplo n.º 8
0
                                       columns=params["languages"])
                return {"search_term": search_term, "results": results}
            else:
                return {"search_term": search_term}


parser = argparse.ArgumentParser()

if __name__ == '__main__':
    parser.add_argument("--term",
                        type=str,
                        help="Search Term",
                        default="child")

    parser.add_argument("--lang", type=str, help="Language", default="english")

    args = parser.parse_args()

    supported_langs = [lang.lower() for lang in settings.LANG_LIST]

    if args.lang not in supported_langs:
        sys.exit("supported language(s): {}".format(supported_langs))

    # search & translate
    output = translate_term(
        search_term=args.term,
        language=args.lang,
    )

    print_output(output)
Exemplo n.º 9
0
    train_metric = metric_func(y_train, y_train_pred)

t_lgbm_pred, y_test_pred = bench.measure_function_time(model_lgbm.predict, X_test,
                                                       params=params)
test_metric_lgbm = metric_func(y_test, y_test_pred)

t_trans, model_daal = bench.measure_function_time(
    daal4py.get_gbt_model_from_lightgbm, model_lgbm, params=params)

if hasattr(params, 'n_classes'):
    predict_algo = daal4py.gbt_classification_prediction(
        nClasses=params.n_classes, resultsToEvaluate='computeClassLabels', fptype='float')
    t_daal_pred, daal_pred = bench.measure_function_time(
        predict_algo.compute, X_test, model_daal, params=params)
    test_metric_daal = metric_func(y_test, daal_pred.prediction)
else:
    predict_algo = daal4py.gbt_regression_prediction()
    t_daal_pred, daal_pred = bench.measure_function_time(
        predict_algo.compute, X_test, model_daal, params=params)
    test_metric_daal = metric_func(y_test, daal_pred.prediction)

utils.print_output(
    library='modelbuilders', algorithm=f'lightgbm_{task}_and_modelbuilder',
    stages=['lgbm_train', 'lgbm_predict', 'daal4py_predict'],
    params=params, functions=['lgbm_dataset', 'lgbm_dataset', 'lgbm_train',
                              'lgbm_predict', 'lgbm_to_daal', 'daal_compute'],
    times=[t_creat_train, t_train, t_creat_test, t_lgbm_pred, t_trans, t_daal_pred],
    accuracy_type=metric_name, accuracies=[train_metric, test_metric_lgbm,
                                           test_metric_daal],
    data=[X_train, X_test, X_test])
Exemplo n.º 10
0
    solution = [
        solve(case, sheeps[case]) for case in range(0, number_of_cases)
    ]
    return solution


def solve(case, sheeps):
    N = int(sheeps[0])
    digits = set()
    i = 1
    while len(digits) < 10:
        M = N * i
        digitsArr = getDigits(M)
        for digit in digitsArr:
            digits.add(digit)
        i += 1
        if N == 0:
            return "Case #" + str(case + 1) + ": INSOMNIA"
    return "Case #" + str(case + 1) + ": " + str(M)


def getDigits(N):
    Ns = [int(d) for d in str(N)]
    return Ns


filename = utils.getFilename()
input = utils.read_input(filename)
output = process(input)
utils.print_output(filename, output)
Exemplo n.º 11
0
    y_train_pred = model_xgb.predict(dtrain)
    train_metric = metric_func(y_train, y_train_pred)

t_xgb_pred, y_test_pred = measure_function_time(predict, params=params)
test_metric_xgb = metric_func(y_test, y_test_pred)

t_trans, model_daal = measure_function_time(
    daal4py.get_gbt_model_from_xgboost, model_xgb, params=params)

if hasattr(params, 'n_classes'):
    predict_algo = daal4py.gbt_classification_prediction(
        nClasses=params.n_classes, resultsToEvaluate='computeClassLabels', fptype='float')
    t_daal_pred, daal_pred = measure_function_time(
        predict_algo.compute, X_test, model_daal, params=params)
    test_metric_daal = metric_func(y_test, daal_pred.prediction)
else:
    predict_algo = daal4py.gbt_regression_prediction()
    t_daal_pred, daal_pred = measure_function_time(
        predict_algo.compute, X_test, model_daal, params=params)
    test_metric_daal = metric_func(y_test, daal_pred.prediction)

print_output(
    library='modelbuilders', algorithm=f'xgboost_{task}_and_modelbuilder',
    stages=['xgboost_train', 'xgboost_predict', 'daal4py_predict'],
    columns=columns, params=params,
    functions=['xgb_dmatrix', 'xgb_dmatrix', 'xgb_train', 'xgb_predict', 'xgb_to_daal',
               'daal_compute'],
    times=[t_creat_train, t_train, t_creat_test, t_xgb_pred, t_trans, t_daal_pred],
    accuracy_type=metric_name, accuracies=[train_metric, test_metric_xgb, test_metric_daal],
    data=[X_train, X_test, X_test])
Exemplo n.º 12
0
# books_scores = np.asarray(res['scores'])
#
# num_of_books_in_library = np.asarray(res['books_in_library'])
# signup_time_for_library = np.asarray(res['signup_time_for_library'])
# books_per_day_from_lib = np.asarray(res['books_per_day_from_lib'])
# book_ids_for_library = np.asarray(res['book_ids_for_library'])
#
# library_capacity = np.ceil(np.divide(num_of_books_in_library, books_per_day_from_lib))
# days_left_for_capacity = np.full(library_capacity.shape, days) - library_capacity
#
# library_time_score = days_left_for_capacity - signup_time_for_library

# libraries_num =


# books_output = np.argsort(, axis=0)


(libraries_sort, books_sort, num_of_books_in_library, books_per_day_from_lib,
 days, signup_time_for_library) = solve_d.solve_d()#solve_c.solve_c()
# libraries_sort = np.argsort(library_time_score)[::-1]
libraries_end_date = utils.get_libraries_signup_end_date(libraries_sort, signup_time_for_library)

# print (book_ids_for_library )

# print(get_books_scores())

# def score_per_library():
utils.print_output(libraries_sort, books_sort, num_of_books_in_library, books_per_day_from_lib,
                   libraries_end_date, days, 'out_d.txt', signup_time_for_library)