Skip to content

Instantly share code, notes, and snippets.

@jfsantos
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsantos/e4a17788656b515a118d to your computer and use it in GitHub Desktop.
Save jfsantos/e4a17788656b515a118d to your computer and use it in GitHub Desktop.
using JuMP, Gurobi, MAT, Base.Test
# Reading problem variables from .mat file
vars = matread("data.mat")
D = vars["D"]
F = vars["F"]
c = vars["c"]
cvx_x = vars["true_x"]
m = Model(solver=GurobiSolver())
@defVar(m, x[1:5])
#@setObjective(m, :Min, c'*x + x'*D*x + sum((F'*x).^2))
@setObjective(m, Min, sum{c[i]*x[i] + D[i,i]*x[i]*x[i], i=1:5} + dot(F[:,1],x)^2 + dot(F[:,2],x)^2)
@addConstraint(m, sum(x) == 1)
status = solve(m)
jump_x = getValue(x).innerArray
@test_approx_eq jump_x cvx_x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment