set_num_vertices Module Subroutine

module subroutine set_num_vertices(this, num_vertices, num_vertex_features)

Set the number of vertices of the graph.

This will deallocate the existing vertices and edges and set the number of vertices. New vertices will be allocated but not initialised.

Arguments

Type IntentOptional Attributes Name
class(graph_type), intent(inout) :: this

Parent. Instance of the graph structure.

integer, intent(in) :: num_vertices

Number of vertices in the graph.

integer, intent(in), optional :: num_vertex_features

Source Code

  module subroutine set_num_vertices(this, num_vertices, num_vertex_features)
    !! Set the number of vertices of the graph.
    !!
    !! This will deallocate the existing vertices and edges
    !! and set the number of vertices.
    !! New vertices will be allocated but not initialised.
    implicit none

    ! Arguments
    class(graph_type), intent(inout) :: this
    !! Parent. Instance of the graph structure.
    integer, intent(in) :: num_vertices
    !! Number of vertices in the graph.
    integer, intent(in), optional :: num_vertex_features

    ! Deallocate existing data
    if(allocated(this%vertex)) deallocate(this%vertex)
    if(allocated(this%edge)) deallocate(this%edge)
    if(allocated(this%adj_ia)) deallocate(this%adj_ia)
    if(allocated(this%adj_ja)) deallocate(this%adj_ja)
    if(allocated(this%adjacency)) deallocate(this%adjacency)
    
    ! Set new dimensions
    this%num_vertices = num_vertices
    this%num_edges = 0
    if(present(num_vertex_features)) this%num_vertex_features = num_vertex_features
    
    ! Allocate appropriate storage
    if(this%is_sparse)then
       allocate(this%vertex_features(this%num_vertex_features, this%num_vertices))
    else
       allocate(this%vertex(num_vertices))
    end if
  end subroutine set_num_vertices