| 16 | |
| 17 | |
| 18 | int main (int argc, const char * argv[]) |
| 19 | { |
| 20 | if (argc < 2) |
| 21 | { |
| 22 | cout << "Usage: components <file-name>" << endl; |
| 23 | exit(1); |
| 24 | } |
| 25 | char filename[256]; |
| 26 | strcpy (filename, argv[1]); |
| 27 | |
| 28 | // --------------------------------------------------------- |
| 29 | // Read graph |
| 30 | |
| 31 | MyGraph G; |
| 32 | |
| 33 | GML_error err = G.load (filename); |
| 34 | if (err.err_num != GML_OK) |
| 35 | { |
| 36 | cerr << "Error (" << err.err_num << ") loading graph from file \"" << filename << "\""; |
| 37 | switch (err.err_num) |
| 38 | { |
| 39 | case GML_FILE_NOT_FOUND: cerr << "A file with that name doesn't exist."; break; |
| 40 | case GML_TOO_MANY_BRACKETS: cerr << "A mismatch of brackets was detected, i.e. there were too many closing brackets (])."; break; |
| 41 | case GML_OPEN_BRACKET: cerr << "Now, there were too many opening brackets ([)"; break; |
| 42 | case GML_TOO_MANY_DIGITS: cerr << "The number of digits a integer or floating point value can have is limited to 1024, this should be enough :-)"; break; |
| 43 | case GML_PREMATURE_EOF: cerr << "An EOF occured, where it wasn't expected, e.g. while scanning a string."; break; |
| 44 | case GML_SYNTAX: cerr << "The file isn't a valid GML file, e.g. a mismatch in the key-value pairs."; break; |
| 45 | case GML_UNEXPECTED: cerr << "A character occured, where it makes no sense, e.g. non-numerical characters"; break; |
| 46 | case GML_OK: break; |
| 47 | } |
| 48 | cerr << endl; |
| 49 | exit(1); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | cout << "Graph read from file \"" << filename << "\" has " << G.number_of_nodes() << " nodes and " << G.number_of_edges() << " edges" << endl; |
| 54 | } |
| 55 | |
| 56 | // Components |
| 57 | G.make_undirected(); |
| 58 | |
| 59 | if (!G.is_connected()) |
| 60 | { |
| 61 | // 2. Get components |
| 62 | components cp; |
| 63 | if (cp.check(G) != algorithm::GTL_OK) |
| 64 | { |
| 65 | cerr << "component check failed at line " << __LINE__ << endl; |
| 66 | exit(1); |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | if (cp.run(G) != algorithm::GTL_OK) |
| 71 | { |
| 72 | cerr << "component algorithm failed at line " << __LINE__ << endl; |
| 73 | exit(1); |
| 74 | } |
| 75 | else |
nothing calls this directly
no test coverage detected