|
Revision 569, 1.1 kB
(checked in by dmitrey, 2 years ago)
|
minor oo doc change
|
| Line | |
|---|
| 1 |
""" |
|---|
| 2 |
Some non-linear functions have much more restricted dom than R^nVars. |
|---|
| 3 |
For example F(x) = log(x); dom F = R+ = {x: x>0} |
|---|
| 4 |
|
|---|
| 5 |
For optimization solvers it is wont to expect user-povided F(x) = nan if x is out of dom. |
|---|
| 6 |
|
|---|
| 7 |
I can't inform how successfully OO-connected solvers |
|---|
| 8 |
will handle a prob instance with restricted dom |
|---|
| 9 |
because it seems to be too prob-specific |
|---|
| 10 |
|
|---|
| 11 |
Still I can inform that ralg handles the problems rather well |
|---|
| 12 |
provided in every point x from R^nVars at least one ineq constraint is active |
|---|
| 13 |
(i.e. value constr[i](x) belongs to R+) |
|---|
| 14 |
|
|---|
| 15 |
Note also that some solvers require x0 inside dom objFunc. |
|---|
| 16 |
For ralg it doesn't matter. |
|---|
| 17 |
""" |
|---|
| 18 |
|
|---|
| 19 |
from numpy import * |
|---|
| 20 |
from openopt import NLP |
|---|
| 21 |
|
|---|
| 22 |
n = 100 |
|---|
| 23 |
an = arange(n) # array [0, 1, 2, ..., n-1] |
|---|
| 24 |
x0 = n+15*(1+cos(an)) |
|---|
| 25 |
|
|---|
| 26 |
f = lambda x: (x**2).sum() + sqrt(x**3).sum() |
|---|
| 27 |
df = lambda x: 2*x + 1.5*x**0.5 |
|---|
| 28 |
|
|---|
| 29 |
lb = zeros(n) |
|---|
| 30 |
solvers = ['ralg'] |
|---|
| 31 |
#solvers = ['ipopt'] |
|---|
| 32 |
for solver in solvers: |
|---|
| 33 |
p = NLP(f, x0, df=df, lb=lb, xtol = 1e-6, iprint = 50, maxIter = 10000, maxFunEvals = 1e8) |
|---|
| 34 |
#p.checkdf() |
|---|
| 35 |
r = p.solve(solver) |
|---|
| 36 |
# expected r.xf = small values near zero |
|---|