|
1 | | -export @minimize |
| 1 | +export @minimize |
2 | 2 |
|
3 | 3 | """ |
4 | | -`@minimize cost [st ctr] [with slv_opt]` |
| 4 | + @minimize cost [st ctr] [with slv_opt] |
5 | 5 |
|
6 | | -Minimize a given problem with cost function `cost`, constraints `ctr` and solver options `slv_opt`. |
| 6 | +Minimize a given problem with cost function `cost`, constraints `ctr` and solver options `slv_opt`. |
7 | 7 |
|
8 | 8 | # Example |
9 | 9 |
|
10 | 10 | ```julia |
11 | | -julia> A, b = randn(10,4), randn(10); |
| 11 | +julia> using StructuredOptimization |
| 12 | +
|
| 13 | +julia> A, b, x = randn(10,4), randn(10), Variable(4); |
12 | 14 |
|
13 | 15 | julia> @minimize ls(A*x-b) + 0.5*norm(x); |
14 | | - it | gamma | fpr | tau | FBE | |
15 | | - ------|------------|------------|------------|------------| |
16 | | - 1 | 2.9152e-02 | 2.7656e+00 | 1.0000e+00 | 5.5181e+00 | |
17 | | - 9 | 2.9152e-02 | 9.9682e-05 | 1.0000e+00 | 4.4086e+00 | |
| 16 | +
|
| 17 | +julia> ~x # access array with solution |
18 | 18 |
|
19 | 19 | julia> @minimize ls(A*x-b) st x >= 0.; |
20 | | - it | gamma | fpr | tau | FBE | |
21 | | - ------|------------|------------|------------|------------| |
22 | | - 1 | 5.8304e-02 | 1.0068e+00 | 1.0000e+00 | 6.6282e+00 | |
23 | | - 3 | 5.8304e-02 | 9.5210e-16 | 1.0000e+00 | 6.5654e+00 | |
24 | 20 |
|
25 | | -julia> it, slv = @minimize ls(A*x-b) st norm(x) == 2.0 with PG(maxit = 5); |
26 | | - it | gamma | fpr | |
27 | | - ------|------------|------------| |
28 | | - 1 | 6.1373e-02 | 2.2090e+01 | |
29 | | - 5 | 3.0686e-02 | 5.5190e-01 | |
| 21 | +julia> ~x # access array with solution |
30 | 22 |
|
31 | | -``` |
| 23 | +julia> @minimize ls(A*x-b) st norm(x) == 2.0 with ForwardBackward(fast=true); |
32 | 24 |
|
33 | | -Returns as output a tuple containing the number of iterations and the constructed solver. |
| 25 | +julia> ~x # access array with solution |
| 26 | +``` |
34 | 27 |
|
| 28 | +Returns as output a tuple containing the optimization variables and the number |
| 29 | +of iterations spent by the solver algorithm. |
35 | 30 | """ |
36 | 31 | macro minimize(cf::Union{Expr, Symbol}) |
37 | 32 | cost = esc(cf) |
|
0 commit comments