Version & licenses
Creative Commons License

Graph.S

Guyslain Naves

  1. module type S =
  2. sig


  3. (**all functions may raise Not_found if called with incorrect arguments *)

  4. type edge
  5. type vertex
  6. type graph

  7. (** Ordering on vertices and edges, also used for test for equality. *)
  8. val compare_vertex : vertex -> vertex -> int
  9. val compare_edge : edge -> edge -> int

  10. (** The graph without vertex *)
  11. val empty : graph

  12. (** [add_vertex graph v]: a graph obtained by adding an isolated vertex [v] to [graph] *)
  13. (** raise Invalid_arg if [v] is already in [graph] *)
  14. val add_vertex : graph -> vertex -> graph

  15. (** [add_edge graph u v e]: a graph obtained by adding an edge [e] between [u] and [v] in [graph] *)
  16. (** raise Invalid_arg if [e] is already in [graph] *)
  17. (** raise Not_found if [u] and [v] are not vertices of [graph] *)
  18. val add_edge : graph -> vertex -> vertex -> edge -> graph

  19. (** [remove_vertex graph v]: a graph obtained by removing [v] from [graph],
  20. and all the incident arcs to [v] in [graph]
  21. *)
  22. val remove_vertex : graph -> vertex -> graph

  23. (** [remove_edge graph edge]: a graph obtained by deleting [edge] in [graph]. *)
  24. val remove_edge : graph -> edge -> graph


  25. (** modules for set of vertices and edges*)
  26. module V : Set.S with type elt = vertex
  27. module E : Set.S with type elt = edge

  28. (** modules for partial function on vertices and edges *)
  29. module VMap : Map.S with type key = vertex
  30. module EMap : Map.S with type key = edge

  31. (** [v graph] is the vertex set of [graph] *)
  32. val v : graph -> V.t

  33. (** [e graph] is the edge set of [graph] *)
  34. val e : graph -> E.t


  35. (** [tail graph edge] is the first vertex of the arc [edge] in [graph] *)
  36. val tail : graph -> edge -> vertex

  37. (** [head graph edge] is the second vertex of the arc [edge] in [graph] *)
  38. val head : graph -> edge -> vertex

  39. (** [extremities graph edge] is the couple of vertices of [edge] in [graph] *)
  40. val extremities : graph -> edge -> vertex * vertex

  41. (** [opposite graph e v], where [v] is an extremity of [e], is the other extremity of [e]
  42. ([v] if [e] is a loop) *)
  43. val opposite : graph -> edge -> vertex -> vertex


  44. (** [delta_in graph v] is the set of arcs entering [v] in [graph] *)
  45. val delta_in : graph -> vertex -> E.t

  46. (** [delta_out graph v] is the set of arcs leaving [v] in [graph] *)
  47. val delta_out : graph -> vertex -> E.t

  48. (** [delta graph v] is the set of arcs incident to [v] in [graph] *)
  49. val delta : graph -> vertex -> E.t

  50. (** [in_neighbour graph v] is the set of vertices with an arc to [v] in [graph] *)
  51. val in_neighbour : graph -> vertex -> V.t

  52. (** [out_neighbour graph v] is the set of vertices with an arc from [v] in [graph] *)
  53. val out_neighbour : graph -> vertex -> V.t

  54. (** [neighbour graph v] is the set of vertices adjacent to [v] in [graph] *)
  55. val neighbour : graph -> vertex -> V.t


  56. (** [adjacent graph u v] checks whether [u] and [v] are adjacent in [graph] *)
  57. val adjacent : graph -> vertex -> vertex -> bool

  58. (** [edge graph u v] is an arbitrary edge with endpoints [u] and [v] in [graph] *)
  59. (** raise Not_found if none exists *)
  60. val edge : graph -> vertex -> vertex -> edge


  61. (** [arcs graph u v] is the set of arcs from [u] to [v] in [graph] *)
  62. val arcs : graph -> vertex -> vertex -> E.t

  63. (** [edges graph u v] is the set of edges with endpoints [u] and [v] in [graph] *)
  64. val edges : graph -> vertex -> vertex -> E.t

  65. (** [induced graph vertex_set] is the graph induced by [vertex_set] in [graph] *)
  66. val induced : graph -> V.t -> graph

  67. (** [subgraph graph edge_set] is the subgraph of [graph] with edge set [edge_set] *)
  68. val subgraph : graph -> E.t -> graph

  69. (** [contract graph ?v e] is the graph obtained by contracting edge [e] in [graph].
  70. The optional argument [v] is the vertex obtained by this contraction.
  71. By default, it is one of the endpoints of [e] in [graph]
  72. *)
  73. val contract : graph -> ?w:vertex -> edge -> graph

  74. (** [identify graph ?v vertex_set] is the graph obtained from [graph]
  75. by identifying all the vertices in [vertex_set].
  76. It may have multiple edges or loops.
  77. The optional argument is the vertex corresponding to the identification in the result graph.
  78. By default, it is a vertex of [vertex_set].
  79. *)
  80. val identify : graph -> ?w:vertex -> V.t -> graph

  81. (** [simplify graph vertex] is the graph obtained by removing all the loops at [vertex],
  82. and keeping only one edge of every set of parallel edges incident to [vertex] in [graph].
  83. *)
  84. val simplify : graph -> vertex -> graph

  85. (** same as simplify, but keeps a copy of an arc in both direction if possible *)
  86. val directed_simplify : graph -> vertex -> graph


  87. (** additional modules for vertices and edges manipulation *)
  88. module VFun : Cmap.CMAP with type elt = vertex
  89. module VCount : Counter.COUNTER with type elt = vertex
  90. module EFun : Cmap.CMAP with type elt = edge
  91. module ECount : Counter.COUNTER with type elt = edge


  92. end