# $Id: testOsi.txt 30 2006-07-26 21:01:43Z leolopes $ # This currently does not work. The tests work, but the doctesting doesn't. The ``osi`` module ====================== Solving a problem from an MPS file. ------------------- Make sure you have the mps file 'stein15.mps' (from the older miplib collection) in the local directory. We chose this problem because it is relatively easy. >>> import osi >>> cbc = osi.OsiCbcSolverInterface() >>> cbc.readMps('stein15.mps') # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE Coin0001I At line 15 NAME STEIN15 ... Coin0008I STEIN15 read with 0 errors 0 >>> cbc.branchAndBound() # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE Clp0006I 0 Obj 0 Primal inf 42 (36) Clp0006I 19 Obj 7 ...Clp0000I Optimal - objective value 9 >>> print "Obj: %10.2f" % cbc.getObjValue() Obj: 9.00 >>> m,n = cbc.getNumRows(), cbc.getNumCols() >>> primal = osi.doubleArray.frompointer(cbc.getColSolution()) >>> dual = osi.doubleArray.frompointer(cbc.getRowPrice()) >>> [(j,primal[j]) for j in range(n) if primal[j]] ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE [(1, 1.0), (2, 1.0), (3, 1.0), ... (12, 1.0)] >>> del cbc >>> cbc = osi.OsiCbcSolverInterface() >>> inf = cbc.getInfinity() >>> m,n = 3,2 >>> c, lb, ub = [3,2], [0,0], [inf,inf] >>> start, index, val= [0,3,5], [0,1,2,0,1], [2,1,1,1,1] >>> lhs, rhs= [-inf,-inf,-inf],[100,80,40] >>> cbc.setObjSense(-1) >>> cbc.loadProblem(n,m,start,index,val,lb,ub,c,lhs,rhs) >>> cbc.branchAndBound() ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE Cbc3007W No integer variables - nothing to do ... Clp0000I Optimal - objective value 180 >>> primal = osi.doubleArray.frompointer(cbc.getColSolution()) >>> dual = osi.doubleArray.frompointer(cbc.getRowPrice()) >>> [(j,primal[j]) for j in range(n) if primal[j]] ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE [(0, 20.0), (1, 60.0)] >>> [(i,dual[i]) for i in range(m) if dual[i]] [(0, 1.0), (1, 1.0)]