Macros | |
#define | NODE_BITS(p) ((p)->attrs.control_bits) |
#define | NODE_COUNTER(p) ((p)->attrs.counter) |
#define | NODE_COLOR(p) ((p)->attrs.counter) |
#define | IS_NODE_VISITED(p, bit) (NODE_BITS(p).get_bit(bit)) |
#define | NODE_COOKIE(p) ((p)->attrs.cookie) |
#define | ARC_COUNTER(p) ((p)->attrs.counter) |
#define | ARC_COLOR(p) ((p)->attrs.counter) |
#define | ARC_BITS(p) ((p)->attrs.control_bits) |
#define | IS_ARC_VISITED(p, bit) (ARC_BITS(p).get_bit(bit)) |
#define | ARC_COOKIE(p) ((p)->attrs.cookie) |
Typedefs | |
template<class GT > | |
using | Aleph::ArcPair = tuple< typename GT::Arc *, typename GT::Node * > |
template<class GT > | |
using | Aleph::__Out_Iterator = typename GT::Out_Iterator |
template<class GT > | |
using | Aleph::__In_Iterator = typename GT::In_Iterator |
Enumerations | |
enum | Aleph::Graph_Bits { Depth_First, Breadth_First, Test_Cycle, Find_Path, Euler, Maximum_Flow, Spanning_Tree, Build_Subtree, Convert_Tree, Cut, Min, Num_Bits_Graph } |
Functions | |
template<class GT , class Write_Node , class Write_Arc , class Shade_Node , class Shade_Arc , class SA > | |
void | Aleph::generate_graphpic (const GT &g, const double &xdist, const double &, std::ostream &output) |
template<class GT , class Write_Node , class Write_Arc , class Shade_Node , class Shade_Arc , class Dashed_Node , class Dashed_Arc , class SA , class SN > | |
void | Aleph::generate_graphviz (const GT &g, std::ostream &output, const string &rankdir="TB", float ranksep=0.2, float nodesep=0.2) |
template<class GT , class Node_Attr , class Arc_Attr , class SN , class SA > | |
void | Aleph::generate_graphviz (const GT &g, std::ostream &out, Node_Attr node_attr=Node_Attr(), Arc_Attr arc_attr=Arc_Attr(), const string &rankdir="TB") |
template<class GT , class Node_Attr , class Arc_Attr , class SN , class SA > | |
void | Aleph::digraph_graphviz (const GT &g, std::ostream &out, Node_Attr node_attr=Node_Attr(), Arc_Attr arc_attr=Arc_Attr(), const string &rankdir="LR") |
template<class GT , class Node_Attr , class Arc_Attr , class SN , class SA > | |
size_t | Aleph::rank_graphviz (const GT &g, std::ostream &out, Node_Attr node_attr=Node_Attr(), Arc_Attr arc_attr=Arc_Attr(), const string &rankdir="LR") |
template<class GT , class Write_Node , class Write_Arc , class Shade_Node , class Shade_Arc , class SA > | |
void | Aleph::generate_cross_graph (GT &g, const size_t &nodes_by_level, const double &xdist, const double &ydist, std::ostream &out) |
template<class GT , class Write_Node , class Write_Arc , class Shade_Node , class Shade_Arc , class SA > | |
void | Aleph::generate_net_graph (GT &g, const size_t &nodes_by_level, const double &xdist, const double &ydist, std::ostream &out) |
template<class GT , typename Key , class Convert , class SA = Dft_Show_Arc<GT>> | |
Tree_Node< Key > * | Aleph::graph_to_tree_node (GT &g, typename GT::Node *groot) |
template<class GT > | |
void | Aleph::kosaraju_connected_components (const GT &g, DynList< GT > &blk_list, DynList< typename GT::Arc *> &arc_list) |
template<class GT > | |
DynList< DynList< typename GT::Node * > > | Aleph::kosaraju_connected_components (const GT &g) |
template<class Mat > | |
void | find_min_path (Mat &p, typename Mat::Node *src_node, typename Mat::Node *tgt_node, Path< typename Mat::Graph_Type > &path) |
template<class Mat > | |
void | find_min_path (Mat &p, const long &src_index, const long &tgt_index, Path< typename Mat::Graph_Type > &path) |
GT | Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::sufficient_hamiltonian (const size_t &__num_nodes, const double &p=0.5) |
GT | Aleph::Random_Graph< GT, Init_Node, Init_Arc >::sufficient_hamiltonian (const size_t &__num_nodes, const double &p=0.5) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
void | Aleph::compute_bipartite (const GT &g, DynDlist< typename GT::Node *> &l, DynDlist< typename GT::Node *> &r) |
template<class GT , template< class > class Max_Flow = Ford_Fulkerson_Maximum_Flow, class SA = Dft_Show_Arc<GT>> | |
void | Aleph::compute_maximum_cardinality_bipartite_matching (const GT &g, DynDlist< typename GT::Arc *> &matching) |
template<class GT , class SN = Dft_Show_Node<GT>> | |
void | Aleph::for_each_node (const GT &g, std::function< void(typename GT::Node *)> operation, SN sn=SN()) noexcept(noexcept(operation) and noexcept(sn)) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
void | Aleph::for_each_arc (const GT &g, std::function< void(typename GT::Arc *)> operation, SA sa=SA()) noexcept(noexcept(operation) and noexcept(sa)) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
void | Aleph::for_each_arc (const GT &, typename GT::Node *p, std::function< void(typename GT::Arc *)> operation, SA sa=SA()) noexcept(noexcept(operation) and noexcept(sa)) |
template<class GT , class SN = Dft_Show_Node<GT>> | |
bool | Aleph::forall_node (const GT &g, std::function< bool(typename GT::Node *)> cond, SN sn=SN()) noexcept(noexcept(cond) and noexcept(sn)) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
bool | Aleph::forall_arc (const GT &g, std::function< bool(typename GT::Arc *)> cond, SA sa=SA()) noexcept(noexcept(cond) and noexcept(sa)) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
bool | Aleph::forall_arc (typename GT::Node *p, std::function< bool(typename GT::Arc *)> cond, SA sa=SA()) noexcept(noexcept(cond) and noexcept(sa)) |
template<class GT , typename T , template< typename > class Container = DynList, class SN = Dft_Show_Node<GT>> | |
Container< T > | Aleph::nodes_map (GT &g, std::function< T(typename GT::Node *)> transformation, SN sn=SN()) |
template<class GT , typename T , template< typename > class Container = DynList, class SA = Dft_Show_Arc<GT>> | |
Container< T > | Aleph::arcs_map (GT &g, std::function< T(typename GT::Arc *)> transformation, SA sa=SA()) |
template<class GT , typename T , template< typename > class Container = DynList, class SA = Dft_Show_Arc<GT>> | |
Container< T > | Aleph::arcs_map (GT &g, typename GT::Node *p, std::function< T(typename GT::Arc *)> transformation, SA sa=SA()) |
template<class GT , typename T , class SN = Dft_Show_Node<GT>> | |
T | Aleph::foldl_nodes (GT &g, const T &init, std::function< T(const T &, typename GT::Node *)> operation, SN sn=SN()) noexcept(noexcept(operation) and noexcept(sn) and std::is_nothrow_copy_assignable< T >::value) |
template<class GT , typename T , class SA = Dft_Show_Arc<GT>> | |
T | Aleph::foldl_arcs (GT &g, const T &init, std::function< T(const T &, typename GT::Arc *)> operation, SA sa=SA()) noexcept(noexcept(operation) and noexcept(sa) and std::is_nothrow_copy_assignable< T >::value) |
template<class GT , typename T , class SA = Dft_Show_Arc<GT>> | |
T | Aleph::foldl_arcs (GT &g, typename GT::Node *p, const T &init, std::function< T(const T &, typename GT::Arc *)> operation, SA sa=SA()) noexcept(noexcept(operation) and noexcept(sa) and std::is_nothrow_copy_assignable< T >::value) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
DynList< typename GT::Node * > | Aleph::out_nodes (typename GT::Node *p, SA sa=SA()) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
DynList< typename GT::Node * > | Aleph::in_nodes (typename GT::Node *p, SA sa=SA()) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
DynList< typename GT::Arc * > | Aleph::out_arcs (typename GT::Node *p, SA sa=SA()) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
DynList< typename GT::Arc * > | Aleph::in_arcs (typename GT::Node *p, SA sa=SA()) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
DynList< typename GT::Arc * > | Aleph::arcs (typename GT::Node *p, SA sa=SA()) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
DynList< ArcPair< GT > > | Aleph::in_pairs (typename GT::Node *p, SA sa=SA()) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
DynList< ArcPair< GT > > | Aleph::out_pairs (typename GT::Node *p, SA sa=SA()) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
size_t | Aleph::in_degree (typename GT::Node *p, SA sa=SA()) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
size_t | Aleph::out_degree (typename GT::Node *p, SA sa=SA()) |
template<class GT , class Itor , class Operation > | |
bool | Aleph::traverse_arcs (typename GT::Node *p, Operation op=Operation()) noexcept(noexcept(op)) |
template<class GT , class Itor , class Operation > | |
void | Aleph::for_each_arc (typename GT::Node *p, Operation op=Operation()) noexcept(noexcept(op)) |
template<class GT , class Op > | |
bool | Aleph::traverse_in_arcs (typename GT::Node *p, Op op=Op()) noexcept(noexcept(op)) |
template<class GT , class Op > | |
void | Aleph::for_each_in_arc (typename GT::Node *p, Op op=Op()) noexcept(noexcept(op)) |
template<class GT , class Op > | |
bool | Aleph::traverse_out_arcs (typename GT::Node *p, Op op=Op()) noexcept(noexcept(op)) |
template<class GT , class Op > | |
void | Aleph::for_each_out_arc (typename GT::Node *p, Op op=Op()) noexcept(noexcept(op)) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
GT::Arc * | Aleph::search_arc (const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
GT::Arc * | Aleph::search_directed_arc (const GT &, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept |
template<class GT > | |
GT::Node * | Aleph::mapped_node (typename GT::Node *p) noexcept |
template<class GT > | |
void | Aleph::copy_graph (GT >gt, const GT &gsrc, const bool cookie_map=false) |
template<class GT > | |
void | Aleph::clear_graph (GT &g) noexcept |
template<class GT > | |
Path< GT > | Aleph::find_path_depth_first (const GT &g, typename GT::Node *start_node, typename GT::Node *end_node) |
template<class GTS , class GTT > | |
void | Aleph::map_nodes (typename GTS::Node *p, typename GTT::Node *q) noexcept |
template<class GTS , class GTT > | |
void | Aleph::map_arcs (typename GTS::Arc *p, typename GTT::Arc *q) noexcept |
template<class GTT , class GTS , class Copy_Node = Dft_Copy_Node<GTT, GTS>, class Copy_Arc = Dft_Copy_Arc<GTT, GTS>> | |
void | Aleph::inter_copy_graph (GTT >gt, const GTS &gsrc, const bool cookie_map=false) |
template<class GT > | |
size_t | Aleph::depth_first_traversal (const GT &g, typename GT::Node *start_node, bool(*visit)(const GT &g, typename GT::Node *, typename GT::Arc *)) |
template<class GT > | |
size_t | Aleph::breadth_first_traversal (const GT &g, typename GT::Node *start, bool(*visit)(const GT &, typename GT::Node *, typename GT::Arc *)) |
template<class GT > | |
Path< GT > | Aleph::find_path_breadth_first (const GT &g, typename GT::Node *start, typename GT::Node *end) |
template<class GT > | |
bool | Aleph::test_connectivity (const GT &g) |
template<class GT > | |
bool | Aleph::test_for_cycle (const GT &g, typename GT::Node *src) |
template<class GT > | |
bool | Aleph::test_for_path (const GT &g, typename GT::Node *start_node, typename GT::Node *end_node) |
template<class GT > | |
DynList< GT > | Aleph::inconnected_components (const GT &g) |
template<class GT > | |
void | Aleph::build_subgraph (const GT &g, GT &sg, typename GT::Node *g_src, size_t &node_count) |
template<class GT > | |
GT | Aleph::find_depth_first_spanning_tree (const GT &g, typename GT::Node *gnode) |
template<class GT > | |
GT | Aleph::find_breadth_first_spanning_tree (GT &g, typename GT::Node *gp) |
template<class GT > | |
GT | Aleph::build_spanning_tree (const DynArray< typename GT::Arc *> &arcs) |
template<class GT > | |
DynList< typename GT::Node * > | Aleph::compute_cut_nodes (const GT &g, typename GT::Node *start) |
template<class GT > | |
long | Aleph::paint_subgraphs (const GT &g, const DynList< typename GT::Node *> &cut_node_list) |
template<class GT > | |
GT | Aleph::map_subgraph (const GT &g, const long color) |
template<class GT > | |
std::tuple< GT, DynList< typename GT::Arc * > > | Aleph::map_cut_graph (const GT &g, const DynList< typename GT::Node *> &cut_node_list) |
template<class GT > | |
GT | Aleph::invert_digraph (const GT &g) |
template<class GT , template< class > class Max_Flow = Random_Preflow_Maximum_Flow, class SA = Dft_Show_Arc<GT>> | |
long | Aleph::edge_connectivity (GT &g) |
template<class GT , template< class > class Max_Flow = Heap_Preflow_Maximum_Flow, class SA = Dft_Show_Arc<GT>> | |
long | Aleph::compute_min_cut (GT &g, Aleph::set< typename GT::Node *> &l, Aleph::set< typename GT::Node *> &r, DynDlist< typename GT::Arc *> &cut) |
template<class GT , template< class > class Max_Flow = Random_Preflow_Maximum_Flow, class SA = Dft_Show_Arc<GT>> | |
long | Aleph::vertex_connectivity (GT &g) |
template<class GT , class SA = Dft_Show_Arc<GT>> | |
void | Aleph::warshall_compute_transitive_clausure (GT &g, Bit_Mat_Graph< GT, SA > &mat) |
template<class Mat > | |
void | Aleph::find_min_path (Mat &p, const long &src_index, const long &tgt_index, Path< typename Mat::Graph_Type > &path) |
Variables | |
const unsigned char | Aleph::Processed |
const unsigned char | Aleph::Processing |
const unsigned char | Aleph::Unprocessed |
Many combinatorial problems can be modeled and solved through Aleph-w
( ) graphs.
There are three types of graphs in Aleph-w
( ):
All the three classes export the same interface. What differentiates them is their performance qualities in speed and space comsuption.
Historically, the first Aleph-w
( ) graph class was List_Graph. This class is very versatile and dynamic in the sense that it allow very fast topological modifications on the graph. By "topological modification" we intend to say that nodes and/or arc are inserted and/or removed. The dynamic sense consists on the possibility that these operations are done very frequently in
. List_Graph in since the choice of fact for applications requering to build partial and/or many graph are very often. However, this speed pays its price in space consumption.
List_SGraph was designed in order to reduce the space consumption of List_Graph. This is managed by using single lists instead of double ones, what reduces aproximatively 4 pointers by node and arc. However, the remove_node()
method is slower , since it requires to traverse all the arcs ir order to remove the arcs pointed to the removed node. So, this class could be very time expensive for application that dinamically remove nodes. Although this class is fully functional and (we hope) correct, we are considering remove it or simply not support it longer in next library releases.
Finally, the class Array_Graph models graphs whose internal representation uses dinamic arrays in order to save the adjacency lists. According our experience, we find this class as a very good trade off between performance and space consumption. The remove_node()
operation is still , but the remaining topological operations are
and definitively this class occupies much less space than the list versions. We recommend to use this class unless that you require to remove nodes many times. There are a few of applications where you perform calculation by removing nodes from a graph. For this type of case, consider to use another graph.
In order to specify a graph and to do computations on it, the first thing that you must do is to define the types of data to store in the nodes and the arcs. Often the nodes and arcs are associated with many data. By example, a graph of cities could map the cities with the nodes and the distances and other sort of costs with the arcs. For each city (node) one could associate coordinates, the name, its population, etc. Now, in order to save space, it is very important that you only associate to the node the required data needed for the graph computations. Remember, the more fat is the data to associate to a node or arc, the more space the graph will use. So, use ids to the data, not all the data. In those case where the data resides in memory associate pointers to it. Of course, this remarks apply specially to the large scale graphs. If your graph is small, then perhaps you must not worry too much.
Once you already have defined data types that you will store in the nodes and arcs, then you must declare the node and arc that you will use.
The graphs interface requires the following specificaction convention:
It is strongly recommended to do these phased by using aliases, typedef
or using
, to the node, arc and graph types.
Before to declare a Aleph-w
( ) graph, you must imperatively you must have declared the node. The node types are:
If you want to use Point
as type of nodes, then you could declare:
using My_Node = Graph_Node<Point>;
Here you have expressed that the nodes of your graph contain data of type Point
and that you will use List_Graph
as graph type (the Aleph-w
( ) graph whose representation is with doubly linked lists.
For the arcs you must also declare its type. There are three types of arcs according to the graph type:
By example, following the previous example, if the weights are euclidian distances between the points, ten you could declare an arc as follows:
using My_Arc = Grap_Arc<double>;
Once you have defined the node and the arc of your graph, you are ready for declare the graph. For the previous example, that would be as follows:
using Euclidian_Graph = Graph_List<My_Node. My_Arc>;
Now, you can instantiate graphs by using the alias Euclidian_Graph
, some as:
Euclidian_Graph g;
Although you have already defined your node and arc with aliases, the interface exports two internal aliases that could be considered as subclasses:
Euclidian_Graph::Node
, andEuclidian_Graph::Arc
You will need to know the types of nodes and arc in order to perform many operations on the graph. In our experience, it is more readable to use the these aliases instead of those that you declared when you was specifiying the graph. The following code snippet traverses all the arcs of a Euclidian_Graph
graph:
Euclidian_Graph g some operations; by example insert nodes and arcs ... for (auto it = g.get_arc_it(); it.has_curr(); it.next()) { Euclidian_Graph::Arc * arc = it.get_curr(); do something with the arc }
The graph classes export several iterators: Node_Iterator
, Arc_Iterator
, Node_Arc_Iterator
, Out_Iterator
and In_Iterator
. These iterator are exported as subclasses of the graph class. Suppose, for example, that you are using a class Map based on Array_Graph
class (but it could have perfectly been base on any other graph class) and the graph is named g
. Then, you could iterate on all the arcs through some such as:
for (auto it = g.get_arc_it(); it.has_cur(); it.next()) auto arc = it.get_curr(); // each arc of the graph is seen
Now, there are several, perhaps many, situations where not all the arcs must be proceses, but a subset of them satisfaying a particular condition. In these cases, the filtered iteratos come for us.
As seen in the class Filter_Iterator
, a filtered iterator is almost exactly the same thing than a normal iterator. The subtle difference is that on it operates a filter condition that filters all the items satisfaying a special condition. Let's show a brief but constructive example.
Suppose that your graph represents pathways of automotive transportation. Node are the cities and arcs are the pathways. Now suppose that your pathways are classified in Highway
, Road
and Trail
. Now suppose that you wish to solve a problem that only envolves highways; for example, you want to find the shortest path between two cities connected by only highways. Then you could specify an filter that catches highways:
struct Only_Highway { bool operator () (GT::Arc * a) { return a->get_info().type == Highway; } };
Now, if your shortest path algorithm receives this filter, this will only see highways and its results will only contain highways.
For each subclass iterator on a graph, it is exported a filtered iterator with the same name of subclassed one. Thus, for the subclass GT::Arc_Iterator
exists a filtered version named Arc_Iterator
and so on for the remainder iterator subclasses on the graphs.
The filtered iterators have a great importance in Aleph-w
( ) algorithms on graphs, since almost every algorithm operates with filtered iterator.
The short answer is: almost always!
Filtered iterators have of course a light but constant impact on performance. For each seen graph object a boolean predicate is tested. So, if you know that your algorithm does not require to filter, the use the subclass iterator. But if, in pursuit of generalization your algorithm could profit the filtered version, then design your algorithm on filtered iterator. In this way you will provide generality, which allows to reuse algorithms in a transparent way.
A very good and concrete example of intensive use of filtered iterator is for solving the problem of maximizing a network flow at minimum cost. First, in order to manage the residual net, the arcs are filtered according to source node. Second, the residual cut arcs are also filtered according to flow value; if the flow is equal to the capacity then the arc is filtered. Third, in order to detect negative cycles the Bellman-Ford algorithm is used with a filter that only sees the arcs cost.
#define ARC_BITS | ( | p | ) | ((p)->attrs.control_bits) |
Return the control bits of arc p
#define ARC_COLOR | ( | p | ) | ((p)->attrs.counter) |
Return the color of arc p
#define ARC_COOKIE | ( | p | ) | ((p)->attrs.cookie) |
Return the arc cookie
#define ARC_COUNTER | ( | p | ) | ((p)->attrs.counter) |
Return the counter
of arc p
#define IS_ARC_VISITED | ( | p, | |
bit | |||
) | (ARC_BITS(p).get_bit(bit)) |
Determine whether the bit
field is or not set to one
p | pointer to arc |
bit | number of bit to be read |
bit
is 1; false otherwise (bit
is set to 0) #define IS_NODE_VISITED | ( | p, | |
bit | |||
) | (NODE_BITS(p).get_bit(bit)) |
Determine whether the control bit is set or not to one
p | pointer to the node |
bit | number of bit to read |
#define NODE_BITS | ( | p | ) | ((p)->attrs.control_bits) |
Get the control bits of a node.
#define NODE_COLOR | ( | p | ) | ((p)->attrs.counter) |
Synonymous of NODE_COUNTER
#define NODE_COOKIE | ( | p | ) | ((p)->attrs.cookie) |
Return the node cookie
#define NODE_COUNTER | ( | p | ) | ((p)->attrs.counter) |
Get the counter of a node.
using Aleph::__In_Iterator = typedef typename GT::In_Iterator |
Basic iterator for outcoming arcs of a node.
using Aleph::__Out_Iterator = typedef typename GT::Out_Iterator |
Basic iterator for outcoming arcs of a node.
using Aleph::ArcPair = typedef tuple<typename GT::Arc*, typename GT::Node*> |
Alias used for encapsulating a pair of arc and node (related between them).
enum Aleph::Graph_Bits |
Bit numbers of nodes or arcs.
Nodes y arcs of graph have as control attributes (internal representation of state), a set of bits. These are their numbers named according to their use by the library.
You can use then for purposes other than the suggested name. However, be careful.
DynList<typename GT::Arc*> Aleph::arcs | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Return all the filtered arcs related to p
[in] | p | node pointer |
[in] | sa | arc filter |
Container<T> Aleph::arcs_map | ( | GT & | g, |
std::function< T(typename GT::Arc *)> | transformation, | ||
SA | sa = SA() |
||
) |
Map the filtered arcs of a graph to a transformed type.
[in] | g | the grapg |
[in] | transformation | function Arc* –> T` |
[in] | sa | arc filter |
Container<T>
object with all the arcs mapped through the transformation Container<T> Aleph::arcs_map | ( | GT & | g, |
typename GT::Node * | p, | ||
std::function< T(typename GT::Arc *)> | transformation, | ||
SA | sa = SA() |
||
) |
Map the filtered nodes of node graph to a transformed type.
[in] | g | the graph |
[in] | p | node pointer |
[in] | transformation | function Node* –> T` |
[in] | sn | node filter |
Container<T>
object with all the nodes arcs mapped through the transformation
|
inline |
Generic breadth first traversal of a graph.
This traverses the graph g
form start_node
in breadth first order. On each node, a visit function is called, whose signature must match as follows:
bool visit(const GT & g, GT::Node * curr, GT::Arc * from)
g
is the graph, curr
is the currently visited node and from
is the arc from whom curr
was discovered. If visit
returns false
then the traversal continues; otherwise it stops.
The traversal uses the contro Breadth_First
[in] | g | the graph |
[in] | start_node | the starting node |
[in] | visit | function |
GT Aleph::build_spanning_tree | ( | const DynArray< typename GT::Arc *> & | arcs | ) |
Build a spanning tree tree whose arcs are stored in a dynamic array.
This function construct a spanning tree into a graph object given the arcs that comprises the tree.
Although this function is conceived for managing trees, it could eventually be used for graphs; for instance, the graph could contain cycles and this could happen even if the number of arcs is lesser than the number of nodes. Of course, it is not intended to use an array for storing a full graph.
[in] | arcs | dynamic array containing the arcs part of tree. |
arcs
array bad_alloc | if there is no enough memory |
|
inline |
Build a mapped subgraph of g
from a starting node.
build_subgraph(g, sg, g_src, node_count)
traverses in depth first order the graph g
from a starting node g_src
and builds in sg
a mapped copy of all nodes and arcs reachable from g_src
. So, it will discover all what is connected to g_src
.
node_count
accumulates the number of visited nodes.
The function uses the control bint Build_Subtree.
This function is more used as helper for inconnected_components()
.
[in] | g | the original graph |
[out] | sg | an initially empty graph where the mappeing will be put |
[in] | g_src | pointer to initial node where start the mapping |
[in,out] | node_count | counter of visited nodes |
bad_alloc | if there is no enough memory |
|
inlinenoexcept |
Clean a graph: all its nodes and arcs are removed and freed.
[in] | g | the graph |
void Aleph::compute_bipartite | ( | const GT & | g, |
DynDlist< typename GT::Node *> & | l, | ||
DynDlist< typename GT::Node *> & | r | ||
) |
Toma un grafo bipartido y calcula los conjuntos de partición.
Un grafo es bipartido si puede dividirse en dos subconjuntos l y r tal que todo nodo de l sólo tiene arcos hacia nodos de r y viceversa.
compute_bipartite(g,l,r) toma un grafo bipartido g y calcula los conjuntos de bipartición nombrados por los parámetros l y r, respectivamente.
[in] | g | el grafo bipartido. |
[out] | l | un conjunto partición. |
[out] | r | un conjunto partición. |
domain_error | si durante el cálculo se determina que el grafo no es bipartido. |
bad_alloc | si no hay suficiente memoria. |
DynList<typename GT::Node*> Aleph::compute_cut_nodes | ( | const GT & | g, |
typename GT::Node * | start | ||
) |
Compute the articulation (or cut) points of a graph.
The control bits Depth_First
and Cut
are used.
This function could combine it with paint_subgraphs()
in order to paint the different components separated by the cut points.
Mapped copies of components could be computed with map_subgraph()
and map_cut_graph()
on a grap peviously painted.
g
must be connected.
[in] | g | the graph |
[in] | start | a starting node by where to star the calculations |
bad_alloc | if there is no enough memory |
void Aleph::compute_maximum_cardinality_bipartite_matching | ( | const GT & | g, |
DynDlist< typename GT::Arc *> & | matching | ||
) |
Calcula el emparejamiento de cardinalidad máxima de un grafo bipartido.
compute_maximum_cardinality_bipartite_matching(g,matching) recibe un grafo bipartido g y calcula el máximo emparejamiento bipartido en la lista matching.
El procedimiento calcula los conjuntos de bipartición, luego construye una red capacitada unitaria equivalente y sobre ella invoca a un algoritmo de maximización de flujo.
La rutina maneja dos parámetros tipo:
[in] | g | el grafo bipartido. |
[out] | matching | lista de arcos componentes del emparejamiento. |
bad_alloc | si no hay suficiente memoria. |
long Aleph::compute_min_cut | ( | GT & | g, |
Aleph::set< typename GT::Node *> & | l, | ||
Aleph::set< typename GT::Node *> & | r, | ||
DynDlist< typename GT::Arc *> & | cut | ||
) |
Calcula el corte mÃnimo de un grafo.
compute_min_cut(g, l, r, cut) indaga la conectividad en arcos del grafo g y retorna los conjuntos de nodos y arcos que conforman el corte.
El algoritmo construye una red capacitada unitaria equivalente y mediante sucesivas maximizaciones de flujo indaga la conectividad en arcos.
La rutina recibe dos paráetros tipo:
[in] | g | el grafo sobre el cual se desea calcular el corte mÃnimo. |
[out] | l | un conjunto de nodos origen que involucra los arcos parte del corte. |
[out] | r | un conjunto de nodos destino que involucra los arcos parte del corte y que son destino de los nodos en l. |
[out] | cut | el conjunto de arcos parte del corte. |
bad_alloc | si no hay suficiente memoria. |
|
inline |
Explicit copy of graph.
This function takes a source graph gsrc
for copying to to another target graph gtgt
. First the function cleans gtgt
; that is all its arc and nodes are removed and freed. Then gsrc
is copyed to gtgt
- The resulting gtgt
is isomorphic to gsrc
.
Eventually, the copy can be mapped through the cookies. For that, a forth bool parameter is specifyed-
[in] | gsrc | source graph |
[in] | gtgt | target graph |
[in] | cookie_map | boolean indicating if the result must be mapped through the nodes and arcs cookies. |
bad_alloc | if there is no enough memory |
|
inline |
Generic depth first traversal of a graph.
This function recursively traverses the graph g
form start_node
. On each node, a visit function is called, whose signature must match as follows:
bool visit(const GT & g, GT::Node * curr, GT::Arc * from)
g
is the graph, curr
is the currently visited node and from
is the arc from whom curr
was discovered. If visit
returns false
then the traversal continues; otherwise it stops.
The traversal uses the contro Depth_First
[in] | g | the graph |
[in] | start_node | the starting node |
[in] | visit | function |
void Aleph::digraph_graphviz | ( | const GT & | g, |
std::ostream & | out, | ||
Node_Attr | node_attr = Node_Attr() , |
||
Arc_Attr | arc_attr = Arc_Attr() , |
||
const string & | rankdir = "LR" |
||
) |
Genera una especificación para el programa de dibujado de grafos graphpic de tipo grafo cruzado.
En un dibujo de grafo cruzado, se distribuyen nodes_by_level - 1 nodos los niveles pares y num_nodes_by_level en los impares.
generate_cross_graph(g,nodes_by_level,xdist,ydist,output) genera una entrada a graphpic de un grafo cruzado de nodes_by_level, separados horizontalmente por xdist y verticalmente por ydist. La salida se emite al archivo asociado a output.
Para tratar con los contenidos de los nodos y arcos y lo que se desee generar, se emplean los siguientes parámetros tipo:
[in] | g | grafo o digrafo del que se desea generar el dibujo. |
[out] | out | archivo hacia donde se emitirá la salida. |
[in] | rankdir | dirección del dibujado entre los valores "TB", "BT", "LR" y "RL" |
long Aleph::edge_connectivity | ( | GT & | g | ) |
Calcula la conectividad en arcos de un grafo.
edge_connectivity(g) calcula la conectividad en arcos de un grafo mediante maximizaciones sucesivas de flujo sobre una red alterna capacitada unitaria.
La rutina recibe dos paráetros tipo:
[in] | g | el grafo. |
bad_alloc | si no hay suficiente memoria. |
|
inline |
Compute a breadth first ordered spanning tree starting from a specific node.
The returned spanning tree is mapped through the nodes and arcs cookies to teh original graph.
The function uses the control bit Spanning_Tree.
g
is not connected then the spanning tree only will have the reachable nodes of the connected component where gnode
is.[in] | g | the graph abarcador en profundidad. |
[in] | gnode | source node in g from which to start the search |
g
bad_alloc | if there is no enough memory |
|
inline |
Compute a depth first ordered spanning tree starting from a specific node.
The returned spanning tree is mapped through the nodes and arcs cookies to teh original graph.
The function uses the control bit Spanning_Tree.
g
is not connected then the spanning tree only will have the reachable nodes of the connected component where gnode
is.[in] | g | the graph abarcador en profundidad. |
[in] | gnode | source node in g from which to start the search |
g
bad_alloc | if there is no enough memory |
void find_min_path | ( | Mat & | p, |
const long & | src_idx, | ||
const long & | tgt_idx, | ||
Path< typename Mat::Graph_Type > & | path | ||
) |
Construye un camino mÃnimo desde un nodo a otro a partir de una matriz de caminos calculada por el algoritmo de Floyd-Warshall.
Este procedimiento toma una matriz p que contiene los Ãndices de caminos mÃnimos calculados por el algoritmo de Floyd-Warshall, dos enteros i y j en la matriz correspondientes a los Ãndices del nodo origen y destino respectivamente, y calcula el camino mÃnimo en la representación con listas de adyacencia usada en el algoritmo de Floyd-Warshall.
Este procedimiento está concebido para llamarse después de ejecutar floyd_all_shortest_paths(), el cual calcula la matriz p.
Resultados son completamente indeterminados si la matriz p es inválida.
Una versión sobrecargada de este método toma como parámetros punteros a nodos, en lugar de Ãndices sobre la matriz.
[in] | p | matriz de Ãndices de caminos mÃnimos. |
[in] | src_idx | Ãndice del nodo origen dentro de la matriz de caminos mÃnimos. |
[in] | tgt_idx | Ãndice del nodo destino dentro de la matriz de caminos mÃnimos. |
[out] | path | el camino mÃnimo en el grafo representado con listas de adyacencia usado cuando se ejecutó floyd_all_shortest_paths(). |
bad_alloc | si no hay suficiente memoria para construir el camino. |
void find_min_path | ( | Mat & | p, |
typename Mat::Node * | src_node, | ||
typename Mat::Node * | tgt_node, | ||
Path< typename Mat::Graph_Type > & | path | ||
) |
Construye un camino mÃnimo desde un nodo a otro a partir de una matriz de caminos calculada por el algoritmo de Floyd-Warshall.
Este procedimiento toma una matriz p que contiene los Ãndices de caminos mÃnimos calculados por el algoritmo de Floyd-Warshall, dos punteros correspondientes a los nodos origen y destino respectivamente en la representación con listas de adyacencia usada cuando se invocó a floyd_all_shortest_paths(), y calcula el camino mÃnimo.
Este procedimiento está concebido para llamarse después de ejecutar floyd_all_shortest_paths(), el cual calcula la matriz p.
Resultados son completamente indeterminados si la matriz p es inválida.
[in] | p | matriz de Ãndices de caminos mÃnimos. |
[in] | src_node | puntero al nodo origen dentro de la representación con listas de adyacencia. |
[in] | tgt_node | puntero al nodo destino dentro de la representación con listas de adyacencia. |
[out] | path | el camino mÃnimo en el grafo representado con listas de adyacencia usado cuando se ejecutó floyd_all_shortest_paths(). |
bad_alloc | si no hay suficiente memoria para construir el camino. |
void find_min_path | ( | Mat & | p, |
const long & | src_idx, | ||
const long & | tgt_idx, | ||
Path< typename Mat::Graph_Type > & | path | ||
) |
Construye un camino mÃnimo desde un nodo a otro a partir de una matriz de caminos calculada por el algoritmo de Floyd-Warshall.
Este procedimiento toma una matriz p que contiene los Ãndices de caminos mÃnimos calculados por el algoritmo de Floyd-Warshall, dos enteros i y j en la matriz correspondientes a los Ãndices del nodo origen y destino respectivamente, y calcula el camino mÃnimo en la representación con listas de adyacencia usada en el algoritmo de Floyd-Warshall.
Este procedimiento está concebido para llamarse después de ejecutar floyd_all_shortest_paths(), el cual calcula la matriz p.
Resultados son completamente indeterminados si la matriz p es inválida.
Una versión sobrecargada de este método toma como parámetros punteros a nodos, en lugar de Ãndices sobre la matriz.
[in] | p | matriz de Ãndices de caminos mÃnimos. |
[in] | src_idx | Ãndice del nodo origen dentro de la matriz de caminos mÃnimos. |
[in] | tgt_idx | Ãndice del nodo destino dentro de la matriz de caminos mÃnimos. |
[out] | path | el camino mÃnimo en el grafo representado con listas de adyacencia usado cuando se ejecutó floyd_all_shortest_paths(). |
bad_alloc | si no hay suficiente memoria para construir el camino. |
|
inline |
Breadth first search of a path between two nodes.
find_path_breadth_first()
searches in breadth first order a path between start_node
y end_node
[in] | g | the graph |
[in] | start_node | pointer to starting node of search |
[in] | end_node | pointer to ending node of search |
Path
object containing the path if this was found; an empty path otherwise bad_alloc | if there is no enough memory |
|
inline |
Depth first search of a path between two nodes.
find_path_depth_first()
recursively searches a path between start_node
y end_node
[in] | g | the graph |
[in] | start_node | pointer to starting node of search |
[in] | end_node | pointer to ending node of search |
Path
object containing the path if this was found; an empty path otherwise bad_alloc | if there is no enough memory |
|
noexcept |
Fold the filtered arcs of a graph.
[in] | g | the graph |
[in] | init | initial value of folded result |
[in] | operation | folding operation on the arc |
[in] | sa | arc filter |
|
noexcept |
Fold the filtered adjacent arcs of a node.
[in] | g | the graph |
[in] | p | node pointer |
[in] | init | initial value of folded result |
[in] | operation | folding operation on the arc |
[in] | sa | arc filter |
|
noexcept |
Fold the filtered nodes of a graph.
[in] | g | the graph |
[in] | init | initial value of folded result |
[in] | operation | folding operation on the node |
[in] | sn | node filter |
|
noexcept |
Traverse all the arcs of graph filtering some ones according to a condition and executing an operation on them.
[in] | g | the graph |
[in] | operation | to be executed on each seen arc |
[in] | sa | an arc filter |
|
noexcept |
Traverse all the arcs adjacent to a node filtering some ones according to a condition and executing an operation on them.
[in] | g | the graph |
[in] | p | a node pointer |
[in] | operation | to be executed on each seen arc |
[in] | sa | an arc filter |
|
inlinenoexcept |
Execute an operation on each arc of a node.
This template function receives threes template parameters:
GT
: the graph type.Itor
: the iterator type; it is intended to be __In_Iterator
or __Out_Iterator
.Operation
: an operation to be executed on each arc. This operation must have the following signature: void operation(typename GT::Arc * arc)
[in] | p | node pointer |
[in] | operation | to be performed on each arc |
|
inlinenoexcept |
Traverse the incoming arcs of a node and executes an operation
[in] | p | node pointer |
[in] | op | operation to perform on each node |
|
noexcept |
Traverse all the nodes of graph filtering some ones according to a condition and executing an operation on them.
[in] | g | the graph |
[in] | operation | to be executed on each seen node |
[in] | sn | a node filter |
|
inlinenoexcept |
Traverse the outcoming arcs of a node and executes an operation
[in] | p | node pointer |
[in] | op | operation to perform on each node |
|
noexcept |
Return true
if condition cond
is met on every filtered arc of the graph.
[in] | g | the graph |
[in] | cond | condition |
[in] | sa | arc filter |
true
if all the arcs satisfy the condition; false
otherwise
|
noexcept |
Return true
if condition cond
is met on every filtered arc of a node.
[in] | p | node pointer |
[in] | cond | condition |
[in] | sa | arc filter |
true
if all the arcs satisfy the condition; false
otherwise
|
noexcept |
Return true
if condition cond
is met on every filtered node of the graph.
[in] | g | the graph |
[in] | cond | condition |
[in] | sn | node filter |
true
if all the nodes satisfy the conition; false
otherwise void Aleph::generate_cross_graph | ( | GT & | g, |
const size_t & | nodes_by_level, | ||
const double & | xdist, | ||
const double & | ydist, | ||
std::ostream & | out | ||
) |
Genera una especificación para el programa de dibujado de grafos graphpic de tipo grafo cruzado.
En un dibujo de grafo cruzado, se distribuyen nodes_by_level - 1 nodos los niveles pares y num_nodes_by_level en los impares.
generate_cross_graph(g,nodes_by_level,xdist,ydist,out) genera una entrada a graphpic de un grafo cruzado de nodes_by_level, separados horizontalmente por xdist y verticalmente por ydist. La salida se emite al archivo asociado a out.
Para tratar con los contenidos de los nodos y arcos y lo que se desee generar, se emplean los siguientes parámetros tipo:
[in] | g | grafo o digrafo del que se desea generar el dibujo. |
[in] | nodes_by_level | cantidad de nodos por nivel. El número de nodos del último nivel dependerá de la cantidad de nodos que contenga el grafo. |
[in] | xdist | separación horizontal entre los nodos. |
[in] | ydist | separación vertical entre los nodos. |
[out] | out | archivo hacia donde se emitirá la salida. |
void Aleph::generate_graphpic | ( | const GT & | g, |
const double & | xdist, | ||
const double & | , | ||
std::ostream & | output | ||
) |
Genera una especificación para el programa de dibujado de grafos graphpic de tipo grafo cruzado.
En un dibujo de grafo cruzado, se distribuyen nodes_by_level - 1 nodos los niveles pares y num_nodes_by_level en los impares.
generate_cross_graph(g,nodes_by_level,xdist,ydist,output) genera una entrada a graphpic de un grafo cruzado de nodes_by_level, separados horizontalmente por xdist y verticalmente por ydist. La salida se emite al archivo asociado a output.
Para tratar con los contenidos de los nodos y arcos y lo que se desee generar, se emplean los siguientes parámetros tipo:
[in] | g | grafo o digrafo del que se desea generar el dibujo. |
[in] | xdist | separación horizontal entre los nodos. |
[out] | output | archivo hacia donde se emitirá la salida. |
void Aleph::generate_graphviz | ( | const GT & | g, |
std::ostream & | output, | ||
const string & | rankdir = "TB" , |
||
float | ranksep = 0.2 , |
||
float | nodesep = 0.2 |
||
) |
Genera una especificación para el programa de dibujado de grafos graphpic de tipo grafo cruzado.
En un dibujo de grafo cruzado, se distribuyen nodes_by_level - 1 nodos los niveles pares y num_nodes_by_level en los impares.
generate_cross_graph(g,nodes_by_level,xdist,ydist,output) genera una entrada a graphpic de un grafo cruzado de nodes_by_level, separados horizontalmente por xdist y verticalmente por ydist. La salida se emite al archivo asociado a output.
Para tratar con los contenidos de los nodos y arcos y lo que se desee generar, se emplean los siguientes parámetros tipo:
[in] | g | grafo o digrafo del que se desea generar el dibujo. |
[out] | output | archivo hacia donde se emitirá la salida. |
[in] | rankdir | dirección del dibujado entre los valores "TB", "BT", "LR" y "RL" |
[in] | ranksep | separación entre rangos topológicos (cuando aplique) |
[in] | nodesep | separación entre los nodos |
void Aleph::generate_graphviz | ( | const GT & | g, |
std::ostream & | out, | ||
Node_Attr | node_attr = Node_Attr() , |
||
Arc_Attr | arc_attr = Arc_Attr() , |
||
const string & | rankdir = "TB" |
||
) |
Genera una especificación para el programa de dibujado de grafos graphpic de tipo grafo cruzado.
En un dibujo de grafo cruzado, se distribuyen nodes_by_level - 1 nodos los niveles pares y num_nodes_by_level en los impares.
generate_cross_graph(g,nodes_by_level,xdist,ydist,output) genera una entrada a graphpic de un grafo cruzado de nodes_by_level, separados horizontalmente por xdist y verticalmente por ydist. La salida se emite al archivo asociado a output.
Para tratar con los contenidos de los nodos y arcos y lo que se desee generar, se emplean los siguientes parámetros tipo:
[in] | g | grafo o digrafo del que se desea generar el dibujo. |
[out] | out | archivo hacia donde se emitirá la salida. |
[in] | rankdir | dirección del dibujado entre los valores "TB", "BT", "LR" y "RL" |
void Aleph::generate_net_graph | ( | GT & | g, |
const size_t & | nodes_by_level, | ||
const double & | xdist, | ||
const double & | ydist, | ||
std::ostream & | out | ||
) |
Genera una especificación para el programa de dibujado de grafos graphpic de tipo red.
En un dibujo de red, siempre se distribuyen nodes_by_level nodos por nivel.
generate_net_graph(g,nodes_by_level,xdist,ydist,out) genera una entrada a graphpic de un grafo red de nodes_by_level, separados horizontalmente por xdist y verticalmente por ydist. La salida se emite al archivo asociado a out.
Para tratar con los contenidos de los nodos y arcos y lo que se desee generar, se emplean los siguientes parámetros tipo:
[in] | g | grafo o digrafo del que se desea generar el dibujo. |
[in] | nodes_by_level | cantidad de nodos por nivel. El número de nodos del último nivel dependerá de la cantidad de nodos que contenga el grafo. |
[in] | xdist | separación horizontal entre los nodos. |
[in] | ydist | separación vertical entre los nodos. |
[out] | out | archivo hacia donde se emitirá la salida. |
|
inline |
Convierte un árbol representado en una representación de grafo a un árbol Tree_Node.
graph_to_tree_node() toma un árbol representado mediante algún tipo de grafo representado con listas de adyacencia y un nodo groot que se asume raÃz del árbol y lo convierte a un árbol representado con el tipo Tree_Node<Key>.
El interés de esta rutina es obtener una representación del árbol en la cual se puedan aplicar otras técnicas, clases y algoritmos. Un ejemplo representativo es el dibujado de árboles inherentes a los grafos; en la ocurrencia, árboles abarcadores.
El procedimiento utiliza el bit spanning_tree para marcar los nodos y arcos ya visitados.
Como medio de representación, el tipo Tree_Node<Key> es menos versátil que cualquier tipo basado en un grafo representado con listas de adyacencia; por ejemplo, List_graph. Note, por instancia, que List_Graph<Node,Arc> estipula un tipo para los arcos, mientras que no ocurre lo mismo para Tree_Node<Key>. En este sentido, como representación, Tree_Node<Key> no tiene ningún medio para guardar los datos asociados a los arcos. Consecuentemente, sólo se podrÃa manejar los datos contenidos en los nodos. Por otra parte, el tipo guardado en GT::Node puede ser de Ãndole distinta al guardado en Tree_Node<Key>.
A menudo (ese es el caso tÃpico del dibujado), el tipo de dato a guardar en Tree_Node<Key> es de Ãndole distinta al guardado en GT::Node. Otras veces, lo que se desea guardar en cada Tree_Node<Key> es un subconjunto de lo que está guardado en GT::Node. Puesto que es imposible generizar todos los casos posibles, la escritura de cada Tree_Node<Key> se delega a una clase cuyo operador ()() es invocado por la rutina de conversión para cada nodo del grafo. La clase en cuestión es el parámetro tipo Convert.
La clase Convert se invoca de la siguiente manera:
void Convert::operator () (gnode, tnode) donde: -# gnode es de tipo GT::Node -# tnode de tipo Tree_Node<Key>
La rutina hace una prueba de aciclicidad sobre g mediante la función is_graph_acyclique(), lo que no afecta la complejidad algorÃtmica de pero que toma tiempo adicional.
El procedimiento maneja los siguientes tipos parametrizados:
[in] | g | el árbol de tipo GT (derivado de List_Graph) que se desea convertir. |
[in] | groot | el nodo de g que se considera raÃz del árbol. |
bad_alloc | si no hay memoria para apartar el árbol de tipo Tree_Node<Key> |
DynList<typename GT::Arc*> Aleph::in_arcs | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Return the filtered incoming arcs of p
.
[in] | p | node pointer |
[in] | sa | arc filter |
size_t Aleph::in_degree | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Compute the filtered in degree of node p
.
[in] | p | node pointer |
[in] | sa | arc filter |
DynList<typename GT::Node*> Aleph::in_nodes | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Return the nodes connected to the filtered incoming arcs to p
.
[in] | p | node pointer |
[in] | sa | arc filter |
DynList<typename GT::Node*>
with the pointer to the incoming nodes DynList<ArcPair<GT> > Aleph::in_pairs | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Return the filtered incoming pairs of (arc,node) related to node p
[in] | p | node pointer |
[in] | sa | arc filter |
|
inline |
Compute a list of subgraphs corresponding to the inconnected component of a graph.
After completion, the subgraphs are mapped through the nodes and arcs cookies to the original graph.
This function uses the control bit Build_Subtree.
The algorithm user depth first search and takes in complexity.
[in] | g | the graph |
g
bad_alloc | if there is no enough memory |
void Aleph::inter_copy_graph | ( | GTT & | gtgt, |
const GTS & | gsrc, | ||
const bool | cookie_map = false |
||
) |
Copy between different types of graphs.
[in] | gtgt | target graph |
[in] | gsrc | source graph |
[in] | cookie_map | if true ==> a mapping will be done through nodes and arcs cookies |
GT Aleph::invert_digraph | ( | const GT & | g | ) |
Compute the inverted graph; that is the seame nodes but its arcs inverted.
After call the graphs are mapped.
[in] | g | the graph |
g
bad_alloc | if there is no enough memory |
|
inline |
Calcula los componentes fuertemente conexos de un grafo según el algoritmo de Kosaraju.
kosaraju_connected_components() toma un digrafo g, "supuestamente débilmente conexo", calcula sus subgrafos o componentes inconexos y los almacena en una lista dinámica list de subdigrafos mapeados, tanto en los nodos como en los arcos. El énfasis en el supuesto carácter conexo del grafo se debe a que si el grafo no fuese conexo, entonces la lista resultante contendrÃa un solo elemento correspondiente al digrafo copia mapeado de g. Si este fuese el caso, entonces es preferible hacerlo con la función copy_graph().
La función se basa en el algoritmo de Tarjan.
La función emplea dos parámetros tipo:
La función se vale del bit build_subtree para marcar nodos y arcos visitados.
El algoritmo internamente descubre los componentes mediante búsquedas en profundidad.
[in] | g | el grafo. |
[out] | blk_list | lista de sub-grafos mapeados a g correspondiente a los componentes fuertemente conexos de g. |
[out] | arc_list | lista de arcos de cruce entre los componentes. |
|
inline |
Calcula los componentes fuertemente conexos de un grafo según el algoritmo de Kosaraju.
kosaraju_connected_components() toma un digrafo g, "supuestamente débilmente conexo", calcula sus subgrafos o componentes inconexos y los almacena en una lista dinámica list de subdigrafos mapeados, tanto en los nodos como en los arcos. El énfasis en el supuesto carácter conexo del grafo se debe a que si el grafo no fuese conexo, entonces la lista resultante contendrÃa un solo elemento correspondiente al digrafo copia mapeado de g. Si este fuese el caso, entonces es preferible hacerlo con la función copy_graph().
La función se basa en el algoritmo de Kosaraju, el cual no es el más eficiente conocido pero sà es el más simple.
La función emplea dos parámetros tipo:
La función se vale del bit build_subtree para marcar nodos y arcos visitados.
El algoritmo internamente descubre los componentes mediante búsquedas en profundidad.
La diferencia y ventaja de esta rutina respecto a la versiòn que calcula los bloques directos es su rapidez; los bloque son comprendidos en listas de listas de nodos y no en lista de subgrafos.
[in] | g | el grafo. |
[out] | list | lista de listas de nodos que conforman los componentes. Cada lista es una listas de los nodos del componente. |
|
noexcept |
Map two arcs of different types of graphs through their cookies
[in] | p | pointer to the source arc |
[in] | q | pointer to the target arc |
std::tuple<GT, DynList<typename GT::Arc*> > Aleph::map_cut_graph | ( | const GT & | g, |
const DynList< typename GT::Node *> & | cut_node_list | ||
) |
Extract a mapped copy of cut graph.
map_cut_graph(g, cut_node_list)
extracts, according to cut_node_list
, the cut graph.
The cut graph is composed by the cut nodes and arcs. A cut arc if an arc linking two cut points.
An arc linking a cut point with a non cut point is called a "cross arc".
The function requires that nodes and arcs are marked with their respective control bits as well as they are painted. So, this requires that the cut points has previously been computed and the graph has been painted.
[in] | g | the graph |
[in] | cut_node_list | list with the cut points grafo es a menudo inconexo. |
tuple<GT, DynList<typename GT::Arc*>>
whose first element is the cut graph and the second is a list with the cross arcs. bad_alloc | if there is no enough memory |
|
noexcept |
Map two nodes of different types of graphs through their cookies
[in] | p | pointer to the source node |
[in] | q | pointer to the target node |
GT Aleph::map_subgraph | ( | const GT & | g, |
const long | color | ||
) |
Extract a mapped copy of a subgraph with a specific color.
map_subgraph(g, color)
searches a node of g
with the color
. Once found, the graph is traversed in depth first order and all the nodes and arcs with color
are copied and mapped to a resulting subgraph.
map_subgraph()
was/is primarily destined to extract a block according to a cut point and paint_subgraphs()
. However, this function could perfectly be used for extracting any painted subgraph.
[in] | g | the graph |
[in] | color | the color value |
color
bad_alloc | if there is no enough memory |
|
noexcept |
Return the mapped node through the cookie of p
Container<T> Aleph::nodes_map | ( | GT & | g, |
std::function< T(typename GT::Node *)> | transformation, | ||
SN | sn = SN() |
||
) |
Map the filtered nodes of a graph to a transformed type.
[in] | g | the grapg |
[in] | transformation | function Node* –> T` |
[in] | sn | node filter |
Container<T>
object with all the nodes mapped through the transformation DynList<typename GT::Arc*> Aleph::out_arcs | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Return the filtered incoming arcs of p
.
[in] | p | node pointer |
[in] | sa | arc filter |
size_t Aleph::out_degree | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Compute the filtered out degree of node p
[in] | p | node pointer |
[in] | sa | arc filter |
DynList<typename GT::Node*> Aleph::out_nodes | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Return the nodes connected to the filtered outcoming arcs of p
.
[in] | p | node pointer |
[in] | sa | arc filter |
DynList<typename GT::Node*>
with the pointer to the outcoming nodes DynList<ArcPair<GT> > Aleph::out_pairs | ( | typename GT::Node * | p, |
SA | sa = SA() |
||
) |
Return the filtered outcoming pairs of (arc,node) related to node p
[in] | p | node pointer |
[in] | sa | arc filter |
DynList<ArcPair<GT>>
containg the outcoming pairs
|
inline |
Paint a connected graph according to its cut points.
paint_subgraphs()
takes a graph and a cut points list previously computed with compute_cut_nodes()
and on the graph paints its nodes and arcs witg different colors according to the cut points. The color would allow to distinguish the components which are separated by cut points. The color is defined with the counter attribute of node and arcs.
The first color starts from one. The number of color is thus the number of different components.
paint_subgraphs()
uses the control bit Cut
in order to differentiate the cut nodes and arcs. So, the graph must remain intact after the cut nodes computation. The procedure internally uses also the control bit Build_Subtree.
compute_cut_nodes()
, whick gives the cut nodes list and leaves the nodes and arcs of the graph adequately marked. You must not alter the control bits of graph. cruce (arcos adyacentes a un punto de corte). If this protocol is respected, the this fuction will not fail, because it does not require memory.[in] | g | the grapg to be painted |
[in] | cut_node_list | cut nodes list previously computed with compute_cut_node() |
size_t Aleph::rank_graphviz | ( | const GT & | g, |
std::ostream & | out, | ||
Node_Attr | node_attr = Node_Attr() , |
||
Arc_Attr | arc_attr = Arc_Attr() , |
||
const string & | rankdir = "LR" |
||
) |
Genera una especificación para el programa de dibujado de grafos graphpic de tipo grafo cruzado.
En un dibujo de grafo cruzado, se distribuyen nodes_by_level - 1 nodos los niveles pares y num_nodes_by_level en los impares.
generate_cross_graph(g,nodes_by_level,xdist,ydist,output) genera una entrada a graphpic de un grafo cruzado de nodes_by_level, separados horizontalmente por xdist y verticalmente por ydist. La salida se emite al archivo asociado a output.
Para tratar con los contenidos de los nodos y arcos y lo que se desee generar, se emplean los siguientes parámetros tipo:
[in] | g | grafo o digrafo del que se desea generar el dibujo. |
[out] | out | archivo hacia donde se emitirá la salida. |
[in] | rankdir | dirección del dibujado entre los valores "TB", "BT", "LR" y "RL" |
|
noexcept |
Arc filtered searching given two nodes.
This function receives two nodes and returns the first arc linking them. The arc sense is irrelevant for this function. Simply, it searches an arc linking the nodes
[in] | g | the graph |
[in] | src | a node |
[in] | tgt | another node |
[in] | sa | filtering condition |
nullptr
otherwise
|
noexcept |
Searching of directed arc linking two nodes.
[in] | g | the graph |
[in] | src | source node pointer |
[in] | tgt | target node pointer |
nullptr
otherwise.
|
inline |
Crea un grafo aleatorio hamiltoniano.
Esta versión construye un grafo aleatorio hamiltoniano.
El proceso primero genera un grafo aleatorio, luego examina el grafo resultante y crea nuevos arcos de modo que el resultado contenga un ciclo hamiltoniano.
[in] | __num_nodes | cantidad de nodos que debe tener el grafo. |
[in] | p | probabilidad de existencia de arco entre cualquier par de nodos. Por omisión este parámetro tiene valor 0.5, valor que intuitiva y empÃricamente tiende a generar menor arcos y consumir menos tiempo. |
bad_alloc | si no hay suficiente memoria. |
domain_error | si el valor de p no está entre 0 y 1. |
|
inline |
Crea un grafo aleatorio hamiltoniano.
Esta versión construye un grafo aleatorio hamiltoniano.
El proceso primero genera un grafo aleatorio, luego examina el grafo resultante y crea nuevos arcos de modo que el resultado contenga un ciclo hamiltoniano.
[in] | __num_nodes | cantidad de nodos que debe tener el grafo. |
[in] | p | probabilidad de existencia de arco entre cualquier par de nodos. Por omisión este parámetro tiene valor 0.5, valor que intuitiva y empÃricamente tiende a generar menor arcos y consumir menos tiempo. |
bad_alloc | si no hay suficiente memoria. |
domain_error | si el valor de p no está entre 0 y 1. |
|
inline |
Simple connectivity test.
[in] | g | a graph |
true
if g is connected domain_error | if g is a directed graph |
|
inline |
Single cycle searching from a node.
test_for_cycle(g, src)
perform a depth first traversal on graph g
searching a cycle starting from node src
.
The control bit Test_Cycle is used.
src
. It takes has_cycle()
instead, which is [in] | g | the graph |
[in] | src | pointer to node |
true
if there is a cycle from src
|
inline |
Test for path between two nodes.
The contros Bit Test_path is used.
The function is worst case
[in] | g | the graph |
[in] | start_node | pointer to start node |
[in] | end_node | pointer to end node |
true
if it exists a path between start_node
and end_node
|
inlinenoexcept |
Generic arcs traverse of a node.
This template function receives threes template parameters:
GT
: the graph type.Itor
: the iterator type; it is intended to be __In_Iterator
or __Out_Iterator
.Operation
: an operation to be executed on each arc. This operation must have the following signature:
bool operation(typename GT::Arc * arc)
If operation
returns true
then the traversal continues to the next arc; otherwise the traversal stops and the result of traverse()
is false
. If all the arcs are traversed, then the result is true
.
[in] | p | node pointer |
[in] | operation | to be performed on each arc |
true
if all the arcs were traversed: false
otherwise
|
inlinenoexcept |
Conditioned traversal of incoming arcs of a node.
[in] | p | node pointer |
[in] | op | operation whose result must be bool . Si the result is false , then the traversal stops and the traverse returns false ; otherwise, all the ars are traversed and it returns true |
true
is all the arcs were traversed: false
otherwise
|
inlinenoexcept |
Conditioned traversal of outcoming arcs of a node.
[in] | p | node pointer |
[in] | op | operation whose result must be bool . Si the result is false , then the traversal stops and the traverse returns false ; otherwise, all the ars are traversed and it returns true |
true
is all the arcs were traversed: false
otherwise long Aleph::vertex_connectivity | ( | GT & | g | ) |
Calcula la conectividad en nodos o vértices de un grafo.
Esta rutina se vale de un algoritmo de maximización de flujo para calcular la conectividad en nodos de un grafo. Como tal, su segundo parámetro plantilla es el algoritmo de maximización de flujo.
[in] | g | el grafo. |
void Aleph::warshall_compute_transitive_clausure | ( | GT & | g, |
Bit_Mat_Graph< GT, SA > & | mat | ||
) |
Cálculo de la clausura transitiva de una matriz de adyacencia.
Esta función calcula la clausura transitiva del grafo g mediante el algoritmo de Warshall. El resultado se almacena en la matriz de bits mat.
Cada entrada mat(i,j) indica existencia de un camino entre el nodo origen con Ãndice i y el nodo destino con Ãndice j. Un valor cero indica que no hay ningún camino; un valor 1 que existe al menos un camino.
El procedimiento utiliza dos matrices de bits; una de uso interno que es liberada al término del procedimiento y la propia matriz mat.
[in] | g | el grafo representado mediante una variante de List_Graph. |
[out] | mat | matriz de bits donde se coloca el resultado. |
bad_alloc | si no hay suficiente memoria. |
const unsigned char Aleph::Processed |
The node or arc has already been processed
const unsigned char Aleph::Processing |
The node are being processed; probably it is inside a queue, stack or heap
const unsigned char Aleph::Unprocessed |
The node have not bees processed. This must be the initial state before general processing