Dynamical system model
Loading...
Searching...
No Matches
dsm::AdjacencyMatrix Class Reference

The AdjacencyMatrix class represents the adjacency matrix of the network. More...

#include <AdjacencyMatrix.hpp>

Public Types

using value_type = Id
 
using difference_type = std::ptrdiff_t
 
using reference = Id&
 
using const_reference = const Id&
 
using iterator = std::vector<Id>::iterator
 
using const_iterator = std::vector<Id>::const_iterator
 
using reverse_iterator = std::vector<Id>::reverse_iterator
 
using const_reverse_iterator = std::vector<Id>::const_reverse_iterator
 

Public Member Functions

 AdjacencyMatrix ()
 Construct a new AdjacencyMatrix object.
 
 AdjacencyMatrix (std::string const &fileName)
 Construct a new AdjacencyMatrix object using the read method.
 
 AdjacencyMatrix (const std::unordered_map< Id, std::unique_ptr< Street > > &streets)
 Construct a new AdjacencyMatrix object using the streets of the network.
 
bool operator== (const AdjacencyMatrix &other) const
 
bool operator() (Id row, Id col) const
 Get the link at the specified row and column.
 
size_t size () const
 Get the number of links in the adjacency matrix.
 
bool empty () const
 Check if the adjacency matrix is empty.
 
size_t n () const
 Get the number of nodes in the adjacency matrix.
 
void insert (Id row, Id col)
 Inserts the link row -> col in the adjacency matrix.
 
bool contains (Id row, Id col) const
 Check if the link row -> col exists in the adjacency matrix.
 
std::vector< Id > getRow (Id row) const
 Get the row at the specified index.
 
std::vector< Id > getCol (Id col) const
 Get the column at the specified index.
 
std::vector< std::pair< Id, Id > > elements () const
 Get a vector containing all the links in the adjacency matrix as pairs of nodes.
 
void clear ()
 Clear the adjacency matrix.
 
void clearRow (Id row)
 Clear the row at the specified index.
 
void clearCol (Id col)
 Clear the column at the specified index.
 
std::vector< int > getInDegreeVector () const
 Get the input degree vector of the adjacency matrix.
 
std::vector< int > getOutDegreeVector () const
 Get the output degree vector of the adjacency matrix.
 
void read (std::string const &fileName)
 Read the adjacency matrix from a binary file.
 
void save (std::string const &fileName) const
 Write the adjacency matrix to a binary file.
 

Friends

std::vector< Id > test::offsets (const AdjacencyMatrix &adj)
 
std::vector< Id > test::indices (const AdjacencyMatrix &adj)
 

Detailed Description

The AdjacencyMatrix class represents the adjacency matrix of the network.

The AdjacencyMatrix class represents the adjacency matrix of the network. It is defined as \(A = (a_{ij})\), where \(a_{ij} \in \{0, 1\}\). Moreover, \(a_{ij} = 1\) if there is an edge from node \(i\) to node \(j\) and \(a_{ij} = 0\) otherwise. It is used to store the adjacency matrix of the network and to perform operations on it. The adjacency matrix is stored in compressed sparse row format.

Constructor & Destructor Documentation

◆ AdjacencyMatrix() [1/2]

dsm::AdjacencyMatrix::AdjacencyMatrix ( std::string const & fileName)

Construct a new AdjacencyMatrix object using the read method.

Parameters
fileNameThe name of the file containing the adjacency matrix

◆ AdjacencyMatrix() [2/2]

dsm::AdjacencyMatrix::AdjacencyMatrix ( const std::unordered_map< Id, std::unique_ptr< Street > > & streets)

Construct a new AdjacencyMatrix object using the streets of the network.

Parameters
streetsAn std::unordered_map containing the streets of the network

Member Function Documentation

◆ clearCol()

void dsm::AdjacencyMatrix::clearCol ( Id col)

Clear the column at the specified index.

The dimension of the matrix does not change.

◆ clearRow()

void dsm::AdjacencyMatrix::clearRow ( Id row)

Clear the row at the specified index.

The dimension of the matrix does not change.

◆ contains()

bool dsm::AdjacencyMatrix::contains ( Id row,
Id col ) const

Check if the link row -> col exists in the adjacency matrix.

Parameters
rowThe row index of the element
colThe column index of the element
Returns
True if the link exists, false otherwise

This function actually returns element \(a_{ij}\) of the adjacency matrix. Where \(i\) is the row index and \(j\) is the column index.

◆ elements()

std::vector< std::pair< Id, Id > > dsm::AdjacencyMatrix::elements ( ) const

Get a vector containing all the links in the adjacency matrix as pairs of nodes.

Returns
A vector containing all the links in the adjacency matrix as pairs of nodes

◆ empty()

bool dsm::AdjacencyMatrix::empty ( ) const

Check if the adjacency matrix is empty.

Returns
True if the adjacency matrix is empty, false otherwise

◆ getCol()

std::vector< Id > dsm::AdjacencyMatrix::getCol ( Id col) const

Get the column at the specified index.

Parameters
colThe column index
Returns
The column at the specified index

◆ getInDegreeVector()

std::vector< int > dsm::AdjacencyMatrix::getInDegreeVector ( ) const

Get the input degree vector of the adjacency matrix.

Returns
The input degree vector of the adjacency matrix

◆ getOutDegreeVector()

std::vector< int > dsm::AdjacencyMatrix::getOutDegreeVector ( ) const

Get the output degree vector of the adjacency matrix.

Returns
The output degree vector of the adjacency matrix

◆ getRow()

std::vector< Id > dsm::AdjacencyMatrix::getRow ( Id row) const

Get the row at the specified index.

Parameters
rowThe row index
Returns
The row at the specified index

◆ insert()

void dsm::AdjacencyMatrix::insert ( Id row,
Id col )

Inserts the link row -> col in the adjacency matrix.

Parameters
rowThe row index of the element
colThe column index of the element

This function inserts the link \((row, col)\) in the adjacency matrix. Where \(row\) is the row index and \(col\) is the column index.

◆ n()

size_t dsm::AdjacencyMatrix::n ( ) const

Get the number of nodes in the adjacency matrix.

Returns
The number of nodes in the adjacency matrix

◆ operator()()

bool dsm::AdjacencyMatrix::operator() ( Id row,
Id col ) const

Get the link at the specified row and column.

Parameters
rowThe row index of the element
colThe column index of the element
Returns
True if the link exists, false otherwise

This function actually returns element \(a_{ij}\) of the adjacency matrix. Where \(i\) is the row index and \(j\) is the column index.

◆ read()

void dsm::AdjacencyMatrix::read ( std::string const & fileName)

Read the adjacency matrix from a binary file.

Parameters
fileNameThe name of the file containing the adjacency matrix

◆ save()

void dsm::AdjacencyMatrix::save ( std::string const & fileName) const

Write the adjacency matrix to a binary file.

Parameters
fileNameThe name of the file where the adjacency matrix will be written

◆ size()

size_t dsm::AdjacencyMatrix::size ( ) const

Get the number of links in the adjacency matrix.

Returns
The number of links in the adjacency matrix

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