Calculate the degree of the vertices in the graph.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(graph_type), | intent(inout) | :: | this |
Parent. Instance of the graph structure. |
module subroutine calculate_degree(this) !! Calculate the degree of the vertices in the graph. implicit none ! Arguments class(graph_type), intent(inout) :: this !! Parent. Instance of the graph structure. ! Local variables integer :: i, j !! Loop indices. ! Calculate vertex degrees based on storage format if(.not. this%is_sparse)then ! Dense graph: count non-zero adjacency entries this%vertex(:)%degree = 0 do i = 1, this%num_vertices do j = 1, this%num_vertices if(this%adjacency(i,j) .gt. 0)then this%vertex(i)%degree = this%vertex(i)%degree + 1 end if end do end do elseif(this%is_sparse .and. .not. this%directed)then ! Sparse undirected graph: use CSR row pointers this%vertex(:)%degree = 0 do i = 1, this%num_vertices this%vertex(i)%degree = this%adj_ia(i+1) - this%adj_ia(i) end do else ! Sparse directed graph not yet implemented call stop_program('Degree calculation for sparse directed graphs not implemented') end if end subroutine calculate_degree