def test_difference():
    frames = read_flow_shop_instances(FLOW_SHOP_INSTANCE_DIR +
                                      '/20jobs_5machines.txt')
    frame = frames[0]

    palmer_solution = palmer_heuristics(frame)
    local_search(frame, palmer_solution)
    print(
        "\npalmer solution: ", palmer_solution, "\npalmer end time: %s\n\n" %
        str(compute_end_time(frame, palmer_solution)))

    cds_solution = cds_heuristics(frame)
    local_search(frame, cds_solution)
    print(
        "cds solution: ", cds_solution,
        "\ncds end time: %s\n\n" % str(compute_end_time(frame, cds_solution)))

    neh_solution = neh_heuristics(frame)
    local_search(frame, neh_solution)
    print(
        "neh solution: ", neh_solution,
        "\nneh end time: %s\n\n" % str(compute_end_time(frame, neh_solution)))

    liu_solution = liu_reeves_heuristics(frame, 20)
    local_search(frame, liu_solution)
    print(
        "liu solution: ", liu_solution,
        "\nliu end time: %s\n\n" % str(compute_end_time(frame, liu_solution)))
def test_fgh_heuristic(file_name, expected_percent_ratio):
    """
    Function for research.

    Problem
    -------
    Flow shop problem.

    Abstract
    --------
    The experiment consists in comparing the results of
    FGH(count_jobs / count_machines) heuristic with the best results obtained
    by many researchers for Taillard's Flow shop problems published
    on the website:
    http://mistic.heig-vd.ch/taillard/problemes.dir/ordonnancement.dir/ordonnancement.html

    Notes
    -----
    Starts as follows (from root folder):
        `pytest amyachev_degree/tests/test_simple_heuristics.py\
            ::test_fgh_heuristic`

    All tests run about 1484 + _ sec.

    """
    frames = read_flow_shop_instances(FLOW_SHOP_INSTANCE_DIR + file_name)
    assert len(frames) == 10

    # these characteristics are the same for all frames
    count_jobs = frames[0].count_jobs
    count_machines = frames[0].count_machines

    # TODO use percentage_deviation func

    solutions_ratio = []
    for i in range(10):
        # TODO need a way to automatically define `count_alpha` variable
        solution = fgh_heuristic(frames[i],
                                 count_alpha=count_jobs // count_machines + 11)
        schedule_end_time = compute_end_time(frames[i], solution)

        end_time_diff = schedule_end_time - frames[i].upper_bound
        solutions_ratio.append(end_time_diff / frames[i].upper_bound)

    average_percent_ratio = sum(solutions_ratio) / len(solutions_ratio) * 100
    assert round(average_percent_ratio, 2) == expected_percent_ratio
    def test_palmer_heuristic(self, file_name, expected_percent_ratio):
        """
        Results
        -------
        First 9 tests run about 25 sec.
        All tests run about 526 sec.

        """
        frames = read_flow_shop_instances(FLOW_SHOP_INSTANCE_DIR + file_name)
        assert len(frames) == 10

        heuristic = make_heuristic_with_local_search(palmer_heuristics,
                                                     local_search)

        average_percent_ratio = percentage_deviation_using_upper_bound(
            heuristic, {}, frames)

        assert round(average_percent_ratio, 2) == expected_percent_ratio
def test_palmer_heuristics(file_name, expected_percent_ratio):
    """
    Function for research.

    Problem
    -------
    Flow shop problem.

    Abstract
    --------
    The experiment consists in comparing the results of Palmer's heuristic
    with the best results obtained by many researchers for Taillard's Flow shop
    problems published on the website:
    http://mistic.heig-vd.ch/taillard/problemes.dir/ordonnancement.dir/ordonnancement.html

    Notes
    -----
    Starts as follows (from root folder):
        `pytest amyachev_degree/tests/test_simple_heuristics.py\
            ::test_palmer_heuristics`

    First 9 tests run about 1.25 sec.
    All tests run about 1.58 sec.

    """
    frames = read_flow_shop_instances(FLOW_SHOP_INSTANCE_DIR + file_name)
    assert len(frames) == 10

    solutions_ratio = []
    for i in range(10):
        solution = palmer_heuristics(frames[i])
        schedule_end_time = compute_end_time(frames[i], solution)

        end_time_diff = schedule_end_time - frames[i].upper_bound
        solutions_ratio.append(end_time_diff / frames[i].upper_bound)

    average_percent_ratio = sum(solutions_ratio) / len(solutions_ratio) * 100
    assert round(average_percent_ratio, 2) == expected_percent_ratio