|
Revision 1025, 1.1 kB
(checked in by dmitrey.kroshko, 3 weeks ago)
|
preparation for new oo ver
|
| Line | |
|---|
| 1 |
__docformat__ = "restructuredtext en" |
|---|
| 2 |
|
|---|
| 3 |
from numpy import * |
|---|
| 4 |
from scikits.openopt import MILP |
|---|
| 5 |
|
|---|
| 6 |
f = [1, 2, 3, 4, 5, 4, 2, 1] |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
intVars = [4, 7] |
|---|
| 13 |
|
|---|
| 14 |
lb = -1.5 * ones([8,1]) |
|---|
| 15 |
ub = 15 * ones([8,1]) |
|---|
| 16 |
A = zeros((5, 8)) |
|---|
| 17 |
b = zeros(5) |
|---|
| 18 |
for i in xrange(5): |
|---|
| 19 |
for j in xrange(8): |
|---|
| 20 |
A[i,j] = -8+sin(8*i) + cos(15*j) |
|---|
| 21 |
b[i] = -150 + 80*sin(80*i) |
|---|
| 22 |
|
|---|
| 23 |
p = MILP(f=f, lb=lb, ub=ub, A=A, b=b, intVars=intVars) |
|---|
| 24 |
|
|---|
| 25 |
r = p.solve('glpk') |
|---|
| 26 |
print 'f_opt:', r.ff |
|---|
| 27 |
print 'x_opt:', r.xf |
|---|
| 28 |
|
|---|
| 29 |
""" |
|---|
| 30 |
if you have installed glpk+cvxopt 1.0 or later |
|---|
| 31 |
(with BUILD_GLPK=1 in setup.py file) |
|---|
| 32 |
you can handle MILP problems with binary constraints |
|---|
| 33 |
(coords x from p.binVars should be in {0, 1}): |
|---|
| 34 |
|
|---|
| 35 |
p = MILP(f=f, lb=lb, ub=ub, A=A, b=b, intVars=intVars, binVars=[1]) |
|---|
| 36 |
#intVars, binVars indexing from ZERO! |
|---|
| 37 |
r = p.solve('glpk') |
|---|
| 38 |
|
|---|
| 39 |
print 'f_opt:', r.ff # 26.566058805272387 |
|---|
| 40 |
print 'x_opt:', r.xf # [15. 1. -1.5 -1.5 -1. -1.5 8.0330294 15.] |
|---|
| 41 |
""" |
|---|