ccsoft  0.0.0
Convolutional codes library with soft decision decoding
/shared/development/google_code/rssoft/libccsoft/lib/CC_TreeGraphviz_FA.h
Go to the documentation of this file.
00001 /*
00002  Copyright 2013 Edouard Griffiths <f4exb at free dot fr>
00003 
00004  This file is part of CCSoft. A Convolutional Codes Soft Decoding library
00005 
00006  This program is free software; you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation; either version 2 of the License, or
00009  (at your option) any later version.
00010 
00011  This program is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with this program; if not, write to the Free Software
00018  Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
00019 
00020  Utility to output dot commands (Graphviz) for a graphical representation
00021  of the decoding tree. Using node+edge combination
00022 
00023  */
00024  
00025 #ifndef _CC_TREE_GRAPHVIZ_FA_H__
00026 #define _CC_TREE_GRAPHVIZ_FA_H__
00027 
00028 #include "CC_TreeNodeEdge_FA.h"
00029 #include "CC_Encoding_FA.h" // for print symbols
00030 #include <vector>
00031 #include <iostream>
00032 
00033 namespace ccsoft
00034 {
00035     template<typename T_IOSymbol, typename T_Register, typename T_Tag, unsigned int N_k>
00036     class CC_TreeGraphviz_FA
00037     {
00038     public:
00044         static void create_dot(CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *root_node, std::ostream& os)
00045         {
00046             std::vector<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*> node_edges;
00047             
00048             explore_node_edge(root_node, node_edges);
00049             print_dot(node_edges, os);
00050         }
00051         
00052     protected:
00059         static void explore_node_edge(CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k> *node_edge,
00060             std::vector<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*>& node_edges)
00061         {
00062             node_edges.push_back(node_edge);
00063             const std::array<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*, (1<<N_k)>& outgoing_node_edges = node_edge->get_outgoing_node_edges();
00064             typename std::array<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*, (1<<N_k)>::const_iterator ne_it = outgoing_node_edges.begin();
00065             
00066             for (; ne_it != outgoing_node_edges.end(); ++ne_it)
00067             {
00068                 node_edges.push_back(*ne_it);
00069                 explore_node_edge(*ne_it, node_edges);
00070             }
00071         }
00072         
00079         static void print_dot(std::vector<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*>& node_edges,
00080             std::ostream& os)
00081         {
00082             os << "digraph G {" << std::endl;
00083             os << "    rankdir=LR" << std::endl << std::endl;
00084             
00085             typename std::vector<CC_TreeNodeEdge_FA<T_IOSymbol, T_Register, T_Tag, N_k>*>::const_iterator ne_it = node_edges.begin();
00086             
00087             for (; ne_it != node_edges.end(); ++ne_it)
00088             {
00089                 os << "    n_" << (*ne_it)->get_id() << " [shape=" << ((*ne_it)->get_id() == 0 ? "box" : "ellipse") << ", label=\"";
00090                 os << (*ne_it)->get_id() << " " << (*ne_it)->get_path_metric() << "\"";
00091                 
00092                 if ((*ne_it)->is_on_final_path())
00093                 {
00094                     os << " style=filled fillcolor=lightblue";
00095                 }
00096                 os  << "]" << std::endl;
00097             }
00098             
00099             ne_it = node_edges.begin();
00100 
00101             for (; ne_it != node_edges.end(); ++ne_it)
00102             {
00103                 os << "    n_" << (*ne_it)->get_incoming_node_edge()->get_id() << " -> n_" << (*ne_it)->get_id() << " [label=\"";
00104                 print_symbol((*ne_it)->get_in_symbol(), os);
00105                 os << " " << (*ne_it)->get_incoming_metric() << "\"]" << std::endl;
00106             }
00107 
00108             os << "}" << std::endl;
00109         }
00110     
00111     };
00112     
00113  } // namespace ccsoft
00114  
00115  #endif // _CC_TREE_GRAPHVIZ_H__
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines