/farmR/src/glpapi14.c

https://code.google.com/p/javawfm/ · C · 336 lines · 69 code · 27 blank · 240 comment · 9 complexity · 808600ba356e4811620fb1104ddf1ac4 MD5 · raw file

  1. /* glpapi14.c (library environment routines) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2000,01,02,03,04,05,06,07,08,2009 Andrew Makhorin,
  6. * Department for Applied Informatics, Moscow Aviation Institute,
  7. * Moscow, Russia. All rights reserved. E-mail: <mao@mai2.rcnet.ru>.
  8. *
  9. * GLPK is free software: you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * GLPK is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  17. * License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  21. ***********************************************************************/
  22. #include "glpapi.h"
  23. /***********************************************************************
  24. * NAME
  25. *
  26. * glp_version - determine library version
  27. *
  28. * SYNOPSIS
  29. *
  30. * const char *glp_version(void);
  31. *
  32. * RETURNS
  33. *
  34. * The routine glp_version returns a pointer to a null-terminated
  35. * character string, which specifies the version of the GLPK library in
  36. * the form "X.Y", where X is the major version number, and Y is the
  37. * minor version number, for example, "4.16". */
  38. const char *glp_version(void)
  39. { return
  40. lib_version();
  41. }
  42. /**********************************************************************/
  43. void glp_printf(const char *fmt, ...)
  44. { /* write formatted output to terminal */
  45. va_list arg;
  46. va_start(arg, fmt);
  47. xvprintf(fmt, arg);
  48. va_end(arg);
  49. return;
  50. }
  51. /***********************************************************************
  52. * NAME
  53. *
  54. * glp_term_out - enable/disable terminal output
  55. *
  56. * SYNOPSIS
  57. *
  58. * void glp_term_out(int flag);
  59. *
  60. * DESCRIPTION
  61. *
  62. * Depending on the parameter flag the routine glp_term_out enables or
  63. * disables terminal output performed by glpk routines:
  64. *
  65. * GLP_ON - enable terminal output;
  66. * GLP_OFF - disable terminal output. */
  67. void glp_term_out(int flag)
  68. { LIBENV *env = lib_link_env();
  69. env->term_out = GLP_ON;
  70. if (!(flag == GLP_ON || flag == GLP_OFF))
  71. xerror("glp_term_out: flag = %d; invalid value\n", flag);
  72. env->term_out = flag;
  73. return;
  74. }
  75. /***********************************************************************
  76. * NAME
  77. *
  78. * glp_term_hook - install hook to intercept terminal output
  79. *
  80. * SYNOPSIS
  81. *
  82. * void glp_term_hook(int (*func)(void *info, const char *s),
  83. * void *info);
  84. *
  85. * DESCRIPTION
  86. *
  87. * The routine glp_term_hook installs the user-defined hook routine to
  88. * intercept all terminal output performed by glpk routines.
  89. *
  90. * This feature can be used to redirect the terminal output to other
  91. * destination, for example to a file or a text window.
  92. *
  93. * The parameter func specifies the user-defined hook routine. It is
  94. * called from an internal printing routine, which passes to it two
  95. * parameters: info and s. The parameter info is a transit pointer,
  96. * specified in the corresponding call to the routine glp_term_hook;
  97. * it may be used to pass some information to the hook routine. The
  98. * parameter s is a pointer to the null terminated character string,
  99. * which is intended to be written to the terminal. If the hook routine
  100. * returns zero, the printing routine writes the string s to the
  101. * terminal in a usual way; otherwise, if the hook routine returns
  102. * non-zero, no terminal output is performed.
  103. *
  104. * To uninstall the hook routine the parameters func and info should be
  105. * specified as NULL. */
  106. void glp_term_hook(int (*func)(void *info, const char *s), void *info)
  107. { lib_term_hook(func, info);
  108. return;
  109. }
  110. /***********************************************************************
  111. * NAME
  112. *
  113. * glp_malloc - allocate memory block
  114. *
  115. * SYNOPSIS
  116. *
  117. * void *glp_malloc(int size);
  118. *
  119. * DESCRIPTION
  120. *
  121. * The routine glp_malloc allocates a memory block of size bytes long.
  122. *
  123. * Note that being allocated the memory block contains arbitrary data
  124. * (not binary zeros).
  125. *
  126. * RETURNS
  127. *
  128. * The routine glp_malloc returns a pointer to the allocated block.
  129. * To free this block the routine glp_free (not free!) must be used. */
  130. void *glp_malloc(int size)
  131. { void *ptr;
  132. ptr = xmalloc(size);
  133. return ptr;
  134. }
  135. /***********************************************************************
  136. * NAME
  137. *
  138. * glp_calloc - allocate memory block
  139. *
  140. * SYNOPSIS
  141. *
  142. * void *glp_calloc(int n, int size);
  143. *
  144. * DESCRIPTION
  145. *
  146. * The routine glp_calloc allocates a memory block of (n*size) bytes
  147. * long.
  148. *
  149. * Note that being allocated the memory block contains arbitrary data
  150. * (not binary zeros).
  151. *
  152. * RETURNS
  153. *
  154. * The routine glp_calloc returns a pointer to the allocated block.
  155. * To free this block the routine glp_free (not free!) must be used. */
  156. void *glp_calloc(int n, int size)
  157. { void *ptr;
  158. ptr = xcalloc(n, size);
  159. return ptr;
  160. }
  161. /***********************************************************************
  162. * NAME
  163. *
  164. * glp_free - free memory block
  165. *
  166. * SYNOPSIS
  167. *
  168. * void glp_free(void *ptr);
  169. *
  170. * DESCRIPTION
  171. *
  172. * The routine glp_free frees a memory block pointed to by ptr, which
  173. * was previuosly allocated by the routine glp_malloc or glp_calloc. */
  174. void glp_free(void *ptr)
  175. { xfree(ptr);
  176. return;
  177. }
  178. /***********************************************************************
  179. * NAME
  180. *
  181. * glp_mem_usage - get memory usage information
  182. *
  183. * SYNOPSIS
  184. *
  185. * void glp_mem_usage(int *count, int *cpeak, glp_long *total,
  186. * glp_long *tpeak);
  187. *
  188. * DESCRIPTION
  189. *
  190. * The routine glp_mem_usage reports some information about utilization
  191. * of the memory by GLPK routines. Information is stored to locations
  192. * specified by corresponding parameters (see below). Any parameter can
  193. * be specified as NULL, in which case corresponding information is not
  194. * stored.
  195. *
  196. * *count is the number of the memory blocks currently allocated by the
  197. * routines xmalloc and xcalloc (one call to xmalloc or xcalloc results
  198. * in allocating one memory block).
  199. *
  200. * *cpeak is the peak value of *count reached since the initialization
  201. * of the GLPK library environment.
  202. *
  203. * *total is the total amount, in bytes, of the memory blocks currently
  204. * allocated by the routines xmalloc and xcalloc.
  205. *
  206. * *tpeak is the peak value of *total reached since the initialization
  207. * of the GLPK library envirionment. */
  208. void glp_mem_usage(int *count, int *cpeak, glp_long *total,
  209. glp_long *tpeak)
  210. { xlong_t total1, tpeak1;
  211. lib_mem_usage(count, cpeak, &total1, &tpeak1);
  212. if (total != NULL) total->lo = total1.lo, total->hi = total1.hi;
  213. if (tpeak != NULL) tpeak->lo = tpeak1.lo, tpeak->hi = tpeak1.hi;
  214. return;
  215. }
  216. /***********************************************************************
  217. * NAME
  218. *
  219. * glp_mem_limit - set memory usage limit
  220. *
  221. * SYNOPSIS
  222. *
  223. * void glp_mem_limit(int limit);
  224. *
  225. * DESCRIPTION
  226. *
  227. * The routine glp_mem_limit limits the amount of memory available for
  228. * dynamic allocation (in GLPK routines) to limit megabytes. */
  229. void glp_mem_limit(int limit)
  230. { if (limit < 0)
  231. xerror("glp_mem_limit: limit = %d; invalid parameter\n",
  232. limit);
  233. lib_mem_limit(xlmul(xlset(limit), xlset(1 << 20)));
  234. return;
  235. }
  236. #if 0
  237. /***********************************************************************
  238. * NAME
  239. *
  240. * glp_fopen - open file
  241. *
  242. * SYNOPSIS
  243. *
  244. * FILE *glp_fopen(const char *fname, const char *mode);
  245. *
  246. * DESCRIPTION
  247. *
  248. * The routine glp_fopen opens a file using the character string fname
  249. * as the file name and the character string mode as the open mode.
  250. *
  251. * RETURNS
  252. *
  253. * If the file is successfully open, the routine glp_fopen returns a
  254. * pointer to an i/o stream associated with the file (i.e. a pointer to
  255. * an object of the FILE type). Otherwise the routine return NULL. */
  256. FILE *glp_fopen(const char *fname, const char *mode)
  257. { FILE *fp;
  258. fp = xfopen(fname, mode);
  259. return fp;
  260. }
  261. /***********************************************************************
  262. * NAME
  263. *
  264. * glp_fclose - close file
  265. *
  266. * SYNOPSIS
  267. *
  268. * void glp_fclose(FILE *fp);
  269. *
  270. * DESCRIPTION
  271. *
  272. * The routine glp_fclose closes a file associated with i/o stream,
  273. * which the parameter fp points to. It is assumed that the file was
  274. * open by the routine glp_fopen. */
  275. void glp_fclose(FILE *fp)
  276. { xfclose(fp);
  277. return;
  278. }
  279. #endif
  280. /***********************************************************************
  281. * NAME
  282. *
  283. * glp_free_env - free GLPK library environment
  284. *
  285. * SYNOPSIS
  286. *
  287. * void glp_free_env(void);
  288. *
  289. * DESCRIPTION
  290. *
  291. * The routine glp_free_env frees all resources used by GLPK routines
  292. * (memory blocks, etc.) which are currently still in use.
  293. *
  294. * USAGE NOTES
  295. *
  296. * Normally the application program does not need to call this routine,
  297. * because GLPK routines always free all unused resources. However, if
  298. * the application program even has deleted all problem objects, there
  299. * will be several memory blocks still allocated for the library needs.
  300. * For some reasons the application program may want GLPK to free this
  301. * memory, in which case it should call glp_free_env.
  302. *
  303. * Note that a call to glp_free_env invalidates all problem objects as
  304. * if no GLPK routine were called. */
  305. void glp_free_env(void)
  306. { lib_free_env();
  307. return;
  308. }
  309. /* eof */