mcknap.h
Go to the documentation of this file.00001
00002 #ifndef MCKNAP_INCLUDED
00003 #define MCKNAP_INCLUDED
00004
00005
00006 #define MCKNAP_RC_OK 0
00007 #define MCKNAP_RC_INF 1
00008 #define MCKNAP_RC_TRIVIAL_MAXSUM 2
00009
00010
00011
00012
00013
00014 #define TRACELEVEL 10
00015 #define START 1
00016 #define TESTS 100
00017
00018 #include <stdlib.h>
00019 #include <stdio.h>
00020 #include <time.h>
00021 #include <stdarg.h>
00022
00023 #include <math.h>
00024 #include <string.h>
00025
00026 #include <limits.h>
00027 #include <memory.h>
00028 #define _INCLUDE_POSIX_SOURCE
00029 #ifndef _MSC_VER
00030 #include <sys/times.h>
00031 #include <unistd.h>
00032 #endif
00033
00034
00035
00036
00037
00038
00039 #ifndef _MSC_VER
00040 #define srand(x) srand48(x)
00041 #define random(x) (lrand48() % (x))
00042 #else
00043 #define random(x) (rand() % (x))
00044 #endif
00045
00046 #define SYNC 5
00047 #define MEDIMAX 15
00048 #define MAXSTACK 100
00049 #define MAXLIST 32
00050 #define MAXVTYPE ULONG_MAX
00051
00052 #define TRUE 1
00053 #define FALSE 0
00054
00055 #define MAXIMIZE 1
00056 #define MINIMIZE 0
00057
00058 #define DET(a1, a2, b1, b2) ((a1) * (stype) (b2) - (a2) * (stype) (b1))
00059 #define SWAPS(a,b) { register itemset t; t=*(a); *(a)=*(b); *(b)=t; }
00060 #define SWAPI(a,b) { register itemrec t; t=*(a); *(a)=*(b); *(b)=t; }
00061 #define SWAPO(a,b) { register ordrec t; t=*(a); *(a)=*(b); *(b)=t; }
00062 #define SIZE(a) ((int) (((a)->lset+1)-(a)->fset))
00063
00064
00065
00066
00067
00068
00069 typedef int boolean;
00070 typedef int ntype;
00071
00072
00073 typedef int itype;
00074
00075 typedef double stype;
00076 typedef unsigned long vtype;
00077
00078
00079
00080 typedef struct {
00081 stype psum;
00082 stype wsum;
00083 vtype vect;
00084 } partvect;
00085
00086
00087 typedef struct {
00088 int i;
00089 int j;
00090 itype psum;
00091 itype wsum;
00092 } itemrec;
00093
00094
00095 typedef struct {
00096 ntype size;
00097 itemrec *fset;
00098 itemrec *lset;
00099 itemrec *no;
00100 itemrec f,l;
00101 boolean used;
00102 } itemset;
00103
00104
00105 typedef struct {
00106 ntype size;
00107 partvect *fset;
00108 partvect *lset;
00109 } partset;
00110
00111
00112 typedef struct {
00113 itemset *fset;
00114 itemset *lset;
00115 ntype size;
00116 } isetset;
00117
00118
00119 typedef struct {
00120 itype dp;
00121 itype dw;
00122 itemset *ref;
00123 } ordrec;
00124
00125
00126 typedef struct {
00127 ordrec *f;
00128 ordrec *l;
00129 } ordintv;
00130
00131
00132 typedef struct {
00133 ordintv intv[MAXSTACK];
00134 int level;
00135 int optim;
00136 ordrec *first;
00137 ordrec *last;
00138 ordrec *i;
00139 } ordstack;
00140
00141
00142 typedef struct {
00143 ntype size;
00144 itemset *set;
00145 } solrec;
00146
00147
00148 typedef struct {
00149 solrec list[MAXLIST];
00150 ntype size;
00151 stype psum;
00152 stype wsum;
00153 vtype vect;
00154 vtype vmax;
00155 ordrec *a;
00156 ordrec *b;
00157 } solstruct;
00158
00159 typedef int (*funcptr) (const void *, const void *);
00160
00161
00162 typedef struct {
00163 ntype k;
00164 ntype n;
00165 int type;
00166 itype range;
00167
00168 stype capacity;
00169 stype dantzig;
00170 stype zstar;
00171 stype summul;
00172 stype antmul;
00173 stype maxmul;
00174 stype redusets;
00175 stype reduitems;
00176 stype redukill;
00177 stype gap;
00178 stype partitions;
00179 stype domikill;
00180 stype lpkill;
00181 long timepar;
00182 long timesort;
00183 long time;
00184 long welldef;
00185 long checked;
00186 long iterates;
00187 } allinfo;
00188
00189
00190
00191
00192 extern int minmcknapSolve(int cap,
00193 isetset * head,
00194 itemrec * solRec,
00195 stype * minObj);
00196 extern void visitems(itemset *d);
00197 extern void inittrace(char *ext);
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 #define DEBUG(x)
00208
00209
00210
00211
00212 #endif