Hi,
How do I declare a matrix objective in JuMP? That is, how do I declare @objective(m, Min, ⋅ )
with ⋅
a matrix?
Thank you for any help.
Details
I am trying to translate the Python code below to Julia. However, the following piece of Julia code returns ERROR: MethodError: no method matching *(::LinearAlgebra.Adjoint{Int64,Array{Int64,1}}, ::VariableRef)
. What
Julia
using JuMP
using DSDP
obj_vec = [0; 1; 2]
m = Model(with_optimizer(DSDP.Optimizer))
@variable(m, X)
@objective(m, Min, obj_vec'*X)
Python
from cvxopt import matrix, solvers
obj_vec = matrix(range(3), (3, 1), 'd')
__sym_grams = [[0, 0, -0.5, 0, 0, 1, 0, 0, -0.5, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, -0.5, 0, 0, 1, 0, 0, -0.5, 0, 0]]
sym_grams = matrix(__sym_grams)
Gs = [-sym_grams]
hs = [matrix([[10, 10, -1.50, 0],
[10, 0, 0, 0.5],
[-1.50, 0, 0, 0],
[0, 0.5, 0, 100]])]
sol = solvers.sdp(c=obj_vec, Gs=Gs, hs=hs, solver='dsdp')
print(sol) # {'status': 'optimal', 'x': <3x1 matrix, tc='d'>, 'sl': <0x1 matrix, tc='d'>, 'ss': [<4x4 matrix, tc='d'>], 'y': <0x1 matrix, tc='d'>, 'zl': <0x1 matrix, tc='d'>, 'zs': [<4x4 matrix, tc='d'>], 'primal objective': 2.8327595103035703, 'dual objective': 2.832759388228712, 'gap': 1.221152672314929e-07, 'relative gap': 4.310823846844613e-08, 'primal infeasibility': 0.0, 'dual infeasibility': 1.7091586164057182e-12, 'residual as primal infeasibility certificate': None, 'residual as dual infeasibility certificate': None, 'primal slack': 5.425580955940478e-09, 'dual slack': 2.857198533975067e-10}