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; this information can be safely ignored if you are not), and a link to more detailed documentation on this subject with the ? links.

Python ModuleC API?
Problem attributes
Create or delete problem object
lp = glpk.LPX() glp_create_prob
del lp or just let garbage collector handle it glp_delete_prob
Reinitialize problem object
lp.erase() glp_erase_prob
Set or get problem name = "pname" or del glp_set_prob_name (either a string or None) glp_get_prob_name
Set or get objective function name = "oname" or del glp_set_obj_name (either a string or None) glp_get_obj_name
Set or get optimization direction
lp.obj.maximize = True or = False glp_set_obj_dir
lp.obj.maximize (either True or False) glp_get_obj_dir
Add new rows or columns to a problem
lp.rows.add(num_to_add) glp_add_rows
lp.cols.add(num_to_add) glp_add_cols
Set or get row or column name
lp.rows[ri].name = "rname" or del lp.rows[rnum].name glp_set_row_name
lp.cols[ci].name = "cname" or del lp.cols[cnum].name glp_set_col_name
lp.rows[ri].name (either a string or None) glp_get_row_name
lp.cols[ci].name (either a string or None) glp_get_col_name
Set or get row or column bounds
lp.rows[ri].bounds = lower, upper or = equals glp_set_row_bnds
lp.cols[ci].bounds = lower, upper or = equals glp_set_col_bnds
lp.rows[ri].bounds (two values, each either a float or None) glp_get_row_type
lp.cols[ci].bounds (two values, each either a float or None) glp_get_col_type
Set or get objective coefficient or shift term
lp.obj[ci] = coef (use index None to get shift term) glp_set_obj_coef
lp.obj[ci] (a float) glp_get_obj_coef
Set or get row or column of the constraint matrix
lp.rows[ri].matrix = [(ci1,val1), (ci2,val2), ...] glp_set_mat_row
lp.cols[ci].matrix = [(ri1,val1), (ri2,val2), ...] glp_set_mat_col
lp.rows[ri].matrix (a list of int-col-index, float-value tuples) glp_get_mat_row
lp.cols[ci].matrix (a list of int-row-index, float-value tuples) glp_get_mat_col
Set or get the whole constraint matrix
lp.matrix = [(ri1,ci1,val1), (ri2,ci2,val2), ...] glp_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] glp_del_rows
del lp.cols[ci1, ci2, ...] or del lp.cols[c_lo:c_hi+1] glp_del_cols
Delete problem object
del lp or just let garbage collector handle it glp_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 glp_find_row
lp.cols['colname'], or 'colname' in lp.cols to check for membership glp_find_col
The index is created when required.glp_create_index
Problem scaling
Automatically scale or unscale problem data
lp.scale() glp_scale_prob
lp.unscale() glp_unscale_prob
Set or get scaling of row and column data
lp.rows[i].scale = factor glp_set_rii
lp.cols[i].scale = factor glp_set_sjj
lp.rows[i].scale (a float) glp_get_rii
lp.cols[i].scale (a float) glp_get_sjj
Basis operations
Construct trivial initial LP basis
lp.std_basis() glp_std_basis
Construct advanced initial LP basis
lp.adv_basis() glp_adv_basis
Construct advanced initial LP basis with Bixby's algorithm
lp.cpx_basis() glp_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 glp_set_row_stat
lp.cols[ci].status = newstatus glp_set_col_stat
Basic simplex solvers
Solve problem with the simplex method
lp.simplex() glp_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) glp_get_status
lp.status_primal (a string) glp_get_prim_stat
lp.status_dual (a string) glp_get_dual_stat
Get objective value
lp.obj.value (or lp.obj.value_s to force simplex value) glp_get_obj_val
Get row or column status
lp.rows[ri].status (a string, one of 'bs', 'nl','nu','nf','ns') glp_get_row_stat
lp.cols[ci].status (a string, one of 'bs', 'nl','nu','nf','ns') glp_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) glp_get_row_prim
lp.rows[ri].dual (or lp.rows[ri].dual_s to force simplex value) glp_get_row_dual
lp.cols[ci].primal (or lp.cols[ci].primal_s to force simplex value) glp_get_col_prim
lp.cols[ci].dual (or lp.cols[ci].dual_s to force simplex value) glp_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. Please write me if my guess is incorrect. It might be nice to have though in the future, for the sake of completeness. lpx_warm_up
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) glp_ipt_status
Get objective value
lp.obj.value (or lp.obj.value_i to force interior point value) glp_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) glp_ipt_row_prim
lp.rows[ri].dual (or lp.rows[ri].dual_i to force interior point value) glp_ipt_row_dual
lp.cols[ci].primal (or lp.cols[ci].primal_i to force interior point value) glp_ipt_col_prim
lp.cols[ci].dual (or lp.cols[ci].dual_i to force interior point value) glp_ipt_col_dual
Mixed-integer programming solvers
Set or get problem class
lp.kind (either int or float) lpx_get_class
Set or get column kind
lp.cols[ci].kind = int or = bool or = float glp_set_col_kind
lp.cols[ci].kind (either int, bool, or float) glp_get_col_kind
Get number of integer columns
lp.nint (an integer) glp_get_num_int
Get number of binary columns
lp.nbin (an integer) glp_get_num_bin
Solve MIP problem with the B&B method
lp.integer() glp_intopt
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) glp_mip_status
Get objective value
lp.obj.value (or lp.obj.value_m to force MIP value) glp_mip_obj_val
Get row or column value
lp.rows[ri].value (or lp.rows[ri].value_m to force MIP value) glp_mip_row_val
lp.cols[ci].value (or lp.cols[ci].value_m to force MIP value) glp_mip_col_val
Check solution's integer feasibility conditions
lp.kktint() lpx_check_int
MIP Branch-&-Cut Advanced Interface
Access the problem object
tree.lp glp_ios_get_prob
Determine the size of the branch and bound tree
tree.num_active (all ints) glp_ios_tree_size
Determine current active subproblem
tree.curr_node glp_ios_curr_node
Determine first active subproblem
tree.first_node glp_ios_next_node
Determine last active subproblem
tree.last_node glp_ios_prev_node
Determine next active subproblem glp_ios_next_node
Determine previous active subproblem
node.prev glp_ios_prev_node
Determine parent subproblem
node.up glp_ios_up_node
Determine subproblem level
node.level (an int) glp_ios_node_level
Determine subproblem local bound
node.bound (a float) glp_ios_node_bound
Find active subproblem with best local bound
tree.best_node glp_ios_best_node
Compute relative MIP gap (a float) glp_ios_mip_gap
Select subproblem to continue the search glp_ios_select_node
Provide solution found by heuristic
tree.heuristic(values) glp_ios_heur_sol
Check if can branch upon specified variable
tree.can_branch(colnum) glp_ios_can_branch
Choose variable to branch upon
tree.branch_upon(colnum, 'D') glp_ios_branch_upon
Terminate the solution process
tree.terminate() glp_ios_terminate
Get GLPK version
glpk.env.version glp_version
Monitor memory usage
glpk.env.blocks (all integers) glp_mem_usage
Limit memory usage
glpk.env.mem_limit = max_megabytes (an integer) glp_mem_limit
Control terminal output
glpk.env.term_on = True or False glp_term_out
glpk.env.term_hook = output_func glp_term_hook
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, 2008