# $Id: testOsiCommands.txt 88 2006-10-23 23:57:50Z 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 cbc.branchAndBound() # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE print "Obj: %10.2f" % cbc.getObjValue() 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]] 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() primal = osi.doubleArray.frompointer(cbc.getColSolution()) dual = osi.doubleArray.frompointer(cbc.getRowPrice()) [(j,primal[j]) for j in range(n) if primal[j]] [(i,dual[i]) for i in range(m) if dual[i]] # Stopping Cbc from another thread def solve(cbc): cbc.branchAndBound() print "done"