Пример #1
0
def solve_conic():

    m = pmo.block()

    m.x = pmo.variable(lb=0)
    m.y = pmo.variable(lb=0)
    m.z = pmo.variable(lb=0)

    m.p = pmo.variable()
    m.q = pmo.variable()
    m.r = pmo.variable(lb=0)

    m.k = pmo.block_tuple([
        pmo.conic.primal_power.as_domain(r1=m.x, r2=m.y, x=[None], alpha=0.2),
        pmo.conic.primal_power.as_domain(r1=m.z, r2=1, x=[None], alpha=0.4)
    ])

    m.c = pmo.constraint(body=m.x + m.y + 0.5 * m.z, rhs=2)

    m.o = pmo.objective(m.k[0].x[0] + m.k[1].x[0] - m.x, sense=pmo.maximize)

    mosek = pmo.SolverFactory("mosek")
    result = mosek.solve(m)
    assert str(result.solver.termination_condition) == "optimal"
    print("conic solution:")
    print("x: {0:.4f}, y: {1:.4f}, z: {2:.4f}".\
          format(m.x(), m.y(), m.z()))
    print("objective: {0: .5f}".\
          format(m.o()))
    print("")
Пример #2
0
def solve_conic():

    m = pmo.block()

    m.t = pmo.variable()
    m.u = pmo.variable()
    m.v = pmo.variable()
    m.w = pmo.variable()

    m.k = pmo.block_tuple([
        # exp(u-t) + exp(2v + w - t) <= 1
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=m.u - m.t),
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=2*m.v + m.w - m.t),
        # exp(0.5u + log(0.1)) + exp(-v + log(2)) <= 1
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=0.5*m.u + pmo.log(0.1)),
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=-m.v + pmo.log(2)),
        # exp(-w) + exp(v-2u) <= 1
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=-m.w),
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=m.v - 2*m.u)])

    m.c = pmo.constraint_tuple([
        pmo.constraint(body=m.k[0].r + m.k[1].r,
                       ub=1),
        pmo.constraint(body=m.k[2].r + m.k[3].r,
                       ub=1),
        pmo.constraint(body=m.k[4].r + m.k[5].r,
                       ub=1)])

    m.o = pmo.objective(m.t,
                        sense=pmo.minimize)

    mosek = pmo.SolverFactory("mosek")
    result = mosek.solve(m)
    assert str(result.solver.termination_condition) == "optimal"
    x, y, z = pmo.exp(m.u()), pmo.exp(m.v()), pmo.exp(m.w())
    print("conic solution:")
    print("x: {0:.4f}, y: {1:.4f}, z: {2:.4f}".\
          format(x, y, z))
    print("objective: {0: .5f}".\
          format(x + (y**2)*z))
    print("")
Пример #3
0
def solve_conic():

    m = pmo.block()

    m.t = pmo.variable()
    m.u = pmo.variable()
    m.v = pmo.variable()
    m.w = pmo.variable()

    m.k = pmo.block_tuple([
        # exp(u-t) + exp(2v + w - t) <= 1
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=m.u - m.t),
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=2*m.v + m.w - m.t),
        # exp(0.5u + log(0.1)) + exp(-v + log(2)) <= 1
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=0.5*m.u + pmo.log(0.1)),
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=-m.v + pmo.log(2)),
        # exp(-w) + exp(v-2u) <= 1
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=-m.w),
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=m.v - 2*m.u)])

    m.c = pmo.constraint_tuple([
        pmo.constraint(body=m.k[0].r + m.k[1].r, ub=1),
        pmo.constraint(body=m.k[2].r + m.k[3].r, ub=1),
        pmo.constraint(body=m.k[4].r + m.k[5].r, ub=1)
    ])

    m.o = pmo.objective(m.t, sense=pmo.minimize)

    mosek = pmo.SolverFactory("mosek")
    result = mosek.solve(m)
    assert str(result.solver.termination_condition) == "optimal"
    x, y, z = pmo.exp(m.u()), pmo.exp(m.v()), pmo.exp(m.w())
    print("conic solution:")
    print("x: {0:.4f}, y: {1:.4f}, z: {2:.4f}".\
          format(x, y, z))
    print("objective: {0: .5f}".\
          format(x + (y**2)*z))
    print("")
Пример #4
0
def solve_conic(Aw, Af, alpha, beta, gamma, delta):

    m = pmo.block()

    m.x = pmo.variable()
    m.y = pmo.variable()
    m.z = pmo.variable()

    m.k = pmo.block_tuple([
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=m.x + m.y + pmo.log(2.0/Aw)),
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=m.x + m.z + pmo.log(2.0/Aw))])

    m.c = pmo.constraint_tuple([
        pmo.constraint(body=m.k[0].r + m.k[1].r,
                       ub=1),
        pmo.constraint(body=m.y + m.z, ub=pmo.log(Af)),
        pmo.constraint(lb=pmo.log(alpha),
                       body=m.x - m.y,
                       ub=pmo.log(beta)),
        pmo.constraint(lb=pmo.log(gamma),
                       body=m.z - m.y,
                       ub=pmo.log(delta))])

    m.o = pmo.objective(m.x + m.y + m.z,
                        sense=pmo.maximize)

    mosek = pmo.SolverFactory("mosek")
    result = mosek.solve(m)
    assert str(result.solver.termination_condition) == "optimal"
    h, w, d = pmo.exp(m.x()), pmo.exp(m.y()), pmo.exp(m.z())
    print("conic solution:")
    print("h: {0:.4f}, w: {1:.4f}, d: {2:.4f}".\
          format(h, w, d))
    print("volume: {0: .5f}".\
          format(h*w*d))
    print("")
Пример #5
0
def solve_conic(Aw, Af, alpha, beta, gamma, delta):

    m = pmo.block()

    m.x = pmo.variable()
    m.y = pmo.variable()
    m.z = pmo.variable()

    m.k = pmo.block_tuple([
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=m.x + m.y + pmo.log(2.0/Aw)),
        pmo.conic.primal_exponential.\
            as_domain(r=None,
                      x1=1,
                      x2=m.x + m.z + pmo.log(2.0/Aw))])

    m.c = pmo.constraint_tuple([
        pmo.constraint(body=m.k[0].r + m.k[1].r, ub=1),
        pmo.constraint(body=m.y + m.z, ub=pmo.log(Af)),
        pmo.constraint(lb=pmo.log(alpha), body=m.x - m.y, ub=pmo.log(beta)),
        pmo.constraint(lb=pmo.log(gamma), body=m.z - m.y, ub=pmo.log(delta))
    ])

    m.o = pmo.objective(m.x + m.y + m.z, sense=pmo.maximize)

    mosek = pmo.SolverFactory("mosek_direct")
    result = mosek.solve(m)
    assert str(result.solver.termination_condition) == "optimal"
    h, w, d = pmo.exp(m.x()), pmo.exp(m.y()), pmo.exp(m.z())
    print("conic solution:")
    print("h: {0:.4f}, w: {1:.4f}, d: {2:.4f}".\
          format(h, w, d))
    print("volume: {0: .5f}".\
          format(h*w*d))
    print("")
Пример #6
0
def solve_conic():

    m = pmo.block()

    m.x = pmo.variable(lb=0)
    m.y = pmo.variable(lb=0)
    m.z = pmo.variable(lb=0)

    m.p = pmo.variable()
    m.q = pmo.variable()
    m.r = pmo.variable(lb=0)

    m.k = pmo.block_tuple([
        pmo.conic.primal_power.as_domain(r1=m.x,
                                         r2=m.y,
                                         x=[None],
                                         alpha=0.2),
        pmo.conic.primal_power.as_domain(r1=m.z,
                                         r2=1,
                                         x=[None],
                                         alpha=0.4)])

    m.c = pmo.constraint(body=m.x + m.y + 0.5*m.z,
                         rhs=2)

    m.o = pmo.objective(m.k[0].x[0] + m.k[1].x[0] - m.x,
                        sense=pmo.maximize)

    mosek = pmo.SolverFactory("mosek")
    result = mosek.solve(m)
    assert str(result.solver.termination_condition) == "optimal"
    print("conic solution:")
    print("x: {0:.4f}, y: {1:.4f}, z: {2:.4f}".\
          format(m.x(), m.y(), m.z()))
    print("objective: {0: .5f}".\
          format(m.o()))
    print("")