📄 lpkit.h
字号:
/* Main header file of the LP_SOLVE toolkit. Original by Jeroen Dirks, 21-2-95 Maintained by Michel Berkelaar Starting at version 3.0, LP_Solve is released under the LGPL license. For full information, see the enclosed file LGPL.txt. See CHANGELOG file for a tracking of changes*/#ifndef __LPKIT_H__#define __LPKIT_H__/* let's please C++ users */#ifdef __cplusplusextern "C" {#endif#if defined _WINDOWS# include <windows.h>#else# if defined WINAPI# undef WINAPI# endif# define WINAPI#endif#include <stdlib.h>#include <stdio.h>#include <math.h>#include "hash.h"#include "fortify.h"#ifndef NULL#define NULL 0#endif#define FALSE 0#define TRUE 1#define AUTOMATIC 2#define ISREAL 0#define ISINTEGER 1#define ISSEMI 2#define ISSOS 4#define ISSOSTEMPINT 8#define ROWNAMEMASK "r_%d"#define COLNAMEMASK "v_%d"/* REPORT defines */#define CRITICALSTOP 0#define CRITICAL 1#define SEVERE 2#define IMPORTANT 3#define NORMAL 4#define DETAILED 5#define FULL 6/* SOS constraint defines */#define SOS1 1#define SOS2 2#define SOS3 -1#define SOS_START_SIZE 10 /* start size of SOS_list array; realloced if needed *//* MESSAGE defines */#define MSG_NONE 0#define MSG_PRESOLVE 1#define MSG_ITERATION 2#define MSG_INVERT 4#define MSG_LPFEASIBLE 8#define MSG_LPEQUAL 16#define MSG_LPBETTER 32#define MSG_MILPFEASIBLE 64#define MSG_MILPEQUAL 128#define MSG_MILPBETTER 256#define MSG_MILPSTRATEGY 512#ifndef DEFNUMINV# define DEFNUMINV 30#endif#ifndef HASHSIZE# define HASHSIZE 10007 /* A prime number! */#endif#ifndef INITIAL_MAT_SIZE# define INITIAL_MAT_SIZE 10000#endif#ifndef DELTACOLALLOC# define DELTACOLALLOC 50#endif/* Improvement defines */#define IMPROVE_NONE 0#define IMPROVE_FTRAN 1#define IMPROVE_BTRAN 2#define IMPROVE_FULL (IMPROVE_FTRAN + IMPROVE_BTRAN);/* Scaling defines */#define MMSCALING 0#define GEOSCALING 1#define POWERSCALE 2#define CURTISREIDSCALE 4#define LAGRANGESCALE 8#define INTEGERSCALE 16/* B&B strategies */#define FIRST_NI 0#define RAND_NI 1#define FIRST_SELECT 0#define RAND_SELECT 1#define WORST_SELECT 2#define BEST_SELECT 3#define MEDIAN_SELECT 4#define GREEDY_SELECT 5/* unused ...#define AUTO_SELECT 6#define USER_SELECT 7*//* solve status values */#define UNKNOWN -5#define NOTRUN -4#define USERABORT -3#define TIMEOUT -2#define IGNORED -1#define OPTIMAL 0#define MILP_FAIL 1#define INFEASIBLE 2#define UNBOUNDED 3#define FAILURE 4#define RUNNING 5/* lag_solve extra status values */#define FEAS_FOUND 6#define NO_FEAS_FOUND 7#define BREAK_BB 8/* Status values internal to the solver */#define SWITCH_TO_PRIMAL 9#define SINGULAR_BASIS 10#define LOST_PRIMAL_FEASIBILITY 11#define OUT_OF_MEMORY 12#define LE 0#define EQ 1#define GE 2#define OF 3/* Solver parameters and tolerances */#ifndef RESIZEFACTOR# define RESIZEFACTOR 1.25#endif#ifndef DEFNUMINV# define DEFNUMINV 30 /* maximum number of pivots before reinversion */#endif#ifndef DEF_MAXRELAX# define DEF_MAXRELAX 4 /* maximum number of non-BB relaxations in MILP */#endif#ifndef DEF_MAXSINGULARITIES# define DEF_MAXSINGULARITIES 10 /* maximum number of singularities in inversion */#endif#ifndef LAG_SINGULARLIMIT# define LAG_SINGULARLIMIT 5 /* Number of times the objective does not change before it is assumed that the Lagrangean constraints are non-binding, and therefore impossible to converge; upper iteration limit is divided by this threshold */#endif#ifndef DEF_INFINITE# define DEF_INFINITE 1e24 /* limit for dynamic range */#endif#ifndef DEF_NEGRANGE# define DEF_NEGRANGE 0 /* downward limit for expanded variable range before the variable is split into positive and negative components */#endif#ifndef DEF_EPSPIVOT# define DEF_EPSPIVOT 1e-5 /* 5 pivot reject (try others first) */#endif#ifndef DEF_EPSEL# ifdef ORGPARAM# define DEF_EPSEL 1e-8 /* for rounding other values (vectors) to 0 */# else# define DEF_EPSEL 1e-11 /* 10 for rounding other values (vectors) to 0 */# endif#endif#ifndef DEF_EPSB# ifdef ORGPARAM# define DEF_EPSB 5.01e-7 /* 8 for rounding RHS values to 0; determine infeasibility basis */# else# define DEF_EPSB 5.01e-9 /* for rounding RHS values to 0 determine infeasibility basis */# endif#endif#ifndef DEF_EPSD# ifdef ORGPARAM# define DEF_EPSD 1e-6 /* for rounding reduced costs to zero */# else# define DEF_EPSD 1e-9 /* 7 for rounding reduced costs to 0 */# endif#endif#ifndef RANDSCALE# define RANDSCALE 100 /* Randomization scaling range */#endif#ifndef DEF_PERTURB# define DEF_PERTURB 1e-5 /* Perturbation scalar for degenerative problems; must at least be RANDSCALE greater than DEF_EPSB */#endif#ifndef SOLUTIONEPS# define SOLUTIONEPS 1e-5 /* Margin of error for solution bounds */#endif#ifndef DEF_EPSILON# ifdef ORGPARAM# define DEF_EPSILON 1e-3 /* to determine if a float value is integer */# else# define DEF_EPSILON 1e-6 /* to determine if a float value is integer */# endif#endif#ifndef DEF_LAGACCEPT# define DEF_LAGACCEPT 1e-3 /* Default Lagrangian convergence acceptance criterion */#endif#ifndef MINSCALAR# define MINSCALAR 1e-10 /* Smallest allowed scaling adjustment */#endif#ifndef MAXSCALAR# define MAXSCALAR 1e+10 /* Largest allowed scaling adjustment */#endif#define MINTIMEPIVOT 5e-2 /* Minimum time per pivot for pivot optimization purposes */#define SCALINGEPS 1e-2 /* Scaling convergence criterion */#define my_abs(x) ((x) < 0 ? -(x) : (x))#define my_min(x, y) ((x) < (y) ? (x) : (y))#define my_max(x, y) ((x) > (y) ? (x) : (y))#define my_if(t, x, y) ((t) ? (x) : (y))#define MAX_WARN_COUNT 20#ifdef CHECK#define my_round(val, eps) { \ REAL absv; \ absv = ((val) < 0 ? -(val) : (val)); \ if(absv < (eps)) \ val = 0; \ if(Warn_count < MAX_WARN_COUNT) \ { \ if(absv > 0.5 * (eps) && absv < 2 * (eps)) \ { \ Warn_count++; \ report(NULL, NORMAL, \ "Warning Value close to epsilon V: %e E: %e\n", \ (double)absv, (double)(eps)); \ if(Warn_count == MAX_WARN_COUNT) \ { \ report(NULL, NORMAL, \ "*** Surpressing further rounding warnings\n"); \ } \ } \ } \}#else#define my_round(val,eps) if (((val) < 0 ? -(val) : (val)) < (eps)) val = 0;#endif#ifndef REAL /* to allow -DREAL=<float type> while compiling */#define REAL double#endif#ifndef LREAL#define LREAL long double#endif#ifndef RREAL#define RREAL long double#endif#ifndef MYBOOL/*#define MYBOOL unsigned short */#define MYBOOL unsigned char#endif#ifndef STATUS#define STATUS short#endif#define NAMELEN 25#define MAXSTRL (NAMELEN-1)#define STD_ROW_NAME_PREFIX "r_"#define MALLOC(ptr, nr)\ ((((nr) == 0) || ((ptr = malloc((size_t)((nr) * sizeof(*ptr)))) == NULL)) ? \ (void *) report(NULL, CRITICAL, "malloc of %d bytes failed on line %d of file %s",\ (nr) * sizeof(*ptr), __LINE__, __FILE__), (ptr = (void *) 0) : \ ptr\ )#define CALLOC(ptr, nr)\ ((((nr) == 0) || ((ptr = calloc((size_t)(nr), sizeof(*ptr))) == NULL)) ? \ (void *) report(NULL, CRITICAL, "calloc of %d bytes failed on line %d of file %s",\ (nr) * sizeof(*ptr), __LINE__, __FILE__), (ptr = (void *) 0) : \ ptr\ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -