00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 #ifndef __UTIL_H
00099 #define __UTIL_H
00100
00101 #include "bc_machdefs.h"
00102 #include "unistd.h"
00103
00104 #define CCutil_MAXDOUBLE (1e30)
00105 #define CCutil_MAXINT (2147483647)
00106
00107 #define CCcheck_rval(rval,msg) { \
00108 if ((rval)) { \
00109 fprintf (stderr, "%s\n", (msg)); \
00110 goto CLEANUP; \
00111 } \
00112 }
00113
00114 #define CCcheck_NULL(item,msg) { \
00115 if ((!item)) { \
00116 fprintf (stderr, "%s\n", (msg)); \
00117 rval = 1; \
00118 goto CLEANUP; \
00119 } \
00120 }
00121
00122
00123 #define CC_SBUFFER_SIZE (4000)
00124 #define CC_SFNAME_SIZE (32)
00125
00126 typedef struct CC_SFILE
00127 {
00128 int status;
00129 int desc;
00130 int type;
00131 int chars_in_buffer;
00132 int current_buffer_char;
00133 int bits_in_last_char;
00134
00135
00136
00137 int pos;
00138 char fname[CC_SFNAME_SIZE];
00139 char hname[CC_SFNAME_SIZE];
00140 unsigned char buffer[CC_SBUFFER_SIZE];
00141 }
00142 CC_SFILE;
00143
00144 #ifdef CC_NETREADY
00145 typedef struct CC_SPORT
00146 {
00147 unsigned short port;
00148 int t;
00149 }
00150 CC_SPORT;
00151 #endif
00152
00153 typedef struct CCrandstate
00154 {
00155 int a;
00156 int b;
00157 int arr[55];
00158 }
00159 CCrandstate;
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 #define CC_SAFE_MALLOC(nnum,type) \
00181 (type *) CCutil_allocrus (((size_t) (nnum)) * sizeof (type))
00182
00183 #define CC_FREE(object,type) { \
00184 CCutil_freerus ((void *) (object)); \
00185 object = (type *) NULL; \
00186 }
00187
00188 #define CC_IFFREE(object,type) { \
00189 if ((object)) CC_FREE ((object),type); \
00190 }
00191
00192 #define CC_PTRWORLD_ALLOC_ROUTINE(type, ptr_alloc_r, ptr_bulkalloc_r) \
00193 \
00194 static int ptr_bulkalloc_r (CCptrworld *world, int nalloc) \
00195 { \
00196 CCbigchunkptr *bp; \
00197 int i; \
00198 int count = CC_BIGCHUNK / sizeof ( type ); \
00199 type *p; \
00200 \
00201 while (nalloc > 0) { \
00202 bp = CCutil_bigchunkalloc (); \
00203 if (bp == (CCbigchunkptr *) NULL) { \
00204 fprintf (stderr, "ptr alloc failed\n"); \
00205 return 1; \
00206 } \
00207 bp->next = world->chunklist ; \
00208 world->chunklist = bp; \
00209 \
00210 p = ( type * ) bp->this_one; \
00211 for (i=count-2; i>=0; i--) { \
00212 p[i].next = &p[i+1]; \
00213 } \
00214 p[count - 1].next = (type *) world->freelist; \
00215 world->freelist = (void *) p; \
00216 nalloc -= count; \
00217 } \
00218 return 0; \
00219 } \
00220 \
00221 static type *ptr_alloc_r (CCptrworld *world) \
00222 { \
00223 type *p; \
00224 \
00225 if (world->freelist == (void *) NULL) { \
00226 if (ptr_bulkalloc_r (world, 1)) { \
00227 fprintf (stderr, "ptr alloc failed\n"); \
00228 return ( type * ) NULL; \
00229 } \
00230 } \
00231 p = (type *) world->freelist ; \
00232 world->freelist = (void *) p->next; \
00233 \
00234 return p; \
00235 }
00236
00237 #define CC_PTRWORLD_FREE_ROUTINE(type, ptr_free_r) \
00238 \
00239 static void ptr_free_r (CCptrworld *world, type *p) \
00240 { \
00241 p->next = (type *) world->freelist ; \
00242 world->freelist = (void *) p; \
00243 }
00244
00245 #define CC_PTRWORLD_LISTADD_ROUTINE(type, entrytype, ptr_listadd_r, ptr_alloc_r) \
00246 \
00247 static int ptr_listadd_r (type **list, entrytype x, CCptrworld *world) \
00248 { \
00249 if (list != (type **) NULL) { \
00250 type *p = ptr_alloc_r (world); \
00251 \
00252 if (p == (type *) NULL) { \
00253 fprintf (stderr, "ptr list add failed\n"); \
00254 return 1; \
00255 } \
00256 p->this = x; \
00257 p->next = *list; \
00258 *list = p; \
00259 } \
00260 return 0; \
00261 }
00262
00263 #define CC_PTRWORLD_LISTFREE_ROUTINE(type, ptr_listfree_r, ptr_free_r) \
00264 \
00265 static void ptr_listfree_r (CCptrworld *world, type *p) \
00266 { \
00267 type *next; \
00268 \
00269 while (p != (type *) NULL) { \
00270 next = p->next; \
00271 ptr_free_r (world, p); \
00272 p = next; \
00273 } \
00274 }
00275
00276 #define CC_PTRWORLD_LEAKS_ROUTINE(type, ptr_leaks_r, field, fieldtype) \
00277 \
00278 static int ptr_leaks_r (CCptrworld *world, int *total, int *onlist) \
00279 { \
00280 int count = CC_BIGCHUNK / sizeof ( type ); \
00281 int duplicates = 0; \
00282 type * p; \
00283 CCbigchunkptr *bp; \
00284 \
00285 *total = 0; \
00286 *onlist = 0; \
00287 \
00288 for (bp = world->chunklist ; bp; bp = bp->next) \
00289 (*total) += count; \
00290 \
00291 for (p = (type *) world->freelist ; p; p = p->next) { \
00292 (*onlist)++; \
00293 p-> field = ( fieldtype ) 0; \
00294 } \
00295 for (p = (type *) world->freelist ; p; p = p->next) { \
00296 if ((unsigned long) p-> field == (unsigned long) (size_t) 1) \
00297 duplicates++; \
00298 else \
00299 p-> field = ( fieldtype ) (size_t) 1; \
00300 } \
00301 if (duplicates) { \
00302 fprintf (stderr, "WARNING: %d duplicates on ptr free list \n", \
00303 duplicates); \
00304 } \
00305 return *total - *onlist; \
00306 }
00307
00308 #define CC_PTRWORLD_ROUTINES(type, ptr_alloc_r, ptr_bulkalloc_r, ptr_free_r) \
00309 CC_PTRWORLD_ALLOC_ROUTINE (type, ptr_alloc_r, ptr_bulkalloc_r) \
00310 CC_PTRWORLD_FREE_ROUTINE (type, ptr_free_r)
00311
00312 #define CC_PTRWORLD_LIST_ROUTINES(type, entrytype, ptr_alloc_r, ptr_bulkalloc_r, ptr_free_r, ptr_listadd_r, ptr_listfree_r) \
00313 CC_PTRWORLD_ROUTINES (type, ptr_alloc_r, ptr_bulkalloc_r, ptr_free_r) \
00314 CC_PTRWORLD_LISTADD_ROUTINE (type, entrytype, ptr_listadd_r, ptr_alloc_r) \
00315 CC_PTRWORLD_LISTFREE_ROUTINE (type, ptr_listfree_r, ptr_free_r)
00316
00317 #define CC_BIGCHUNK ((int) ((1<<16) - sizeof (CCbigchunkptr) - 16))
00318
00319 struct CCbigchunk;
00320
00321 typedef struct CCbigchunkptr
00322 {
00323 void *this_one;
00324 struct CCbigchunk *this_chunk;
00325 struct CCbigchunkptr *next;
00326 }
00327 CCbigchunkptr;
00328
00329
00330 typedef struct CCptrworld
00331 {
00332 int refcount;
00333 void *freelist;
00334 CCbigchunkptr *chunklist;
00335 }
00336 CCptrworld;
00337
00338
00339
00340 void *CCutil_allocrus (size_t size),
00341 *CCutil_reallocrus (void *ptr,
00342 size_t size),
00343 CCutil_freerus (void *p),
00344 CCutil_bigchunkfree (CCbigchunkptr * bp),
00345 CCptrworld_init (CCptrworld * world),
00346 CCptrworld_add (CCptrworld * world),
00347 CCptrworld_delete (CCptrworld * world);
00348
00349 int CCutil_reallocrus_scale (void **pptr,
00350 int *pnnum,
00351 int count,
00352 double scale,
00353 size_t size),
00354 CCutil_reallocrus_count (void **pptr,
00355 int count,
00356 size_t size);
00357
00358 CCbigchunkptr *CCutil_bigchunkalloc (void);
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 int CCutil_bix_getopt (int argc,
00371 char **argv,
00372 const char *def,
00373 int *p_optind,
00374 char **p_optarg);
00375
00376
00377 #define CC_BIX_GETOPT_UNKNOWN -3038
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 typedef struct CCdheap
00388 {
00389 double *key;
00390 int *entry;
00391 int *loc;
00392 int total_space;
00393 int size;
00394 }
00395 CCdheap;
00396
00397
00398 void CCutil_dheap_free (CCdheap * h),
00399 CCutil_dheap_delete (CCdheap * h,
00400 int i),
00401 CCutil_dheap_changekey (CCdheap * h,
00402 int i,
00403 double newkey);
00404
00405 int CCutil_dheap_init (CCdheap * h,
00406 int k),
00407 CCutil_dheap_resize (CCdheap * h,
00408 int newsize),
00409 CCutil_dheap_findmin (CCdheap * h),
00410 CCutil_dheap_deletemin (CCdheap * h),
00411 CCutil_dheap_insert (CCdheap * h,
00412 int i);
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 typedef struct CCelist
00423 {
00424 int ecount;
00425 int *ends;
00426 }
00427 CCelist;
00428
00429 typedef struct CCelistl
00430 {
00431 int ecount;
00432 int *ends;
00433 int *len;
00434 }
00435 CCelistl;
00436
00437 typedef struct CCelistw
00438 {
00439 int ecount;
00440 int *ends;
00441 double *weight;
00442 }
00443 CCelistw;
00444
00445 typedef struct CCelistlw
00446 {
00447 int ecount;
00448 int *ends;
00449 int *len;
00450 double *weight;
00451 }
00452 CCelistlw;
00453
00454 void CCelist_init (CCelist * elist),
00455 CCelistl_init (CCelistl * elist),
00456 CCelistw_init (CCelistw * elist),
00457 CCelistlw_init (CCelistlw * elist),
00458 CCelist_free (CCelist * elist),
00459 CCelistl_free (CCelistl * elist),
00460 CCelistw_free (CCelistw * elist),
00461 CCelistlw_free (CCelistlw * elist);
00462
00463 int CCelist_alloc (CCelist * elist,
00464 int ecount),
00465 CCelistl_alloc (CCelistl * elist,
00466 int ecount),
00467 CCelistw_alloc (CCelistw * elist,
00468 int ecount),
00469 CCelistlw_alloc (CCelistlw * elist,
00470 int ecount),
00471 CCutil_edge_to_cycle (int ncount,
00472 int *elist,
00473 int *yesno,
00474 int *cyc);
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 #undef CCUTIL_EDGELEN_FUNCTIONPTR
00495
00496 typedef struct CCdata_user
00497 {
00498 double *x;
00499 double *y;
00500 }
00501 CCdata_user;
00502
00503 typedef struct CCdata_rhvector
00504 {
00505 int dist_00;
00506 int dist_01;
00507 int dist_02;
00508 int dist_12;
00509 int dist_22;
00510 double p;
00511 int rhlength;
00512 char *space;
00513 char **vectors;
00514 }
00515 CCdata_rhvector;
00516
00517 typedef struct CCdatagroup
00518 {
00519 int (*edgelen) (int i,
00520 int j,
00521 struct CCdatagroup * dat);
00522 double *x;
00523 double *y;
00524 double *z;
00525 int **adj;
00526 int *adjspace;
00527 int **len;
00528 int *lenspace;
00529 int *degree;
00530 int norm;
00531 int dsjrand_param;
00532 int default_len;
00533 int sparse_ecount;
00534 double gridsize;
00535 double dsjrand_factor;
00536 CCdata_rhvector rhdat;
00537 CCdata_user userdat;
00538 int ndepot;
00539 int orig_ncount;
00540 int *depotcost;
00541 int *orig_names;
00542 }
00543 CCdatagroup;
00544
00545
00546
00547 #ifdef CCUTIL_EDGELEN_FUNCTIONPTR
00548 extern int (*CCutil_dat_edgelen) (int i,
00549 int j,
00550 CCdatagroup * dat);
00551 #else
00552 int CCutil_dat_edgelen (int i,
00553 int j,
00554 CCdatagroup * dat);
00555 #endif
00556
00557 int CCutil_dat_setnorm (CCdatagroup * dat,
00558 int norm);
00559
00560 void CCutil_dat_getnorm (CCdatagroup * dat,
00561 int *norm),
00562 CCutil_dsjrand_init (CCdatagroup * dat,
00563 int maxdist,
00564 int seed),
00565 CCutil_init_datagroup (CCdatagroup * dat),
00566 CCutil_freedatagroup (CCdatagroup * dat);
00567
00568
00569 #define CC_KD_NORM_TYPE 128
00570 #define CC_X_NORM_TYPE 256
00571 #define CC_JUNK_NORM_TYPE 512
00572
00573 #define CC_D2_NORM_SIZE 1024
00574 #define CC_D3_NORM_SIZE 2048
00575 #define CC_MATRIX_NORM_SIZE 4096
00576
00577 #define CC_NORM_BITS (CC_KD_NORM_TYPE | CC_X_NORM_TYPE | \
00578 CC_JUNK_NORM_TYPE)
00579 #define CC_NORM_SIZE_BITS (CC_D2_NORM_SIZE | CC_D3_NORM_SIZE | \
00580 CC_MATRIX_NORM_SIZE)
00581
00582 #define CC_MAXNORM (0 | CC_KD_NORM_TYPE | CC_D2_NORM_SIZE)
00583 #define CC_EUCLIDEAN_CEIL (1 | CC_KD_NORM_TYPE | CC_D2_NORM_SIZE)
00584 #define CC_EUCLIDEAN (2 | CC_KD_NORM_TYPE | CC_D2_NORM_SIZE)
00585 #define CC_EUCLIDEAN_3D (3 | CC_X_NORM_TYPE | CC_D3_NORM_SIZE)
00586 #define CC_USER (4 | CC_JUNK_NORM_TYPE | 0)
00587 #define CC_ATT (5 | CC_X_NORM_TYPE | CC_D2_NORM_SIZE)
00588 #define CC_GEOGRAPHIC (6 | CC_X_NORM_TYPE | CC_D2_NORM_SIZE)
00589 #define CC_MATRIXNORM (7 | CC_JUNK_NORM_TYPE | CC_MATRIX_NORM_SIZE)
00590 #define CC_DSJRANDNORM (8 | CC_JUNK_NORM_TYPE | 0)
00591 #define CC_CRYSTAL (9 | CC_X_NORM_TYPE | CC_D3_NORM_SIZE)
00592 #define CC_SPARSE (10 | CC_JUNK_NORM_TYPE | 0)
00593 #define CC_RHMAP1 (11 | CC_JUNK_NORM_TYPE | 0)
00594 #define CC_RHMAP2 (12 | CC_JUNK_NORM_TYPE | 0)
00595 #define CC_RHMAP3 (13 | CC_JUNK_NORM_TYPE | 0)
00596 #define CC_RHMAP4 (14 | CC_JUNK_NORM_TYPE | 0)
00597 #define CC_RHMAP5 (15 | CC_JUNK_NORM_TYPE | 0)
00598 #define CC_EUCTOROIDAL (16 | CC_JUNK_NORM_TYPE | CC_D2_NORM_SIZE)
00599 #define CC_GEOM (17 | CC_X_NORM_TYPE | CC_D2_NORM_SIZE)
00600 #define CC_MANNORM (18 | CC_KD_NORM_TYPE | CC_D2_NORM_SIZE)
00601 #define CC_SUBDIVISION (99 | CC_JUNK_NORM_TYPE | 0)
00602
00603 #define CC_GEOGRAPHIC_SCALE (6378.388 * 3.14 / 180.0)
00604 #define CC_GEOM_SCALE (6378388.0 * 3.14 / 180.0)
00605 #define CC_ATT_SCALE (.31622)
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 typedef struct CCutil_edgeinf
00621 {
00622 int ends[2];
00623 int val;
00624 struct CCutil_edgeinf *next;
00625 }
00626 CCutil_edgeinf;
00627
00628 typedef struct CCutil_edgehash
00629 {
00630 CCutil_edgeinf **table;
00631 CCptrworld edgeinf_world;
00632 unsigned int size;
00633 unsigned int mult;
00634 }
00635 CCutil_edgehash;
00636
00637
00638 int CCutil_edgehash_init (CCutil_edgehash * h,
00639 int size),
00640 CCutil_edgehash_add (CCutil_edgehash * h,
00641 int end1,
00642 int end2,
00643 int val),
00644 CCutil_edgehash_set (CCutil_edgehash * h,
00645 int end1,
00646 int end2,
00647 int val),
00648 CCutil_edgehash_del (CCutil_edgehash * h,
00649 int end1,
00650 int end2),
00651 CCutil_edgehash_find (CCutil_edgehash * h,
00652 int end1,
00653 int end2,
00654 int *val),
00655 CCutil_edgehash_getall (CCutil_edgehash * h,
00656 int *ecount,
00657 int **elist,
00658 int **elen);
00659
00660 void CCutil_edgehash_delall (CCutil_edgehash * h),
00661 CCutil_edgehash_free (CCutil_edgehash * h);
00662
00663
00664
00665
00666
00667
00668
00669
00670 int CCutil_edge_file_union (int ncount,
00671 int nfiles,
00672 char **flist,
00673 int *ecount,
00674 int **elist,
00675 int **elen,
00676 int *foundtour,
00677 double *besttourlen);
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688 int CCutil_readint (FILE * f);
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 struct CCgenhash_elem;
00701
00702 typedef struct CCgenhash
00703 {
00704 int nelem;
00705 int maxelem;
00706 int size;
00707 int (*hcmp) (void *key1,
00708 void *key2,
00709 void *u_data);
00710 unsigned int (*hfunc) (void *key,
00711 void *u_data);
00712 void *u_data;
00713 double maxdensity;
00714 double lowdensity;
00715 CCptrworld elem_world;
00716 struct CCgenhash_elem **table;
00717 }
00718 CCgenhash;
00719
00720 typedef struct CCgenhash_iter
00721 {
00722 int i;
00723 struct CCgenhash_elem *next;
00724 }
00725 CCgenhash_iter;
00726
00727
00728 int CCutil_genhash_init (CCgenhash * h,
00729 int size,
00730 int (*hcmp) (void *key1,
00731 void *key2,
00732 void *u_data),
00733 unsigned int (*hfunc) (void *key,
00734 void *u_data),
00735 void *u_data,
00736 double maxdensity,
00737 double lowdensity),
00738 CCutil_genhash_insert (CCgenhash * h,
00739 void *key,
00740 void *data),
00741 CCutil_genhash_insert_h (CCgenhash * h,
00742 unsigned int hashval,
00743 void *key,
00744 void *data),
00745 CCutil_genhash_replace (CCgenhash * h,
00746 void *key,
00747 void *data),
00748 CCutil_genhash_replace_h (CCgenhash * h,
00749 unsigned int hashval,
00750 void *key,
00751 void *data),
00752 CCutil_genhash_delete (CCgenhash * h,
00753 void *key),
00754 CCutil_genhash_delete_h (CCgenhash * h,
00755 unsigned int hashval,
00756 void *key);
00757
00758 unsigned int CCutil_genhash_hash (CCgenhash * h,
00759 void *key);
00760
00761 void *CCutil_genhash_lookup (CCgenhash * h,
00762 void *key),
00763 *CCutil_genhash_lookup_h (CCgenhash * h,
00764 unsigned int hashval,
00765 void *key),
00766 *CCutil_genhash_next (CCgenhash * h,
00767 CCgenhash_iter * iter,
00768 void **key,
00769 int *keysize);
00770
00771 void CCutil_genhash_u_data (CCgenhash * h,
00772 void *u_data),
00773 CCutil_genhash_free (CCgenhash * h,
00774 void (*freefunc) (void *key,
00775 void *data,
00776 void *u_data)),
00777 CCutil_genhash_start (CCgenhash * h,
00778 CCgenhash_iter * iter);
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790 #define CC_MASTER_NO_DAT 100
00791 #define CC_MASTER_DAT 101
00792
00793 void CCutil_cycle_len (int ncount,
00794 CCdatagroup * dat,
00795 int *cycle,
00796 double *len);
00797
00798 int CCutil_getdata (char *datname,
00799 int binary_in,
00800 int innorm,
00801 int *ncount,
00802 CCdatagroup * dat,
00803 int gridsize,
00804 int allow_dups,
00805 CCrandstate * rstate),
00806 CCutil_writedata (char *datname,
00807 int binary_out,
00808 int ncount,
00809 CCdatagroup * dat),
00810 CCutil_putmaster (char *mastername,
00811 int ncount,
00812 CCdatagroup * dat,
00813 int *perm),
00814 CCutil_writemaster (CC_SFILE * out,
00815 int ncount,
00816 CCdatagroup * dat,
00817 int *perm),
00818 CCutil_getmaster (char *mastername,
00819 int *ncount,
00820 CCdatagroup * dat,
00821 int **perm),
00822 CCutil_readmaster (CC_SFILE * in,
00823 int *ncount,
00824 CCdatagroup * dat,
00825 int **perm),
00826 CCutil_getnodeweights (char *weightname,
00827 int ncount,
00828 int weight_limit,
00829 double **wcoord,
00830 CCrandstate * rstate),
00831 CCutil_gettsplib (char *datname,
00832 int *ncount,
00833 CCdatagroup * dat),
00834 CCutil_writetsplib (const char *fname,
00835 int ncount,
00836 CCdatagroup * dat),
00837 CCutil_datagroup_perm (int ncount,
00838 CCdatagroup * dat,
00839 int *perm),
00840 CCutil_copy_datagroup (int ncount,
00841 CCdatagroup * indat,
00842 CCdatagroup * outdat),
00843 CCutil_getedgelist (int ncount,
00844 char *fname,
00845 int *ecount,
00846 int **elist,
00847 int **elen,
00848 int binary_in),
00849 CCutil_getedgelist_n (int *ncount,
00850 char *fname,
00851 int *ecount,
00852 int **elist,
00853 int **elen,
00854 int binary_in),
00855 CCutil_genedgelist (int ncount,
00856 int ecount,
00857 int **elist,
00858 int **elen,
00859 CCdatagroup * dat,
00860 int maxlen,
00861 CCrandstate * rstate),
00862 CCutil_getcycle_tsplib (int ncount,
00863 char *cyclename,
00864 int *outcycle),
00865 CCutil_getcycle_edgelist (int ncount,
00866 char *cyclename,
00867 int *outcycle,
00868 int binary_in),
00869 CCutil_getcycle (int ncount,
00870 char *cyclename,
00871 int *outcycle,
00872 int binary_in),
00873 CCutil_getedges_double (int *ncount,
00874 char *fname,
00875 int *ecount,
00876 int **elist,
00877 double **elen,
00878 int binary_in),
00879 CCutil_writeedges (int ncount,
00880 char *outedgename,
00881 int ecount,
00882 int *elist,
00883 CCdatagroup * dat,
00884 int binary_out),
00885 CCutil_writecycle_edgelist (int ncount,
00886 char *outedgename,
00887 int *cycle,
00888 CCdatagroup * dat,
00889 int binary_out),
00890 CCutil_writecycle (int ncount,
00891 char *outcyclename,
00892 int *cycle,
00893 int binary_out),
00894 CCutil_writeedges_int (int ncount,
00895 char *outedgename,
00896 int ecount,
00897 int *elist,
00898 int *elen,
00899 int binary_out),
00900 CCutil_writeedges_double (int ncount,
00901 char *outedgename,
00902 int ecount,
00903 int *elist,
00904 double *elen,
00905 int binary_out),
00906 CCutil_tri2dat (int ncount,
00907 int *elen,
00908 CCdatagroup * dat),
00909 CCutil_graph2dat_matrix (int ncount,
00910 int ecount,
00911 int *elist,
00912 int *elen,
00913 int defaultlen,
00914 CCdatagroup * dat),
00915 CCutil_graph2dat_sparse (int ncount,
00916 int ecount,
00917 int *elist,
00918 int *elen,
00919 int defaultlen,
00920 CCdatagroup * dat),
00921 CCutil_get_sparse_dat_edges (int ncount,
00922 CCdatagroup * dat,
00923 int *ecount,
00924 int **elist,
00925 int **elen),
00926 CCutil_sparse_strip_edges (CCdatagroup * dat,
00927 int in_ecount,
00928 int *in_elist,
00929 int *in_elen,
00930 int *ecount,
00931 int **elist,
00932 int **elen),
00933 CCutil_sparse_real_tour (int ncount,
00934 CCdatagroup * dat,
00935 int *cyc,
00936 int *yesno);
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947 typedef struct CCpriority
00948 {
00949 CCdheap heap;
00950 union CCpri_data
00951 {
00952 void *data;
00953 int next;
00954 }
00955 *pri_info;
00956 int space;
00957 int freelist;
00958 }
00959 CCpriority;
00960
00961
00962 void CCutil_priority_free (CCpriority * pri),
00963 CCutil_priority_delete (CCpriority * pri,
00964 int handle),
00965 CCutil_priority_changekey (CCpriority * pri,
00966 int handle,
00967 double newkey),
00968 *CCutil_priority_findmin (CCpriority * pri,
00969 double *keyval),
00970 *CCutil_priority_deletemin (CCpriority * pri,
00971 double *keyval);
00972
00973 int CCutil_priority_init (CCpriority * pri,
00974 int k),
00975 CCutil_priority_insert (CCpriority * pri,
00976 void *data,
00977 double keyval);
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988 CC_SFILE *CCutil_sopen (const char *f,
00989 const char *s),
00990 *CCutil_sdopen (int d,
00991 const char *s);
00992
00993 int CCutil_swrite (CC_SFILE * f,
00994 char *buf,
00995 int size),
00996 CCutil_swrite_bits (CC_SFILE * f,
00997 int x,
00998 int xbits),
00999 CCutil_swrite_ubits (CC_SFILE * f,
01000 unsigned int x,
01001 int xbits),
01002 CCutil_swrite_char (CC_SFILE * f,
01003 int x),
01004 CCutil_swrite_string (CC_SFILE * f,
01005 const char *x),
01006 CCutil_swrite_short (CC_SFILE * f,
01007 short x),
01008 CCutil_swrite_ushort (CC_SFILE * f,
01009 unsigned x),
01010 CCutil_swrite_int (CC_SFILE * f,
01011 int x),
01012 CCutil_swrite_uint (CC_SFILE * f,
01013 unsigned int x),
01014 CCutil_swrite_double (CC_SFILE * f,
01015 double x),
01016 CCutil_sread (CC_SFILE * f,
01017 char *buf,
01018 int size),
01019 CCutil_sread_bits (CC_SFILE * f,
01020 int *x,
01021 int xbits),
01022 CCutil_sread_ubits (CC_SFILE * f,
01023 unsigned int *x,
01024 int xbits),
01025 CCutil_sread_char (CC_SFILE * f,
01026 char *x),
01027 CCutil_sread_string (CC_SFILE * f,
01028 char *x,
01029 int maxlen),
01030 CCutil_sread_short (CC_SFILE * f,
01031 short *x),
01032 CCutil_sread_ushort (CC_SFILE * f,
01033 unsigned short *x),
01034 CCutil_sread_short_r (CC_SFILE * f,
01035 short *x),
01036 CCutil_sread_int (CC_SFILE * f,
01037 int *x),
01038 CCutil_sread_uint (CC_SFILE * f,
01039 unsigned int *x),
01040 CCutil_sread_int_r (CC_SFILE * f,
01041 int *x),
01042 CCutil_sread_double (CC_SFILE * f,
01043 double *x),
01044 CCutil_sread_double_r (CC_SFILE * f,
01045 double *x),
01046 CCutil_sflush (CC_SFILE * f),
01047 CCutil_stell (CC_SFILE * f),
01048 CCutil_sseek (CC_SFILE * f,
01049 int offset),
01050 CCutil_srewind (CC_SFILE * f),
01051 CCutil_sclose (CC_SFILE * f),
01052 CCutil_sbits (unsigned int x),
01053 CCutil_sdelete_file (const char *fname),
01054 CCutil_sdelete_file_backup (const char *fname);
01055
01056 #ifdef CC_NETREADY
01057 CC_SFILE *CCutil_snet_open (const char *hname,
01058 unsigned p),
01059 *CCutil_snet_receive (CC_SPORT * s);
01060
01061 CC_SPORT *CCutil_snet_listen (unsigned p);
01062
01063 void CCutil_snet_unlisten (CC_SPORT * s);
01064
01065 #endif
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077 #define CCutil_SIGHUP 1
01078 #define CCutil_SIGINT 2
01079 #define CCutil_SIGQUIT 3
01080 #define CCutil_SIGILL 4
01081 #define CCutil_SIGTRAP 5
01082 #define CCutil_SIGABRT 6
01083 #define CCutil_SIGEMT 7
01084 #define CCutil_SIGFPE 8
01085 #define CCutil_SIGKILL 9
01086 #define CCutil_SIGBUS 10
01087 #define CCutil_SIGSEGV 11
01088 #define CCutil_SIGSYS 12
01089 #define CCutil_SIGPIPE 13
01090 #define CCutil_SIGALRM 14
01091 #define CCutil_SIGTERM 15
01092 #define CCutil_SIGUSR1 16
01093 #define CCutil_SIGUSR2 17
01094 #define CCutil_SIGCHLD 18
01095 #define CCutil_SIGPWR 19
01096 #define CCutil_SIGWINCH 20
01097 #define CCutil_SIGURG 21
01098 #define CCutil_SIGIO 22
01099 #define CCutil_SIGSTOP 23
01100 #define CCutil_SIGTSTP 24
01101 #define CCutil_SIGCONT 25
01102 #define CCutil_SIGTTIN 26
01103 #define CCutil_SIGTTOU 27
01104 #define CCutil_SIGVTALRM 28
01105 #define CCutil_SIGPROF 29
01106 #define CCutil_SIGXCPU 30
01107 #define CCutil_SIGXFSZ 31
01108 #define CCutil_SIGSTKFLT 32
01109 #define CCutil_SIGIOT 33
01110 #define CCutil_SIGPOLL 34
01111 #define CCutil_SIGMSG 35
01112 #define CCutil_SIGDANGER 36
01113 #define CCutil_SIGMIGRATE 37
01114 #define CCutil_SIGPRE 38
01115 #define CCutil_SIGVIRT 39
01116 #define CCutil_MAXSIG 39
01117
01118
01119 typedef void (*CCutil_handler) (int signum);
01120
01121 int CCutil_signal_handler (int ccsignum,
01122 CCutil_handler handler),
01123 CCutil_signal_default (int ccsignum),
01124 CCutil_signal_ignore (int ccsignum),
01125 CCutil_sig_to_ccsig (int signum);
01126
01127 void CCutil_signal_init (void),
01128 CCutil_handler_fatal (int signum),
01129 CCutil_handler_warn (int signum),
01130 CCutil_handler_exit (int signum);
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142 void CCutil_int_array_quicksort (int *len,
01143 int n),
01144 CCutil_int_perm_quicksort (int *perm,
01145 int *len,
01146 int n),
01147 CCutil_double_perm_quicksort (int *perm,
01148 double *len,
01149 int n),
01150 CCutil_rselect (int *arr,
01151 int l,
01152 int r,
01153 int m,
01154 double *coord,
01155 CCrandstate * rstate);
01156
01157 char *CCutil_linked_radixsort (char *data,
01158 char *datanext,
01159 char *dataval,
01160 int valsize);
01161
01162
01163
01164
01165
01166
01167
01168
01169 #define CC_SUBDIV_PORT ((unsigned short) 32141)
01170 #define CC_SUBGATE_PORT ((unsigned short) 32143)
01171 #define CCutil_FILE_NAME_LEN (128)
01172
01173 typedef struct CCsubdiv
01174 {
01175 double xrange[2];
01176 double yrange[2];
01177 int cnt;
01178 int id;
01179 double bound;
01180 int status;
01181 }
01182 CCsubdiv;
01183
01184 typedef struct CCsubdiv_lkh
01185 {
01186 int id;
01187 int cnt;
01188 int start;
01189 double origlen;
01190 double newlen;
01191 int status;
01192 }
01193 CCsubdiv_lkh;
01194
01195
01196 int CCutil_karp_partition (int ncount,
01197 CCdatagroup * dat,
01198 int partsize,
01199 int *p_scount,
01200 CCsubdiv ** p_slist,
01201 int ***partlist,
01202 CCrandstate * rstate),
01203 CCutil_write_subdivision_index (char *problabel,
01204 int ncount,
01205 int scount,
01206 CCsubdiv * slist),
01207 CCutil_read_subdivision_index (char *index_name,
01208 char **p_problabel,
01209 int *p_ncount,
01210 int *p_scount,
01211 CCsubdiv ** p_slist),
01212 CCutil_write_subdivision_lkh_index (char *problabel,
01213 int ncount,
01214 int scount,
01215 CCsubdiv_lkh * slist,
01216 double tourlen),
01217 CCutil_read_subdivision_lkh_index (char *index_name,
01218 char **p_problabel,
01219 int *p_ncount,
01220 int *p_scount,
01221 CCsubdiv_lkh ** p_slist,
01222 double *p_tourlen);
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239 #define CC_PRANDMAX 1000000007
01240
01241 void CCutil_sprand (int seed,
01242 CCrandstate * r);
01243
01244 int CCutil_lprand (CCrandstate * r);
01245
01246 double CCutil_normrand (CCrandstate * r);
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259 char *CCutil_strchr (char *s,
01260 int c),
01261 *CCutil_strrchr (char *s,
01262 int c),
01263 *CCutil_strdup (const char *s),
01264 *CCutil_strdup2 (const char *s);
01265
01266 const char *CCutil_strchr_c (const char *s,
01267 int c),
01268 *CCutil_strrchr_c (const char *s,
01269 int c);
01270
01271 unsigned int CCutil_nextprime (unsigned int x);
01272
01273 int CCutil_our_gcd (int a,
01274 int b),
01275 CCutil_our_lcm (int a,
01276 int b),
01277 CCutil_print_command (int ac,
01278 char **av);
01279
01280 void CCutil_readstr (FILE * f,
01281 char *s,
01282 int len),
01283 CCutil_printlabel (void);
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295 typedef struct CCutil_timer
01296 {
01297 double szeit;
01298 double cum_zeit;
01299 char name[40];
01300 int count;
01301 }
01302 CCutil_timer;
01303
01304
01305 double CCutil_zeit (void),
01306 CCutil_real_zeit (void),
01307 CCutil_stop_timer (CCutil_timer * t,
01308 int printit),
01309 CCutil_total_timer (CCutil_timer * t,
01310 int printit);
01311
01312
01313 void CCutil_init_timer (CCutil_timer * t,
01314 const char *name),
01315 CCutil_start_timer (CCutil_timer * t),
01316 CCutil_suspend_timer (CCutil_timer * t),
01317 CCutil_resume_timer (CCutil_timer * t);
01318
01319
01320
01321 #endif