Created
April 13, 2017 04:45
-
-
Save rdeits/f780228c722ad4550482dcb386f00f4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using JuMP | |
| using SCS | |
| using Gurobi | |
| # Objective is min. 1/2 x'Qx + q'x | |
| Q = [1 0.1; 0.1 1] | |
| q = [-3., 4] | |
| ## Solve with SCS | |
| m = Model(solver=SCSSolver()) | |
| @variable m x[1:2] | |
| @constraint m x[1] >= 1 | |
| @constraint m x[2] >= 1.5 | |
| # trick from http://www.seas.ucla.edu/~vandenbe/publications/socp.pdf | |
| @variable m slack >= 0 | |
| P = sqrtm(Q) | |
| @constraint m norm(P * x + P \ q) <= slack | |
| @objective m Min slack | |
| solve(m) | |
| getvalue(x) | |
| ## Solve with Gurobi | |
| m = Model(solver=GurobiSolver()) | |
| @variable m x[1:2] | |
| @objective m Min (x' * Q * x)[1] + 2 * (q' * x)[1] | |
| @constraint m x[1] >= 1 | |
| @constraint m x[2] >= 1.5 | |
| solve(m) | |
| getvalue(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment