Module Glpk

* OCaml bindings to glpk. Please see the glpk manual for further explanations * on the semantics of functions. * * Warning: contrarily to the C version of glpk, all indexes are 0-based. * *

Types

type lp

A linear programmation problem.

type direction =
| Minimize
| Maximize

Direction of the optimization.

type aux_var_type =
| Free_var
| Lower_bounded_var
| Upper_bounded_var
| Double_bounded_var
| Fixed_var

Type of bounds of an auxiliary variable.

type prob_class =
| Linear_prog(*

linear programming

*)
| Mixed_integer_prog(*

mixed integer programming

*)

Class of a problem.

type var_kind =
| Continuous_var(*

continuous variable

*)
| Integer_var(*

integer variable

*)

Kind of a variable.

Exceptions

exception Fault

The problem has no rows/columns, or the initial basis is invalid, or the initial basis matrix is singular or ill-conditionned.

exception Empty

The problem has no rows and/or column.

exception Bad_basis

The LP basis is invalid beacause the number of basic variables is not the same as the number of rows.

exception Lower_limit

The objective function being minimized has reached its lower limit and continues decreasing.

exception Upper_limit

The objective function being maximized has reached its upper limit and continues increasing.

exception No_primal_feasible_solution

The problem has no primal feasible solution.

exception No_dual_feasible_solution

The problem has no dual feasible solution.

exception Iteration_limit

Iterations limit exceeded.

exception Time_limit

Time limit exceeded.

exception No_convergence

Very slow convergence or divergence.

exception Solver_failure

Failure of the solver (the current basis matrix got singular or ill-conditionned).

exception Unknown_error

Unknown error (this exception should disappear in future versions).

Functions

Creating, reading and saving problems

val new_problem : unit -> lp

Create a new linear programmation problem.

val make_problem : direction -> float array -> float array array -> (float * float) array -> (float * float) array -> lp

make_problem dir zcoefs constrs pbounds xbounds creates the new linear programmation problem where Z = Sum_i zcoefs.(i) * x_ i should be optimized in the direction dir under the constraints fst pbounds.(i) <= p_i <= snd pbounds.(i) and fst xbounds.(i) <= x_i <= snd xbounds.(i) where p_i = Sum_j constrs.(i).(j) * x_j. The bounds may be + / - infinity.

val read_cplex : string -> lp

Read problem data in CPLEX LP format from a file.

val write_cplex : lp -> string -> unit

Write prblem data in CPLEX LP format into a file.

Setting and retreiving paramters of a problem

val set_prob_name : lp -> string -> unit

Set the problem name.

val get_prob_name : lp -> string

Retrieve the problem name.

val set_class : lp -> prob_class -> unit

Set the problem class.

val get_class : lp -> prob_class

Retrieve the problem class.

val set_direction : lp -> direction -> unit

Set the direction of the optimization.

val get_direction : lp -> direction

Retrieve the direction of the optimization.

val set_obj_name : lp -> string -> unit

Set the objective name.

val get_obj_name : lp -> string

Retrieve the objective name.

val add_rows : lp -> int -> unit

Add rows.

val get_num_rows : lp -> int

Retreive the number of rows.

val set_row_name : lp -> int -> string -> unit

Set the name of a row.

val get_row_name : lp -> int -> string

Retrieve the name of a row.

val set_row_bounds : lp -> int -> aux_var_type -> float -> float -> unit

Set a row bound.

val add_columns : lp -> int -> unit

Add columns.

val get_num_cols : lp -> int

Retreive the number of columns.

val set_col_name : lp -> int -> string -> unit

Set the name of a column.

val get_col_name : lp -> int -> string

Retrieve the name of a column.

val set_col_kind : lp -> int -> var_kind -> unit

Set column kind.

val set_col_bounds : lp -> int -> aux_var_type -> float -> float -> unit

Set a column boudaries.

val set_obj_coef : lp -> int -> float -> unit

Set an objective coefficient.

val load_matrix : lp -> float array array -> unit

Load a constraint matrix.

val load_sparse_matrix : lp -> ((int * int) * float) array -> unit

Load a sparse constraint matrix stored as an array whose elements are of the * form ((row, column), value) indicating non-null elements of the matrix.

Solving problems and retreiving solutions

val scale_problem : lp -> unit

Scale problem data.

val unscale_problem : lp -> unit

Unscale problem data.

val warm_up : lp -> unit

Warm up the LP basis for the specified problem object using current statuses assigned to rows and columns.

val simplex : lp -> unit

Solve an LP problem using the simplex method. You must use builtin presolver * (see use_presolver) to get an exception if the problem has no feasible * solution.

val interior : lp -> unit

Solve an LP problem using the primal-dual interior point method.

val branch_and_bound : lp -> unit

Solve a MIP proble using the branch-and-bound method.

val branch_and_bound_opt : lp -> unit

Solve a MIP proble using and optimized version of the branch-and-bound method.

val get_obj_val : lp -> float

Retrieve objective value.

val get_col_primal : lp -> int -> float

Get the primal value of the structural variable associated with a column.

val get_col_primals : lp -> float array

Get the primal values of the structural variables associated with each column.

val get_row_primal : lp -> int -> float

Get the primal value of the structural variable associated with a row.

val get_row_dual : lp -> int -> float

Get the dual value of the structural variable associated with a row.

Setting parameters of the solver

val set_message_level : lp -> int -> unit

Set the level of messages output by sover routines. The second argument might be:

  • 0: no output
  • 1: error message only
  • 2: normal output
  • 3: full output (includes informational messages)
val use_presolver : lp -> bool -> unit

Use the builtin LP-presolver in simplex?

val set_simplex_iteration_count : lp -> int -> unit

Initialize the simplex iteration counter.

val reset_simplex_iteration_count : lp -> unit

Reset the simplex iteration counter.

val get_simplex_iteration_count : lp -> int

This number is incremented after each simplex iteration.

val set_simplex_iteration_limit : lp -> int -> unit

Set the maximum number of iterations that simplex should do.

val get_simplex_iteration_limit : lp -> int

Retrieve the maximum number of iterations that simplex should do.

val set_simplex_time_limit : lp -> float -> unit

Set the maximum amount of time that simplex should take.

val get_simplex_time_limit : lp -> float

Retrieve the maximum amount of time that simplex should take.