Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Matrix_Graph< GT, SA > Class Template Reference

Adjacency matrix storing copies of graph attributes. More...

#include <tpl_matgraph.H>

Collaboration diagram for Aleph::Matrix_Graph< GT, SA >:
[legend]

Public Types

using Graph_Type = GT
 Graph type.
 
using Node_Type = typename GT::Node_Type
 Node attribute type.
 
using Arc_Type = typename GT::Arc_Type
 Arc attribute type.
 
using Node = typename GT::Node
 Node type.
 
using Arc = typename GT::Arc
 Arc type.
 

Public Member Functions

size_t get_num_nodes () const noexcept
 Get number of nodes (matrix dimension)
 
const Arc_Typenull_value () const noexcept
 Get the null value indicating no arc.
 
 Matrix_Graph (GT &g, const Arc_Type &null, SA &&__sa=SA())
 Construct from graph with null value.
 
 Matrix_Graph (GT &g, const Arc_Type &null, SA &__sa)
 
 Matrix_Graph (Matrix_Graph &other)
 Copy constructor.
 
Matrix_Graphoperator= (Matrix_Graph &other)
 Copy assignment.
 
Matrix_Graphoperator= (GT &g)
 Assign from graph.
 
const Arc_Typeoperator() (long i, long j) const
 Get arc attribute by indices (const).
 
Node_Typeoperator() (long i) const
 Get node attribute by index.
 
Arc_Typeoperator() (long i, long j)
 Get/set arc attribute by indices.
 

Private Member Functions

void copy (Matrix_Graph &other)
 
void copy (GT &g)
 

Private Attributes

DynArray< Node_Typenodes
 
DynArray< Arc_Typearcs
 
size_t n = 0
 
Arc_Type Null_Value {}
 
SA sa
 

Detailed Description

template<typename GT, class SA = Dft_Show_Arc<GT>>
class Aleph::Matrix_Graph< GT, SA >

Adjacency matrix storing copies of graph attributes.

Matrix_Graph creates a self-contained adjacency matrix by copying the node and arc attributes from an adjacency list graph. Unlike Map_Matrix_Graph, this matrix does not maintain references to the original graph.

Key Features

  • Stores actual attribute values, not pointers
  • Modifiable entries (can add arcs by setting entries)
  • null_value() indicates absence of arc
  • Memory proportional to number of arcs (sparse storage)

Usage Example

// ... build graph ...
// -1 indicates no arc
// Read arc weight
int weight = mat(0, 1); // Returns -1 if no arc
// Add/modify arc
mat(0, 2) = 5; // Set arc weight
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:428
Adjacency matrix storing copies of graph attributes.
Note
Only stores primitive attribute values, not derived node/arc types.
Template Parameters
GTGraph type
SAArc filter (default: show all arcs)
See also
Map_Matrix_Graph For pointer-based matrix
Ady_Mat For auxiliary matrices with custom types

Definition at line 487 of file tpl_matgraph.H.

Member Typedef Documentation

◆ Arc

template<typename GT , class SA = Dft_Show_Arc<GT>>
using Aleph::Matrix_Graph< GT, SA >::Arc = typename GT::Arc

Arc type.

Definition at line 503 of file tpl_matgraph.H.

◆ Arc_Type

template<typename GT , class SA = Dft_Show_Arc<GT>>
using Aleph::Matrix_Graph< GT, SA >::Arc_Type = typename GT::Arc_Type

Arc attribute type.

Definition at line 497 of file tpl_matgraph.H.

◆ Graph_Type

template<typename GT , class SA = Dft_Show_Arc<GT>>
using Aleph::Matrix_Graph< GT, SA >::Graph_Type = GT

Graph type.

Definition at line 491 of file tpl_matgraph.H.

◆ Node

template<typename GT , class SA = Dft_Show_Arc<GT>>
using Aleph::Matrix_Graph< GT, SA >::Node = typename GT::Node

Node type.

Definition at line 500 of file tpl_matgraph.H.

◆ Node_Type

template<typename GT , class SA = Dft_Show_Arc<GT>>
using Aleph::Matrix_Graph< GT, SA >::Node_Type = typename GT::Node_Type

Node attribute type.

Definition at line 494 of file tpl_matgraph.H.

Constructor & Destructor Documentation

◆ Matrix_Graph() [1/3]

template<typename GT , class SA = Dft_Show_Arc<GT>>
Aleph::Matrix_Graph< GT, SA >::Matrix_Graph ( GT g,
const Arc_Type null,
SA &&  __sa = SA() 
)
inline

Construct from graph with null value.

Parameters
gSource graph
nullValue indicating absence of arc
__saArc filter
Exceptions
std::bad_allocif memory allocation fails

Definition at line 575 of file tpl_matgraph.H.

References Aleph::Matrix_Graph< GT, SA >::copy().

◆ Matrix_Graph() [2/3]

template<typename GT , class SA = Dft_Show_Arc<GT>>
Aleph::Matrix_Graph< GT, SA >::Matrix_Graph ( GT g,
const Arc_Type null,
SA __sa 
)
inline

Definition at line 581 of file tpl_matgraph.H.

References Aleph::Matrix_Graph< GT, SA >::copy().

◆ Matrix_Graph() [3/3]

template<typename GT , class SA = Dft_Show_Arc<GT>>
Aleph::Matrix_Graph< GT, SA >::Matrix_Graph ( Matrix_Graph< GT, SA > &  other)
inline

Copy constructor.

Definition at line 588 of file tpl_matgraph.H.

References Aleph::Matrix_Graph< GT, SA >::copy(), and Aleph::maps().

Member Function Documentation

◆ copy() [1/2]

◆ copy() [2/2]

◆ get_num_nodes()

template<typename GT , class SA = Dft_Show_Arc<GT>>
size_t Aleph::Matrix_Graph< GT, SA >::get_num_nodes ( ) const
inlinenoexcept

Get number of nodes (matrix dimension)

Definition at line 563 of file tpl_matgraph.H.

References Aleph::Matrix_Graph< GT, SA >::n.

Referenced by TEST_F().

◆ null_value()

template<typename GT , class SA = Dft_Show_Arc<GT>>
const Arc_Type & Aleph::Matrix_Graph< GT, SA >::null_value ( ) const
inlinenoexcept

Get the null value indicating no arc.

Definition at line 566 of file tpl_matgraph.H.

References Aleph::Matrix_Graph< GT, SA >::Null_Value.

Referenced by TEST_F().

◆ operator()() [1/3]

template<typename GT , class SA = Dft_Show_Arc<GT>>
Node_Type & Aleph::Matrix_Graph< GT, SA >::operator() ( long  i) const
inline

Get node attribute by index.

Parameters
iNode index
Returns
Reference to node attribute
Exceptions
std::out_of_rangeif i >= n

Definition at line 623 of file tpl_matgraph.H.

References Aleph::DynArray< T >::access(), ah_out_of_range_error_if, Aleph::maps(), Aleph::Matrix_Graph< GT, SA >::n, and Aleph::Matrix_Graph< GT, SA >::nodes.

◆ operator()() [2/3]

template<typename GT , class SA = Dft_Show_Arc<GT>>
Arc_Type & Aleph::Matrix_Graph< GT, SA >::operator() ( long  i,
long  j 
)
inline

Get/set arc attribute by indices.

Parameters
iSource index
jTarget index
Returns
Reference to arc entry (creates if needed)

Definition at line 636 of file tpl_matgraph.H.

References Aleph::Matrix_Graph< GT, SA >::arcs, Aleph::matgraph_detail::checked_index_array(), Aleph::Matrix_Graph< GT, SA >::n, and Aleph::DynArray< T >::touch().

◆ operator()() [3/3]

template<typename GT , class SA = Dft_Show_Arc<GT>>
const Arc_Type & Aleph::Matrix_Graph< GT, SA >::operator() ( long  i,
long  j 
) const
inline

Get arc attribute by indices (const).

Parameters
iSource index
jTarget index
Returns
Arc attribute, or null_value() if no arc
Exceptions
std::out_of_rangeif indices out of bounds

Definition at line 611 of file tpl_matgraph.H.

References Aleph::DynArray< T >::access(), Aleph::Matrix_Graph< GT, SA >::arcs, Aleph::matgraph_detail::checked_index_array(), Aleph::DynArray< T >::exist(), Aleph::Matrix_Graph< GT, SA >::n, and Aleph::Matrix_Graph< GT, SA >::Null_Value.

◆ operator=() [1/2]

template<typename GT , class SA = Dft_Show_Arc<GT>>
Matrix_Graph & Aleph::Matrix_Graph< GT, SA >::operator= ( GT g)
inline

Assign from graph.

Definition at line 598 of file tpl_matgraph.H.

References Aleph::Matrix_Graph< GT, SA >::copy().

◆ operator=() [2/2]

template<typename GT , class SA = Dft_Show_Arc<GT>>
Matrix_Graph & Aleph::Matrix_Graph< GT, SA >::operator= ( Matrix_Graph< GT, SA > &  other)
inline

Copy assignment.

Definition at line 591 of file tpl_matgraph.H.

References Aleph::Matrix_Graph< GT, SA >::copy(), and Aleph::maps().

Member Data Documentation

◆ arcs

◆ n

◆ nodes

◆ Null_Value

◆ sa

template<typename GT , class SA = Dft_Show_Arc<GT>>
SA Aleph::Matrix_Graph< GT, SA >::sa
private

Definition at line 510 of file tpl_matgraph.H.

Referenced by Aleph::Matrix_Graph< GT, SA >::copy().


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