subroutinedescribe_graphprivate
subroutine describe_graph(p, s, relation, job, w, g, found)
Put the graph of job in g. found is false if it would have only one node or no edges. Nodes go
in as they are reached, and edges after them. A node that leads to more than graph_maxdepth and
graph_maxnodes let in has an edge to a node ....
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| p | type(project_t) | in | the project | |
| s | type(settings_t) | in | the settings | |
| relation | type(adjacency_t) | in | the relation | |
| job | type(graph_job_t) | in | the graph | |
| w | type(walk_t) | inout | the working space | |
| g | type(layout_t) | out | the description | |
| found | logical | out | whether there is a graph |
Calls
- leads_on
- grow_edges
- add_node
- add_edge
Called by
Source
Show the code
subroutine describe_graph(p, s, relation, job, w, g, found)
type(project_t), intent(in) :: p !! the project
type(settings_t), intent(in) :: s !! the settings
type(adjacency_t), intent(in) :: relation !! the relation
type(graph_job_t), intent(in) :: job !! the graph
type(walk_t), intent(inout) :: w !! the working space
type(layout_t), intent(out) :: g !! the description
logical, intent(out) :: found !! whether there is a graph
integer, allocatable :: next(:)
integer :: head, k, id, other, j, reached, edges, dots
w%stamp = w%stamp + 1
reached = size(job%roots)
do k = 1, reached
w%marked(job%roots(k)) = w%stamp
w%queue(k) = job%roots(k)
w%levels(k) = 0
end do
w%more(:reached) = .false.
head = 1
edges = 0
do while (head <= reached)
id = w%queue(head)
if (w%levels(head) >= job%max_depth) then
w%more(head) = leads_on(id)
else
if (job%forward) then
if (allocated(relation%out(id)%ids)) then
next = relation%out(id)%ids
else
allocate (next(0))
end if
else
if (allocated(relation%in(id)%ids)) then
next = relation%in(id)%ids
else
allocate (next(0))
end if
end if
do j = 1, size(next)
other = next(j)
if (p%list%box(other)%e%kind == E_NONE) cycle
if (w%marked(other) /= w%stamp) then
if (reached >= job%max_nodes) then
w%more(head) = .true.
cycle
end if
w%marked(other) = w%stamp
reached = reached + 1
w%queue(reached) = other
w%levels(reached) = w%levels(head) + 1
w%more(reached) = .false.
end if
edges = edges + 1
if (edges > size(w%from)) call grow_edges(w)
w%from(edges) = merge(id, other, job%forward)
w%to(edges) = merge(other, id, job%forward)
end do
deallocate (next)
end if
head = head + 1
end do
found = reached > 1 .and. edges > 0
if (.not. found) return
call g%initialize(direction=job%direction, concentrate=.true.)
do k = 1, reached
call add_node(p, w%queue(k), k == 1 .and. size(job%roots) == 1, g, w%places(w%queue(k)))
end do
do k = 1, edges
call add_edge(s, relation, w%from(k), w%to(k), w%places, g)
end do
do k = 1, reached
if (.not. w%more(k)) cycle
call g%add_node('...', dots, fill='#8a93a5')
if (job%forward) then
call g%add_edge(w%places(w%queue(k)), dots, dashed=.true.)
else
call g%add_edge(dots, w%places(w%queue(k)), dashed=.true.)
end if
end do
contains
!> True if entity `id` has neighbours in the direction of the graph that are not in it.
logical function leads_on(id)
integer, intent(in) :: id !! the entity
integer :: m
leads_on = .false.
if (job%forward) then
if (.not. allocated(relation%out(id)%ids)) return
do m = 1, size(relation%out(id)%ids)
if (p%list%box(relation%out(id)%ids(m))%e%kind == E_NONE) cycle
if (w%marked(relation%out(id)%ids(m)) /= w%stamp) leads_on = .true.
end do
else
if (.not. allocated(relation%in(id)%ids)) return
do m = 1, size(relation%in(id)%ids)
if (p%list%box(relation%in(id)%ids(m))%e%kind == E_NONE) cycle
if (w%marked(relation%in(id)%ids(m)) /= w%stamp) leads_on = .true.
end do
end if
end function leads_on
end subroutine describe_graph