コード例 #1
0
def limits_plots():
    right_limits = [i * 1000 for i in range(1, 101, 10)]
    max_len = [i * 100 for i in range(1, 101, 10)]

    times_greedy = []
    times_recursive = []
    times_dynamic = []

    tf_greedy = []
    tf_recursive = []
    tf_dynamic = []

    for i, j in zip(right_limits, max_len):
        exps_list = generate_random_condition(N, 1, i, 'Рівномірний для відрізків обмеженної довжини', j)
        exps_task = ExpertsTask(exps_list)

        times_greedy.append(execution_time_greedy(exps_task))
        tf_greedy.append(exps_task.tf_res)

        times_recursive.append(execution_time_recursive(exps_task))
        tf_recursive.append(exps_task.tf_res)

        times_dynamic.append(execution_time_dynamic(exps_task))
        tf_dynamic.append(exps_task.tf_res)

    plt.plot(right_limits, times_recursive, 'mediumpurple', right_limits, times_greedy, right_limits, times_dynamic,
             'limegreen')
    plt.legend(['Recursive optimization', 'Greedy algorithm', 'dynamic algorithm'])
    plt.ylabel('Execution time (in milliseconds)')
    plt.xlabel('Right limit of the end point')
    plt.show()
コード例 #2
0
def limits_plots():
    right_limits = [i * 10000 for i in range(1, 101, 10)]
    max_len = [i * 1000 for i in range(1, 101, 10)]

    times_greedy_1 = []
    times_greedy_2= []
    times_greedy_3 = []
    times_bee = []

    tf_greedy_1 = []
    tf__greedy_2= []
    tf_greedy_3 = []
    tf_bee = []

    for i, j in zip(right_limits, max_len):
        schedules_list = generate_random_condition(N, 100, 1, i, 1, j)
        schedules_task = ScheduleTask(schedules_list)

        times_greedy_1.append(execution_time_greedy_1(schedules_task))
        tf_greedy_1.append(schedules_task.tf_res)

        times_greedy_2.append(execution_time_greedy_2(schedules_task))
        tf__greedy_2.append(schedules_task.tf_res)

        times_greedy_3.append(execution_time_greedy_3(schedules_task))
        tf_greedy_3.append(schedules_task.tf_res)

        times_bee.append(execution_time_bee(schedules_task))
        tf_bee.append(schedules_task.tf_res)

    plt.plot(right_limits, times_greedy_1, 'mediumpurple', right_limits, times_greedy_2,'orange' ,right_limits, times_greedy_3,
             'limegreen',right_limits, times_bee,
             'red')
    plt.legend(['Greedy #1 algorithm', 'Greedy #1 algorithm', 'Greedy #3 algorithm', 'Bee algorithm'])
    plt.ylabel('Execution time (in milliseconds)')
    plt.xlabel('Right limit of the end point')
    plt.show()
コード例 #3
0
def solution_page():
    st.title('Сторінка з розв\'язанням задачі')

    session_state = SessionState.get(choose_button=False,
                                     input_type='',
                                     random='',
                                     file='',
                                     db='')
    session_state.input_type = st.selectbox('Оберіть спосіб вхідних даних',
                                            ['З файлу', 'Рандомізовано'])

    if session_state.input_type == 'Рандомізовано':
        quantity = st.number_input('Кількість робіт',
                                   step=1,
                                   value=50,
                                   min_value=1,
                                   max_value=500)
        work_end = st.number_input('Кінець роботи машини',
                                   step=1,
                                   value=1000,
                                   min_value=1,
                                   max_value=1000)

        min_fine = st.number_input('Мінімальний штраф',
                                   step=1,
                                   value=10,
                                   min_value=1,
                                   max_value=1000)
        max_fine = st.number_input('Максимальний штраф',
                                   step=1,
                                   value=100,
                                   min_value=1,
                                   max_value=1000)

        min_execution_time = st.number_input(
            'Мінімальний термін виконання роботи',
            step=1,
            value=5,
            min_value=1,
            max_value=1000)
        max_execution_time = st.number_input(
            'Максимальний термін виконання роботи',
            step=1,
            value=40,
            min_value=1,
            max_value=1000)

        method = st.selectbox('Оберіть метод вирішення задачі', [
            'Жадібний алгоритм №1', 'Жадібний алгоритм №2',
            'Жадібний алгоритм №3', 'Бджолиний алгоритм'
        ])

        if st.button('Розв\'язати'):
            condition = generate_random_condition(quantity, work_end, min_fine,
                                                  max_fine, min_execution_time,
                                                  max_execution_time)
            show_answer(condition, method)
            st.table(condition2table(condition))

    if session_state.input_type == 'З файлу':
        filename = file_selector()
        # st.write('Ви обрали `%s`' % filename)
        condition = parse_condition_csv(filename)
        st.table(condition2table(condition))
        method = st.selectbox('Оберіть метод вирішення задачі', [
            'Жадібний алгоритм №1', 'Жадібний алгоритм №2',
            'Жадібний алгоритм №3', 'Бджолиний алгоритм'
        ])
        if st.button('Розв\'язати'):
            show_answer(condition, method)
コード例 #4
0
def complexity_plots():
    amounts = range(1, N + 1)

    times_greedy_1 = []
    times_greedy_2 = []
    times_greedy_3 = []
    times_bee = []

    tf_greedy_1 = []
    tf_greedy_2 = []
    tf_greedy_3 = []
    tf_bee = []

    for i in range(1, N + 1):
        # b = random.randint(1, 200)
        # e = random.randint(b, int(40 + b * 0.8))
        # exps_list.append((b, e))
        shedules_list = generate_random_condition(i, 100, 1, 100, 1, 200)
        shedules_task = ScheduleTask(shedules_list)

        times_greedy_1.append(execution_time_greedy_1(shedules_task))
        tf_greedy_1.append(shedules_task.tf_res)

        times_greedy_2.append(execution_time_greedy_2(shedules_task))
        tf_greedy_2.append(shedules_task.tf_res)

        times_greedy_3.append(execution_time_greedy_3(shedules_task))
        tf_greedy_3.append(shedules_task.tf_res)

        times_bee.append(execution_time_bee(shedules_task))
        tf_bee.append(shedules_task.tf_res)

    comp_log = [n * math.log(n, 2) / 5000 for n in amounts]
    comp_sq = [n * n / 400000 for n in amounts]
    plt.plot(amounts, times_greedy_1, amounts, comp_log, comp_sq, 'red')
    plt.legend(['f(N)', 'N*log(N)', 'N^2'])
    plt.ylabel('Execution time of Greedy Algorithm #1 (in milliseconds)')
    plt.xlabel('Amount of works')
    plt.show()

    comp_log = [n * math.log(n, 2) / 500 for n in amounts]
    comp_sq = [n * n / 30000 for n in amounts]
    plt.plot(amounts, times_greedy_2, amounts, comp_log, comp_sq, 'red')
    plt.legend(['f(N)', 'N*log(N)', 'N^2'])
    plt.ylabel('Execution time of Greedy Algorithm #2 (in milliseconds)')
    plt.xlabel('Amount of works')
    plt.show()

    comp_log = [n * math.log(n, 2) / 7000 for n in amounts]
    comp_sq = [n * n / 500000 for n in amounts]
    plt.plot(amounts, times_greedy_3, amounts, comp_log, comp_sq, 'red')
    plt.legend(['f(N)', 'N*log(N)', 'N^2'])
    plt.ylabel('Execution time of Greedy Algorithm #3 (in milliseconds)')
    plt.xlabel('Amount of works')
    plt.show()

    comp_log = [n * math.log(n, 2) / 7000 for n in amounts]
    comp_sq = [n * n / 500000 for n in amounts]
    plt.plot(amounts, times_bee, amounts, comp_log, comp_sq, 'red')
    plt.legend(['f(N)', 'N*log(N)', 'N^2'])
    plt.ylabel('Execution time of Bee Algorithm (in milliseconds)')
    plt.xlabel('Amount of works')
    plt.show()

    plt.plot(amounts, times_bee, 'mediumpurple', amounts, times_greedy_1, 'red', amounts, times_greedy_3, 'limegreen',
             amounts, times_greedy_2, 'blue')
    plt.legend(['Bee algorithm', 'Greedy #1 algorithm', 'Greedy #3 algorithm', 'Greedy #2 algorithm'])
    plt.ylabel('Execution time (in milliseconds)')
    plt.xlabel('Amount of works')
    plt.show()

    eval_greedy1_bee = [abs(((j - i) / j) * 100) for i, j in zip(tf_greedy_1, tf_bee)]
    eval_greedy2_bee = [abs(((j - i) / j) * 100) for i, j in zip(tf_greedy_2, tf_bee)]
    eval_greedy3_bee = [abs(((j - i) / j) * 100) for i, j in zip(tf_greedy_3, tf_bee)]

    plt.plot(amounts, eval_greedy1_bee,'blue', amounts, eval_greedy2_bee, 'limegreen',  amounts, eval_greedy3_bee, 'mediumpurple')
    plt.legend(['Greedy #1 algorithm', 'Greedy #2 algorithm', 'Greedy #3 algorithm'])
    plt.ylabel('Deviation from the optimal value (in %)')
    plt.xlabel('Amount of works')
    plt.show()
コード例 #5
0
def complexity_plots():
    amounts = range(1, N + 1)

    times_greedy = []
    times_recursive = []
    times_dynamic = []

    tf_greedy = []
    tf_recursive = []
    tf_dynamic = []

    for i in range(1, N + 1):
        # b = random.randint(1, 200)
        # e = random.randint(b, int(40 + b * 0.8))
        # exps_list.append((b, e))
        exps_list = generate_random_condition(i, 1, 1000, 'Рівномірний для відрізків обмеженної довжини', 200)
        exps_task = ExpertsTask(exps_list)

        times_greedy.append(execution_time_greedy(exps_task))
        tf_greedy.append(exps_task.tf_res)

        times_recursive.append(execution_time_recursive(exps_task))
        tf_recursive.append(exps_task.tf_res)

        times_dynamic.append(execution_time_dynamic(exps_task))
        tf_dynamic.append(exps_task.tf_res)

    comp_log = [n * math.log(n, 2) / 5000 for n in amounts]
    comp_sq = [n * n / 400000 for n in amounts]
    plt.plot(amounts, times_greedy, amounts, comp_log, comp_sq, 'red')
    plt.legend(['f(N)', 'N*log(N)', 'N^2'])
    plt.ylabel('Execution time (in milliseconds)')
    plt.xlabel('Amount of experts')
    plt.show()

    comp_log = [n * math.log(n, 2) / 500 for n in amounts]
    comp_sq = [n * n / 30000 for n in amounts]
    plt.plot(amounts, times_recursive, amounts, comp_log, comp_sq, 'red')
    plt.legend(['f(N)', 'N*log(N)', 'N^2'])
    plt.ylabel('Execution time (in milliseconds)')
    plt.xlabel('Amount of experts')
    plt.show()

    comp_log = [n * math.log(n, 2) / 7000 for n in amounts]
    comp_sq = [n * n / 500000 for n in amounts]
    plt.plot(amounts, times_dynamic, amounts, comp_log, comp_sq, 'red')
    plt.legend(['f(N)', 'N*log(N)', 'N^2'])
    plt.ylabel('Execution time (in milliseconds)')
    plt.xlabel('Amount of experts')
    plt.show()

    plt.plot(amounts, times_recursive, 'mediumpurple', amounts, times_greedy, amounts, times_dynamic, 'limegreen')
    plt.legend(['Recursive optimization', 'Greedy algorithm', 'dynamic algorithm'])
    plt.ylabel('Execution time (in milliseconds)')
    plt.xlabel('Amount of experts')
    plt.show()

    eval_greedy = [abs(((j - i) / j) * 100) for i, j in zip(tf_greedy, tf_dynamic)]
    eval_recursive = [abs(((j - i) / j) * 100) for i, j in zip(tf_recursive, tf_dynamic)]

    plt.plot(amounts, eval_greedy, amounts, eval_recursive, 'limegreen')
    plt.legend(['Greedy algorithm', 'Recursive optimization'])
    plt.ylabel('Deviation from the optimal value (in %)')
    plt.xlabel('Amount of experts')
    plt.show()
コード例 #6
0
def solution_page():
    st.title('Сторінка з розв\'язанням задачі')

    session_state = SessionState.get(choose_button=False,
                                     input_type='',
                                     random='',
                                     file='',
                                     db='')
    session_state.input_type = st.selectbox('Оберіть спосіб вхідних даних',
                                            ['File', 'Data Base', 'Random'])

    if session_state.input_type == 'Random':
        quantity = st.number_input('Кількість експертів',
                                   step=1,
                                   value=50,
                                   min_value=1,
                                   max_value=500)
        min_val = st.number_input('Мінімальне значеня',
                                  step=1,
                                  value=1,
                                  min_value=1,
                                  max_value=99999)
        max_val = st.number_input('Максимальне значеня',
                                  step=1,
                                  value=1000,
                                  min_value=1,
                                  max_value=99999)
        max_len = st.number_input('Максимальна тривалість роботи експерта',
                                  step=1,
                                  value=200,
                                  min_value=1,
                                  max_value=99999)
        distribution = st.selectbox('Оберіть розподіл випадкових велечин', [
            'Рівномірний', 'Усічений нормальний',
            'Рівномірний для відрізків обмеженної довжини'
        ])

        method = st.selectbox('Оберіть метод вирішення задачі', [
            'Метод динамічного програмування',
            'Жадібний алгоритм + рекурсивний покращувач', 'Обидва метода'
        ])

        if st.button('Розв\'язати'):
            condition = generate_random_condition(quantity, min_val, max_val,
                                                  distribution, max_len)
            st.write('Згенерували наступну умову: {}'.format(condition))
            st.bokeh_chart(draw_graphic_of_condition(condition))

            if method == 'Обидва метода':
                show_answer(condition, 'Метод динамічного програмування')
                show_answer(condition,
                            'Жадібний алгоритм + рекурсивний покращувач')
            else:
                show_answer(condition, method)

    if session_state.input_type == 'Data Base':
        conditions = get_presets_conditions()
        st.table(conditions)
        session_state.condition_id2solve = st.number_input(
            'Введіть ID',
            step=1,
            value=1,
            min_value=1,
            max_value=len(conditions))

        condition2solve = list(
            filter(
                lambda cond: cond.get('task_id') == session_state.
                condition_id2solve, conditions))[0]
        method = st.selectbox('Оберіть метод вирішення задачі', [
            'Метод динамічного програмування',
            'Жадібний алгоритм + рекурсивний покращувач', 'Обидва метода'
        ])

        if st.button('Розв\'язати'):
            show_answer(condition2solve.get('experts', []), method)

    if session_state.input_type == 'File':
        filename = file_selector()
        st.write('Ви обрали `%s`' % filename)
        condition = parse_condition_csv(filename)
        st.bokeh_chart(draw_graphic_of_condition(condition))
        # st.write(condition)
        method = st.selectbox('Оберіть метод вирішення задачі', [
            'Метод динамічного програмування',
            'Жадібний алгоритм + рекурсивний покращувач', 'Обидва метода'
        ])
        if st.button('Розв\'язати'):
            show_answer(condition, method)