예제 #1
0
        print("This feature is currently not supported in Gurobi.")
    else:
        m.verbose = 0

        x = m.add_var_tensor(shape=(2, 1), name="x", var_type=INTEGER)

        m.objective = maximize(2 * x[0] + x[1])

        m += 7 * x[0] + x[1] <= 28
        m += -x[0] + 3 * x[1] <= 7
        m += -8 * x[0] - 9 * x[1] <= -32

        m.optimize(relax=True)
        olr = m.objective_value

        cp = m.generate_cuts([ct])
        if cp and cp.cuts:
            print("{} cuts generated:".format(len(cp.cuts)))
            for c in cp.cuts:
                print("  " + str(c))

        if cp.cuts:
            m += cp
            m.optimize(relax=True)

            print("Dual bound now: {}".format(m.objective_value))
            assert m.status == OptimizationStatus.OPTIMAL
            diff = m.objective_value - olr
            if diff > larger_diff:
                larger_diff = diff
                best_cut = ct
예제 #2
0
    G = DiGraph()
    for a in A:
        G.add_edge(a[0], a[1], capacity=x[a].x)

    newConstraints = False
    for (n1, n2) in [(i, j) for (i, j) in product(N, N) if i != j]:
        cut_value, (S, NS) = minimum_cut(G, n1, n2)
        if cut_value <= 0.99:
            m += (
                xsum(x[a] for a in A if (a[0] in S and a[1] in S))
                <= len(S) - 1
            )
            newConstraints = True
    if not newConstraints and m.solver_name.lower() == "cbc":
        cp = m.generate_cuts(
            [
                CutType.GOMORY,
                CutType.MIR,
                CutType.ZERO_HALF,
                CutType.KNAPSACK_COVER,
            ]
        )
        if cp.cuts:
            m += cp
            newConstraints = True

# sanity checks
assert m.status == OptimizationStatus.OPTIMAL
assert 260.99 <= m.objective_value <= 262.000001