PageRenderTime 40ms CodeModel.GetById 13ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

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