Exemplo n.º 1
0
def test_weighted_instance_failure_aware():
    """Checks that the CF and PICEF formulations agree on the optimal
    result for an instance with weighted edges, using failure-aware solving.
    """
    EPS = 0.000001
    d, ndds = read_with_ndds("test-fixtures/100-random-weights")
    fns = [k_ip.optimise_picef, k_ip.optimise_ccf]
    for max_cycle in [0, 1, 2, 3, 4]:
        for max_chain in [0, 1, 2, 3]:
            cfg = k_ip.OptConfig(d,
                                 ndds,
                                 max_cycle,
                                 max_chain,
                                 edge_success_prob=0.7)
            opt_result_cf = k_ip.optimise_ccf(cfg)
            opt_result_picef = k_ip.optimise_picef(cfg)
            opt_result_cf_relabelled = k_ip.optimise_relabelled(
                k_ip.optimise_ccf, cfg)
            opt_result_picef_relabelled = k_ip.optimise_relabelled(
                k_ip.optimise_picef, cfg)
            assert abs(opt_result_cf.total_score -
                       opt_result_picef.total_score) < EPS
            assert abs(opt_result_cf.total_score -
                       opt_result_cf_relabelled.total_score) < EPS
            assert abs(opt_result_cf.total_score -
                       opt_result_picef_relabelled.total_score) < EPS
Exemplo n.º 2
0
def solve_kep(cfg, formulation, use_relabelled=True):

    formulations = {
        "uef": ("Uncapped edge formulation", kidney_ip.optimise_uuef),
        "eef": ("EEF", kidney_ip.optimise_eef),
        "eef_full_red": ("EEF with full reduction by cycle generation",
                         kidney_ip.optimise_eef_full_red),
        "hpief_prime": ("HPIEF'", kidney_ip.optimise_hpief_prime),
        "hpief_prime_full_red":
        ("HPIEF' with full reduction by cycle generation",
         kidney_ip.optimise_hpief_prime_full_red),
        "hpief_2prime": ("HPIEF''", kidney_ip.optimise_hpief_2prime),
        "hpief_2prime_full_red":
        ("HPIEF'' with full reduction by cycle generation",
         kidney_ip.optimise_hpief_2prime_full_red),
        "picef": ("PICEF", kidney_ip.optimise_picef),
        "nhs": ("PICEF-NHS", kidney_ip.optimise_picef_nhs),
        #"nhs_chains": ("PICEF-NHS-CHAINS", kidney_ip.optimise_picef_nhs_chains),
        "cf": ("Cycle formulation", kidney_ip.optimise_ccf)
    }

    if formulation in formulations:
        formulation_name, formulation_fun = formulations[formulation]
        if use_relabelled:
            opt_result = kidney_ip.optimise_relabelled(formulation_fun, cfg)
        else:
            opt_result = formulation_fun(cfg)
        if opt_result:
            kidney_utils.check_validity(opt_result, cfg.digraph, cfg.ndds,
                                        cfg.max_cycle, cfg.max_chain)
            opt_result.formulation_name = formulation_name
        return opt_result
    else:
        raise ValueError("Unrecognised IP formulation name")
Exemplo n.º 3
0
def test_weighted_instance_failure_aware():
    """Checks that the CF and PICEF formulations agree on the optimal
    result for an instance with weighted edges, using failure-aware solving.
    """
    EPS = 0.000001
    d, ndds = read_with_ndds("test-fixtures/100-random-weights")
    fns = [k_ip.optimise_picef, k_ip.optimise_ccf]
    for max_cycle in [0, 1, 2, 3, 4]:
        for max_chain in [0, 1, 2, 3]:
            cfg = k_ip.OptConfig(d, ndds, max_cycle, max_chain, edge_success_prob=0.7) 
            opt_result_cf = k_ip.optimise_ccf(cfg)
            opt_result_picef = k_ip.optimise_picef(cfg)
            opt_result_cf_relabelled = k_ip.optimise_relabelled(k_ip.optimise_ccf, cfg)
            opt_result_picef_relabelled = k_ip.optimise_relabelled(k_ip.optimise_picef, cfg)
            assert abs(opt_result_cf.total_score - opt_result_picef.total_score) < EPS
            assert abs(opt_result_cf.total_score - opt_result_cf_relabelled.total_score) < EPS
            assert abs(opt_result_cf.total_score - opt_result_picef_relabelled.total_score) < EPS
Exemplo n.º 4
0
def test_relabelled_solve():
    """Checks whether the vertex-ordering heuristic affects the
    result for a weighted instance
    """
    EPS = 0.000001
    d, ndds = read_with_ndds("test-fixtures/100-random-weights")
    for max_cycle in [0, 3]:
        for max_chain in [0, 5]:
            opt_result_0 = k_ip.optimise_picef(k_ip.OptConfig(d, ndds, max_cycle, max_chain))
            print opt_result_0.total_score
            opt_result = k_ip.optimise_relabelled(
                    k_ip.optimise_picef, k_ip.OptConfig(d, ndds, max_cycle, max_chain))
            print "   ", opt_result.total_score
            assert abs(opt_result.total_score - opt_result_0.total_score) < EPS
Exemplo n.º 5
0
def test_relabelled_solve():
    """Checks whether the vertex-ordering heuristic affects the
    result for a weighted instance
    """
    EPS = 0.000001
    d, ndds = read_with_ndds("test-fixtures/100-random-weights")
    for max_cycle in [0, 3]:
        for max_chain in [0, 5]:
            opt_result_0 = k_ip.optimise_picef(
                k_ip.OptConfig(d, ndds, max_cycle, max_chain))
            print(opt_result_0.total_score)
            opt_result = k_ip.optimise_relabelled(
                k_ip.optimise_picef,
                k_ip.OptConfig(d, ndds, max_cycle, max_chain))
            print("   ", opt_result.total_score)
            assert abs(opt_result.total_score - opt_result_0.total_score) < EPS