Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of SecondOrderCone: Supply value of t #157

Closed
DanielDoehring opened this issue Jun 9, 2022 · 1 comment
Closed

Usage of SecondOrderCone: Supply value of t #157

DanielDoehring opened this issue Jun 9, 2022 · 1 comment

Comments

@DanielDoehring
Copy link

I have a constraint of the form
$$ \Vert A \boldsymbol x + \boldsymbol b \Vert_2 \leq 1 $$ which seems to be a perfect fit for the COSMO.Constraint together with SecondOrderCone with $t=1$. However, there seems to be no way to supply the value of $t$, but only the dimensionality dimof the argument of the norm (in my case $A \boldsymbol x + \boldsymbol b$).

Unfortunately, there are no examples how to use theSecondOrderCone cone without using JuMP. I would like to avoid JuMP since it seems unnecessary overhead for my problem and also complicates (if not completely prevents) the use of higher precision types then Float64.

@DanielDoehring DanielDoehring changed the title Usage of SecondOrderCone: Supply value of $t$ Usage of SecondOrderCone: Supply value of t Jun 9, 2022
@migarstka
Copy link
Member

Hi Daniel,

COSMO's native constraints are of the form $A x + b \in \mathcal{K}$
where $\mathcal{K}$ is one of the supported proper convex cones.

The second-order cone is defined as $(t,z) \in \mathcal{K}_{socp}$ such that
$| z|_2 \leq t $.

Therefore, to get your norm constraint into the right form, we define the vector $s = (t,z) = (1,z)$ and model the constraint
$| \hat{A} x + \hat{b} |_2 = z \leq 1$ as

(0, hat_A ) x + (1, hat_b) = $s \in \mathcal{K}_{socp}$.

Example

To solve the problem

$$ \begin{array}{ll} \text{maximize} & x_1 + x_2\\ \text{s.t.} & | \hat{A} x + \hat{b} |_2 \leq 1 \end{array} $$

where A = [sqrt(2)/4, 0; 0, \sqrt(2)/4] and b = [sqrt(2)/4; sqrt(2)/4], I would write the constraints natively like this:

using COSMO, SparseArrays, LinearAlgebra, Test

q = [-1; -1.];
P = spzeros(2, 2);
A = [sqrt(2)/4 0; 0 sqrt(2)/4];
b = [2/4; 2/4]
# We model the norm constraint using `COSMO.SecondOrderCone` as the convex set:
Aa = [0. 0; A]
ba = [1; b]
constraint1 = COSMO.Constraint(Aa, ba, COSMO.SecondOrderCone(3));

# Next, we define the settings object, the model and then assemble everything:
settings = COSMO.Settings(verbose=true);
model = COSMO.Model();
assemble!(model, P, q, constraint1, settings = settings);
res = COSMO.optimize!(model);

The solution should be $x_1=x_2 = 1$ if I am not mistaken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants