| 1 |
""" |
|---|
| 2 |
OpenOpt GUI: |
|---|
| 3 |
function manage() usage example |
|---|
| 4 |
""" |
|---|
| 5 |
|
|---|
| 6 |
from scikits.openopt import NLP, manage |
|---|
| 7 |
from numpy import cos, arange, ones, asarray, abs, zeros |
|---|
| 8 |
N = 100 |
|---|
| 9 |
M = 5 |
|---|
| 10 |
p = NLP(lambda x: ((x-M)**2).sum(), cos(arange(N))) |
|---|
| 11 |
p.lb, p.ub = -6*ones(p.n), 6*ones(p.n) |
|---|
| 12 |
p.lb[3] = 5.5 |
|---|
| 13 |
p.ub[4] = 4.5 |
|---|
| 14 |
p.c = lambda x: [2* x[0] **4-32, x[1]**2+x[2]**2 - 8] |
|---|
| 15 |
p.h = (lambda x: 1e1*(x[-1]-1)**4, lambda x: (x[-2]-1.5)**4) |
|---|
| 16 |
|
|---|
| 17 |
""" |
|---|
| 18 |
minTime is used here |
|---|
| 19 |
for to provide enough time for user |
|---|
| 20 |
to play with GUI |
|---|
| 21 |
""" |
|---|
| 22 |
|
|---|
| 23 |
minTime = 15 |
|---|
| 24 |
p.name = 'GUI_example' |
|---|
| 25 |
p.minTime = minTime |
|---|
| 26 |
|
|---|
| 27 |
""" |
|---|
| 28 |
hence maxIter, maxFunEvals etc |
|---|
| 29 |
will not trigger till minTime |
|---|
| 30 |
|
|---|
| 31 |
only same iter point x_k-1=x_k |
|---|
| 32 |
or some coords = nan |
|---|
| 33 |
can stop calculations |
|---|
| 34 |
|
|---|
| 35 |
other antistop criteria: minFunEvals, minIter, minCPUTime |
|---|
| 36 |
however, some solvers cannot handle them |
|---|
| 37 |
""" |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
r = manage(p,'ralg', plot=1, start=True) |
|---|
| 41 |
""" |
|---|
| 42 |
or calling manage() as filed of p: |
|---|
| 43 |
r = p.manage('algencan', plot=1) |
|---|
| 44 |
""" |
|---|
| 45 |
if r is not None: |
|---|
| 46 |
|
|---|
| 47 |
print 'objfunc val:', r.ff |
|---|