check_graph Function

private function check_graph(graph, source, err) result(ok)

Validate the structural preconditions shared by every algorithm here.

The adjacency must be a structurally sound csr_t, square, non-empty, small enough for a vertex index to fit the heap’s int32 payload, and source must be a real vertex.

Arguments

Type IntentOptional Attributes Name
type(csr_t), intent(in) :: graph

Adjacency matrix to check

integer(kind=default_int), intent(in) :: source

Vertex index that must lie in 1:n

type(error_t), intent(out), optional :: err

Return Value logical

.true. when the graph and vertex are usable


Calls

proc~~check_graph~~CallsGraph proc~check_graph check_graph proc~csr_is_valid csr_t%csr_is_valid proc~check_graph->proc~csr_is_valid proc~csr_n_cols csr_t%csr_n_cols proc~check_graph->proc~csr_n_cols proc~csr_n_rows csr_t%csr_n_rows proc~check_graph->proc~csr_n_rows proc~fail fail proc~check_graph->proc~fail proc~fail~3 fail proc~csr_is_valid->proc~fail~3 proc~error_set error_t%error_set proc~fail->proc~error_set proc~fail~3->proc~error_set

Called by

proc~~check_graph~~CalledByGraph proc~check_graph check_graph proc~a_star a_star proc~a_star->proc~check_graph proc~bfs bfs proc~bfs->proc~check_graph proc~connected_components connected_components proc~connected_components->proc~check_graph proc~dijkstra dijkstra proc~dijkstra->proc~check_graph proc~path_cost path_cost proc~path_cost->proc~check_graph

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: n

Source Code

   function check_graph(graph, source, err) result(ok)
      !! Validate the structural preconditions shared by every algorithm here.
      !!
      !! The adjacency must be a structurally sound `csr_t`, square, non-empty,
      !! small enough for a vertex index to fit the heap's `int32` payload,
      !! and `source` must be a real vertex.
      type(csr_t), intent(in) :: graph
         !! Adjacency matrix to check
      integer(default_int), intent(in) :: source
         !! Vertex index that must lie in `1:n`
      type(error_t), intent(out), optional :: err
      logical :: ok
         !! `.true.` when the graph and vertex are usable

      integer(default_int) :: n

      ok = .false.
      if (.not. graph%is_valid(err)) return

      n = graph%n_rows()
      if (n /= graph%n_cols()) then
         call fail(err, "pic_graph: the adjacency matrix of a graph must be square")
         return
      end if
      if (n < 1) then
         call fail(err, "pic_graph: a graph must have at least one vertex")
         return
      end if
      if (int(n, int64) > int(huge(0_int32), int64)) then
         call fail(err, "pic_graph: vertex count exceeds the int32 payload of the priority queue")
         return
      end if
      if (source < 1 .or. source > n) then
         call fail(err, "pic_graph: vertex index is outside 1:n")
         return
      end if

      ok = .true.
   end function check_graph