1 # ifndef GENERATE_GRAPH_H
2 # define GENERATE_GRAPH_H
5 # include <tpl_dynArray.H>
6 # include <tpl_sort_utils.H>
7 # include <tpl_graph.H>
10 using namespace Aleph;
15 template <
class GT,
class SA>
inline static
16 bool is_there_a_double_arc(GT * g,
17 typename GT::Node * src,
18 typename GT::Node * tgt)
20 if (not g->is_digraph())
23 return search_arc<GT,SA>(*g, src, tgt) != NULL and
24 search_arc<GT,SA>(*g, tgt, src) != NULL;
30 typename GT::Node * p)
74 class Shade_Node,
class Shade_Arc,
class SA>
78 std::ostream & output)
82 typename GT::Node_Iterator it(g);
83 for (
int i = 0; it.has_current(); it.next(), ++i)
85 typename GT::Node * p = it.get_current_node();
89 if (Shade_Node() (p).size() != 0)
90 output << Shade_Node() (p) <<
" " << i << endl;
94 if (text_node.size() == 0)
97 output <<
"NODE-TEXT " << i <<
" \"" << text_node <<
"\" 0 0" << endl;
102 typename GT::Arc * a = it.get_current_arc();
104 typename GT::Node * src = g.get_src_node(a);
105 typename GT::Node * tgt = g.get_tgt_node(a);
107 const int src_idx = search_node <GT> (nodes, src);
108 const int tgt_idx = search_node <GT> (nodes, tgt);
110 if (is_there_a_double_arc <GT, SA> (&g, src, tgt))
111 output <<
"CURVE-ARC " << src_idx <<
" " << tgt_idx <<
" "
112 << xdist/5 <<
" L" << endl;
114 output <<
"ARC " << src_idx <<
" " << tgt_idx << endl;
116 if ( Shade_Arc()(a).size() != 0)
117 output << Shade_Arc()(a) <<
" "
118 << src_idx <<
" " << tgt_idx <<
" " << endl;
120 const string text_arc = Write_Arc() (a);
122 if (text_arc.size() == 0)
125 output <<
"ARC-TEXT " << src_idx <<
" " << tgt_idx <<
" \""
126 << text_arc <<
"\" 0 0 " << endl;
177 const string & rankdir =
"TB",
181 output <<
"// Generated by generate_graphviz() from Aleph library. See at:" << endl
182 <<
"// http://webdelprofesor.ula.ve/ingenieria/lrleon/aleph/html/index.html" << endl
183 <<
"// for documentation" << endl
184 <<
"// Copyleft Leandro Leon lrleon@ula.ve" << endl
185 <<
"// for using of graphviz system. See at http://graphviz.org/"
191 output <<
"digraph {" << endl;
196 output <<
"graph {" << endl;
199 <<
"rankdir = " << rankdir << endl
200 <<
"style = none" << endl
201 <<
"truecolor=false" << endl
202 <<
"ranksep = " << ranksep << endl
203 <<
"nodesep = " << nodesep << endl << endl;
208 for (
int i = 0; it.has_current(); it.
next(), ++i)
210 output << i <<
" [ ";
212 typename GT::Node * p = it.get_current_node();
215 if (Shade_Node () (p))
216 output <<
"style = bold ";
220 if (text_node.size() != 0)
221 output <<
"label = \"" << text_node <<
"\"";
222 output <<
"]" << endl;
229 typename GT::Arc * a = it.get_current_arc();
231 typename GT::Node * src = g.get_src_node(a);
232 typename GT::Node * tgt = g.get_tgt_node(a);
234 int src_idx = search_node <GT> (nodes, src);
235 int tgt_idx = search_node <GT> (nodes, tgt);
237 output << src_idx << arc_str << tgt_idx <<
" [";
239 if (Shade_Arc () (a))
240 output <<
"style = bold ";
242 const string text_arc = Write_Arc() (a);
244 if (text_arc.size() != 0)
245 output <<
"label = \"" << text_arc <<
"\"";
246 output <<
"]" << endl;
249 output <<
"}" << endl;
288 Node_Attr node_attr = Node_Attr(),
289 Arc_Attr arc_attr = Arc_Attr(),
290 const string & rankdir =
"TB")
292 out <<
"// Generated by generate_graphviz() from Aleph library" << endl
294 <<
"// http://webdelprofesor.ula.ve/ingenieria/lrleon/aleph/html/index.html" << endl
295 <<
"// for documentation of Aleph library" << endl
296 <<
"// Copyleft Leandro Leon lrleon@ula.ve" << endl
297 <<
"// for using of graphviz system. See at http://graphviz.org/"
299 << (g.is_digraph() ?
"digraph {" :
"graph {") << endl
301 <<
"rankdir = " << rankdir << endl
303 <<
"// Node list" << endl
309 for (
int i = 0; it.has_current(); it.
next(), ++i)
311 typename GT::Node * p = it.get_current_node();
313 nodes_table.insert(p, i);
317 node_attr (g, p, out);
324 <<
"// Arc list" << endl
327 const string arrow = g.is_digraph() ?
"->" :
"--";
331 typename GT::Arc * a = it.get_current_arc();
333 typename GT::Node * src = g.get_src_node(a);
334 typename GT::Node * tgt = g.get_tgt_node(a);
336 const int src_idx = nodes_table.find(src);
337 const int tgt_idx = nodes_table.find(tgt);
339 out << src_idx << arrow << tgt_idx <<
" [";
340 arc_attr (g, a, out) ;
350 void operator () (GT&,
typename GT::Node * p, std::ostream & out)
352 out <<
"label = \"" << p->get_info() <<
" \"";
359 void operator () (GT&,
typename GT::Arc * a, std::ostream & out)
361 out <<
"label = \"" << a->get_info() <<
" \"";
432 void operator () (GT & g, std::ostream & out,
433 const Node_Attr & node_attr = Node_Attr(),
434 const Arc_Attr & arc_attr = Arc_Attr(),
435 const string & rankdir =
"TB")
437 generate_graphviz <GT, Node_Attr, Arc_Attr, SN, SA>
438 (g, out, node_attr, arc_attr, rankdir);
447 bool operator () (
typename GT::Node *)
const {
return false; }
449 bool operator () (
typename GT::Arc *)
const {
return false; }
506 void operator () (GT & g, std::ostream & out,
507 const string & rankdir =
"TB",
508 float ranksep = 0.4,
float nodesep = 0.4)
511 Shade_Arc, Dashed_Node, Dashed_Arc, SA, SN> (g, out, rankdir,
557 class Shade_Node,
class Shade_Arc,
class SA>
559 const size_t & nodes_by_level,
560 const double & xdist,
561 const double & ydist,
565 out <<
"cross-net-digraph ";
567 out <<
"cross-net-graph ";
569 out << g.get_num_nodes() <<
" " << nodes_by_level <<
" "
570 << xdist <<
" " << ydist << endl
573 generate_graphpic<GT, Write_Node, Write_Arc, Shade_Node, Shade_Arc, SA>
574 (g, xdist, ydist, out);
579 class Shade_Node,
class Shade_Arc>
581 const size_t & nodes_by_level,
582 const double & xdist,
583 const double & ydist,
587 generate_cross_graph<GT, Write_Node, Write_Arc, Shade_Node, Shade_Arc, DSA>
588 (g, nodes_by_level, xdist, ydist, out);
630 class Shade_Node,
class Shade_Arc,
class SA>
632 const size_t & nodes_by_level,
633 const double & xdist,
634 const double & ydist,
638 out <<
"net-digraph ";
642 out << g.get_num_nodes() <<
" " << nodes_by_level <<
" "
643 << xdist <<
" " << ydist << endl
646 generate_graphpic<GT, Write_Node, Write_Arc, Shade_Node, Shade_Arc, SA>
647 (g, xdist, ydist, out);
652 class Shade_Node,
class Shade_Arc>
654 const size_t & nodes_by_level,
655 const double & xdist,
656 const double & ydist,
660 generate_net_graph<GT, Write_Node, Write_Arc, Shade_Node, Shade_Arc, DSA>
661 (g, nodes_by_level, xdist, ydist, out);
667 string operator () (
typename GT::Node *)
const
676 string operator () (
typename GT::Arc *)
const
683 template <
class GT,
class Write_Node,
class Write_Arc,
class SA>
685 const size_t & nodes_by_level,
686 const double & xdist,
687 const double & ydist,
692 (g, nodes_by_level, xdist, ydist, out);
695 template <
class GT,
class Write_Node,
class Write_Arc,
class SA>
697 const size_t & nodes_by_level,
698 const double & xdist,
699 const double & ydist,
704 (g, nodes_by_level, xdist, ydist, out);
708 template <
class GT,
class Write_Node,
class Write_Arc>
710 const size_t & nodes_by_level,
711 const double & xdist,
712 const double & ydist,
718 (g, nodes_by_level, xdist, ydist, out);
721 template <
class GT,
class Write_Node,
class Write_Arc>
723 const size_t & nodes_by_level,
724 const double & xdist,
725 const double & ydist,
731 (g, nodes_by_level, xdist, ydist, out);
738 # endif // GENERATE_GRAPH_H
Definition: generate_graph.H:445
int sequential_search(T *a, const T &x, const int l, const int r, Equal &eq)
Definition: tpl_sort_utils.H:260
void generate_graphpic(GT &g, const double &xdist, const double &, std::ostream &output)
Definition: generate_graph.H:75
size_t size() const
Retorna dimensión actual (más lejano índice escrito)
Definition: tpl_dynArray.H:523
Definition: tpl_graph.H:751
Definition: generate_graph.H:348
Definition: generate_graph.H:492
Definition: generate_graph.H:665
Definition: generate_df_tree.H:41
Definition: tpl_graph.H:794
void generate_graphviz(GT &g, std::ostream &out, Node_Attr node_attr=Node_Attr(), Arc_Attr arc_attr=Arc_Attr(), const string &rankdir="TB")
Definition: generate_graph.H:287
Definition: tpl_graph.H:634
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
Definition: tpl_dynMapTree.H:289
void generate_net_graph(GT &g, const size_t &nodes_by_level, const double &xdist, const double &ydist, std::ostream &out)
Definition: generate_graph.H:631
Definition: tpl_graph.H:814
Definition: generate_graph.H:674
void generate_cross_graph(GT &g, const size_t &nodes_by_level, const double &xdist, const double &ydist, std::ostream &out)
Definition: generate_graph.H:558
Definition: generate_graph.H:357
Definition: generate_graph.H:418