1#ifndef GRAPH_VISUALIZATION_H
2#define GRAPH_VISUALIZATION_H
17namespace graph_visualization {
19#define OPEN_COMMAND "open"
28inline void visualize(std::string& _generate, std::string newFileName =
"unnamed.dot") {
29 auto start_time = std::chrono::high_resolution_clock::now();
31 if (newFileName.size() < 5 || newFileName.substr(newFileName.length() - 4) !=
".dot")
32 newFileName +=
".dot";
35 std::ofstream outFile(newFileName);
38 if (outFile.is_open()) {
40 outFile <<
"graph G{" << std::endl;
45 outFile <<
"}" << std::endl;
50 std::cout <<
"Visualization file '" << newFileName <<
"' created successfully."
52 auto end_time = std::chrono::high_resolution_clock::now();
54 std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
55 double runtime_sec =
static_cast<double>(duration.count()) / 1e6;
57 std::cout <<
"Visualization runtime: " << runtime_sec <<
" sec" << std::endl;
58 std::string openCommand = OPEN_COMMAND + std::string(
" ") + newFileName;
59 system(openCommand.c_str());
61 std::cerr <<
"Error: Unable to open file '" << newFileName <<
"' for writing."
64 }
catch (
const std::exception& e) {
65 std::cerr <<
"Error: " << e.what() << std::endl;
74namespace digraph_visualization {
76#define OPEN_COMMAND "open"
85inline void visualize(std::string& _generate, std::string newFileName =
"unnamed.dot") {
86 auto start_time = std::chrono::high_resolution_clock::now();
88 if (newFileName.size() < 5 || newFileName.substr(newFileName.length() - 4) !=
".dot")
89 newFileName +=
".dot";
92 std::ofstream outFile(newFileName);
95 if (outFile.is_open()) {
97 outFile <<
"digraph G{" << std::endl;
100 outFile << _generate;
102 outFile <<
"}" << std::endl;
107 std::cout <<
"Visualization file '" << newFileName <<
"' created successfully."
109 auto end_time = std::chrono::high_resolution_clock::now();
111 std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
112 double runtime_sec =
static_cast<double>(duration.count()) / 1e6;
114 std::cout <<
"Visualization runtime: " << runtime_sec <<
" sec" << std::endl;
115 std::string openCommand = OPEN_COMMAND + std::string(
" ") + newFileName;
116 system(openCommand.c_str());
118 std::cerr <<
"Error: Unable to open file '" << newFileName <<
"' for writing."
121 }
catch (
const std::exception& e) {
122 std::cerr <<
"Error: " << e.what() << std::endl;