Brief Reference

The following table is a brief overview of the functionality of PyGLPK. The intention was to present functionality in roughly the same order and groupings that they do in the GLPK reference manual, at least where appropriate. This table contains a brief description of some functionality, some simple Python code illustrating the general principles of usage, the related C API function (for the benefit of those familiar with GLPK), and a link to more detailed documentation on this subject.

Python ModuleC API?
Problem attributes
Create or delete problem object
lp = glpk.LPX() lpx_create_prob
del lp or just let garbage collector handle it lpx_delete_prob
Set or get problem name
lp.name = "pname" or del lp.name lpx_set_prob_name
lp.name (either a string or None) lpx_get_prob_name
Set or get objective function name
lp.obj.name = "oname" or del lp.obj.name lpx_set_obj_name
lp.obj.name (either a string or None) lpx_get_obj_name
Set or get optimization direction
lp.obj.maximize = True or = False lpx_set_obj_dir
lp.obj.maximize (either True or False) lpx_get_obj_dir
Add new rows or columns to a problem
lp.rows.add(num_to_add) lpx_add_rows
lp.cols.add(num_to_add) lpx_add_cols
Set or get row or column name
lp.rows[ri].name = "rname" or del lp.rows[rnum].name lpx_set_row_name
lp.cols[ci].name = "cname" or del lp.cols[cnum].name lpx_set_col_name
lp.rows[ri].name (either a string or None) lpx_get_row_name
lp.cols[ci].name (either a string or None) lpx_get_col_name
Set or get row or column bounds
lp.rows[ri].bounds = lower, upper or = equals lpx_set_row_bnds
lp.cols[ci].bounds = lower, upper or = equals lpx_set_col_bnds
lp.rows[ri].bounds (two values, each either a float or None) lpx_get_row_type
lpx_get_row_lb
lpx_get_row_ub
lp.cols[ci].bounds (two values, each either a float or None) lpx_get_col_type
lpx_get_col_lb
lpx_get_col_ub
Set or get objective coefficient or shift term
lp.obj[ci] = coef (use index None to get shift term) lpx_set_obj_coef
lp.obj[ci] (a float) lpx_get_obj_coef
Set or get row or column of the constraint matrix
lp.rows[ri].matrix = [(ci1,val1), (ci2,val2), ...] lpx_set_mat_row
lp.cols[ci].matrix = [(ri1,val1), (ri2,val2), ...] lpx_set_mat_col
lp.rows[ri].matrix (a list of int-col-index, float-value tuples) lpx_get_mat_row
lp.cols[ci].matrix (a list of int-row-index, float-value tuples) lpx_get_mat_col
Set or get the whole constraint matrix
lp.matrix = [(ri1,ci1,val1), (ri2,ci2,val2), ...] lpx_load_matrix
lp.matrix (a list of row, column, value tuples) (no analogy)
Delete rows or columns from problem object
del lp.rows[ri1, ri2, ...] or del lp.rows[r_lo:r_hi+1] lpx_del_rows
del lp.cols[ci1, ci2, ...] or del lp.cols[c_lo:c_hi+1] lpx_del_cols
Delete problem object
del lp or just let garbage collector handle it lpx_delete_prob
Indexing rows and columns by name
Index row or column by its name
lp.rows['rowname'], or 'rowname' in lp.rows to check for membership lpx_find_row
lp.cols['colname'], or 'colname' in lp.cols to check for membership lpx_find_col
The index is created when required.lpx_create_index
lpx_delete_index
Problem scaling
Scale or unscale problem data
lp.scale() lpx_scale_prob
lp.scale(False) lpx_unscale_prob
Basis operations
Construct trivial initial LP basis
lp.std_basis() lpx_std_basis
Construct advanced initial LP basis
lp.adv_basis() lpx_adv_basis
Construct advanced initial LP basis with Bixby's algorithm
lp.cpx_basis() lpx_cpx_basis
Read initial LP basis from a file
lp.read_basis(filename) lpx_read_bas
Set row or column status
lp.rows[ri].status = newstatus lpx_set_row_stat
lp.cols[ci].status = newstatus lpx_set_col_stat
Basic simplex solvers
Solve problem with the simplex method
lp.simplex() lpx_simplex
Solve problem with an exact arithmetic using simplex method
lp.exact() lpx_exact
Get generic, primal, or dual status of basic solution
lp.status (or lp.status_s to force simplex status) lpx_get_status
lp.status_primal (a string) lpx_get_prim_stat
lp.status_dual (a string) lpx_get_dual_stat
Get objective value
lp.obj.value (or lp.obj.value_s to force simplex value) lpx_get_obj_val
Get row or column status
lp.rows[ri].status (a string, one of 'bs', 'nl','nu','nf','ns') lpx_get_row_stat
lp.cols[ci].status (a string, one of 'bs', 'nl','nu','nf','ns') lpx_get_col_stat
Get row or column primal or dual value
lp.rows[ri].primal (or lp.rows[ri].primal_s to force simplex value) lpx_get_row_prim
lp.rows[ri].dual (or lp.rows[ri].dual_s to force simplex value) lpx_get_row_dual
lp.cols[ci].primal (or lp.cols[ci].primal_s to force simplex value) lpx_get_col_prim
lp.cols[ci].dual (or lp.cols[ci].dual_s to force simplex value) lpx_get_col_dual
Get non-basic variable causing unboundness
lp.ray (a row or column, or None if none has been identified) lpx_get_ray_info
Check solution's Karush-Kuhn-Tucker conditions
lp.kkt() lpx_check_kkt
Manual simplex tableau operations
I may be wrong, but I do not anticipate much desire for people to roll their own simplex solvers within the Python module. It might be nice to have though in the future, for the sake of completeness. lpx_warm_up
lpx_eval_tab_row
lpx_eval_tab_col
lpx_transform_row
lpx_transform_col
lpx_prim_ratio_test
lpx_dual_ratio_test
Interior-point solver
Solve problem with the interior-point method
lp.interior() lpx_interior
Get status of interior-point solution
lp.status (or lp.status_i to force interior point status) lpx_ipt_status
Get objective value
lp.obj.value (or lp.obj.value_i to force interior point value) lpx_ipt_obj_val
Get row or column primal or dual value
lp.rows[ri].primal (or lp.rows[ri].primal_i to force interior point value) lpx_ipt_row_prim
lp.rows[ri].dual (or lp.rows[ri].dual_i to force interior point value) lpx_ipt_row_dual
lp.cols[ci].primal (or lp.cols[ci].primal_i to force interior point value) lpx_ipt_col_prim
lp.cols[ci].dual (or lp.cols[ci].dual_i to force interior point value) lpx_ipt_col_dual
Mixed-integer programming solvers
Set or get problem class
lp.kind = int or = float lpx_set_class
lp.kind (either int or float) lpx_get_class
Set or get column kind
lp.cols[ci].kind = int or = float lpx_set_col_kind
lp.cols[ci].kind (either int or float) lpx_get_col_kind
Get number of integer columns
lp.nint (an integer) lpx_get_num_int
Get number of binary columns
lp.nbin (an integer) lpx_get_num_bin
Solve MIP problem with the B&B method
lp.integer() lpx_integer
Solve MIP problem with the advanced B&B solver
lp.intopt() lpx_intopt
Get status of MIP solution
lp.status (or lp.status_m to force MIP status) lpx_mip_status
Get objective value
lp.obj.value (or lp.obj.value_m to force MIP value) lpx_mip_obj_val
Get row or column value
lp.rows[ri].value (or lp.rows[ri].value_m to force MIP value) lpx_mip_row_val
lp.cols[ci].value (or lp.cols[ci].value_m to force MIP value) lpx_mip_col_val
Check solution's integer feasibility conditions
lp.kktint() lpx_check_int
Parameters and statistics
Reset default parameter values
lp.params.reset() lpx_reset_parms
Set or get parameters
lp.params.paramname = new_value lpx_set_int_parm
lpx_set_real_parm
lp.params.paramname lpx_get_int_parm
lpx_get_real_parm
Problem readers
Read fixed MPS format file
lp = glpk.LPX(mps=filename) lpx_read_mps
Read free MPS format file
lp = glpk.LPX(freemps=filename) lpx_read_freemps
Read GNU LP format file
lp = glpk.LPX(glp=filename) lpx_read_prob
Read CPLEX LP format file
lp = glpk.LPX(cpxlp=filename) lpx_read_cpxlp
Read GNU MathProg model file
lp = glpk.LPX(gmp=filename) or lp = glpk.LPX(gmp=(model_file, data_file, output_file)) lpx_read_model
Problem and data writers
Write problem to fixed MPS format file
lp.write(mps=filename) lpx_write_mps
Write problem to free MPS format file
lp.write(freemps=filename) lpx_write_freemps
Write problem to GNU LP format file
lp.write(glp=filename) lpx_write_prob
Write problem to CPLEX LP format file
lp.write(cpxlp=filename) lpx_write_cpxlp
Write LP basis to fixed MPS format file
lp.write(bas=filename) lpx_write_bas
Write problem to plain text file
lp.write(prob=filename) lpx_print_prob
Write basic solution to plain text file
lp.write(sol=filename) lpx_print_sol
Write bounds sensitivity information to plain text file
lp.write(sens_bnds=filename) lpx_print_sens_bnds
Write interior point solution to plain text file
lp.write(ips=filename) lpx_print_ips
Write MIP solution to plain text file
lp.write(mip=filename) lpx_print_mip

Thomas Finley, 2007