00001 #ifndef _GREEDYTYPES 00002 #define _GREEDYTYPES 00003 00004 #include<stdio.h> 00005 #include<stdlib.h> 00006 #include<math.h> 00007 00008 #include "eg_timer.h" 00009 #include "eg_mempool.h" 00010 #include "eg_list.h" 00011 00012 #include "eg_heap.h" 00013 #include "eg_dgraph.h" 00014 #include "eg_dijkstra.h" 00015 #include "eg_dijkstra_app.h" 00016 #include "eg_ddomino.h" 00017 #include "eg_ddpconstraint.h" 00018 00019 #define KP_DEBUG 0 00020 #define EG_DEBUG_TRACE 0 00021 #define EG_KP_NOST 0xfff 00022 #define EG_KP_MAX_CUTS 250 00023 00024 /* EG_USE_ZERO_DOMINOES. 0 or 1 (DEFAULT 1) 00025 00026 When set to one, the code will loop through all the 1-dominoes generated 00027 by Letchford's algorithm in order to generate 0-dominoes to be used as 00028 starting points for the 2P algorithm. */ 00029 00030 #define EG_USE_ZERO_DOMINOES 1 00031 00032 /* EG_USE_KARGER. 0 or 1 (DEFAULT 0) 00033 00034 When set to one, the code will utilize Sanjeeb Dash's karger algorithm 00035 in order to generate 0-dominoes to be used as starting points for 00036 the 2P algorithm. */ 00037 00038 #define EG_USE_KARGER 1 00039 00040 /* SAMPLING DEFINITIONS (DEFAULT 1 1 1) 00041 00042 In order to use sampling, EG_USE_SAMPLING, EG_KP_HEURISTIC and 00043 EG_GREEDYKP_FILLTABLE should all be set to one. Otherwise, they 00044 should be set to zero. */ 00045 00046 #define EG_KP_HEURISTIC 1 00047 #define EG_GREEDYKP_FILLTABLE 1 00048 #define EG_USE_SAMPLING 1 00049 00050 /* EG_KP_SAMPLE_TIME (DEFAULT 1.0) 00051 00052 Thie is the base amount of time which will be to generate cuts from 00053 each zero-domino. 00054 00055 EG_KP_MAX_SAMPLE (DEFAULT 10) 00056 00057 The amount of zero-dominoes which will be kept during the cut generation 00058 process for later use in sampling. 00059 00060 Hence, if EG_KP_MAX_SAMPLE == 5 and EG_KP_SAMPLE_TIME == 10, then the 00061 algorithm will spend a total of 50 seconds sampling. */ 00062 00063 #define EG_KP_SAMPLE_TIME 1.0 00064 #define EG_KP_MAX_SAMPLE 10 00065 00066 /* Seed for sampling (DEFAULT 1) */ 00067 00068 #define EG_KP_SAMPLE_SEED 1 00069 00070 /* EG_DOMINO_K (DEFAULT 1) 00071 00072 In theory, for the USE_ZERO_DOMINOES heuristic, the best value for this 00073 constant is = to the number of handles. However, for the growth stage it 00074 suffices to set this value to 1.0. When generating two-pies there are 00075 speed-quality tradeoffs between setting it to 1 or 2. */ 00076 00077 #define EG_DOMINO_K 2 00078 00079 /* EG_KPC_MAX_HANDLES 1...N (DEFAULT 5) 00080 00081 For now, this value should be two for the KP algorithm to run. */ 00082 00083 #define EG_KPC_MAX_HANDLES 5 00084 00085 /* EG_KARGER_SEED (DEFAULT 1) 00086 00087 Seed used by srandom() before running the karger algorithm */ 00088 00089 #define EG_KARGER_SEED 1 00090 00091 /* EG_KARGER_MAX_ITER (DEFAULT INT_MAX) 00092 00093 Max number of iterations to be performed by the karger algorithm. 00094 Note that if we are stopping by time, this should be set to 00095 EG_KARGER_MAX_ITER. */ 00096 00097 #define EG_KARGER_MAX_ITER INT_MAX 00098 00099 /* EG_KARGER_TIME_PER_NODE (DEFAULT 0.1) 00100 00101 Amount of time dedicated to generating cuts, as a function of the 00102 number of nodes in the original primal graph. */ 00103 00104 #define EG_KARGER_MAX_TOT_TIME 15.0 00105 #define EG_KARGER_TIME_PER_NODE 0.3 00106 00107 /* EGgreedyData 00108 * 00109 * The idea is as follows: Nodes in cycleG are either even or odd. 00110 * Even nodes are those on the 'left' hand side. That is, nodes whose 00111 * node id is even. Odd nodes are those on the 'right' hand side. That 00112 * is, nodes whose node id is odd. 00113 * 00114 * ee_dist : distance between pairs (s,t) of even nodes, such that s < t. 00115 * ee_prec : father (in tree) of node t in shortest path between pairs 00116 * (s,t) of even nodes, such that s < t. 00117 * eo_prec : father (in tree) of node t of shortest path between pairs 00118 * (s,t) where s is even, t is odd, and s < t. 00119 * bdGnodeMap : element i is a pointer to the i-th node of the list 00120 * bdG->nodes (with regard to the actual list ordering) 00121 * cycleEdgeMap : element i points to the edge whose id is i in cycleG 00122 * bdGtoCycleGmap : consider a node in bdG with id i. Element i of 00123 this array corresponds to the even copy of this 00124 node in graph cycleG. 00125 */ 00126 00127 typedef struct 00128 { 00129 int norig_nodes, norig_edges, nplanar_edges; 00130 int *orig_edges, *planar_edges; 00131 double *orig_weight, *planar_weight; 00132 EGlist_t** dembed; 00133 EGdGraph_t *bdG; 00134 EGdGraph_t *cycleG; 00135 graphP G; 00136 EGdGraphNode_t **bdGnodeMap; 00137 EGdGraphEdge_t **cycleEdgeMap; 00138 EGlist_t *ddom_list; 00139 EGdijkstraCost_t **ee_dist; 00140 #if EG_KP_HEURISTIC 00141 EGdijkstraCost_t **eo_dist; 00142 EGdGraphNode_t **bdGtoCycleGmap; 00143 #endif 00144 int **ee_prec, **eo_prec; 00145 unsigned int* randa; 00146 unsigned int* randb; 00147 EGheap_t *cut_heap; 00148 EGheap_t *dc_heap; 00149 int max_handles; 00150 double percentage; 00151 00152 unsigned int nviolated; 00153 double min_violated; 00154 double max_violated; 00155 unsigned delta_distr[7]; 00156 unsigned char *pndummy; 00157 unsigned char *pedummy; 00158 EGdGraphNode_t **bdnodes; 00159 EGdGraphEdge_t **pedges; 00160 double *pedgevals; 00161 } EGgreedyData_t; 00162 00163 /* ========================================================================= */ 00168 typedef struct EGdualCut_t 00169 { 00170 unsigned int sz; 00171 EGdGraphEdge_t **edges; 00172 EGdijkstraCost_t value; 00173 } EGdualCut_t; 00174 00175 /* ========================================================================= */ 00179 struct EGdkdomino_t; 00180 typedef struct EGinternalPairs_t 00181 { 00182 EGdGraphNode_t *s; 00183 EGdGraphNode_t *t; 00184 EGdijkstraCost_t value; 00185 EGdijkstraCost_t ivalue; 00186 EGdijkstraCost_t evalue; 00187 unsigned int npath; 00188 EGdGraphEdge_t **stpath; 00189 EGlist_t *extpath; 00190 } EGinternalPairs_t; 00191 00192 /* ========================================================================= */ 00194 void EGfreeInternalPairs(void*pair,EGmemPool_t*mem); 00195 00196 /* ========================================================================= */ 00198 typedef struct EGdkdomino_t 00199 { 00200 unsigned int k; 00201 unsigned int max_k; 00202 unsigned int orientation; 00203 EGinternalPairs_t* pairs; 00204 unsigned int * handleid; 00205 EGdualCut_t *cut; 00206 } EGdkdomino_t; 00207 00208 typedef struct 00209 { 00210 unsigned int nhandles; 00211 EGlist_t* FH[EG_KPC_MAX_HANDLES]; 00212 EGlist_t* dkdom; 00213 EGdijkstraCost_t slack; 00214 } EGdkpc_t; 00215 00216 /* given a list of ddominos, keeps track of the zdom we are currently 00217 * analyzing. For this, it takes a ddom, removes a path (which one 00218 * is determined by current_middle) and considers the side given 00219 * by current_side. current_side \in {0,1}. current_middle \in {0,1,2}. 00220 */ 00221 00222 typedef struct 00223 { 00224 int num_it; 00225 EGlistNode_t *ddit; 00226 int current_side; 00227 int current_middle; 00228 EGgreedyData_t *gdata; 00229 } EGdcutIter_t; 00230 00231 typedef struct 00232 { 00233 int nhandles; 00234 int *handle_size; 00235 int **handles; 00236 int nteeth; 00237 int *teeth_size; 00238 int **teeth; 00239 int *teeth_k; 00240 int **teeth_handle; 00241 int **teeth_nhalf; 00242 int ***teeth_halves; 00243 double slack; 00244 00245 unsigned int randa; 00246 unsigned int randb; 00247 00248 } EGpkpc_t; 00249 00250 typedef struct 00251 { 00252 00253 EGdualCut_t *dc; 00254 int orientation; 00255 00256 } EGcutSeed_t; 00257 00258 void EGdisplayDualCut(FILE *fout, 00259 EGdualCut_t* dc); 00260 00261 int EGincreaseDKdomino(EGdkdomino_t *dkd, 00262 EGinternalPairs_t *p); 00263 00264 #endif