0001 /****************************************************************************************** 0002 * 图Graph 0003 ******************************************************************************************/ 0004 template <typename Tv, typename Te> //顶点类型、边类型 0005 void UniPrint::p ( GraphMatrix<Tv, Te>& s ) { //引用 0006 int inD = 0; for ( int i = 0; i < s.n; i++ ) inD += s.inDegree ( i ); 0007 int outD = 0; for ( int i = 0; i < s.n; i++ ) outD += s.outDegree ( i ); 0008 printf ( "%s[%d]*(%d, %d):\n", typeid ( s ).name(), &s, s.n, s.e ); //基本信息 0009 // 标题行 0010 print ( s.n ); printf ( " " ); print ( inD ); printf ( "|" ); 0011 for ( int i = 0; i < s.n; i++ ) { print ( s.vertex ( i ) ); printf ( "[" ); print ( s.status ( i ) ); printf ( "] " ); } 0012 printf ( "\n" ); 0013 // 标题行(续) 0014 print ( outD ); printf ( " " ); print ( s.e ); printf ( "|" ); 0015 for ( int i = 0; i < s.n; i++ ) { print ( s.inDegree ( i ) ); printf ( " " ); } 0016 printf ( "| dTime fTime Parent Weight\n" ); 0017 // 水平分隔线 0018 printf ( "-----------+" ); for ( int i = 0; i < s.n; i++ ) printf ( "------" ); 0019 printf ( "+----------------------------\n" ); 0020 // 逐行输出各顶点 0021 for ( int i = 0; i < s.n; i++ ) { 0022 print ( s.vertex ( i ) ); printf ( "[" ); print ( s.status ( i ) ); printf ( "] " ); print ( s.outDegree ( i ) ); printf ( "|" ); 0023 for ( int j = 0; j < s.n; j++ ) 0024 if ( s.exists ( i, j ) ) { print ( s.edge ( i, j ) ); print ( s.type ( i, j ) ); } 0025 else printf ( " ." ); 0026 printf ( "| " ); print ( s.dTime ( i ) ); printf ( " " ); print ( s.fTime ( i ) ); 0027 printf ( " " ); if ( 0 > s.parent ( i ) ) print ( "^" ); else print ( s.vertex ( s.parent ( i ) ) ); 0028 printf ( " " ); if ( INT_MAX > s.priority ( i ) ) print ( s.priority ( i ) ); else print ( " INF" ); 0029 printf ( "\n" ); 0030 } 0031 printf ( "\n" ); 0032 }