1
Fork 0
mirror of https://github.com/Jaxan/hybrid-ads.git synced 2025-04-27 23:17:44 +02:00
hybrid-ads/lib/write_tree_to_dot.hpp
2015-03-19 17:25:33 +01:00

45 lines
1.3 KiB
C++

#pragma once
#include <functional>
#include <ostream>
#include <queue>
#include <utility>
// Generic printer for tree
template <typename T, typename NodeString>
void write_tree_to_dot(const T & tree, NodeString && node_string, std::ostream & out){
using namespace std;
out << "digraph g {\n";
// breadth first
int global_id = 0;
queue<pair<int, reference_wrapper<const T>>> work;
work.push({global_id++, tree});
while(!work.empty()){
const auto id = work.front().first;
const T & node = work.front().second;
work.pop();
out << "\n\ts" << id << " [label=\"";
node_string(node, out);
out << "\"];\n";
for(auto && c : node.children){
int new_id = global_id++;
out << "\ts" << id << " -> " << "s" << new_id << ";\n";
work.push({new_id, c});
}
}
out << "}" << endl;
}
// Specialized printing for splitting trees and dist seqs
struct splijtboom;
void write_splitting_tree_to_dot(const splijtboom & root, std::ostream & out);
void write_splitting_tree_to_dot(const splijtboom & root, std::string const & filename);
struct distinguishing_sequence;
void write_adaptive_distinguishing_sequence_to_dot(const distinguishing_sequence & root, std::ostream & out);
void write_adaptive_distinguishing_sequence_to_dot(const distinguishing_sequence & root, std::string const & filename);