In [1]:
using Convex
using SCS
# passing in verbose=0 to hide output from SCS
solver = SCSSolver(verbose=0)
set_default_solver(solver);
In [2]:
x = Variable(4)
c = [1; 2; 3; 4]
A = eye(4)
b = [10; 10; 10; 10]
p = minimize(dot(c, x)) # or c' * x
p.constraints += A * x <= b
p.constraints += [x >= 1; x <= 10; x[2] <= 5; x[1] + x[4] - x[2] <= 10]
solve!(p)
println(round(p.optval, 2))
println(round(x.value, 2))
println(evaluate(x[1] + x[4] - x[2]))
In [3]:
X = Variable(2, 2)
y = Variable()
# X is a 2 x 2 variable, and y is scalar. X' + y promotes y to a 2 x 2 variable before adding them
p = minimize(sum(X) + y, 2 * X <= 1, X' + y >= 1, X >= 0, y >= 0)
solve!(p)
println(round(X.value, 2))
println(y.value)
p.optval
Out[3]:
In [4]:
x = Variable(4)
p = satisfy(norm(x) <= 100, exp(x[1]) <= 5, x[2] >= 7, geo_mean(x[3], x[4]) >= x[2])
solve!(p, SCSSolver(verbose=0))
println(p.status)
x.value
Out[4]:
In [5]:
y = Semidefinite(2)
p = maximize(lambda_min(y), trace(y)<=6)
solve!(p, SCSSolver(verbose=0))
p.optval
Out[5]:
In [6]:
x = Variable()
y = Variable((2, 2))
# SDP constraints
p = minimize(x + y[1, 1], isposdef(y), x >= 1, y[2, 1] == 1)
solve!(p)
y.value
Out[6]:
In [7]:
using GLPKMathProgInterface
x = Variable(4, :Int)
p = minimize(sum(x), x >= 0.5)
solve!(p, GLPKSolverMIP())
x.value
Out[7]: