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

History | View | Annotate | Download (7.13 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 |
(** Class of a problem. *) |

26 |
type prob_class = |

27 |
| Linear_prog (** linear programming *) |

28 |
| Mixed_integer_prog (** mixed integer programming *) |

29 | |

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

31 |
type var_kind = |

32 |
| Continuous_var (** continuous variable *) |

33 |
| Integer_var (** integer variable *) |

34 | |

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

36 | |

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

38 |
exception Fault |

39 | |

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

41 |
exception Empty |

42 | |

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

44 |
exception Bad_basis |

45 | |

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

47 |
exception Lower_limit |

48 | |

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

50 |
exception Upper_limit |

51 | |

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

53 |
exception No_primal_feasible_solution |

54 | |

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

56 |
exception No_dual_feasible_solution |

57 | |

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

59 |
exception Iteration_limit |

60 | |

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

62 |
exception Time_limit |

63 | |

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

65 |
exception No_convergence |

66 | |

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

68 |
exception Solver_failure |

69 | |

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

71 |
exception Unknown_error |

72 | |

73 | |

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

75 | |

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

77 | |

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

79 |
val new_problem : unit -> lp |

80 | |

81 |
(** [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]. *) |

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

83 | |

84 |
(** Read problem data in CPLEX LP format from a file. *) |

85 |
val read_cplex : string -> lp |

86 | |

87 |
(** Write prblem data in CPLEX LP format into a file. *) |

88 |
val write_cplex : lp -> string -> unit |

89 | |

90 | |

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

92 | |

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

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

95 | |

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

97 |
val get_prob_name : lp -> string |

98 | |

99 |
(** Set the problem class. *) |

100 |
val set_class : lp -> prob_class -> unit |

101 | |

102 |
(** Retrieve the problem class. *) |

103 |
val get_class : lp -> prob_class |

104 | |

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

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

107 | |

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

109 |
val get_direction : lp -> direction |

110 | |

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

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

113 | |

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

115 |
val get_obj_name : lp -> string |

116 | |

117 |
(** Add rows. *) |

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

119 | |

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

121 |
val get_num_rows : lp -> int |

122 | |

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

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

125 | |

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

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

128 | |

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

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

131 | |

132 |
(** Add columns. *) |

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

134 | |

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

136 |
val get_num_cols : lp -> int |

137 | |

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

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

140 | |

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

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

143 | |

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

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

146 | |

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

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

149 | |

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

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

152 | |

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

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

155 | |

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

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

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

159 | |

160 | |

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

162 | |

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

164 |
val scale_problem : lp -> unit |

165 | |

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

167 |
val unscale_problem : lp -> unit |

168 | |

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

170 |
val warm_up : lp -> unit |

171 | |

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

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

174 |
* solution. *) |

175 |
val simplex : lp -> unit |

176 | |

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

178 |
val interior : lp -> unit |

179 | |

180 |
(** Solve a MIP proble using the branch-and-bound method. *) |

181 |
val branch_and_bound : lp -> unit |

182 | |

183 |
(** Solve a MIP proble using and optimized version of the branch-and-bound method. *) |

184 |
val branch_and_bound_opt : lp -> unit |

185 | |

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

187 |
val get_obj_val : lp -> float |

188 | |

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

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

191 | |

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

193 |
val get_col_primals : lp -> float array |

194 | |

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

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

197 | |

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

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

200 | |

201 | |

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

203 | |

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

205 |
- 0: no output |

206 |
- 1: error message only |

207 |
- 2: normal output |

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

209 |
*) |

210 |
val set_message_level : lp -> int -> unit |

211 | |

212 |
(** Use the builtin LP-presolver in [simplex]? *) |

213 |
val use_presolver : lp -> bool -> unit |

214 | |

215 |
(** Initialize the simplex iteration counter. *) |

216 |
val set_simplex_iteration_count : lp -> int -> unit |

217 | |

218 |
(** Reset the simplex iteration counter. *) |

219 |
val reset_simplex_iteration_count : lp -> unit |

220 | |

221 |
(** This number is incremented after each simplex iteration. *) |

222 |
val get_simplex_iteration_count : lp -> int |

223 | |

224 |
(** Set the maximum number of iterations that [simplex] should do. *) |

225 |
val set_simplex_iteration_limit : lp -> int -> unit |

226 | |

227 |
(** Retrieve the maximum number of iterations that [simplex] should do. *) |

228 |
val get_simplex_iteration_limit : lp -> int |

229 | |

230 |
(** Set the maximum amount of time that [simplex] should take. *) |

231 |
val set_simplex_time_limit : lp -> float -> unit |

232 | |

233 |
(** Retrieve the maximum amount of time that [simplex] should take. *) |

234 |
val get_simplex_time_limit : lp -> float |