Dip  0.92.4
mcknap.h
Go to the documentation of this file.
1 
2 #ifndef MCKNAP_INCLUDED
3 #define MCKNAP_INCLUDED
4 
5 /* ====================================================================== */
6 #define MCKNAP_RC_OK 0
7 #define MCKNAP_RC_INF 1
8 #define MCKNAP_RC_TRIVIAL_MAXSUM 2
9 
10 /* ======================================================================
11  definitions
12  ====================================================================== */
13 
14 #define TRACELEVEL 10 /* level of debug information */
15 #define START 1 /* first test to be run */
16 #define TESTS 100 /* last test to be run */
17 
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <time.h>
21 #include <stdarg.h>
22 /*#include <values.h>*/
23 #include <math.h>
24 #include <string.h>
25 /*#include <values.h>*/
26 #include <limits.h>
27 #include <memory.h>
28 #define _INCLUDE_POSIX_SOURCE
29 #ifndef _MSC_VER
30 #include <sys/times.h>
31 #include <unistd.h>
32 #endif
33 
34 
35 /* ======================================================================
36  macros
37  ====================================================================== */
38 
39 #ifndef _MSC_VER
40 #define srand(x) srand48(x)
41 #define random(x) (lrand48() % (x))
42 #else
43 #define random(x) (rand() % (x))
44 #endif
45 
46 #define SYNC 5 /* when to switch to linear scan in binary scan */
47 #define MEDIMAX 15
48 #define MAXSTACK 100
49 #define MAXLIST 32
50 #define MAXVTYPE ULONG_MAX
51 
52 #define TRUE 1
53 #define FALSE 0
54 
55 #define MAXIMIZE 1
56 #define MINIMIZE 0
57 
58 #define DET(a1, a2, b1, b2) ((a1) * (stype) (b2) - (a2) * (stype) (b1))
59 #define SWAPS(a,b) { register itemset t; t=*(a); *(a)=*(b); *(b)=t; }
60 #define SWAPI(a,b) { register itemrec t; t=*(a); *(a)=*(b); *(b)=t; }
61 #define SWAPO(a,b) { register ordrec t; t=*(a); *(a)=*(b); *(b)=t; }
62 #define SIZE(a) ((int) (((a)->lset+1)-(a)->fset))
63 
64 
65 /* ======================================================================
66  type declarations
67  ====================================================================== */
68 
69 typedef int boolean; /* logical variable */
70 typedef int ntype; /* number of stages */
71 
72 
73 typedef int itype; /* item profits and weights */
74 /*typedef long stype;*/ /* sum of pofit or weight */
75 typedef double stype; /* sum of pofit or weight */
76 typedef unsigned long vtype; /* solution vector */
77 
78 
79 /* partial vector */
80 typedef struct {
84 } partvect;
85 
86 /* item */
87 typedef struct {
88  int i;/*MVG*/
89  int j;/*MVG*/
92 } itemrec;
93 
94 /* set of partial vectors */
95 typedef struct {
101  boolean used;
102 } itemset;
103 
104 /* set of partial vectors */
105 typedef struct {
109 } partset;
110 
111 /* set of itemsets */
112 typedef struct {
116 } isetset;
117 
118 /* order record */
119 typedef struct {
123 } ordrec;
124 
125 /* order interval */
126 typedef struct {
129 } ordintv;
130 
131 /* order stack */
132 typedef struct {
134  int level;
135  int optim;
139 } ordstack;
140 
141 /* solution record */
142 typedef struct {
145 } solrec;
146 
147 /* solution structure */
148 typedef struct {
157 } solstruct;
158 
159 typedef int (*funcptr) (const void *, const void *);
160 
161 
162 typedef struct { /* all problem information */
165  int type;
167 
168  stype capacity; /* capacity of knapsack */
169  stype dantzig; /* the dantzig upper bound */
170  stype zstar; /* optimal solution */
171  stype summul; /* sum of multiplications */
172  stype antmul; /* number of multiplications */
173  stype maxmul; /* max multiplied set */
174  stype redusets; /* sum of reduced sets */
175  stype reduitems; /* sum of items which are tested for reduce */
176  stype redukill; /* sum of tested items which were reduced */
177  stype gap; /* current gap */
178  stype partitions; /* number of partitions */
179  stype domikill; /* number of dominated-kills */
180  stype lpkill; /* number of lp-kills */
181  long timepar; /* time used for partitioning */
182  long timesort; /* time used for sorting of gradients */
183  long time; /* time used for all solution */
184  long welldef; /* is the found solution correct */
185  long checked; /* optimal solution checked */
186  long iterates; /* number of iterations to find optimal sol */
187 } allinfo;
188 
189 
190 
191 
192 extern int minmcknapSolve(int cap,
193  isetset * head,
194  itemrec * solRec,
195  stype * minObj);
196 extern void visitems(itemset *d);
197 extern void inittrace(char *ext);
198 
199 
200 
201 /* ======================================================================
202  global variables
203  ====================================================================== */
204 /*MVG: TODO - not reentrant*/
205 
206 /* #define DEBUG(x) x */
207 #define DEBUG(x)
208 
209 /*solstruct solution;*/
210 /*solstruct optsol;*/
211 
212 #endif
int(* funcptr)(const void *, const void *)
Definition: mcknap.h:159
Definition: mcknap.h:142
int itype
Definition: mcknap.h:73
#define MAXSTACK
Definition: mcknap.h:48
stype redukill
Definition: mcknap.h:176
Definition: mcknap.h:119
stype summul
Definition: mcknap.h:171
ntype size
Definition: mcknap.h:96
long timesort
Definition: mcknap.h:182
stype wsum
Definition: mcknap.h:152
int level
Definition: mcknap.h:134
stype gap
Definition: mcknap.h:177
itype dp
Definition: mcknap.h:120
stype partitions
Definition: mcknap.h:178
ntype size
Definition: mcknap.h:150
partvect * lset
Definition: mcknap.h:108
stype capacity
Definition: mcknap.h:168
itemrec * fset
Definition: mcknap.h:97
ordrec * last
Definition: mcknap.h:137
stype reduitems
Definition: mcknap.h:175
itemrec * no
Definition: mcknap.h:99
partvect * fset
Definition: mcknap.h:107
int optim
Definition: mcknap.h:135
Definition: mcknap.h:87
itemset * ref
Definition: mcknap.h:122
itemset * lset
Definition: mcknap.h:114
stype antmul
Definition: mcknap.h:172
long welldef
Definition: mcknap.h:184
ntype size
Definition: mcknap.h:143
ntype size
Definition: mcknap.h:106
int ntype
Definition: mcknap.h:70
itemrec l
Definition: mcknap.h:100
long timepar
Definition: mcknap.h:181
ordrec * i
Definition: mcknap.h:138
#define MAXLIST
Definition: mcknap.h:49
Definition: mcknap.h:95
itype wsum
Definition: mcknap.h:91
stype psum
Definition: mcknap.h:81
ordrec * b
Definition: mcknap.h:156
vtype vmax
Definition: mcknap.h:154
ordrec * a
Definition: mcknap.h:155
ntype k
Definition: mcknap.h:163
stype domikill
Definition: mcknap.h:179
int j
Definition: mcknap.h:89
long iterates
Definition: mcknap.h:186
void inittrace(char *ext)
stype maxmul
Definition: mcknap.h:173
stype redusets
Definition: mcknap.h:174
itype dw
Definition: mcknap.h:121
long time
Definition: mcknap.h:183
int i
Definition: mcknap.h:88
stype psum
Definition: mcknap.h:151
vtype vect
Definition: mcknap.h:83
itemrec * lset
Definition: mcknap.h:98
boolean used
Definition: mcknap.h:101
itemset * set
Definition: mcknap.h:144
long checked
Definition: mcknap.h:185
itype range
Definition: mcknap.h:166
ordrec * first
Definition: mcknap.h:136
int boolean
Definition: mcknap.h:69
ordrec * l
Definition: mcknap.h:128
stype zstar
Definition: mcknap.h:170
stype lpkill
Definition: mcknap.h:180
itype psum
Definition: mcknap.h:90
double stype
Definition: mcknap.h:75
itemset * fset
Definition: mcknap.h:113
vtype vect
Definition: mcknap.h:153
int type
Definition: mcknap.h:165
ntype n
Definition: mcknap.h:164
stype dantzig
Definition: mcknap.h:169
void visitems(itemset *d)
stype wsum
Definition: mcknap.h:82
int minmcknapSolve(int cap, isetset *head, itemrec *solRec, stype *minObj)
ntype size
Definition: mcknap.h:115
unsigned long vtype
Definition: mcknap.h:76
ordrec * f
Definition: mcknap.h:127