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
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
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
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