|
Revision 1300, 0.9 KB
(checked in by dmitrey.kroshko, 18 months ago)
|
|
minor bugfix + changes in examples/llsp2.py
|
| Line | |
|---|
| 1 | __docformat__ = "restructuredtext en" |
|---|
| 2 | |
|---|
| 3 | from numpy import diag, ones, sin, cos, arange, sqrt, vstack, zeros, dot |
|---|
| 4 | from scikits.openopt import LLSP, NLP |
|---|
| 5 | |
|---|
| 6 | N = 150 |
|---|
| 7 | C1 = diag(sqrt(arange(N))) |
|---|
| 8 | C2 = (1.5+arange(N)).reshape(1, -1) * (0.8+arange(N)).reshape(-1, 1) |
|---|
| 9 | C = vstack((C1, C2)) |
|---|
| 10 | d = arange(2*N) |
|---|
| 11 | lb = -2.0+sin(arange(N)) |
|---|
| 12 | ub = 5+cos(arange(N)) |
|---|
| 13 | |
|---|
| 14 | ############################LLSP################################ |
|---|
| 15 | LLSPsolver = 'bvls' |
|---|
| 16 | p = LLSP(C, d, lb=lb, ub=ub) |
|---|
| 17 | r = p.solve(LLSPsolver) |
|---|
| 18 | #############################NLP################################ |
|---|
| 19 | NLPsolver = 'scipy_lbfgsb'# you could try scipy_tnc or ralg as well |
|---|
| 20 | #NLPsolver = 'scipy_tnc' |
|---|
| 21 | p2 = LLSP(C, d, lb=lb, ub=ub) |
|---|
| 22 | r2=p2.solve('nlp:'+NLPsolver) |
|---|
| 23 | ################################################################## |
|---|
| 24 | print '###########Results:###########' |
|---|
| 25 | print 'LLSP solver '+ LLSPsolver + ':', r.ff |
|---|
| 26 | print 'NLP solver '+ NLPsolver + ':', r2.ff |
|---|