1 /* permuteETree.c */
2
3 #include "../ETree.h"
4 #include "../../timings.h"
5
6 /*--------------------------------------------------------------------*/
7 int
main(int argc,char * argv[])8 main ( int argc, char *argv[] )
9 /*
10 -----------------------------------------------------------
11 read in an ETree object.
12 if the ETree is defined on a compressed graph
13 read in an equivalence map IV object.
14 expand the ETree to be defined on the unit weight graph.
15 endif
16 get the old-to-new vertex permutation.
17 permute the vtx-to-front map.
18
19 created -- 97feb28, cca
20 -----------------------------------------------------------
21 */
22 {
23 char *inEqmapIVfileName, *inETreeFileName, *outETreeFileName,
24 *outIVfileName ;
25 double t1, t2 ;
26 int msglvl, rc ;
27 IV *eqmapIV, *vtxOldToNewIV ;
28 ETree *etree, *etree2 ;
29 FILE *msgFile ;
30
31 if ( argc != 7 ) {
32 fprintf(stdout,
33 "\n\n usage : %s msglvl msgFile inETreeFile inEqmapFile "
34 "\n outETreeFile outIVfile "
35 "\n msglvl -- message level"
36 "\n msgFile -- message file"
37 "\n inETreeFile -- input file, must be *.etreef or *.etreeb"
38 "\n inEqmapFile -- input file, must be *.ivf or *.ivb"
39 "\n outETreeFile -- output file, must be *.etreef or *.etreeb"
40 "\n outIVfile -- output file for oldToNew vector,"
41 "\n must be *.ivf or *.ivb"
42 "\n", argv[0]) ;
43 return(0) ;
44 }
45 msglvl = atoi(argv[1]) ;
46 if ( strcmp(argv[2], "stdout") == 0 ) {
47 msgFile = stdout ;
48 } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
49 fprintf(stderr, "\n fatal error in %s"
50 "\n unable to open file %s\n",
51 argv[0], argv[2]) ;
52 return(-1) ;
53 }
54 inETreeFileName = argv[3] ;
55 inEqmapIVfileName = argv[4] ;
56 outETreeFileName = argv[5] ;
57 outIVfileName = argv[6] ;
58 fprintf(msgFile,
59 "\n %s "
60 "\n msglvl -- %d"
61 "\n msgFile -- %s"
62 "\n inETreeFile -- %s"
63 "\n inEqmapFile -- %s"
64 "\n outETreeFile -- %s"
65 "\n outIVfile -- %s"
66 "\n",
67 argv[0], msglvl, argv[2], inETreeFileName, inEqmapIVfileName,
68 outETreeFileName, outIVfileName) ;
69 fflush(msgFile) ;
70 /*
71 ------------------------
72 read in the ETree object
73 ------------------------
74 */
75 if ( strcmp(inETreeFileName, "none") == 0 ) {
76 fprintf(msgFile, "\n no file to read from") ;
77 exit(0) ;
78 }
79 etree = ETree_new() ;
80 MARKTIME(t1) ;
81 rc = ETree_readFromFile(etree, inETreeFileName) ;
82 MARKTIME(t2) ;
83 fprintf(msgFile, "\n CPU %9.5f : read in etree from file %s",
84 t2 - t1, inETreeFileName) ;
85 if ( rc != 1 ) {
86 fprintf(msgFile, "\n return value %d from ETree_readFromFile(%p,%s)",
87 rc, etree, inETreeFileName) ;
88 exit(-1) ;
89 }
90 ETree_leftJustify(etree) ;
91 fprintf(msgFile, "\n\n after reading ETree object from file %s",
92 inETreeFileName) ;
93 if ( msglvl > 2 ) {
94 ETree_writeForHumanEye(etree, msgFile) ;
95 } else {
96 ETree_writeStats(etree, msgFile) ;
97 }
98 fflush(msgFile) ;
99
100 if ( strcmp(inEqmapIVfileName, "none") != 0 ) {
101 /*
102 -------------------------------------
103 read in the equivalence map IV object
104 -------------------------------------
105 */
106 eqmapIV = IV_new() ;
107 MARKTIME(t1) ;
108 rc = IV_readFromFile(eqmapIV, inEqmapIVfileName) ;
109 MARKTIME(t2) ;
110 fprintf(msgFile, "\n CPU %9.5f : read in eqmapIV from file %s",
111 t2 - t1, inEqmapIVfileName) ;
112 if ( rc != 1 ) {
113 fprintf(msgFile, "\n return value %d from IV_readFromFile(%p,%s)",
114 rc, eqmapIV, inEqmapIVfileName) ;
115 exit(-1) ;
116 }
117 fprintf(msgFile, "\n\n after reading IV object from file %s",
118 inEqmapIVfileName) ;
119 if ( msglvl > 2 ) {
120 IV_writeForHumanEye(eqmapIV, msgFile) ;
121 } else {
122 IV_writeStats(eqmapIV, msgFile) ;
123 }
124 fflush(msgFile) ;
125 /*
126 ---------------------
127 expand the front tree
128 ---------------------
129 */
130 MARKTIME(t1) ;
131 etree2 = ETree_expand(etree, eqmapIV) ;
132 MARKTIME(t2) ;
133 fprintf(msgFile, "\n\n CPU %9.5f : expand the ETree", t2 - t1) ;
134 fprintf(msgFile, "\n\n expanded ETree") ;
135 if ( msglvl > 2 ) {
136 ETree_writeForHumanEye(etree2, msgFile) ;
137 } else {
138 ETree_writeStats(etree2, msgFile) ;
139 }
140 /*
141 ------------------------------------------------
142 free the old ETree object and the eqmapIV object
143 ------------------------------------------------
144 */
145 ETree_free(etree) ;
146 etree = etree2 ;
147 etree2 = NULL ;
148 IV_free(eqmapIV) ;
149 }
150 /*
151 -----------------------------
152 get the permutation IV object
153 -----------------------------
154 */
155 MARKTIME(t1) ;
156 vtxOldToNewIV = ETree_oldToNewVtxPerm(etree) ;
157 MARKTIME(t2) ;
158 fprintf(msgFile,
159 "\n\n CPU %9.5f : get the old-to-new permutation", t2 - t1) ;
160 if ( msglvl > 2 ) {
161 fprintf(msgFile, "\n\n vertex old-to-new IV object") ;
162 IV_writeForHumanEye(vtxOldToNewIV, msgFile) ;
163 } else {
164 fprintf(msgFile, "\n\n vertex old-to-new IV object") ;
165 IV_writeStats(vtxOldToNewIV, msgFile) ;
166 }
167 fflush(msgFile) ;
168 /*
169 ------------------------------------------------
170 overwrite the ETree object with the new ordering
171 ------------------------------------------------
172 */
173 ETree_permuteVertices(etree, vtxOldToNewIV) ;
174 fprintf(msgFile, "\n\n after permuting the vertices") ;
175 if ( msglvl > 2 ) {
176 ETree_writeForHumanEye(etree, msgFile) ;
177 } else {
178 ETree_writeStats(etree, msgFile) ;
179 }
180 /*
181 -------------------------------------
182 optionally write out the ETree object
183 -------------------------------------
184 */
185 if ( strcmp(outETreeFileName, "none") != 0 ) {
186 MARKTIME(t1) ;
187 rc = ETree_writeToFile(etree, outETreeFileName) ;
188 MARKTIME(t2) ;
189 fprintf(msgFile, "\n CPU %9.5f : write etree to file %s",
190 t2 - t1, outETreeFileName) ;
191 }
192 /*
193 ----------------------------------
194 optionally write out the IV object
195 ----------------------------------
196 */
197 if ( strcmp(outIVfileName, "none") != 0 ) {
198 MARKTIME(t1) ;
199 rc = IV_writeToFile(vtxOldToNewIV, outIVfileName) ;
200 MARKTIME(t2) ;
201 fprintf(msgFile, "\n CPU %9.5f : write vtxOldToNewIV to file %s",
202 t2 - t1, outIVfileName) ;
203 }
204 /*
205 ----------------
206 free the objects
207 ----------------
208 */
209 ETree_free(etree) ;
210 IV_free(vtxOldToNewIV) ;
211
212 fprintf(msgFile, "\n") ;
213 fclose(msgFile) ;
214
215 return(1) ; }
216
217 /*--------------------------------------------------------------------*/
218