Polymake Template Library (PTL): pm::graph::Graph Class Reference
Polymake Template Library (PTL)  4.2

Directed or undirected finite graphs. More...

Collaboration diagram for pm::graph::Graph:

Public Types

typedef graph::node_container< TDir > node_container
 node type
 
typedef node_containernode_container_ref
 node reference type
 

Public Member Functions

 Graph ()
 Create an empty Graph with 0 nodes.
 
 Graph (Int n)
 Create a Graph with n isolated nodes (without edges).
 
Graphoperator= (const Graph &G2)
 assignment from Graph of the same type
 
Graphoperator= (const GenericGraph< Graph > &G2)
 assignment from GenericGraph
 
template<typename Graph2 , typename TDir2 >
Graphoperator= (const GenericGraph< Graph2, TDir2 > &G2)
 assignment from GenericGraph with other flavor of directedness
 
Int nodes () const
 number of nodes
 
void resize (Int n)
 resize the Graph to given number of nodes
 
void clear (Int n=0)
 clear all edges and resize (to zero nodes by default)
 
bool has_gaps () const
 true of nodes are not (known to be) consecutively ordered
 
Int dim () const
 "output dimension"; relevant for proper output in the polymake shell
 
void swap (Graph &G)
 swap function
 
void squeeze ()
 force renumbering of the nodes in consecutive order
 
void delete_node (Int n)
 delete a node
 
template<typename TPerm >
std::enable_if_t< isomorphic_to_container_of< TPerm, Int >::value > permute_nodes (const TPerm &perm)
 permute the nodes
 
template<typename TInvPerm >
std::enable_if_t< isomorphic_to_container_of< TInvPerm, Int >::value > permute_inv_nodes (const TInvPerm &inv_perm)
 inverse permutation of nodes
 
template<typename TPerm , typename TInvPerm >
std::enable_if_t< isomorphic_to_container_of< TPerm, Int >::value &&isomorphic_to_container_of< TInvPerm, Int >::value, Graphcopy_permuted (const TPerm &perm, const TInvPerm &inv_perm) const
 permuted copy
 
Int edges () const
 number of edges
 
Int add_node ()
 add a node; may reuse a currently unused node
 
bool invalid_node (Int n) const
 true if node is unused
 
bool node_out_of_range (Int n) const
 true if node number is higher than currently reserved maximum number of nodes
 
Int out_degree (Int n) const
 out-degree of a node
 
Int in_degree (Int n) const
 in-degree of a node
 
Int degree (Int n) const
 total degree of a node
 
bool node_exists (Int n) const
 true if node exists
 
Int edge (Int n1, Int n2)
 
Int edge (Int n1, Int n2) const
 
Int add_edge (Int n1, Int n2)
 
bool edge_exists (Int n1, Int n2) const
 Check whether there is an edge between the two given nodes.
 
parallel_edge_iterator all_edges (Int n1, Int n2)
 Return the iterator over all edges connecting two given nodes.
 
parallel_edge_const_iterator all_edges (Int n1, Int n2) const
 Return the iterator over all edges connecting two given nodes.
 
void delete_edge (Int n1, Int n2)
 Delete the edge (if it exists) connecting the two given nodes.
 
void delete_edge (const parallel_edge_iterator &where)
 Delete an edge pointed by the given iterator over a sequence of (parallel) edges.
 
void delete_all_edges (Int n1, Int n2)
 Delete all (parallel) edges connecting the two given nodes.
 
void contract_edge (Int n1, Int n2)
 
out_edge_list_ref out_edges (Int n)
 reference to list of outgoing edges
 
const_out_edge_list_ref out_edges (Int n) const
 constant reference to list of outgoing edges
 
in_edge_list_ref in_edges (Int n)
 reference to list of incoming edges
 
const_in_edge_list_ref in_edges (Int n) const
 constant reference to list of incoming edges
 
out_adjacent_node_list_ref out_adjacent_nodes (Int n)
 reference to list of nodes which are adjacent via out-arcs
 
const_out_adjacent_node_list_ref out_adjacent_nodes (Int n) const
 constant reference to list of nodes which are adjacent via out-arcs
 
in_adjacent_node_list_ref in_adjacent_nodes (Int n)
 reference to list of nodes which are adjacent via in-arcs
 
const_in_adjacent_node_list_ref in_adjacent_nodes (Int n) const
 constant reference to list of nodes which are adjacent via in-arcs
 
adjacent_node_list_ref adjacent_nodes (Int n)
 reference to list of all adjacent nodes
 
const_adjacent_node_list_ref adjacent_nodes (Int n) const
 constant reference to list of all adjacent nodes
 
void enumerate_edges () const
 

Public Attributes

const typedef node_containerconst_node_container_ref
 constant node reference type
 

Detailed Description

Directed or undirected finite graphs.

NodeAttr and EdgeAttr specify the type of additional data associated with nodes and edges (sometimes also called node and edge attributes.) The default setting nothing denotes the absence of any attributes, it doesn't waste extra memory.

The nodes of the graph are referred to via integer indices, starting with 0; they are stored in a contiguous array. This allows constant-time random node access, while inserting or deleting of nodes incurs storage reallocation. However, due to some kind of forecasting strategy of memory allocation (similar to that deployed in std::vector), the amortized cost of node insertion is proportional to nodes log(nodes).

The edges are organized in incidence lists, which are implemented as a 2-d mesh of AVL trees. Hence, a random access to an edge (with given source and target nodes) takes a logarithmical time of the source node degree. Multiple edges (i.e., with the same source and target nodes) are not allowed; they could be modeled, however, by choosing some container class as the edge attribute.

The kind of the graph decides about how the incidence edge lists are organized. In the directed case each edge naturally appears in the outgoing list of its source node and in the ingoing list of its target node. In the undirected case the notions of outgoing and ingoing edges are the same; each edge manages to appear in the outgoing lists of both adjacent nodes, although it is stored only once. The @i skew case is a special variant of the indirect case, intended for numerical edge attributes only. Depending on the reading direction, the edge attribute changes its sign: { edge(n1,n2) == -edge(n2,n1) }.

The whole data structure is attached to the Graph object via a smart pointer with reference counting.

Member Function Documentation

◆ add_edge()

Int pm::graph::Graph::add_edge ( Int  n1,
Int  n2 
)
inline

Create a new edge between two given nodes and return its number. In a multigraph, a new edge is always created; the exact position of the new edge among its parallel twins can't be predicted. In a normal graph, a new edge is only created if the nodes were not adjacent before.

◆ contract_edge()

void pm::graph::Graph::contract_edge ( Int  n1,
Int  n2 
)
inline

Contract the edge between the two given nodes. The second node is deleted afterwards. If the specified edge belongs to one or more triangles in a multigraph, the lateral edges become parallel after contraction. In a normal graph, the lateral edges incident to n2 are deleted.

◆ edge() [1/2]

Int pm::graph::Graph::edge ( Int  n1,
Int  n2 
)
inline

Return the number of the edge between two given nodes. The edge is created if it did not exist before. In a multigraph, one (arbitrary) edge from a parallel bundle will be returned.

◆ edge() [2/2]

Int pm::graph::Graph::edge ( Int  n1,
Int  n2 
) const
inline

Return the number of the edge between two given nodes. If the edge does not exist, an exception is raised.

◆ enumerate_edges()

void pm::graph::Graph::enumerate_edges ( ) const
inline

Provide each edge with a unique integer id. The ids are assigned in the order of visiting them by Edges<Graph>::iterator, but you shouldn't rely on any special order later, after having added or deleted some edges, because the enumeration is effectively performed only once in the life of a Graph object. Later calls to this function are no-ops. Moreover, the edges are also enumerated when an edge attribute map is attached to the Graph object for the first time.


The documentation for this class was generated from the following files: