LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
lal::graphs::graph Class Referenceabstract

Abstract class for graphs. More...

#include <graph.hpp>

Inheritance diagram for lal::graphs::graph:
lal::graphs::directed_graph lal::graphs::tree lal::graphs::undirected_graph lal::graphs::rooted_tree lal::graphs::free_tree lal::graphs::rooted_tree lal::graphs::free_tree

Public Member Functions

 graph () noexcept
 Empty constructor.
 
 graph (const uint64_t n) noexcept
 Constructor with number of nodes.
 
 graph (const graph &g) noexcept
 Copy constructor.
 
 graph (graph &&g) noexcept
 Move constructor.
 
virtual ~graph () noexcept
 Destructor.
 
graphoperator= (const graph &g) noexcept
 Copy assignment operator.
 
graphoperator= (graph &&g) noexcept
 Move assignment operator.
 
virtual void init (const uint64_t n) noexcept
 Allocates the necessary memory for this class.
 
virtual void clear () noexcept
 Frees the memory occupied by this graph.
 
virtual void normalize () noexcept
 Normalizes the graph.
 
virtual bool check_normalized () noexcept
 Checks if the graph is normalized.
 
virtual void finish_bulk_add (const bool norm=true, const bool check=true) noexcept=0
 Completes the inner structure of the graph after adding a bulk of edges.
 
virtual void finish_bulk_remove (const bool norm=true, const bool check=true) noexcept=0
 Completes the inner structure of the graph after removing edges in bulk.
 
void set_normalized (const bool v=true) noexcept
 Sets whether this graph is normalized or not.
 
virtual std::vector< edge_pairget_Q () const noexcept=0
 Returns all independent pairs of edges of this graph.
 
bool has_node (const node u) const noexcept
 Returns true if node u is in this graph.
 
virtual bool has_edge (const node u, const node v) const =0
 Returns true if the undirected edge (u, v) exists in the graph.
 
uint64_t get_num_nodes () const noexcept
 Returns the number of ndoes.
 
uint64_t get_num_edges () const noexcept
 Returns the number of edges.
 
virtual std::vector< edgeget_edges () const noexcept=0
 Returns all edges of this graph.
 
bool is_normalized () const noexcept
 Returns whether this graph is normalized or not.
 
virtual bool is_directed () const noexcept=0
 Returns whether this graph is directed or not.
 
virtual bool is_undirected () const noexcept=0
 Returns whether this graph is undirected or not.
 

Protected Member Functions

virtual void _init (const uint64_t n) noexcept
 Initializes memory of graph class.
 
virtual void _clear () noexcept
 Clears memory for the graph class.
 
void copy_full_graph (const graph &g) noexcept
 Copies all members of this class.
 
void move_full_graph (graph &&g) noexcept
 Moves all members of this class.
 
void __add_node () noexcept
 Adds a node to the graph.
 
void __disjoint_union (const graph &g) noexcept
 Disjoint union of graphs.
 
virtual void actions_after_add_edge (const node u, const node v) noexcept
 Do some extra work after the addition of an edge.
 
virtual void actions_after_add_edges (const edge_list &e) noexcept
 Do some extra work after the addition of several edges.
 
virtual void actions_after_add_edges_bulk () noexcept
 Do some extra work after the addition of several edges in bulk.
 
virtual void actions_after_remove_edge (const node u, const node v) noexcept
 Do some extra work after the removal of an edge.
 
virtual void actions_after_remove_edges (const edge_list &e) noexcept
 Do some extra work after the removal of several edges.
 
virtual void actions_after_remove_edges_bulk () noexcept
 Do some extra work after the removal of several edges in bulk.
 
virtual void actions_before_remove_edges_incident_to (const node u) noexcept
 Do some work before all edges incident to a node is removed.
 
virtual void actions_after_remove_node (const node u) noexcept
 Do some work before the removal of a vertex.
 
void normalize_after_edge_addition (const bool norm, const bool check) noexcept
 Normalize the graph after one (or more) edges have been added.
 
void normalize_after_edge_removal (const bool norm, const bool check) noexcept
 Normalize the graph after one (or more) edges have been removed.
 

Protected Attributes

std::vector< neighbourhoodm_adjacency_list
 Data structure that implements the graph.
 
uint64_t m_num_edges = 0
 Amount of edges of this graph.
 
bool m_is_normalized = true
 Is this graph normalized?
 

Detailed Description

Abstract class for graphs.

Class used as an interface for all types of graphs. This means that this class cannot be instantiated. The classes that can be instantiated are undirected_graph, directed_graph, free_tree, rooted_tree.

A usual way of initialising classes inheriting from this one is to use one of the init methods available. Depending on the subclass, this method admits either the number of nodes of the graph or a whole other graph and further data (see rooted_tree::init_rooted(const lal::graphs::free_tree&, node, bool, bool)). While these classes' internal memory can be initialized, it can also be cleared using method clear. Each class reimplements this method to carry this task appropriately.

Constructor & Destructor Documentation

◆ graph() [1/3]

lal::graphs::graph::graph ( const uint64_t n)
inlinenoexcept

Constructor with number of nodes.

Parameters
nNumber of nodes.

◆ graph() [2/3]

lal::graphs::graph::graph ( const graph & g)
inlinenoexcept

Copy constructor.

Parameters
gGraph.

◆ graph() [3/3]

lal::graphs::graph::graph ( graph && g)
inlinenoexcept

Move constructor.

Parameters
gGraph.

Member Function Documentation

◆ __disjoint_union()

void lal::graphs::graph::__disjoint_union ( const graph & g)
protectednoexcept

Disjoint union of graphs.

Given a graph, append it to the current graph.

All the nodes in g are relabelled starting at n, the number of nodes of the current graph.

Parameters
gInput graph.
Precondition
This graph and g must be of the same type (both must be either undirected, or both directed).
Postcondition
The graph is normalized only if it was normalized before the call and g is also normalized.

◆ _init()

virtual void lal::graphs::graph::_init ( const uint64_t n)
inlineprotectedvirtualnoexcept

Initializes memory of graph class.

Parameters
nNumber of nodes.
Precondition
The graph is cleared.

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ actions_after_add_edge()

virtual void lal::graphs::graph::actions_after_add_edge ( const node u,
const node v )
protectedvirtualnoexcept

Do some extra work after the addition of an edge.

Parameters
uNode of the edge
vNode of the edge

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ actions_after_add_edges()

virtual void lal::graphs::graph::actions_after_add_edges ( const edge_list & e)
protectedvirtualnoexcept

Do some extra work after the addition of several edges.

Parameters
eList of edges.

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ actions_after_add_edges_bulk()

virtual void lal::graphs::graph::actions_after_add_edges_bulk ( )
protectedvirtualnoexcept

Do some extra work after the addition of several edges in bulk.

This method should only be called after several calls to undirected_graph::add_edge_bulk or directed_graph::add_edge_bulk.

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ actions_after_remove_edge()

virtual void lal::graphs::graph::actions_after_remove_edge ( const node u,
const node v )
protectedvirtualnoexcept

Do some extra work after the removal of an edge.

Parameters
uNode of the edge
vNode of the edge

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ actions_after_remove_edges()

virtual void lal::graphs::graph::actions_after_remove_edges ( const edge_list & e)
protectedvirtualnoexcept

Do some extra work after the removal of several edges.

Parameters
eList of edges.

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ actions_after_remove_edges_bulk()

virtual void lal::graphs::graph::actions_after_remove_edges_bulk ( )
protectedvirtualnoexcept

Do some extra work after the removal of several edges in bulk.

This method should only be called after several calls to undirected_graph::remove_edge_bulk or directed_graph::remove_edge_bulk.

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ actions_after_remove_node()

virtual void lal::graphs::graph::actions_after_remove_node ( const node u)
protectedvirtualnoexcept

Do some work before the removal of a vertex.

Parameters
uNode to be removed.

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ actions_before_remove_edges_incident_to()

virtual void lal::graphs::graph::actions_before_remove_edges_incident_to ( const node u)
protectedvirtualnoexcept

Do some work before all edges incident to a node is removed.

Parameters
uNode whose incident edges are to be removed.

Reimplemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ check_normalized()

virtual bool lal::graphs::graph::check_normalized ( )
virtualnoexcept

Checks if the graph is normalized.

Checks, whether the graph's adjacency structure is normalized or not. In case it is, attribute m_is_normalized is set to true, so method is_normalized evaluates to true.

Reimplemented in lal::graphs::directed_graph.

◆ clear()

virtual void lal::graphs::graph::clear ( )
virtualnoexcept

Frees the memory occupied by this graph.

See _clear for details.

Postcondition
The graph is normalized. The number of edges is 0.

◆ finish_bulk_add()

virtual void lal::graphs::graph::finish_bulk_add ( const bool norm = true,
const bool check = true )
pure virtualnoexcept

Completes the inner structure of the graph after adding a bulk of edges.

This is meant to be used after several calls to undirected_graph::add_edge_bulk, directed_graph::add_edge_bulk.

Parameters
normNormalize the graph.
checkCheck wether the graph is normalized or not.

Implemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ finish_bulk_remove()

virtual void lal::graphs::graph::finish_bulk_remove ( const bool norm = true,
const bool check = true )
pure virtualnoexcept

Completes the inner structure of the graph after removing edges in bulk.

This is meant to be used after several calls to undirected_graph::remove_edge_bulk, directed_graph::remove_edge_bulk.

Parameters
normNormalize the graph.
checkCheck wether the graph is normalized or not.

Implemented in lal::graphs::directed_graph, lal::graphs::free_tree, lal::graphs::rooted_tree, and lal::graphs::undirected_graph.

◆ get_Q()

virtual std::vector< edge_pair > lal::graphs::graph::get_Q ( ) const
nodiscardpure virtualnoexcept

Returns all independent pairs of edges of this graph.

The set \(Q(G)\) is defined as the pairs of edges of \(G\), \(E(G) \times E(G)\), that are independent, that is, that share no nodes.

Implemented in lal::graphs::directed_graph, and lal::graphs::undirected_graph.

◆ init()

virtual void lal::graphs::graph::init ( const uint64_t n)
virtualnoexcept

Allocates the necessary memory for this class.

See _init for details.

Parameters
nNumber of nodes.

◆ is_normalized()

bool lal::graphs::graph::is_normalized ( ) const
inlinenodiscardnoexcept

Returns whether this graph is normalized or not.

A graph is normalized if every node's adjacency list is sorted increasingly. For this, use method normalize().

Returns
The value of m_is_normalized.

◆ normalize()

virtual void lal::graphs::graph::normalize ( )
virtualnoexcept

Normalizes the graph.

Sorts this graph's adjacency list structure in increasing order.

Besides expensive, this method may be unnecessary. Method check_normalized() checks whether the graph is normalized or not; in case it is, using this method is completely unnecessary.

Postcondition
Method is_normalized evaluates to true.

Reimplemented in lal::graphs::directed_graph.

◆ operator=() [1/2]

graph & lal::graphs::graph::operator= ( const graph & g)
inlinenoexcept

Copy assignment operator.

Parameters
gGraph.

◆ operator=() [2/2]

graph & lal::graphs::graph::operator= ( graph && g)
inlinenoexcept

Move assignment operator.

Parameters
gGraph.

Member Data Documentation

◆ m_is_normalized

bool lal::graphs::graph::m_is_normalized = true
protected

Is this graph normalized?

An undirected graph is normalized iff every node's adjacency list is sorted in increasing order.

In directed graphs, however, it is necessary that the adjacency lists of the out-neighbors and in-neighbors of nodes be sorted.

This attribute is set to 'true' in all graph's initialisation and destruction (when clear() method is called).


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