## cool / src / lib / glpk.mli @ b75e5a66

History | View | Annotate | Download (5.7 KB)

1 |
(** |
---|---|

2 |
* OCaml bindings to glpk. Please see the glpk manual for further explanations |

3 |
* on the semantics of functions. |

4 |
* |

5 |
* Warning: contrarily to the C version of glpk, all indexes are 0-based. |

6 |
* |

7 |
* @author Samuel Mimram |

8 |
*) |

9 | |

10 | |

11 |
(* $Id$ *) |

12 | |

13 | |

14 |
(** {1 Types} *) (* TODO: better comment! *) |

15 | |

16 |
(** A linear programmation problem. *) |

17 |
type lp |

18 | |

19 |
(** Direction of the optimization. *) |

20 |
type direction = Minimize | Maximize |

21 | |

22 |
(** Type of bounds of an auxiliary variable. *) |

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

24 | |

25 |
(** Kind of a variable. *) |

26 |
type var_kind = |

27 |
| Continuous_var (** continuous variable *) |

28 |
| Integer_var (** integer variable *) |

29 | |

30 |
(** {1 Exceptions} *) |

31 | |

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

33 |
exception Fault |

34 | |

35 |
(** The problem has no rows and/or column. *) |

36 |
exception Empty |

37 | |

38 |
(** The LP basis is invalid beacause the number of basic variables is not the same as the number of rows. *) |

39 |
exception Bad_basis |

40 | |

41 |
(** The objective function being minimized has reached its lower limit and continues decreasing. *) |

42 |
exception Lower_limit |

43 | |

44 |
(** The objective function being maximized has reached its upper limit and continues increasing. *) |

45 |
exception Upper_limit |

46 | |

47 |
(** The problem has no primal feasible solution. *) |

48 |
exception No_primal_feasible_solution |

49 | |

50 |
(** The problem has no dual feasible solution. *) |

51 |
exception No_dual_feasible_solution |

52 | |

53 |
(** Iterations limit exceeded. *) |

54 |
exception Iteration_limit |

55 | |

56 |
(** Time limit exceeded. *) |

57 |
exception Time_limit |

58 | |

59 |
(** Very slow convergence or divergence. *) |

60 |
exception No_convergence |

61 | |

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

63 |
exception Solver_failure |

64 | |

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

66 |
exception Unknown_error |

67 | |

68 | |

69 |
(** {1 Functions} *) |

70 | |

71 |
(** {2 Creating, reading and saving problems} *) |

72 | |

73 |
(** Create a new linear programmation problem. *) |

74 |
val new_problem : unit -> lp |

75 | |

76 |
(** [make_problem dir zcoefs constrs pbounds xbounds] |

77 |
* creates the new linear programmation problem where |

78 |
* Z = Sum_i [zcoefs.(i)] * x_ i should be optimized in the direction |

79 |
* [dir] under the constraints |

80 |
* [fst pbounds.(i)] <= p_i <= [snd pbounds.(i)] and |

81 |
* [fst xbounds.(i)] <= x_i <= [snd xbounds.(i)] where p_i = Sum_j [constrs.(i).(j)] * x_j. |

82 |
* The bounds may be [+] / [- infinity]. *) |

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

84 | |

85 | |

86 |
(** {2 Setting and retreiving paramters of a problem} *) |

87 | |

88 |
(** Set the problem name. *) |

89 |
val set_prob_name : lp -> string -> unit |

90 | |

91 |
(** Retrieve the problem name. *) |

92 |
val get_prob_name : lp -> string |

93 | |

94 |
(** Set the direction of the optimization. *) |

95 |
val set_direction : lp -> direction -> unit |

96 | |

97 |
(** Retrieve the direction of the optimization. *) |

98 |
val get_direction : lp -> direction |

99 | |

100 |
(** Set the objective name. *) |

101 |
val set_obj_name : lp -> string -> unit |

102 | |

103 |
(** Retrieve the objective name. *) |

104 |
val get_obj_name : lp -> string |

105 | |

106 |
(** Add rows. *) |

107 |
val add_rows : lp -> int -> unit |

108 | |

109 |
(** Retreive the number of rows. *) |

110 |
val get_num_rows : lp -> int |

111 | |

112 |
(** Set the name of a row. *) |

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

114 | |

115 |
(** Retrieve the name of a row. *) |

116 |
val get_row_name : lp -> int -> string |

117 | |

118 |
(** Set a row bound. *) |

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

120 | |

121 |
(** Add columns. *) |

122 |
val add_columns : lp -> int -> unit |

123 | |

124 |
(** Retreive the number of columns. *) |

125 |
val get_num_cols : lp -> int |

126 | |

127 |
(** Set the name of a column. *) |

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

129 | |

130 |
(** Retrieve the name of a column. *) |

131 |
val get_col_name : lp -> int -> string |

132 | |

133 |
(** Set column kind. *) |

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

135 | |

136 |
(** Set a column boudaries. *) |

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

138 | |

139 |
(** Set an objective coefficient. *) |

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

141 | |

142 |
(** Load a constraint matrix. *) |

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

144 | |

145 |
(** Load a sparse constraint matrix stored as an array whose elements are of the |

146 |
* form ((row, column), value) indicating non-null elements of the matrix. *) |

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

148 | |

149 | |

150 |
(** {2 Solving problems and retreiving solutions} *) |

151 | |

152 |
(** Scale problem data. *) |

153 |
val scale_problem : lp -> unit |

154 | |

155 |
(** Unscale problem data. *) |

156 |
val unscale_problem : lp -> unit |

157 | |

158 |
(** Warm up the LP basis for the specified problem object using current statuses assigned to rows and columns. *) |

159 |
val warm_up : lp -> unit |

160 | |

161 |
(** Solve an LP problem using the simplex method. You must use builtin presolver |

162 |
* (see [use_presolver]) to get an exception if the problem has no feasible |

163 |
* solution. *) |

164 |
val simplex : lp -> unit |

165 | |

166 |
(** Solve an LP problem using the primal-dual interior point method. *) |

167 |
val interior : lp -> unit |

168 | |

169 |
(** Retrieve objective value. *) |

170 |
val get_obj_val : lp -> float |

171 | |

172 |
(** Get the primal value of the structural variable associated with a column. *) |

173 |
val get_col_primal : lp -> int -> float |

174 | |

175 |
(** Get the primal values of the structural variables associated with each column. *) |

176 |
val get_col_primals : lp -> float array |

177 | |

178 |
(** Get the primal value of the structural variable associated with a row. *) |

179 |
val get_row_primal : lp -> int -> float |

180 | |

181 |
(** Get the dual value of the structural variable associated with a row. *) |

182 |
val get_row_dual : lp -> int -> float |

183 | |

184 |
(** Returns whether the LP is feasible *) |

185 |
val get_status : lp -> bool |

186 | |

187 | |

188 |
(** {2 Setting parameters of the solver} *) |

189 | |

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

191 |
- 0: no output |

192 |
- 1: error message only |

193 |
- 2: normal output |

194 |
- 3: full output (includes informational messages) |

195 |
*) |

196 |
(*val set_message_level : lp -> int -> unit*) |