def test_nonsing_none_forbidden(n_eqs, seed):
    log('seed =', seed)
    rng = Random(seed)
    g, eqs = create_rnd_bipartite(n_eqs, n_eqs, seed, rng, nonsing=True, c=3)
    #serialize((g, eqs), DATADIR + 'ilp_poor_performance_c=5_r=2997.pkl.gz')
    #plot_bipartite(g, eqs, forbidden)
    solve_problem(g, eqs)
    log()
def difficult(size):
    print('Solving patterns leading to many ties (backtracking) of size', size)
    msg = 'Size: ' + str(size)
    fname = '{0:03d}a'.format(size)
    g = create_difficult_pattern(size)
    to_pdf(g, list(irange(size)), irange(size, 2 * size), msg, fname)
    #
    solve_problem(g, set(irange(size)))
    #
    explored, g, _, rowp, colp, ub = _worst_cases[0]
    msg = 'OPT = {}, BT: {}'.format(ub, explored)
    fname = '{0:03d}b'.format(size)
    to_pdf(g, rowp, colp, msg, fname)
    _worst_cases[:] = []
    print_timestamp()
def naughty_brute_force():
    for size in irange(3, 6):
        print_timestamp()
        print('Testing (naughty) bipartite graphs of size', size)
        # serialized in test_utils, but optimums can be serialized here
        #opts = [ ]
        #opts = marshal_load('data/all_bips/opt_n'+str(size)+'.bin')
        #all_edgelists = marshal_load('data/all_bips/bip_n'+str(size)+'.bin')
        opts = marshal_load('data/bip_filt/opt_n' + str(size) + '.bin')
        all_edgelists = marshal_load('data/bip_filt/filt_n' + str(size) +
                                     '.bin')
        print('Loaded', len(all_edgelists), 'graphs')
        print_timestamp()
        #for edgelist in all_edgelists:
        for i, (edgelist, opt) in enumerate(izip(all_edgelists, opts)):
            assert len(edgelist) % 2 == 0
            g = Graph()
            g.add_edges_from(e for e in izip(edgelist[::2], edgelist[1::2]))
            assert len(g) == 2 * size
            g.graph['name'] = str(i)
            _, _, _, tear_set, _ = solve_problem(g, set(irange(size)))
            assert opt == len(tear_set)
            #---
            #solve_problem(g, set(irange(size)))
            #---
            #opt = len(solve_problem(g, set(irange(size)))[3])
            #opts.append(opt)
            #---
            #to_pdf(g, rowp,  colp)
        #assert len(opts) == len(all_edgelists)
        #marshal_dump(opts, '/tmp/opt_n'+str(size)+'.bin')
        print([t[0] for t in _worst_cases])
        #print('Len:', len(_worst_cases))
        _worst_cases.sort(key=sort_patterns)
        #         for i, (explored, g, _, rowp, colp, ub) in enumerate(_worst_cases, 1):
        #             msg   = 'Index: ' + g.graph['name']
        #             fname = '{0:03d}a'.format(i)
        #             to_pdf(g, list(irange(size)), irange(size, 2*size), msg, fname)
        #             msg   = 'OPT = {}, BT: {}'.format(ub, explored)
        #             fname = '{0:03d}b'.format(i)
        #             to_pdf(g, rowp, colp, msg, fname)
        _worst_cases[:] = []
        print_timestamp()
        print()
def solve_difficult_for_bb():
    filepath = 'data/worst_of_10M_runs/bb_bad_perf_n=10_c=0.5_1.pkl.gz'
    g, eqs, _ = deserialize(filepath)
    rowp, colp = solve_problem(g, eqs)[0:2]
    to_pdf(g, rowp, colp)
def test_to_hessenberg_none_forbidden(n_eqs, n_vars, seed):
    log('seed =', seed)
    rng = Random(seed)
    g, eqs = create_rnd_bipartite(n_eqs, n_vars, seed, rng, nonsing=False, c=3)
    solve_problem(g, eqs)
    log()