Skip to content

Instantly share code, notes, and snippets.

@ruloweb
Created September 30, 2018 04:12
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 ruloweb/d1c2653a29321cde43158076d1890cf9 to your computer and use it in GitHub Desktop.
Save ruloweb/d1c2653a29321cde43158076d1890cf9 to your computer and use it in GitHub Desktop.
from cvxpy import *
import numpy
# Problem data.
m = 30
n = 20
numpy.random.seed(1)
A = numpy.random.randn(m, n)
b = numpy.random.randn(m)
# Construct the problem.
x = Variable(n)
objective = Minimize(sum_squares(A*x - b))
constraints = [0 <= x, x <= 1]
prob = Problem(objective, constraints)
# The optimal objective is returned by prob.solve().
result = prob.solve("SCS", gpu=True, verbose=True)
# The optimal value for x is stored in x.value.
print(x.value)
# The optimal Lagrange multiplier for a constraint
# is stored in constraint.dual_value.
print(constraints[0].dual_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment