Build connectivity matrices up to starting from . Results are stored in an array of boolean sparse matrix in Yale format in such a way that ; since FORTRAN is 1-based the useless is not stored.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(yale_sparse), | intent(in) | :: | adj |
Adjacency matrix in Yale format |
||
integer(kind=ip), | intent(in) | :: | n |
Maximum level of connectivity that should be computed |
||
type(yale_sparse), | intent(out), | allocatable | :: | res(:) |
Results connectivity matrices |
|
logical | :: | start_id |
Specifies if the first matrix allocated res(1) should be the identity (true) or the adjacency (false). |
subroutine build_conn_upto_n(adj, n, res, start_id)
!! Build connectivity matrices up to \(\mathbb C_n\)
!! starting from \(\mathbb C_1\). Results are stored in an
!! array of boolean sparse matrix in Yale format in such a way that
!! \(res(n) := \mathbb C_n\); since FORTRAN is 1-based the useless
!! \(\mathbb C_0\) is not stored.
implicit none
type(yale_sparse), intent(in) :: adj
!! Adjacency matrix in Yale format
integer(ip), intent(in) :: n
!! Maximum level of connectivity that should be computed
type(yale_sparse), intent(out), allocatable :: res(:)
!! Results connectivity matrices
logical :: start_id
!! Specifies if the first matrix allocated res(1) should be the
!! identity (true) or the adjacency (false).
integer(ip) :: i, adj_idx
type(yale_sparse) :: tmp, id
if(start_id) then
allocate(res(n+1))
call sparse_identity(adj%n, res(1))
adj_idx = 2
else
allocate(res(n))
adj_idx = 1
end if
call copy_yale_sparse(adj, res(adj_idx))
do i=adj_idx+1, adj_idx+n-1
if(size(res(i-1)%ci) == 0) then
! Create a null matrix
res(i)%n = res(i-1)%n
allocate(res(i)%ri(res(i)%n+1))
res(i)%ri = 1
allocate(res(i)%ci(0))
else
call mat_mult(res(i-1), res(adj_idx), res(i))
!call matcpy(res(i-1), res(i))
call mat_andnot(res(i), res(i-1), tmp)
if(i == adj_idx+1) then
call sparse_identity(adj%n, id)
call mat_andnot(tmp, id, res(i))
if(start_id) then
call copy_yale_sparse(id, res(1))
end if
call free_yale_sparse(id)
else
call mat_andnot(tmp, res(i-2), res(i))
end if
end if
end do
call free_yale_sparse(tmp)
end subroutine build_conn_upto_n