Remove edges from the graph.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(graph_type), | intent(inout) | :: | this |
Parent. Instance of the graph structure. |
||
| integer, | intent(in), | dimension(:) | :: | indices |
Indices of the edges to be removed. |
|
| logical, | intent(in), | optional | :: | update_adjacency |
Boolean whether to update the adjacency matrix. Default is True. |
module subroutine remove_edges(this, indices, update_adjacency) !! Remove edges from the graph. implicit none ! Arguments class(graph_type), intent(inout) :: this !! Parent. Instance of the graph structure. integer, dimension(:), intent(in) :: indices !! Indices of the edges to be removed. logical, intent(in), optional :: update_adjacency !! Boolean whether to update the adjacency matrix. Default is True. ! Local variables integer :: i, k !! Loop indices. logical :: update_adjacency_ = .true. !! Boolean whether to update the adjacency matrix. integer, dimension(size(indices, dim=1)) :: edge_indices !! Indices of the vertices to be removed. if(present(update_adjacency)) update_adjacency_ = update_adjacency ! Remove edges in descending order to maintain index validity edge_indices = indices do i = 1, size(indices) k = maxval(edge_indices) ! Update vertex degrees this%vertex(this%edge(k)%index(1))%degree = & this%vertex(this%edge(k)%index(1))%degree - 1 if(.not. this%directed)then this%vertex(abs(this%edge(k)%index(2)))%degree = & this%vertex(abs(this%edge(k)%index(2)))%degree - 1 elseif(this%edge(k)%index(2) .gt. 0)then this%vertex(this%edge(k)%index(2))%degree = & this%vertex(this%edge(k)%index(2))%degree - 1 end if ! Remove edge from array this%edge = [this%edge(1:k-1:1), this%edge(k+1:this%num_edges)] this%num_edges = this%num_edges - 1 edge_indices(maxloc(edge_indices,1)) = 0 end do if(update_adjacency_) call this%generate_adjacency() end subroutine remove_edges