-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from oxfordcontrol/pg/v0.5.0
Pg/v0.5.0
- Loading branch information
Showing
44 changed files
with
675 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# [Supported Cone Types](@id api-cone-types) | ||
|
||
|
||
Clarabel natively supports optimization problems with conic constraints defined on the following cones: | ||
|
||
Cone Type| Constructor | Definition | ||
----- | :----- | :----- | ||
Zero cone | `ZeroConeT(n)` | ``\{ 0 \}^{n}`` | ||
Nonnegative orthant | `NonnegativeConeT(n)` | ``\{ x \in \mathbb{R}^{n} : x_i \ge 0, \forall i=1,\dots,\mathrm{n} \}`` | ||
Second order cone | `SecondOrderConeT(n)` | ``\{ (t,x) \in \mathbb{R}^{n} : \|x\|_2 \leq t \}`` | ||
Exponential Cone | `ExponentialConeT()` | ``\{(x, y, z) : y > 0,~~ ye^{x/y} ≤ z \}`` | ||
Power cone | `PowerConeT(a)` | ``\{(x, y, z) : x^a y^{(1-a)} \geq \|z\|,~ (x,y) \geq 0 \}`` with ``a \in (0,1)`` | ||
Positive semidefinite cone (triangular part) | `PSDTriangleConeT(n)` | Upper triangular part of the positive semidefinite cone ``\mathbb{S}^{n}_+``. The elements ``x`` of this cone represent the columnwise stacking of the upper triangular part of a positive semidefinite matrix ``X \in \mathbb{S}^{n}_+``, so that ``x \in \mathbb{R}^d`` with ``d = {n(n+1)}/{2}.`` |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Exponential Cone Example | ||
|
||
In this example we show how to model optimization problems with exponential cone constraints. The exponential cone is defined as | ||
```math | ||
\begin{aligned} | ||
\mathcal{K}_{exp} =& \{(x, y, z) \mid y \geq 0,~ ye^{x/y} \le z\} ~\cup~ \\ | ||
& \{ (x,y,z) \mid x \leq 0, y = 0, z \geq 0 \} | ||
\end{aligned} | ||
``` | ||
|
||
We will solve the following optimization problem: | ||
|
||
```math | ||
\begin{array}{ll} \text{maximize} &x\\[2ex] | ||
\text{subject to} & | ||
\begin{array}{rl} | ||
y e^{x / y} &\!\le~z \\ | ||
y \!&=~1\\ | ||
z \!&=~e^5. | ||
\end{array} | ||
\end{array} | ||
``` | ||
|
||
### Objective function | ||
|
||
The Clarabel solver's default configuration expects problems to be posed as minimization problems, so we define: | ||
|
||
```math | ||
P = 0 | ||
\textrm{~~~and~~~} | ||
q = - | ||
\begin{bmatrix} 1 & 0 & 0 | ||
\end{bmatrix}^T. | ||
``` | ||
|
||
|
||
### Constraints | ||
|
||
The solver's default configuration expects constraints in the form $Ax + s = b$, where $s$ is in a cone or composition of cones. In this case we can write | ||
```math | ||
\begin{bmatrix} 0 \\ 0 \\ 0 | ||
\end{bmatrix} | ||
- I | ||
\begin{bmatrix} x \\ y \\ z | ||
\end{bmatrix} = s | ||
\in \mathcal{K}_{exp}, | ||
``` | ||
and then append the two additional equality constraints. | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Power Cone Example | ||
|
||
In this example we show how to model optimization problems with 3-dimensional power cone constraints. The power cone is defined as | ||
```math | ||
`\mathcal{K}_{pow}(\alpha) = \{(x, y, z) \mid x^\alpha y^{(1-\alpha)} | ||
\geq |z|, (x,y) \geq 0 \} | ||
``` | ||
with $\alpha \in (0,1)$. | ||
|
||
We will solve the following optimization problem: | ||
|
||
```math | ||
\begin{array}{ll} \text{maximize} & x_1^{0.6} y^{0.4} + x_2^{0.1}\\[2ex] | ||
\text{subject to} & | ||
\begin{array}{rl} | ||
(x_1, y, x_2) &\ge 0 \\ | ||
x_1 + 2y + 3x_2 &= 3 | ||
\end{array} | ||
\end{array} | ||
``` | ||
which is equivalent to | ||
|
||
```math | ||
\begin{array}{ll} \text{maximize} & z_1 + z_2\\[2ex] | ||
\text{subject to} & | ||
\begin{array}{rl} | ||
(x1, y, z1) &\in~\mathcal{K}_{pow}(0.6) \\ | ||
(x2, 1, z2) &\in~\mathcal{K}_{pow}(0.1) \\ | ||
x_1 + 2y + 3x_2 &=~3. | ||
\end{array} | ||
\end{array} | ||
``` | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Semidefinite Program (SDP) Example | ||
|
||
In this example we show how to model semidefinite programming problems, i.e. problems defined with constraints on the symmetric positive semidefinite cone. | ||
|
||
Given some symmetric matrix $X \in \mathbb{R}^{n\times n}$, Clarabel takes only the upper triangular vector of $n(n+1)/2$ entries when imposing semidefinite constraints. For example, given a $3 \times 3$ symmetric matrix variable | ||
```math | ||
X = \begin{bmatrix} | ||
x_1 & x_2 & x_4 \\ | ||
x_2 & x_3 & x_5 \\ | ||
x_4 & x_5 & x_6 | ||
\end{bmatrix} | ||
``` | ||
we would take as our decision variable the 6 element vector | ||
```math | ||
x = | ||
\begin{bmatrix} | ||
x_1 & x_2 & x_3 & x_4 & x_5 & x_6 | ||
\end{bmatrix}. | ||
``` | ||
|
||
We define an operation | ||
```math | ||
\textrm{vec}(X) = | ||
\begin{bmatrix} | ||
x_1 & \sqrt{2}x_2 & x_3 & \sqrt{2}x_4 & \sqrt{2}x_5 & x_6 | ||
\end{bmatrix} | ||
``` | ||
on symmetric matrices such that inner products are preserved, i.e. $\textrm{tr}(AB) = | ||
\textrm{vec}(A)^T\textrm{vec}(B)$, and will use the relationship | ||
```math | ||
S \in \mathbb{R}^{n} \quad \Longleftrightarrow \quad \textrm{vec}(S) \in \mathcal{K}_{\text{tri}}^n | ||
``` | ||
where $\mathcal{K}_{\text{tri}}^n$ is the positive semidefinite triangle cone. | ||
|
||
### Problem statement | ||
|
||
We will solve the following optimization problem: | ||
|
||
```math | ||
\begin{array}{ll} \text{minimize} &\textrm{trace}(X)\\[2ex] | ||
\text{subject to} & | ||
\begin{gathered} | ||
\langle A,X\rangle = 1 \\ | ||
X \succeq 0 | ||
\end{gathered} | ||
\end{array} | ||
``` | ||
|
||
where $X = X^T \in\mathbb{R}^{3\times 3}$ and the symmetric matrix $A$ is defined as | ||
```math | ||
A = \begin{bmatrix} | ||
1 & 2 & 4 \\ | ||
2 & 3 & 5 \\ | ||
4 & 5 & 6 | ||
\end{bmatrix} | ||
``` | ||
|
||
### Objective function | ||
|
||
We can model the trace of the matrix $X$ by defining our objective function as | ||
```math | ||
\frac{1}{2}x^TPx + q^Tx | ||
``` | ||
with $P = 0$ and | ||
$q = \begin{bmatrix} | ||
1 & 0 & 1 & 0 & 0 & 1 | ||
\end{bmatrix}^T$, | ||
where the elements of $q$ are chosen to select those elements of $x$ corresonding to the diagonal of the matrix $X$. | ||
|
||
### Constraints | ||
|
||
The solver's default configuration expects constraints in the form $Ax + s = b$. In this we can write our semidefiniteness constraint as | ||
```math | ||
-\text{vec}(X) = s \in \mathcal{K}_{\text{tri}}^n | ||
``` | ||
where $\mathcal{K}_{\text{tri}}^n$ is the cone of vectors representing the triangular part of matrices in $\mathbb{S}_+^n$. | ||
|
||
|
||
For the equality constraint can we must be careful to rewrite the inner product on $X$ in a form that is an equivalent linear function of $x$. We therefore write | ||
```math | ||
\begin{aligned} | ||
\langle A,X\rangle &= \textrm{vec}(A)^T\textrm{vec}(X) \\ | ||
&= \begin{bmatrix} | ||
1 & (2\cdot 2) & 3 & (2\cdot 4) & (2\cdot 5) & 6 | ||
\end{bmatrix} | ||
\begin{bmatrix} | ||
x_1 \\ x_2 \\ x_3 \\ x_4 \\ x_5 \\ x_6 | ||
\end{bmatrix} = 1. | ||
\end{aligned} | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
example_*.md | ||
example_*.md |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Julia examples in this directory are automatically built from the <repo>/examples/jl using the Literate.jl package during documentation build. | ||
Julia examples in this directory are automatically built from the <repo>/examples/jl using the Literate.jl package during documentation build. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
````@eval | ||
using Documenter | ||
Documenter.md_include( | ||
source = "examples/py/example_QP.py", | ||
source = "examples/py/example_qp.py", | ||
language = :python) | ||
```` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
````@eval | ||
using Documenter | ||
Documenter.md_include( | ||
source = "examples/py/example_SOCP.py", | ||
source = "examples/py/example_socp.py", | ||
language = :python) | ||
```` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
````@eval | ||
using Documenter | ||
Documenter.md_include( | ||
source = "examples/py/example_expcone.py", | ||
language = :python) | ||
```` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
````@eval | ||
using Documenter | ||
Documenter.md_include( | ||
source = "examples/py/example_powcone.py", | ||
language = :python) | ||
```` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
````@eval | ||
using Documenter | ||
Documenter.md_include( | ||
source = "examples/py/example_sdp.py", | ||
language = :python) | ||
```` |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Complete Cargo projects for all Rust examples can be found in [examples/rs](https://github.com/oxfordcontrol/ClarabelDocs/tree/main/examples/rs). | ||
|
||
````@eval | ||
using Documenter | ||
Documenter.md_include( | ||
source = "examples/rs/example_expcone/src/main.rs", | ||
language = :rust) | ||
```` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Complete Cargo projects for all Rust examples can be found in [examples/rs](https://github.com/oxfordcontrol/ClarabelDocs/tree/main/examples/rs). | ||
|
||
````@eval | ||
using Documenter | ||
Documenter.md_include( | ||
source = "examples/rs/example_powcone/src/main.rs", | ||
language = :rust) | ||
```` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Complete Cargo projects for all Rust examples can be found in [examples/rs](https://github.com/oxfordcontrol/ClarabelDocs/tree/main/examples/rs). | ||
|
||
````@eval | ||
using Documenter | ||
Documenter.md_include( | ||
source = "examples/rs/example_sdp/src/main.rs", | ||
language = :rust) | ||
```` |
This file contains 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
This file contains 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
Oops, something went wrong.