|
Revision 1456, 0.8 kB
(checked in by dmitrey.kroshko, 2 months ago)
|
some more code for GUI
|
| Line | |
|---|
| 1 |
from scikits.openopt import NLP |
|---|
| 2 |
from numpy import cos, arange, ones, asarray, abs, zeros |
|---|
| 3 |
N = 30 |
|---|
| 4 |
M = 5 |
|---|
| 5 |
ff = lambda x: ((x-M)**2).sum() |
|---|
| 6 |
p = NLP(ff, cos(arange(N))) |
|---|
| 7 |
p.df = lambda x: 2*(x-M) |
|---|
| 8 |
p.c = lambda x: [2* x[0] **4-32, x[1]**2+x[2]**2 - 8] |
|---|
| 9 |
|
|---|
| 10 |
def DC(x): |
|---|
| 11 |
r = zeros((2, p.n)) |
|---|
| 12 |
r[0,0] = 2 * 4 * x[0]**3 |
|---|
| 13 |
r[1,1] = 2 * x[1] |
|---|
| 14 |
r[1,2] = 2 * x[2] |
|---|
| 15 |
return r |
|---|
| 16 |
p.dc = DC |
|---|
| 17 |
|
|---|
| 18 |
h1 = lambda x: 1e1*(x[-1]-1)**4 |
|---|
| 19 |
h2 = lambda x: (x[-2]-1.5)**4 |
|---|
| 20 |
p.h = (h1, h2) |
|---|
| 21 |
|
|---|
| 22 |
def DH(x): |
|---|
| 23 |
r = zeros((2, p.n)) |
|---|
| 24 |
r[0,-1] = 1e1*4*(x[-1]-1)**3 |
|---|
| 25 |
r[1,-2] = 4*(x[-2]-1.5)**3 |
|---|
| 26 |
return r |
|---|
| 27 |
p.dh = DH |
|---|
| 28 |
|
|---|
| 29 |
p.lb = -6*ones(p.n) |
|---|
| 30 |
p.ub = 6*ones(p.n) |
|---|
| 31 |
p.lb[3] = 5.5 |
|---|
| 32 |
p.ub[4] = 4.5 |
|---|
| 33 |
|
|---|
| 34 |
r = p.solve('lincher') |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
print 'objfunc val:', r.ff |
|---|