93using Info_Nodo = std::pair<std::string, DynDlist<std::string>>;
115inline void split(
const std::string & text,
116 const std::string & separators,
119 const size_t n = text.length();
120 size_t start = text.find_first_not_of(separators);
124 size_t stop = text.find_first_of(separators, start);
127 words.
append(text.substr(start, stop - start));
128 start = text.find_first_not_of(separators, stop + 1);
144 return o1.first == o2.first;
165 for (
auto it = g.get_node_it(); it.has_curr(); it.next_ne())
167 auto *n = it.get_curr();
168 if (n->get_info().first == s)
173 return g.insert_node(
Info_Nodo(s, empty_fields));
202 std::istream & nodes_input,
203 std::istream & arcs_input)
208 std::getline(nodes_input, line);
210 while (std::getline(nodes_input, line))
213 split(line,
"|", fields);
216 g.insert_node(
Info_Nodo(fields[0], fields));
219 while (std::getline(arcs_input, line))
222 split(line,
" ,", nums);
289 output << info.first <<
" [color=";
291 const std::string & plazo = fields[1];
294 else if (plazo ==
"mp")
296 else if (plazo ==
"lp")
299 output <<
" label=\"" << info.first;
302 output <<
"\\n" << fields[6];
305 output <<
"\\nP=" << fields[5];
308 output <<
"\\n" << fields[4] <<
"%";
314 const std::string & clase = fields[2];
316 output <<
" shape = box ";
317 else if (clase ==
"ef")
318 output <<
" shape = ellipse ";
319 else if (clase ==
"pp")
320 output <<
" shape = hexagon ";
330 output <<
"// WARNING: Cycle detected in ";
333 Info_Nodo & info = it.get_current_node_ne()->get_info();
334 output <<
"(" << info.first <<
")" << info.second[6];
335 if (not it.is_in_last())
346 for (
auto it =
ranks.
get_it(); it.has_curr(); it.next_ne())
349 output <<
"{ rank = same; \n";
350 for (
auto ni = level.
get_it(); ni.has_curr(); ni.next_ne())
351 output << ni.get_curr()->get_info().first <<
" ";
359 output << g.get_src_node(a)->get_info().first <<
" -> "
360 << g.get_tgt_node(a)->get_info().first <<
"\n";
Tarjan's algorithm for strongly connected components.
Determines if a digraph contains a cycle and constructs it.
auto has_curr() const noexcept(noexcept(std::declval< I & >().has_curr())) -> decltype(std::declval< I & >().has_curr())
true if there is a current item.
Generic directed graph (digraph) wrapper template.
typename BaseGraph::Arc Arc
typename BaseGraph::Node Node
Dynamic doubly linked list with O(1) size and bidirectional access.
const size_t & size() const noexcept
Return the number of elements (constant time)
T & append(const T &item)
Append a copied item at the end of the list.
Doubly-linked list (defined in tpl_dynList.H).
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Filtered iterator on the nodes of a graph.
Iterator on nodes and arcs of a path.
Computes topological ordering using breadth-first search (Kahn's algorithm).
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
bool with_power
Configuration options for DOT file generation.
bool with_class
If true, set node shapes based on class field.
Digrafo::Node * search_node(Digrafo &g, const std::string &s)
Find or create a node by ID.
bool vertical
If true, use vertical layout (default).
void load_digraph(Digrafo &g, std::istream &nodes_input, std::istream &arcs_input)
Load nodes and arcs from streams into the directed graph.
bool only_num
If true, show only the node number, not the full label.
size_t font_size
Font size for the DOT output.
void generate_dot_file(Digrafo &g, std::ostream &output)
Generate a DOT representation of the digraph.
bool with_nes
If true, include NES percentage in node labels.
Main namespace for Aleph-w library functions.
static int search_node(DynArray< typename GT::Node * > &nodes, typename GT::Node *p) noexcept
constexpr size_t MIN_NODE_FIELDS
Minimum expected columns for a node record.
Array< size_t > ranks(const Array< T > &array)
Computes the rank of each element in an Array.
std::pair< std::string, DynDlist< std::string > > Info_Nodo
Node payload: (id, fields) where fields come from the input row.
std::vector< std::string > & split(const std::string &s, const char delim, std::vector< std::string > &elems)
Split a std::string by a single delimiter character.
Filtered iterator on all the arcs of a graph.
Functor to compare nodes by their ID.
bool operator()(const Info_Nodo &o1, const Info_Nodo &o2) const
Compare two node info objects by ID.
Arc of graph implemented with double-linked adjacency lists.
Node belonging to a graph implemented with a double linked adjacency list.
Topological sorting algorithms for directed acyclic graphs (DAGs).
Generic graph and digraph implementations.