1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/* testDM.c */
#include "../BPG.h"
#include "../../timings.h"
/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
---------------------------------------------------------------
read BPG from file and get the Dulmage-Mendelsohn decomposition
created -- 96mar08, cca
---------------------------------------------------------------
*/
{
char *inBPGFileName ;
double t1, t2 ;
int ierr, msglvl, rc ;
int *dmflags, *stats ;
BPG *bpg ;
FILE *msgFile ;
if ( argc != 4 ) {
fprintf(stdout,
"\n\n usage : %s msglvl msgFile inFile "
"\n msglvl -- message level"
"\n msgFile -- message file"
"\n inFile -- input file, must be *.bpgf or *.bpgb"
"\n", argv[0]) ;
return(0) ;
}
msglvl = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
fprintf(stderr, "\n fatal error in %s"
"\n unable to open file %s\n",
argv[0], argv[2]) ;
return(-1) ;
}
inBPGFileName = argv[3] ;
fprintf(msgFile,
"\n %s "
"\n msglvl -- %d"
"\n msgFile -- %s"
"\n inFile -- %s"
"\n",
argv[0], msglvl, argv[2], inBPGFileName) ;
fflush(msgFile) ;
/*
----------------------
read in the BPG object
----------------------
*/
if ( strcmp(inBPGFileName, "none") == 0 ) {
fprintf(msgFile, "\n no file to read from") ;
exit(0) ;
}
bpg = BPG_new() ;
MARKTIME(t1) ;
rc = BPG_readFromFile(bpg, inBPGFileName) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %9.5f : read in graph from file %s",
t2 - t1, inBPGFileName) ;
if ( rc != 1 ) {
fprintf(msgFile, "\n return value %d from BPG_readFromFile(%p,%s)",
rc, bpg, inBPGFileName) ;
exit(-1) ;
}
fprintf(msgFile, "\n\n after reading BPG object from file %s",
inBPGFileName) ;
if ( msglvl > 2 ) {
BPG_writeForHumanEye(bpg, msgFile) ;
} else {
BPG_writeStats(bpg, msgFile) ;
}
fflush(msgFile) ;
/*
--------------------------------------------
test out the max flow DMdecomposition method
--------------------------------------------
*/
dmflags = IVinit(bpg->nX + bpg->nY, -1) ;
stats = IVinit(6, 0) ;
MARKTIME(t1) ;
BPG_DMviaMaxFlow(bpg, dmflags, stats, msglvl, msgFile) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n\n CPU %9.5f : find DM via maxflow", t2 - t1) ;
if ( msglvl > 0 ) {
fprintf(msgFile,
"\n\n BPG_DMviaMaxFlow"
"\n |X_I| = %6d, |X_E| = %6d, |X_R| = %6d"
"\n |Y_I| = %6d, |Y_E| = %6d, |Y_R| = %6d",
stats[0], stats[1], stats[2],
stats[3], stats[4], stats[5]) ;
}
if ( msglvl > 1 ) {
fprintf(msgFile, "\n dmflags") ;
IVfp80(msgFile, bpg->nX + bpg->nY, dmflags, 80, &ierr) ;
fflush(msgFile) ;
}
/*
------------------------------------------
test out the matching DMcomposition method
------------------------------------------
*/
IVfill(bpg->nX + bpg->nY, dmflags, -1) ;
IVfill(6, stats, -1) ;
MARKTIME(t1) ;
BPG_DMdecomposition(bpg, dmflags, stats, msglvl, msgFile) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n\n CPU %9.5f : find DM via matching", t2 - t1) ;
if ( msglvl > 0 ) {
fprintf(msgFile,
"\n\n BPG_DMdecomposition"
"\n |X_I| = %6d, |X_E| = %6d, |X_R| = %6d"
"\n |Y_I| = %6d, |Y_E| = %6d, |Y_R| = %6d",
stats[0], stats[1], stats[2],
stats[3], stats[4], stats[5]) ;
}
if ( msglvl > 1 ) {
fprintf(msgFile, "\n dmflags") ;
IVfp80(msgFile, bpg->nX + bpg->nY, dmflags, 80, &ierr) ;
fflush(msgFile) ;
}
/*
----------------
free the storage
----------------
*/
IVfree(dmflags) ;
IVfree(stats) ;
BPG_free(bpg) ;
fprintf(msgFile, "\n") ;
fclose(msgFile) ;
return(1) ; }
/*--------------------------------------------------------------------*/
|