Skip to content

Commit

Permalink
added a method to add edges one at a time
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
jacobwilliams committed Dec 30, 2023
1 parent 3bef523 commit 0bcac21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/dag_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module dag_module
procedure,public :: set_vertices => dag_set_vertices
generic,public :: set_edges => dag_set_edges_no_atts, &
dag_set_edges_vector_atts
procedure,public :: add_edge => dag_add_edge
procedure,public :: remove_edge => dag_remove_edge
procedure,public :: remove_vertex => dag_remove_node
procedure,public :: set_vertex_info => dag_set_vertex_info
Expand Down Expand Up @@ -393,6 +394,26 @@ function dag_get_vertex(me,i) result(v)
end function dag_get_vertex
!*******************************************************************************

!*******************************************************************************
!>
! Add an edge to a dag.

subroutine dag_add_edge(me,ivertex,iedge,label,attributes)

class(dag),intent(inout) :: me
integer(ip),intent(in) :: ivertex !! vertex number
integer(ip),intent(in) :: iedge !! the vertex to connect to `ivertex`
character(len=*),intent(in),optional :: label !! edge label
character(len=*),intent(in),optional :: attributes !! other attributes when
!! saving as a diagraph.

call me%vertices(ivertex)%set_edges(iedge,&
label=label,&
attributes=attributes)

end subroutine dag_add_edge
!*******************************************************************************

!*******************************************************************************
!>
! set the edges for a vertex in a dag
Expand Down
6 changes: 6 additions & 0 deletions test/dag_example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ program dag_example
call d%remove_edge(5_ip,4_ip) ! the orignal node 6 is now 5
call save_plot('test1_node-5-removed_6-4-edge-removed')

! test adding an edge:
call d%add_edge(ivertex=5_ip,iedge=1_ip, &
label='added',&
attributes='penwidth=2,arrowhead=none,color=red')
call save_plot('test1_node-5-removed_6-4-edge-removed-edge-added')

! cleanup:
call d%destroy()

Expand Down

0 comments on commit 0bcac21

Please sign in to comment.