You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-2Lines changed: 24 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# DNLP — Disciplined Nonlinear Programming
2
2
The DNLP package is an extension of [CVXPY](https://www.cvxpy.org/) to general nonlinear programming (NLP).
3
3
DNLP allows smooth functions to be freely mixed with nonsmooth convex and concave functions,
4
-
with some rules governing how nonsmooth convex and concave functions can appear. For details, see our paper [Disciplined Nonlinear Programming](XXX).
4
+
with some rules governing how the nonsmooth functions can be used. For details, see our paper [Disciplined Nonlinear Programming](XXX).
5
5
6
6
---
7
7
## Installation
@@ -24,10 +24,32 @@ pip install .
24
24
25
25
---
26
26
## Example
27
-
Below we give a toy example. Many more examples, including the ones in the paper, can be found at [DNLP-examples](https://github.com/cvxgrp/dnlp-examples).
27
+
Below we give a toy example where we maximize a convex quadratic function subject to a nonlinear equality constraint. Many more examples, including the ones in the paper, can be found at [DNLP-examples](https://github.com/cvxgrp/dnlp-examples).
28
28
```python
29
29
import cvxpy as cp
30
+
import numpy as np
31
+
import cvxpy as cp
32
+
33
+
# problem data
34
+
np.random.seed(0)
35
+
n =3
36
+
A = np.random.randn(n, n)
37
+
A = A.T @ A
38
+
39
+
# formulate optimization problem
40
+
x = cp.Variable(n)
41
+
obj = cp.Maximize(cp.quad_form(x, A))
42
+
constraints = [cp.sum_squares(x) ==1]
43
+
44
+
# initialize and solve
45
+
x.value = np.ones(n)
46
+
prob = cp.Problem(obj, constraints)
47
+
prob.solve(nlp=True, verbose=True)
48
+
print("Optimal value from DNLP: ", prob.value)
30
49
50
+
# the optimal value for this toy problem can also be found by computing the maximum eigenvalue of A
0 commit comments