Remove lp_solve headers.

This commit is contained in:
czeidler 2012-05-08 07:28:16 +12:00
parent b74906293b
commit 9c7f297dd6
7 changed files with 0 additions and 3244 deletions

View File

@ -1,43 +0,0 @@
#ifndef HEADER_lp_hash
#define HEADER_lp_hash
/* For row and column name hash tables */
typedef struct _hashelem
{
char *name;
int index;
struct _hashelem *next;
struct _hashelem *nextelem;
} hashelem;
typedef struct _hashtable
{
hashelem **table;
int size;
int base;
int count;
struct _hashelem *first;
struct _hashelem *last;
} hashtable;
#ifdef __cplusplus
extern "C" {
#endif
STATIC hashtable *create_hash_table(int size, int base);
STATIC void free_hash_table(hashtable *ht);
STATIC hashelem *findhash(const char *name, hashtable *ht);
STATIC hashelem *puthash(const char *name, int index, hashelem **list, hashtable *ht);
STATIC void drophash(const char *name, hashelem **list, hashtable *ht);
STATIC void free_hash_item(hashelem **hp);
STATIC hashtable *copy_hash_table(hashtable *ht, hashelem **list, int newsize);
STATIC int find_var(lprec *lp, char *name, MYBOOL verbose);
STATIC int find_row(lprec *lp, char *name, MYBOOL Unconstrained_rows_found);
#ifdef __cplusplus
}
#endif
#endif /* HEADER_lp_hash */

View File

@ -1,108 +0,0 @@
#ifndef HEADER_lp_SOS
#define HEADER_lp_SOS
/* Specially Ordered Sets (SOS) prototypes and settings */
/* ------------------------------------------------------------------------- */
#include "lp_types.h"
#include "lp_utils.h"
#include "lp_matrix.h"
/* SOS constraint defines */
/* ------------------------------------------------------------------------- */
#define SOS1 1
#define SOS2 2
#define SOS3 -1
#define SOSn MAXINT32
#define SOS_START_SIZE 10 /* Start size of SOS_list array; realloced if needed */
/* Define SOS_is_feasible() return values */
/* ------------------------------------------------------------------------- */
#define SOS3_INCOMPLETE -2
#define SOS_INCOMPLETE -1
#define SOS_COMPLETE 0
#define SOS_INFEASIBLE 1
#define SOS_INTERNALERROR 2
typedef struct _SOSgroup SOSgroup;
typedef struct _SOSrec
{
SOSgroup *parent;
int tagorder;
char *name;
int type;
MYBOOL isGUB;
int size;
int priority;
int *members;
REAL *weights;
int *membersSorted;
int *membersMapped;
} SOSrec;
/* typedef */ struct _SOSgroup
{
lprec *lp; /* Pointer to owner */
SOSrec **sos_list; /* Array of pointers to SOS lists */
int sos_alloc; /* Size allocated to specially ordered sets (SOS1, SOS2...) */
int sos_count; /* Number of specially ordered sets (SOS1, SOS2...) */
int maxorder; /* The highest-order SOS in the group */
int sos1_count; /* Number of the lowest order SOS in the group */
int *membership; /* Array of variable-sorted indeces to SOSes that the variable is member of */
int *memberpos; /* Starting positions of the each column's membership list */
} /* SOSgroup */;
#ifdef __cplusplus
extern "C" {
#endif
/* SOS storage structure */
STATIC SOSgroup *create_SOSgroup(lprec *lp);
STATIC void resize_SOSgroup(SOSgroup *group);
STATIC int append_SOSgroup(SOSgroup *group, SOSrec *SOS);
STATIC int clean_SOSgroup(SOSgroup *group, MYBOOL forceupdatemap);
STATIC void free_SOSgroup(SOSgroup **group);
STATIC SOSrec *create_SOSrec(SOSgroup *group, char *name, int type, int priority, int size, int *variables, REAL *weights);
STATIC MYBOOL delete_SOSrec(SOSgroup *group, int sosindex);
STATIC int append_SOSrec(SOSrec *SOS, int size, int *variables, REAL *weights);
STATIC void free_SOSrec(SOSrec *SOS);
/* SOS utilities */
STATIC int make_SOSchain(lprec *lp, MYBOOL forceresort);
STATIC int SOS_member_updatemap(SOSgroup *group);
STATIC MYBOOL SOS_member_sortlist(SOSgroup *group, int sosindex);
STATIC MYBOOL SOS_shift_col(SOSgroup *group, int sosindex, int column, int delta, LLrec *usedmap, MYBOOL forceresort);
int SOS_member_delete(SOSgroup *group, int sosindex, int member);
int SOS_get_type(SOSgroup *group, int sosindex);
int SOS_infeasible(SOSgroup *group, int sosindex);
int SOS_member_index(SOSgroup *group, int sosindex, int member);
int SOS_member_count(SOSgroup *group, int sosindex);
int SOS_memberships(SOSgroup *group, int column);
int *SOS_get_candidates(SOSgroup *group, int sosindex, int column, MYBOOL excludetarget, REAL *upbound, REAL *lobound);
int SOS_is_member(SOSgroup *group, int sosindex, int column);
MYBOOL SOS_is_member_of_type(SOSgroup *group, int column, int sostype);
MYBOOL SOS_set_GUB(SOSgroup *group, int sosindex, MYBOOL state);
MYBOOL SOS_is_GUB(SOSgroup *group, int sosindex);
MYBOOL SOS_is_marked(SOSgroup *group, int sosindex, int column);
MYBOOL SOS_is_active(SOSgroup *group, int sosindex, int column);
MYBOOL SOS_is_full(SOSgroup *group, int sosindex, int column, MYBOOL activeonly);
MYBOOL SOS_can_activate(SOSgroup *group, int sosindex, int column);
MYBOOL SOS_set_marked(SOSgroup *group, int sosindex, int column, MYBOOL asactive);
MYBOOL SOS_unmark(SOSgroup *group, int sosindex, int column);
int SOS_fix_unmarked(SOSgroup *group, int sosindex, int variable, REAL *bound, REAL value,
MYBOOL isupper, int *diffcount, DeltaVrec *changelog);
int SOS_fix_list(SOSgroup *group, int sosindex, int variable, REAL *bound,
int *varlist, MYBOOL isleft, DeltaVrec *changelog);
int SOS_is_satisfied(SOSgroup *group, int sosindex, REAL *solution);
MYBOOL SOS_is_feasible(SOSgroup *group, int sosindex, REAL *solution);
#ifdef __cplusplus
}
#endif
#endif /* HEADER_lp_SOS */

File diff suppressed because it is too large Load Diff

View File

@ -1,257 +0,0 @@
#ifndef HEADER_lp_matrix
#define HEADER_lp_matrix
#include "lp_types.h"
#include "lp_utils.h"
/* Sparse matrix element (ordered columnwise) */
typedef struct _MATitem
{
int rownr;
int colnr;
REAL value;
} MATitem;
/* Constants for matrix product rounding options */
#define MAT_ROUNDNONE 0
#define MAT_ROUNDABS 1
#define MAT_ROUNDREL 2
#define MAT_ROUNDABSREL (MAT_ROUNDABS + MAT_ROUNDREL)
#define MAT_ROUNDRC 4
#define MAT_ROUNDRCMIN 1.0 /* lp->epspivot */
#if 1
#define MAT_ROUNDDEFAULT MAT_ROUNDREL /* Typically increases performance */
#else
#define MAT_ROUNDDEFAULT MAT_ROUNDABS /* Probably gives more precision */
#endif
/* Compiler option development features */
/*#define DebugInv*/ /* Report array values at factorization/inversion */
#define NoLoopUnroll /* Do not do loop unrolling */
#define DirectArrayOF /* Reference lp->obj[] array instead of function call */
/* Matrix column access macros to be able to easily change storage model */
#define CAM_Record 0
#define CAM_Vector 1
#if 0
#define MatrixColAccess CAM_Record
#else
#define MatrixColAccess CAM_Vector
#endif
#if MatrixColAccess==CAM_Record
#define SET_MAT_ijA(item,i,j,A) mat->col_mat[item].rownr = i; \
mat->col_mat[item].colnr = j; \
mat->col_mat[item].value = A
#define COL_MAT_COLNR(item) (mat->col_mat[item].colnr)
#define COL_MAT_ROWNR(item) (mat->col_mat[item].rownr)
#define COL_MAT_VALUE(item) (mat->col_mat[item].value)
#define COL_MAT_COPY(left,right) mat->col_mat[left] = mat->col_mat[right]
#define COL_MAT_MOVE(to,from,rec) MEMMOVE(&(mat->col_mat[to]),&(mat->col_mat[from]),rec)
#define COL_MAT2_COLNR(item) (mat2->col_mat[item].colnr)
#define COL_MAT2_ROWNR(item) (mat2->col_mat[item].rownr)
#define COL_MAT2_VALUE(item) (mat2->col_mat[item].value)
#define matRowColStep (sizeof(MATitem)/sizeof(int))
#define matValueStep (sizeof(MATitem)/sizeof(REAL))
#else /* if MatrixColAccess==CAM_Vector */
#define SET_MAT_ijA(item,i,j,A) mat->col_mat_rownr[item] = i; \
mat->col_mat_colnr[item] = j; \
mat->col_mat_value[item] = A
#define COL_MAT_COLNR(item) (mat->col_mat_colnr[item])
#define COL_MAT_ROWNR(item) (mat->col_mat_rownr[item])
#define COL_MAT_VALUE(item) (mat->col_mat_value[item])
#define COL_MAT_COPY(left,right) COL_MAT_COLNR(left) = COL_MAT_COLNR(right); \
COL_MAT_ROWNR(left) = COL_MAT_ROWNR(right); \
COL_MAT_VALUE(left) = COL_MAT_VALUE(right)
#define COL_MAT_MOVE(to,from,rec) MEMMOVE(&COL_MAT_COLNR(to),&COL_MAT_COLNR(from),rec); \
MEMMOVE(&COL_MAT_ROWNR(to),&COL_MAT_ROWNR(from),rec); \
MEMMOVE(&COL_MAT_VALUE(to),&COL_MAT_VALUE(from),rec)
#define COL_MAT2_COLNR(item) (mat2->col_mat_colnr[item])
#define COL_MAT2_ROWNR(item) (mat2->col_mat_rownr[item])
#define COL_MAT2_VALUE(item) (mat2->col_mat_value[item])
#define matRowColStep 1
#define matValueStep 1
#endif
/* Matrix row access macros to be able to easily change storage model */
#define RAM_Index 0
#define RAM_FullCopy 1
#define MatrixRowAccess RAM_Index
#if MatrixRowAccess==RAM_Index
#define ROW_MAT_COLNR(item) COL_MAT_COLNR(mat->row_mat[item])
#define ROW_MAT_ROWNR(item) COL_MAT_ROWNR(mat->row_mat[item])
#define ROW_MAT_VALUE(item) COL_MAT_VALUE(mat->row_mat[item])
#elif MatrixColAccess==CAM_Record
#define ROW_MAT_COLNR(item) (mat->row_mat[item].colnr)
#define ROW_MAT_ROWNR(item) (mat->row_mat[item].rownr)
#define ROW_MAT_VALUE(item) (mat->row_mat[item].value)
#else /* if MatrixColAccess==CAM_Vector */
#define ROW_MAT_COLNR(item) (mat->row_mat_colnr[item])
#define ROW_MAT_ROWNR(item) (mat->row_mat_rownr[item])
#define ROW_MAT_VALUE(item) (mat->row_mat_value[item])
#endif
typedef struct _MATrec
{
/* Owner reference */
lprec *lp;
/* Active dimensions */
int rows;
int columns;
/* Allocated memory */
int rows_alloc;
int columns_alloc;
int mat_alloc; /* The allocated size for matrix sized structures */
/* Sparse problem matrix storage */
#if MatrixColAccess==CAM_Record
MATitem *col_mat; /* mat_alloc : The sparse data storage */
#else /*MatrixColAccess==CAM_Vector*/
int *col_mat_colnr;
int *col_mat_rownr;
REAL *col_mat_value;
#endif
int *col_end; /* columns_alloc+1 : col_end[i] is the index of the
first element after column i; column[i] is stored
in elements col_end[i-1] to col_end[i]-1 */
int *col_tag; /* user-definable tag associated with each column */
#if MatrixRowAccess==RAM_Index
int *row_mat; /* mat_alloc : From index 0, row_mat contains the
row-ordered index of the elements of col_mat */
#elif MatrixColAccess==CAM_Record
MATitem *row_mat; /* mat_alloc : From index 0, row_mat contains the
row-ordered copy of the elements in col_mat */
#else /*if MatrixColAccess==CAM_Vector*/
int *row_mat_colnr;
int *row_mat_rownr;
REAL *row_mat_value;
#endif
int *row_end; /* rows_alloc+1 : row_end[i] is the index of the
first element in row_mat after row i */
int *row_tag; /* user-definable tag associated with each row */
REAL *colmax; /* Array of maximum values of each column */
REAL *rowmax; /* Array of maximum values of each row */
REAL epsvalue; /* Zero element rejection threshold */
REAL infnorm; /* The largest absolute value in the matrix */
REAL dynrange;
MYBOOL row_end_valid; /* TRUE if row_end & row_mat are valid */
MYBOOL is_roworder; /* TRUE if the current (temporary) matrix order is row-wise */
} MATrec;
typedef struct _DeltaVrec
{
lprec *lp;
int activelevel;
MATrec *tracker;
} DeltaVrec;
#ifdef __cplusplus
__EXTERN_C {
#endif
/* Sparse matrix routines */
STATIC MATrec *mat_create(lprec *lp, int rows, int columns, REAL epsvalue);
STATIC MYBOOL mat_memopt(MATrec *mat, int rowextra, int colextra, int nzextra);
STATIC void mat_free(MATrec **matrix);
STATIC MYBOOL inc_matrow_space(MATrec *mat, int deltarows);
STATIC int mat_mapreplace(MATrec *mat, LLrec *rowmap, LLrec *colmap, MATrec *insmat);
STATIC int mat_matinsert(MATrec *mat, MATrec *insmat);
STATIC int mat_zerocompact(MATrec *mat);
STATIC int mat_rowcompact(MATrec *mat, MYBOOL dozeros);
STATIC int mat_colcompact(MATrec *mat, int prev_rows, int prev_cols);
STATIC MYBOOL inc_matcol_space(MATrec *mat, int deltacols);
STATIC MYBOOL inc_mat_space(MATrec *mat, int mindelta);
STATIC int mat_shiftrows(MATrec *mat, int *bbase, int delta, LLrec *varmap);
STATIC int mat_shiftcols(MATrec *mat, int *bbase, int delta, LLrec *varmap);
STATIC MATrec *mat_extractmat(MATrec *mat, LLrec *rowmap, LLrec *colmap, MYBOOL negated);
STATIC int mat_appendrow(MATrec *mat, int count, REAL *row, int *colno, REAL mult, MYBOOL checkrowmode);
STATIC int mat_appendcol(MATrec *mat, int count, REAL *column, int *rowno, REAL mult, MYBOOL checkrowmode);
MYBOOL mat_get_data(lprec *lp, int matindex, MYBOOL isrow, int **rownr, int **colnr, REAL **value);
MYBOOL mat_set_rowmap(MATrec *mat, int row_mat_index, int rownr, int colnr, int col_mat_index);
STATIC MYBOOL mat_indexrange(MATrec *mat, int index, MYBOOL isrow, int *startpos, int *endpos);
STATIC MYBOOL mat_validate(MATrec *mat);
STATIC MYBOOL mat_equalRows(MATrec *mat, int baserow, int comprow);
STATIC int mat_findelm(MATrec *mat, int row, int column);
STATIC int mat_findins(MATrec *mat, int row, int column, int *insertpos, MYBOOL validate);
STATIC void mat_multcol(MATrec *mat, int col_nr, REAL mult, MYBOOL DoObj);
STATIC REAL mat_getitem(MATrec *mat, int row, int column);
STATIC MYBOOL mat_setitem(MATrec *mat, int row, int column, REAL value);
STATIC MYBOOL mat_additem(MATrec *mat, int row, int column, REAL delta);
STATIC MYBOOL mat_setvalue(MATrec *mat, int Row, int Column, REAL Value, MYBOOL doscale);
STATIC int mat_nonzeros(MATrec *mat);
STATIC int mat_collength(MATrec *mat, int colnr);
STATIC int mat_rowlength(MATrec *mat, int rownr);
STATIC void mat_multrow(MATrec *mat, int row_nr, REAL mult);
STATIC void mat_multadd(MATrec *mat, REAL *lhsvector, int varnr, REAL mult);
STATIC MYBOOL mat_setrow(MATrec *mat, int rowno, int count, REAL *row, int *colno, MYBOOL doscale, MYBOOL checkrowmode);
STATIC MYBOOL mat_setcol(MATrec *mat, int colno, int count, REAL *column, int *rowno, MYBOOL doscale, MYBOOL checkrowmode);
STATIC MYBOOL mat_mergemat(MATrec *target, MATrec *source, MYBOOL usecolmap);
STATIC int mat_checkcounts(MATrec *mat, int *rownum, int *colnum, MYBOOL freeonexit);
STATIC int mat_expandcolumn(MATrec *mat, int colnr, REAL *column, int *nzlist, MYBOOL signedA);
STATIC MYBOOL mat_computemax(MATrec *mat);
STATIC MYBOOL mat_transpose(MATrec *mat);
/* Refactorization and recomputation routine */
MYBOOL __WINAPI invert(lprec *lp, MYBOOL shiftbounds, MYBOOL final);
/* Vector compression and expansion routines */
STATIC MYBOOL vec_compress(REAL *densevector, int startpos, int endpos, REAL epsilon, REAL *nzvector, int *nzindex);
STATIC MYBOOL vec_expand(REAL *nzvector, int *nzindex, REAL *densevector, int startpos, int endpos);
/* Sparse matrix products */
STATIC MYBOOL get_colIndexA(lprec *lp, int varset, int *colindex, MYBOOL append);
STATIC int prod_Ax(lprec *lp, int *coltarget, REAL *input, int *nzinput, REAL roundzero, REAL ofscalar, REAL *output, int *nzoutput, int roundmode);
STATIC int prod_xA(lprec *lp, int *coltarget, REAL *input, int *nzinput, REAL roundzero, REAL ofscalar, REAL *output, int *nzoutput, int roundmode);
STATIC MYBOOL prod_xA2(lprec *lp, int *coltarget, REAL *prow, REAL proundzero, int *pnzprow,
REAL *drow, REAL droundzero, int *dnzdrow, REAL ofscalar, int roundmode);
/* Equation solution */
STATIC MYBOOL fimprove(lprec *lp, REAL *pcol, int *nzidx, REAL roundzero);
STATIC void ftran(lprec *lp, REAL *rhsvector, int *nzidx, REAL roundzero);
STATIC MYBOOL bimprove(lprec *lp, REAL *rhsvector, int *nzidx, REAL roundzero);
STATIC void btran(lprec *lp, REAL *rhsvector, int *nzidx, REAL roundzero);
/* Combined equation solution and matrix product for simplex operations */
STATIC MYBOOL fsolve(lprec *lp, int varin, REAL *pcol, int *nzidx, REAL roundzero, REAL ofscalar, MYBOOL prepareupdate);
STATIC MYBOOL bsolve(lprec *lp, int row_nr, REAL *rhsvector, int *nzidx, REAL roundzero, REAL ofscalar);
STATIC void bsolve_xA2(lprec *lp, int* coltarget,
int row_nr1, REAL *vector1, REAL roundzero1, int *nzvector1,
int row_nr2, REAL *vector2, REAL roundzero2, int *nzvector2, int roundmode);
/* Change-tracking routines (primarily for B&B and presolve) */
STATIC DeltaVrec *createUndoLadder(lprec *lp, int levelitems, int maxlevels);
STATIC int incrementUndoLadder(DeltaVrec *DV);
STATIC MYBOOL modifyUndoLadder(DeltaVrec *DV, int itemno, REAL target[], REAL newvalue);
STATIC int countsUndoLadder(DeltaVrec *DV);
STATIC int restoreUndoLadder(DeltaVrec *DV, REAL target[]);
STATIC int decrementUndoLadder(DeltaVrec *DV);
STATIC MYBOOL freeUndoLadder(DeltaVrec **DV);
/* Specialized presolve undo functions */
STATIC MYBOOL appendUndoPresolve(lprec *lp, MYBOOL isprimal, REAL beta, int colnrDep);
STATIC MYBOOL addUndoPresolve(lprec *lp, MYBOOL isprimal, int colnrElim, REAL alpha, REAL beta, int colnrDep);
#ifdef __cplusplus
}
#endif
#endif /* HEADER_lp_matrix */

View File

@ -1,64 +0,0 @@
#ifndef HEADER_lp_mipbb
#define HEADER_lp_mipbb
#include "lp_types.h"
#include "lp_utils.h"
/* Bounds storage for B&B routines */
typedef struct _BBrec
{
struct _BBrec *parent;
struct _BBrec *child;
lprec *lp;
int varno;
int vartype;
int lastvarcus; /* Count of non-int variables of the previous branch */
int lastrcf;
int nodesleft;
int nodessolved;
int nodestatus;
REAL noderesult;
REAL lastsolution; /* Optimal solution of the previous branch */
REAL sc_bound;
REAL *upbo, *lowbo;
REAL UPbound, LObound;
int UBtrack, LBtrack; /* Signals that incoming bounds were changed */
MYBOOL contentmode; /* Flag indicating if we "own" the bound vectors */
MYBOOL sc_canset;
MYBOOL isSOS;
MYBOOL isGUB;
int *varmanaged; /* Extended list of variables managed by this B&B level */
MYBOOL isfloor; /* State variable indicating the active B&B bound */
MYBOOL UBzerobased; /* State variable indicating if bounds have been rebased */
} BBrec;
#ifdef __cplusplus
extern "C" {
#endif
STATIC BBrec *create_BB(lprec *lp, BBrec *parentBB, MYBOOL dofullcopy);
STATIC BBrec *push_BB(lprec *lp, BBrec *parentBB, int varno, int vartype, int varcus);
STATIC MYBOOL initbranches_BB(BBrec *BB);
STATIC MYBOOL fillbranches_BB(BBrec *BB);
STATIC MYBOOL nextbranch_BB(BBrec *BB);
STATIC MYBOOL strongbranch_BB(lprec *lp, BBrec *BB, int varno, int vartype, int varcus);
STATIC MYBOOL initcuts_BB(lprec *lp);
STATIC int updatecuts_BB(lprec *lp);
STATIC MYBOOL freecuts_BB(lprec *lp);
STATIC BBrec *findself_BB(BBrec *BB);
STATIC int solve_LP(lprec *lp, BBrec *BB);
STATIC int rcfbound_BB(BBrec *BB, int varno, MYBOOL isINT, REAL *newbound, MYBOOL *isfeasible);
STATIC MYBOOL findnode_BB(BBrec *BB, int *varno, int *vartype, int *varcus);
STATIC int solve_BB(BBrec *BB);
STATIC MYBOOL free_BB(BBrec **BB);
STATIC BBrec *pop_BB(BBrec *BB);
STATIC int run_BB(lprec *lp);
#ifdef __cplusplus
}
#endif
#endif /* HEADER_lp_mipbb */

View File

@ -1,326 +0,0 @@
#ifndef HEADER_lp_types
#define HEADER_lp_types
/* Define data types */
/* ------------------------------------------------------------------------- */
#ifndef LLONG
#if defined __BORLANDC__
#define LLONG __int64
#elif !defined _MSC_VER || _MSC_VER >= 1310
#define LLONG long long
#else
#define LLONG __int64
#endif
#endif
#ifndef COUNTER
#define COUNTER LLONG
#endif
#ifndef REAL
#define REAL double
#endif
#ifndef REALXP
#if 1
#define REALXP long double /* Set local accumulation variable as long double */
#else
#define REALXP REAL /* Set local accumulation as default precision */
#endif
#endif
#ifndef LREAL
#if 0
#define LREAL long double /* Set global solution update variable as long double */
#else
#define LREAL REAL /* Set global solution update variable as default precision */
#endif
#endif
#define RESULTVALUEMASK "%18.12g" /* Set fixed-format real-valued output precision;
suggested width: ABS(exponent of DEF_EPSVALUE)+6. */
#define INDEXVALUEMASK "%8d" /* Set fixed-format integer-valued output width */
#ifndef DEF_STRBUFSIZE
#define DEF_STRBUFSIZE 512
#endif
#ifndef MAXINT32
#define MAXINT32 2147483647
#endif
#ifndef MAXUINT32
#define MAXUINT32 4294967295
#endif
#ifndef MAXINT64
#if defined _LONGLONG || defined __LONG_LONG_MAX__ || defined LLONG_MAX
#define MAXINT64 9223372036854775807ll
#else
#define MAXINT64 9223372036854775807l
#endif
#endif
#ifndef MAXUINT64
#if defined _LONGLONG || defined __LONG_LONG_MAX__ || defined LLONG_MAX
#define MAXUINT64 18446744073709551616ll
#else
#define MAXUINT64 18446744073709551616l
#endif
#endif
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
#ifndef MYBOOL
#define MYBOOL unsigned char /* Conserve memory, could be unsigned int */
#endif
/* Constants */
/* ------------------------------------------------------------------------- */
#ifndef NULL
#define NULL 0
#endif
/* Byte-sized Booleans and extended options */
#define FALSE 0
#define TRUE 1
#define AUTOMATIC 2
#define DYNAMIC 4
/* Sorting and comparison constants */
#define COMP_PREFERCANDIDATE 1
#define COMP_PREFERNONE 0
#define COMP_PREFERINCUMBENT -1
/* Library load status values */
#define LIB_LOADED 0
#define LIB_NOTFOUND 1
#define LIB_NOINFO 2
#define LIB_NOFUNCTION 3
#define LIB_VERINVALID 4
#define LIB_STR_LOADED "Successfully loaded"
#define LIB_STR_NOTFOUND "File not found"
#define LIB_STR_NOINFO "No version data"
#define LIB_STR_NOFUNCTION "Missing function header"
#define LIB_STR_VERINVALID "Incompatible version"
#define LIB_STR_MAXLEN 23
/* Compiler/target settings */
/* ------------------------------------------------------------------------- */
#if (defined _WIN32) || (defined WIN32) || (defined _WIN64) || (defined WIN64)
# define __WINAPI WINAPI
#else
# define __WINAPI
#endif
#if (defined _WIN32) || (defined WIN32) || (defined _WIN64) || (defined WIN64)
# define __VACALL __cdecl
#else
# define __VACALL
#endif
#ifndef __BORLANDC__
#ifdef _USRDLL
#if 1
#define __EXPORT_TYPE __declspec(dllexport)
#else
/* Set up for the Microsoft compiler */
#ifdef LP_SOLVE_EXPORTS
#define __EXPORT_TYPE __declspec(dllexport)
#else
#define __EXPORT_TYPE __declspec(dllimport)
#endif
#endif
#else
#define __EXPORT_TYPE
#endif
#ifdef __cplusplus
#define __EXTERN_C extern "C"
#else
#define __EXTERN_C
#endif
#else /* Otherwise set up for the Borland compiler */
#ifdef __DLL__
#define _USRDLL
#define __EXTERN_C extern "C"
#ifdef __READING_THE_DLL
#define __EXPORT_TYPE __import
#else
#define __EXPORT_TYPE __export
#endif
#else
#define __EXPORT_TYPE
#define __EXTERN_C extern "C"
#endif
#endif
#if 0
#define STATIC static
#else
#define STATIC
#endif
#if !defined INLINE
#if defined __cplusplus
#define INLINE inline
#elif (defined _WIN32) || (defined WIN32) || (defined _WIN64) || (defined WIN64)
#define INLINE __inline
#else
#define INLINE static
#endif
#endif
/* Function macros */
/* ------------------------------------------------------------------------- */
#define my_limitrange(x, lo, hi) ((x) < (lo) ? (lo) : ((x) > (hi) ? (hi) : (x)))
#ifndef my_mod
#define my_mod(n, m) ((n) % (m))
#endif
#define my_if(t, x, y) ((t) ? (x) : (y))
#define my_sign(x) ((x) < 0 ? -1 : 1)
#if 0
#define my_chsign(t, x) ( ((t) && ((x) != 0)) ? -(x) : (x))
#else
#define my_chsign(t, x) ( (2*((t) == 0) - 1) * (x) ) /* "Pipelined" */
#endif
#define my_flipsign(x) ( fabs((REAL) (x)) == 0 ? 0 : -(x) )
#define my_roundzero(val, eps) if (fabs((REAL) (val)) < eps) val = 0
#define my_avoidtiny(val, eps) (fabs((REAL) (val)) < eps ? 0 : val)
#if 1
#define my_infinite(lp, val) ( (MYBOOL) (fabs(val) >= lp->infinite) )
#else
#define my_infinite(lp, val) is_infinite(lp, val)
#endif
#define my_inflimit(lp, val) ( my_infinite(lp, val) ? lp->infinite * my_sign(val) : (val) )
#if 0
#define my_precision(val, eps) ((fabs((REAL) (val))) < (eps) ? 0 : (val))
#else
#define my_precision(val, eps) restoreINT(val, eps)
#endif
#define my_reldiff(x, y) (((x) - (y)) / (1.0 + fabs((REAL) (y))))
#define my_boundstr(x) (fabs(x) < lp->infinite ? sprintf("%g",x) : ((x) < 0 ? "-Inf" : "Inf") )
#ifndef my_boolstr
#define my_boolstr(x) (!(x) ? "FALSE" : "TRUE")
#endif
#define my_basisstr(isbasic) ((isbasic) ? "BASIC" : "NON-BASIC")
#define my_simplexstr(isdual) ((isdual) ? "DUAL" : "PRIMAL")
#define my_plural_std(count) (count == 1 ? "" : "s")
#define my_plural_y(count) (count == 1 ? "y" : "ies")
#define my_lowbound(x) ((FULLYBOUNDEDSIMPLEX) ? (x) : 0)
/* Bound macros usable for both the standard and fully bounded simplex */
/* ------------------------------------------------------------------------- */
/*
#define my_lowbo(lp, varnr) ( lp->isfullybounded ? lp->lowbo[varnr] : 0.0 )
#define my_upbo(lp, varnr) ( lp->isfullybounded ? lp->upbo[varnr] : lp->lowbo[varnr] + lp->upbo[varnr] )
#define my_rangebo(lp, varnr) ( lp->isfullybounded ? lp->upbo[varnr] - lp->lowbo[varnr] : lp->upbo[varnr] )
*/
#define my_lowbo(lp, varnr) ( 0.0 )
#define my_upbo(lp, varnr) ( lp->lowbo[varnr] + lp->upbo[varnr] )
#define my_rangebo(lp, varnr) ( lp->upbo[varnr] )
#define my_unbounded(lp, varnr) ((lp->upbo[varnr] >= lp->infinite) && (lp->lowbo[varnr] <= -lp->infinite))
#define my_bounded(lp, varnr) ((lp->upbo[varnr] < lp->infinite) && (lp->lowbo[varnr] > -lp->infinite))
/* Forward declarations */
/* ------------------------------------------------------------------------- */
typedef struct _lprec lprec;
typedef struct _INVrec INVrec;
union QSORTrec;
#ifndef UNIONTYPE
#ifdef __cplusplus
#define UNIONTYPE
#else
#define UNIONTYPE union
#endif
#endif
/* B4 factorization optimization data */
typedef struct _B4rec
{
int *B4_var; /* Position of basic columns in the B4 basis */
int *var_B4; /* Variable in the B4 basis */
int *B4_row; /* B4 position of the i'th row */
int *row_B4; /* Original position of the i'th row */
REAL *wcol;
int *nzwcol;
} B4rec;
#define OBJ_STEPS 5
typedef struct _OBJmonrec {
lprec *lp;
int oldpivstrategy,
oldpivrule, pivrule, ruleswitches,
limitstall[2], limitruleswitches,
idxstep[OBJ_STEPS], countstep, startstep, currentstep,
Rcycle, Ccycle, Ncycle, Mcycle, Icount;
REAL thisobj, prevobj,
objstep[OBJ_STEPS],
thisinfeas, previnfeas,
epsvalue;
char spxfunc[10];
MYBOOL pivdynamic;
MYBOOL isdual;
MYBOOL active;
} OBJmonrec;
typedef struct _edgerec
{
REAL *edgeVector;
} edgerec;
typedef struct _pricerec
{
REAL theta;
REAL pivot;
REAL epspivot;
int varno;
lprec *lp;
MYBOOL isdual;
} pricerec;
typedef struct _multirec
{
lprec *lp;
int size; /* The maximum number of multiply priced rows/columns */
int used; /* The current / active number of multiply priced rows/columns */
int limit; /* The active/used count at which a full update is triggered */
pricerec *items; /* Array of best multiply priced rows/columns */
int *freeList; /* The indeces of available positions in "items" */
UNIONTYPE QSORTrec *sortedList; /* List of pointers to "pricerec" items in sorted order */
REAL *stepList; /* Working array (values in sortedList order) */
REAL *valueList; /* Working array (values in sortedList order) */
int *indexSet; /* The final exported index list of pivot variables */
int active; /* Index of currently active multiply priced row/column */
int retries;
REAL step_base;
REAL step_last;
REAL obj_base;
REAL obj_last;
REAL epszero;
REAL maxpivot;
REAL maxbound;
MYBOOL sorted;
MYBOOL truncinf;
MYBOOL objcheck;
MYBOOL dirty;
} multirec;
#endif /* HEADER_lp_types */

View File

@ -1,164 +0,0 @@
#ifndef HEADER_lp_utils
#define HEADER_lp_utils
#ifdef FORTIFY
#include "lp_fortify.h"
#define allocCHAR allocCHAR_FORTIFY
#define allocMYBOOL allocMYBOOL_FORTIFY
#define allocINT allocINT_FORTIFY
#define allocREAL allocREAL_FORTIFY
#define allocLREAL allocLREAL_FORTIFY
#endif
#include "lp_types.h"
/* Temporary data storage arrays */
typedef struct _workarraysrec
{
lprec *lp;
int size;
int count;
char **vectorarray;
int *vectorsize;
} workarraysrec;
typedef struct _LLrec
{
int size; /* The allocated list size */
int count; /* The current entry count */
int firstitem;
int lastitem;
int *map; /* The list of forward and backward-mapped entries */
} LLrec;
typedef struct _PVrec
{
int count; /* The allocated list item count */
int *startpos; /* Starting index of the current value */
REAL *value; /* The list of forward and backward-mapped entries */
struct _PVrec *parent; /* The parent record in a pushed chain */
} PVrec;
#ifdef __cplusplus
extern "C" {
#endif
/* Put function headers here */
STATIC MYBOOL allocCHAR(lprec *lp, char **ptr, int size, MYBOOL clear);
STATIC MYBOOL allocMYBOOL(lprec *lp, MYBOOL **ptr, int size, MYBOOL clear);
STATIC MYBOOL allocINT(lprec *lp, int **ptr, int size, MYBOOL clear);
STATIC MYBOOL allocREAL(lprec *lp, REAL **ptr, int size, MYBOOL clear);
STATIC MYBOOL allocLREAL(lprec *lp, LREAL **ptr, int size, MYBOOL clear);
STATIC MYBOOL allocFREE(lprec *lp, void **ptr);
REAL *cloneREAL(lprec *lp, REAL *origlist, int size);
MYBOOL *cloneMYBOOL(lprec *lp, MYBOOL *origlist, int size);
int *cloneINT(lprec *lp, int *origlist, int size);
#if defined INLINE
INLINE void set_biton(MYBOOL *bitarray, int item)
{
bitarray[item / 8] |= (1 << (item % 8));
}
INLINE void set_bitoff(MYBOOL *bitarray, int item)
{
bitarray[item / 8] &= ~(1 << (item % 8));
}
INLINE MYBOOL is_biton(MYBOOL *bitarray, int item)
{
return( (MYBOOL) ((bitarray[item / 8] & (1 << (item % 8))) != 0) );
}
#else
void set_biton(MYBOOL *bitarray, int item);
MYBOOL set_bitoff(MYBOOL *bitarray, int item);
MYBOOL is_biton(MYBOOL *bitarray, int item);
#endif
int comp_bits(MYBOOL *bitarray1, MYBOOL *bitarray2, int items);
STATIC workarraysrec *mempool_create(lprec *lp);
STATIC char *mempool_obtainVector(workarraysrec *mempool, int count, int unitsize);
STATIC MYBOOL mempool_releaseVector(workarraysrec *mempool, char *memvector, MYBOOL forcefree);
STATIC MYBOOL mempool_free(workarraysrec **mempool);
STATIC void roundVector(LREAL *myvector, int endpos, LREAL roundzero);
STATIC REAL normalizeVector(REAL *myvector, int endpos);
STATIC void swapINT(int *item1, int *item2);
STATIC void swapREAL(REAL *item1, REAL *item2);
STATIC void swapPTR(void **item1, void **item2);
STATIC REAL restoreINT(REAL valREAL, REAL epsilon);
STATIC REAL roundToPrecision(REAL value, REAL precision);
STATIC int searchFor(int target, int *attributes, int size, int offset, MYBOOL absolute);
STATIC MYBOOL isINT(lprec *lp, REAL value);
STATIC MYBOOL isOrigFixed(lprec *lp, int varno);
STATIC void chsign_bounds(REAL *lobound, REAL *upbound);
STATIC REAL rand_uniform(lprec *lp, REAL range);
/* Doubly linked list routines */
STATIC int createLink(int size, LLrec **linkmap, MYBOOL *usedpos);
STATIC MYBOOL freeLink(LLrec **linkmap);
STATIC int sizeLink(LLrec *linkmap);
STATIC MYBOOL isActiveLink(LLrec *linkmap, int itemnr);
STATIC int countActiveLink(LLrec *linkmap);
STATIC int countInactiveLink(LLrec *linkmap);
STATIC int firstActiveLink(LLrec *linkmap);
STATIC int lastActiveLink(LLrec *linkmap);
STATIC MYBOOL appendLink(LLrec *linkmap, int newitem);
STATIC MYBOOL insertLink(LLrec *linkmap, int afteritem, int newitem);
STATIC MYBOOL setLink(LLrec *linkmap, int newitem);
STATIC MYBOOL fillLink(LLrec *linkmap);
STATIC int nextActiveLink(LLrec *linkmap, int backitemnr);
STATIC int prevActiveLink(LLrec *linkmap, int forwitemnr);
STATIC int firstInactiveLink(LLrec *linkmap);
STATIC int lastInactiveLink(LLrec *linkmap);
STATIC int nextInactiveLink(LLrec *linkmap, int backitemnr);
STATIC int prevInactiveLink(LLrec *linkmap, int forwitemnr);
STATIC int removeLink(LLrec *linkmap, int itemnr);
STATIC LLrec *cloneLink(LLrec *sourcemap, int newsize, MYBOOL freesource);
STATIC int compareLink(LLrec *linkmap1, LLrec *linkmap2);
STATIC MYBOOL verifyLink(LLrec *linkmap, int itemnr, MYBOOL doappend);
/* Packed vector routines */
STATIC PVrec *createPackedVector(int size, REAL *values, int *workvector);
STATIC void pushPackedVector(PVrec *PV, PVrec *parent);
STATIC MYBOOL unpackPackedVector(PVrec *PV, REAL **target);
STATIC REAL getvaluePackedVector(PVrec *PV, int index);
STATIC PVrec *popPackedVector(PVrec *PV);
STATIC MYBOOL freePackedVector(PVrec **PV);
#ifdef __cplusplus
}
#endif
#endif /* HEADER_lp_utils */
#ifdef FORTIFY
#if defined CODE_lp_utils && !defined CODE_lp_utils_
int _Fortify_ret;
#else
extern int _Fortify_ret;
#endif
#ifdef CODE_lp_utils
#define CODE_lp_utils_
#else
# undef allocCHAR
# undef allocMYBOOL
# undef allocINT
# undef allocREAL
# undef allocLREAL
# define allocCHAR(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocCHAR_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
# define allocMYBOOL(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocMYBOOL_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
# define allocINT(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocINT_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
# define allocREAL(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocREAL_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
# define allocLREAL(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocLREAL_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
#endif
#endif