You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

441 lines
12 KiB

  1. %* glpk06.tex *%
  2. \chapter{Miscellaneous API Routines}
  3. \section{GLPK environment routines}
  4. \subsection{glp\_init\_env --- initialize GLPK environment}
  5. \synopsis
  6. \begin{verbatim}
  7. int glp_init_env(void);
  8. \end{verbatim}
  9. \description
  10. The routine \verb|glp_init_env| initializes the GLPK environment.
  11. Normally the application program does not need to call this routine,
  12. because it is called automatically on the first call to any API
  13. routine.
  14. \returns
  15. \begin{retlist}
  16. 0 & initialization successful;\\
  17. 1 & environment is already initialized;\\
  18. 2 & initialization failed (insufficient memory);\\
  19. 3 & initialization failed (unsupported programming model).\\
  20. \end{retlist}
  21. \subsection{glp\_version --- determine library version}
  22. \synopsis
  23. \begin{verbatim}
  24. const char *glp_version(void);
  25. \end{verbatim}
  26. \returns
  27. The routine \verb|glp_version| returns a pointer to a null-terminated
  28. character string, which specifies the version of the GLPK library in
  29. the form \verb|"X.Y"|, where `\verb|X|' is the major version number,
  30. and `\verb|Y|' is the minor version number, for example, \verb|"4.16"|.
  31. \newpage
  32. \subsection{glp\_free\_env --- free GLPK environment}
  33. \synopsis
  34. \begin{verbatim}
  35. int glp_free_env(void);
  36. \end{verbatim}
  37. \description
  38. The routine \verb|glp_free_env| frees all resources used by GLPK
  39. routines (memory blocks, etc.) which are currently still in use.
  40. Normally the application program does not need to call this routine,
  41. because GLPK routines always free all unused resources. However, if
  42. the application program even has deleted all problem objects, there
  43. will be several memory blocks still allocated for the internal library
  44. needs. For some reasons the application program may want GLPK to free
  45. this memory, in which case it should call \verb|glp_free_env|.
  46. Note that a call to \verb|glp_free_env| invalidates all problem objects
  47. which still exist.
  48. \returns
  49. \begin{retlist}
  50. 0 & termination successful;\\
  51. 1 & environment is inactive (was not initialized).\\
  52. \end{retlist}
  53. \subsection{glp\_printf --- write formatted output to terminal}
  54. \synopsis
  55. \begin{verbatim}
  56. void glp_printf(const char *fmt, ...);
  57. \end{verbatim}
  58. \description
  59. The routine \verb|glp_printf| uses the format control string
  60. \verb|fmt| to format its parameters and writes the formatted output to
  61. the terminal.
  62. This routine is a replacement of the standard C function
  63. \verb|printf| and used by all GLPK routines to perform terminal
  64. output. The application program may use \verb|glp_printf| for the same
  65. purpose that allows controlling its terminal output with the routines
  66. \verb|glp_term_out| and \verb|glp_term_hook|.
  67. \subsection{glp\_vprintf --- write formatted output to terminal}
  68. \synopsis
  69. \begin{verbatim}
  70. void glp_vprintf(const char *fmt, va_list arg);
  71. \end{verbatim}
  72. \description
  73. The routine \verb|glp_vprintf| uses the format control string
  74. \verb|fmt| to format its parameters specified by the list \verb|arg|
  75. and writes the formatted output to the terminal.
  76. This routine is a replacement of the standard C function
  77. \verb|vprintf| and used by all GLPK routines to perform terminal
  78. output. The application program may use \verb|glp_vprintf| for the same
  79. purpose that allows controlling its terminal output with the routines
  80. \verb|glp_term_out| and \verb|glp_term_hook|.
  81. \newpage
  82. \subsection{glp\_term\_out --- enable/disable terminal output}
  83. \synopsis
  84. \begin{verbatim}
  85. int glp_term_out(int flag);
  86. \end{verbatim}
  87. \description
  88. Depending on the parameter flag the routine \verb|glp_term_out| enables
  89. or disables terminal output performed by glpk routines:
  90. \verb|GLP_ON | --- enable terminal output;
  91. \verb|GLP_OFF| --- disable terminal output.
  92. \returns
  93. The routine \verb|glp_term_out| returns the previous value of the
  94. terminal output flag.
  95. \subsection{glp\_term\_hook --- intercept terminal output}
  96. \synopsis
  97. \begin{verbatim}
  98. void glp_term_hook(int (*func)(void *info, const char *s), void *info);
  99. \end{verbatim}
  100. \description
  101. The routine \verb|glp_term_hook| installs the user-defined hook routine
  102. to intercept all terminal output performed by GLPK routines.
  103. %This feature can be used to redirect the terminal output to other
  104. %destination, for example, to a file or a text window.
  105. The parameter {\it func} specifies the user-defined hook routine. It is
  106. called from an internal printing routine, which passes to it two
  107. parameters: {\it info} and {\it s}. The parameter {\it info} is a
  108. transit pointer specified in corresponding call to the routine
  109. \verb|glp_term_hook|; it may be used to pass some additional information
  110. to the hook routine. The parameter {\it s} is a pointer to the null
  111. terminated character string, which is intended to be written to the
  112. terminal. If the hook routine returns zero, the printing routine writes
  113. the string {\it s} to the terminal in a usual way; otherwise, if the
  114. hook routine returns non-zero, no terminal output is performed.
  115. To uninstall the hook routine both parameters {\it func} and {\it info}
  116. should be specified as \verb|NULL|.
  117. \para{Example}
  118. \begin{footnotesize}
  119. \begin{verbatim}
  120. static int hook(void *info, const char *s)
  121. { FILE *foo = info;
  122. fputs(s, foo);
  123. return 1;
  124. }
  125. int main(void)
  126. { FILE *foo;
  127. . . .
  128. glp_term_hook(hook, foo); /* redirect terminal output */
  129. . . .
  130. glp_term_hook(NULL, NULL); /* resume terminal output */
  131. . . .
  132. }
  133. \end{verbatim}
  134. \end{footnotesize}
  135. \newpage
  136. \subsection{glp\_open\_tee --- start copying terminal output}
  137. \synopsis
  138. \begin{verbatim}
  139. int glp_open_tee(const char *fname);
  140. \end{verbatim}
  141. \description
  142. The routine \verb|glp_open_tee| starts copying all the terminal output
  143. to an output text file, whose name is specified by the character string
  144. \verb|fname|.
  145. \returns
  146. \begin{retlist}
  147. 0 & operation successful;\\
  148. 1 & copying terminal output is already active;\\
  149. 2 & unable to create output file.\\
  150. \end{retlist}
  151. \subsection{glp\_close\_tee --- stop copying terminal output}
  152. \synopsis
  153. \begin{verbatim}
  154. int glp_close_tee(void);
  155. \end{verbatim}
  156. \description
  157. The routine \verb|glp_close_tee| stops copying the terminal output to
  158. the output text file previously open by the routine \verb|glp_open_tee|
  159. closing that file.
  160. \returns
  161. \begin{retlist}
  162. 0 & operation successful;\\
  163. 1 & copying terminal output was not started.\\
  164. \end{retlist}
  165. \subsection{glp\_error --- display error message and terminate
  166. execution}
  167. \synopsis
  168. \begin{verbatim}
  169. void glp_error(const char *fmt, ...);
  170. \end{verbatim}
  171. \description
  172. The routine \verb|glp_error| (implemented as a macro) formats its
  173. parameters using the format control string \verb|fmt|, writes the
  174. formatted message to the terminal, and then abnormally terminates the
  175. program.
  176. \newpage
  177. \subsection{glp\_assert --- check logical condition}
  178. \synopsis
  179. \begin{verbatim}
  180. void glp_assert(int expr);
  181. \end{verbatim}
  182. \description
  183. The routine \verb|glp_assert| (implemented as a macro) checks
  184. a logical condition specified by the expression \verb|expr|. If the
  185. condition is true (non-zero), the routine does nothing; otherwise, if
  186. the condition is false (zero), the routine prints an error message and
  187. abnormally terminates the program.
  188. This routine is a replacement of the standard C function \verb|assert|
  189. and used by all GLPK routines to check program logic. The application
  190. program may use \verb|glp_assert| for the same purpose.
  191. \subsection{glp\_error\_hook --- install hook to intercept abnormal
  192. termination}
  193. \synopsis
  194. \begin{verbatim}
  195. void glp_error_hook(void (*func)(void *info), void *info);
  196. \end{verbatim}
  197. \description
  198. The routine \verb|glp_error_hook| installs a user-defined hook routine
  199. to intercept abnormal termination.
  200. The parameter \verb|func| specifies the user-defined hook routine. It
  201. is called from the routine \verb|glp_error| before the latter calls the
  202. abort function to abnormally terminate the application program because
  203. of fatal error. The parameter \verb|info| is a transit pointer,
  204. specified in the corresponding call to the routine
  205. \verb|glp_error_hook|; it may be used to pass some information to the
  206. hook routine.
  207. To uninstall the hook routine the parameters \verb|func| and \verb|info|
  208. should be specified as \verb|NULL|.
  209. If the hook routine returns, the application program is abnormally
  210. terminated. To prevent abnormal termnation the hook routine may perform
  211. a global jump using the standard function \verb|longjmp|, in which case
  212. the application program {\it must} call the routine \verb|glp_free_env|.
  213. \subsection{glp\_malloc --- allocate memory block}
  214. \synopsis
  215. \begin{verbatim}
  216. void *glp_malloc(int size);
  217. \end{verbatim}
  218. \description
  219. The routine \verb|glp_malloc| dynamically allocates a memory block of
  220. \verb|size| bytes long. Note that:
  221. 1) the parameter \verb|size| must be positive;
  222. 2) being allocated the memory block contains arbitrary data, that is,
  223. it is {\it not} initialized by binary zeros;
  224. 3) if the block cannot be allocated due to insufficient memory, the
  225. routine prints an error message and abnormally terminates the program.
  226. This routine is a replacement of the standard C function \verb|malloc|
  227. and used by all GLPK routines for dynamic memory allocation. The
  228. application program may use \verb|glp_malloc| for the same purpose.
  229. \returns
  230. The routine \verb|glp_malloc| returns a pointer to the memory block
  231. allocated. To free this block the routine \verb|glp_free| (not the
  232. standard C function \verb|free|!) must be used.
  233. \subsection{glp\_calloc --- allocate memory block}
  234. \synopsis
  235. \begin{verbatim}
  236. void *glp_calloc(int n, int size);
  237. \end{verbatim}
  238. \description
  239. The routine \verb|glp_calloc| dynamically allocates a memory block of
  240. \verb|n|$\times$\verb|size| bytes long. Note that:
  241. 1) both parameters \verb|n| and \verb|size| must be positive;
  242. 2) being allocated the memory block contains arbitrary data, that is,
  243. it is {\it not} initialized by binary zeros;
  244. 3) if the block cannot be allocated due to insufficient memory, the
  245. routine prints an error message and abnormally terminates the program.
  246. This routine is a replacement of the standard C function \verb|calloc|
  247. (with exception that the block is not cleaned) and used by all GLPK
  248. routines for dynamic memory allocation. The application program may use
  249. \verb|glp_calloc| for the same purpose.
  250. \returns
  251. The routine \verb|glp_calloc| returns a pointer to the memory block
  252. allocated. To free this block the routine \verb|glp_free| (not the
  253. standard C function \verb|free|!) must be used.
  254. \subsection{glp\_free --- free memory block}
  255. \synopsis
  256. \begin{verbatim}
  257. void glp_free(void *ptr);
  258. \end{verbatim}
  259. \description
  260. The routine \verb|glp_free| deallocates a memory block pointed to by
  261. \verb|ptr|, which was previously allocated by the routine
  262. \verb|glp_malloc| or \verb|glp_calloc|. Note that the pointer
  263. \verb|ptr| must be valid and must not be \verb|NULL|.
  264. This routine is a replacement of the standard C function \verb|free|
  265. and used by all GLPK routines for dynamic memory allocation. The
  266. application program may use \verb|glp_free| for the same purpose.
  267. \newpage
  268. \subsection{glp\_mem\_usage --- get memory usage information}
  269. \synopsis
  270. \begin{verbatim}
  271. void glp_mem_usage(int *count, int *cpeak, size_t *total, size_t *tpeak);
  272. \end{verbatim}
  273. \description
  274. The routine \verb|glp_mem_usage| reports some information about
  275. utilization of the memory by the routines \verb|glp_malloc|,
  276. \verb|glp_calloc|, and \verb|glp_free|. Information is stored to
  277. locations specified by corresponding parameters (see below). Any
  278. parameter can be specified as \verb|NULL|, in which case corresponding
  279. information is not stored.
  280. \verb|*count| is the number of currently allocated memory blocks.
  281. \verb|*cpeak| is the peak value of \verb|*count| reached since the
  282. initialization of the GLPK library environment.
  283. \verb|*total| is the total amount, in bytes, of currently allocated
  284. memory blocks.
  285. \verb|*tpeak| is the peak value of \verb|*total| reached since the
  286. initialization of the GLPK library envirionment.
  287. \para{Example}
  288. \begin{footnotesize}
  289. \begin{verbatim}
  290. glp_mem_usage(&count, NULL, NULL, NULL);
  291. printf("%d memory block(s) are still allocated\n", count);
  292. \end{verbatim}
  293. \end{footnotesize}
  294. \subsection{glp\_mem\_limit --- set memory usage limit}
  295. \synopsis
  296. \begin{verbatim}
  297. void glp_mem_limit(int limit);
  298. \end{verbatim}
  299. \description
  300. The routine \verb|glp_mem_limit| limits the amount of memory available
  301. for dynamic allocation (with the routines \verb|glp_malloc| and
  302. \verb|glp_calloc|) to \verb|limit| megabytes.
  303. %* eof *%