Ticket #6456: 6456-cvxopt-glpk-interface.patch

File 6456-cvxopt-glpk-interface.patch, 2.4 KB (added by dimpase, 9 years ago)

option to linear_program() to use glpk as the solver

• sage/numerical/optimize.py

```# HG changeset patch
# User Dmitrii Pasechnik <dimpase@gmail.com>
# Date 1289397322 -28800
# Node ID bab1edefee5568cd8b1f22d8924c119a1eeb5b9b
# Parent  1f29c94e03ac8c047bd2ac6358d3a649d73724eb
6456 option to linear_program() to use glpk as the solver

diff -r 1f29c94e03ac -r bab1edefee55 sage/numerical/optimize.py```
 a return vector(RDF,min) def linear_program(c,G,h,A=None,b=None): def linear_program(c,G,h,A=None,b=None,solver=None): """ Solves the dual linear programs: - ``A`` -- a matrix - ``b`` --- a vector - ``solver`` (optional) --- solver to use. If None, the cvxopt's lp-solver is used. If it is 'glpk', then glpk's solver is used. These can be over any field that can be turned into a floating point number. sage: sol=linear_program(v,m,h) sage: sol['x'] (45.000000..., 6.2499999...3, 1.00000000...) sage: sol=linear_program(v,m,h,solver='glpk') sage: sol['x'] (45.0..., 6.25, 1.0...) """ from cvxopt.base import matrix as m from cvxopt import solvers solvers.options['show_progress']=False if solver=='glpk': from cvxopt import glpk glpk.options['LPX_K_MSGLEV'] = 0 c_=m(c.base_extend(RDF).numpy()) G_=m(G.base_extend(RDF).numpy()) h_=m(h.base_extend(RDF).numpy()) if A!=None and b!=None: A_=m(A.base_extend(RDF).numpy()) b_=m(b.base_extend(RDF).numpy()) sol=solvers.lp(c_,G_,h_,A_,b_) sol=solvers.lp(c_,G_,h_,A_,b_,solver=solver) else: sol=solvers.lp(c_,G_,h_) sol=solvers.lp(c_,G_,h_,solver=solver) status=sol['status'] if status != 'optimal': return  {'primal objective':None,'x':None,'s':None,'y':None, 'z':None,'status':status} x=vector(RDF,list(sol['x'])) s=vector(RDF,list(sol['s'])) y=vector(RDF,list(sol['y'])) z=vector(RDF,list(sol['z'])) return  {'x':x,'s':s,'y':y,'z':z} return  {'primal objective':sol['primal objective'],'x':x,'s':s,'y':y, 'z':z,'status':status} def find_fit(data, model, initial_guess = None, parameters = None, variables = None, solution_dict = False):