|
Revision 971, 1.1 kB
(checked in by dmitrey.kroshko, 7 months ago)
|
some code cleanup + some changes
|
| Line | |
|---|
| 1 |
""" |
|---|
| 2 |
Example of using additional parameters for user f, c, h functions |
|---|
| 3 |
""" |
|---|
| 4 |
|
|---|
| 5 |
from scikits.openopt import NLP |
|---|
| 6 |
from numpy import asfarray |
|---|
| 7 |
|
|---|
| 8 |
f = lambda x, a: (x**2).sum() + a * x[0]**4 |
|---|
| 9 |
x0 = [8, 15, 80] |
|---|
| 10 |
p = NLP(f, x0) |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
p.c = lambda x, b, c: (x[0]-4)**2 - 1 + b*x[1]**4 + c*x[2]**4 |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
p.h = lambda x, d: (x[2]-4)**2 + d*x[2]**4 - 15 |
|---|
| 18 |
|
|---|
| 19 |
p.args.f = 4 |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
p.args.c = (1,2) |
|---|
| 23 |
|
|---|
| 24 |
p.args.h = 15 |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
r = p.solve('ralg') |
|---|
| 40 |
""" |
|---|
| 41 |
If you will encounter any problems with additional args implementation, |
|---|
| 42 |
you can use the simple python trick |
|---|
| 43 |
p.f = lambda x: other_f(x, <your_args>) |
|---|
| 44 |
same to c, h, df, etc |
|---|
| 45 |
""" |
|---|