23

TheAverellLibrarysimonet/soft/averell/averell-0.03.pdf · 2015-04-18 · val iter_nodes : (node -> unit) -> graph -> unit iter_nodes f gappliesfoneverynodesofthegraphg. Theorderinwhichnodesare

  • Upload
    others

  • View
    30

  • Download
    0

Embed Size (px)

Citation preview

The Averell Library

December 2, 2002

Contents1 Module Avl_topo : Topological sort of a graph. 1

1.1 Module type Avl_topo.GRAPH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Module Avl_topo.Make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Module Avl_tarjan : Tarjan's algorithm: calculating SCC of a graph in lineartime. 22.1 Module type Avl_tarjan.GRAPH : The client must provide an implementation of

graphs which full�lls the signature GRAPH. . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Module Avl_tarjan.Make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Module Avl_closure : Transitive closure of a directed graph. 43.1 Module type Avl_closure.GRAPH : The client must provide an implementation of

graph which full�lls the signature GRAPH. . . . . . . . . . . . . . . . . . . . . . . . . . 43.2 Module Avl_closure.Make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

4 Module Avl_kernel : Transitive reduction of a directed graph. 54.1 Case of acyclic graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64.2 General case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64.3 Module type Avl_kernel.GRAPH_acyclic : For this implementation, the client must

provide an implementation of graph which full�lls the signature GRAPH_acyclic . . . 64.4 Module Avl_kernel.Make_acyclic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.5 Module type Avl_kernel.GRAPH : The client must provide an implementation of

graph which full�lls the signature GRAPH. . . . . . . . . . . . . . . . . . . . . . . . . . 74.6 Module Avl_kernel.Make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

5 Module Avl_graphviz : Interface with GraphViz 85.1 Common stu� . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5.1.1 Common attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95.2 Interface with the dot engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95.3 The neato engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95.4 Module Avl_graphviz.CommonAttributes : The CommonAttributes module de�nes

attributes for graphs, nodes and edges that are available in the two engines, dot andneato. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5.5 Module Avl_graphviz.Dot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105.5.1 Module Avl_graphviz.Dot.Attributes . . . . . . . . . . . . . . . . . . . . . 11

1

5.5.2 Module type Avl_graphviz.Dot.INPUT . . . . . . . . . . . . . . . . . . . . . 135.5.3 Module Avl_graphviz.Dot.Make . . . . . . . . . . . . . . . . . . . . . . . . . 14

5.6 Module Avl_graphviz.Neato . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145.6.1 Module Avl_graphviz.Neato.Attributes . . . . . . . . . . . . . . . . . . . . 155.6.2 Module type Avl_graphviz.Neato.INPUT . . . . . . . . . . . . . . . . . . . . 165.6.3 Module Avl_graphviz.Neato.Make . . . . . . . . . . . . . . . . . . . . . . . . 17

6 Module Avl_draw : Drawing graphs. 176.1 Drawing attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

6.1.1 Nodes attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.1.2 Edges attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

6.2 Client's signatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.3 Make functor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.4 Module type Avl_draw.GRAPH : The client must provide an implementation of graphs

which full�lls the signature GRAPH. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.5 Module type Avl_draw.DRAW : The client must provide drawing functions which full-

�lls the signature DRAW. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.6 Module Avl_draw.DrawGraphics : DrawGraphics provides an implementation of sig-

nature DRAW for the graphics library of Objective Caml. . . . . . . . . . . . . . . . . 216.7 Module Avl_draw.Make : Given an implementation of drawing capabilities and of

graphs structures, the functor Make provide drawing functions for graphs. . . . . . . 216.8 Module Avl_draw.MakeGraphics : Given an implementation of graphs structures,

the functor MakeGraphics provides drawing functions for the Objective Caml graphicslibrary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

1 Module Avl_topo : Topological sort of a graph.Let G be a graph whose nodes are x1, . . ., xn. Sorting G in the topological order consists inenumerating succesivelly the nodes xs(1), . . ., xs(n) such that for all i and j, if G has an edge xs(i) →x(j) then i < j.

The client must provide an implementation of graph which full�lls the signature GRAPH.module type GRAPH = sig end

[1.1]module Make : functor (X : GRAPH) -> sig end

[1.2]

1.1 Module type Avl_topo.GRAPH

module type GRAPH = sig

type graphThe type of graphs.

type nodeThe type of nodes.

2

val iter_nodes :(node -> unit) -> graph -> unit

iter_nodes f g applies f on every nodes of the graph g. The order in which nodes areconsidered does not matter. However, each node must be considered exactly once.

val iter_successors :(node -> unit) -> node -> unit

iter_successors f nd applies f on every successors of the node nd in its graph. The orderin which successors are considere does not matter. Multiple occurences of the same successorare allowed.

val get : node -> intEvery node must carry a transient integer �eld. No assumption is made on the initialcontent of this �eld. The following functions allows reading and updating this �eld.

val set : node -> int -> unitend

1.2 Module Avl_topo.Make

module Make : sigParameters:

• X : Avl_topo.GRAPH

exception CyclicWhen applied on a graph containing a cycle, functions of this module raise the exceptionCyclic.

val fold : (X.node -> 'a -> 'a) -> 'a -> X.graph -> 'afold f accu g performs a topological sort of the graph g. The result is f xn (f ... (fx2 (f x1 accu))) where x1, . . ., xn is an acceptable ordering of the nodes.

val iter : (X.node -> unit) -> X.graph -> unititer f g applies f on every node of the graph g, in an order compatible with topologicalsort.

val list : X.graph -> X.node listlist g returns the list of nodes of g ordered topologically.

val stack : X.graph -> X.node Stack.t

3

stack g returns a stack containing the nodes of g ordered topologically.

val queue : X.graph -> X.node Queue.tqueue g returns a queue containing the nodes of g ordered topologically.

end

2 Module Avl_tarjan : Tarjan's algorithm: calculating SCC of agraph in linear time.

This module provides an implementation of Tarjan's algorithm. This algorithm computes the strongconnex composants of a directed graph (SCC). A SCC of a graph $G = (X, E)$ is a subset of $X$such that for every pair of nodes $x_1$ and $x_2$ in $X$ there exists a path from the former tothe latter in $G$. The SCCs of $G$ form a partition of $X$.

The Tarjan's algorithm has a time complexity in $O(n)$ (where $n$ is the number of nodes ofthe input graph).

Functions provided by this module are not reentering thread safe as long as at most one threadoperates on the same graph at the same time.

module type GRAPH = sig end[2.1]

module Make : functor (X : GRAPH) -> sig end[2.2]

2.1 Module type Avl_tarjan.GRAPH : The client must provide an implementationof graphs which full�lls the signature GRAPH.

module type GRAPH = sig

type graphThe type of graphs.

type nodeThe type of nodes.

val iter_nodes :(node -> unit) -> graph -> unit

iter_nodes f g applies f on every nodes of the graph g. The order in which nodes areconsidered does not matter and may change between di�erent application of the function onthe same graph. However, each node must be considered exactly once.

val iter_successors :(node -> unit) -> node -> unit

4

iter_successors f nd applies f on every successors of the node nd in its graph. The orderin which successors are considere does not matter. The graph is not required to be simple(i.e. iter_successors f nd may apply f an arbitrary number of time the function f oneach of nd's successors, as long as this number is �xed.

val get : node -> intEvery node must carry a transient integer �eld. The following functions allows reading andupdating this �eld. No assumption is made by the module on the initial content of this �eldat each function call. However, the client cannot make any assumption on the �nal contenttoo.

val set : node -> int -> unitend

2.2 Module Avl_tarjan.Make

module Make : sigParameters:

• X : Avl_tarjan.GRAPH

val fold :'a -> (X.node -> 'a -> 'a) -> 'b -> ('a -> 'b -> 'b) -> X.graph -> 'b

fold empty add_class singleton add g runs the Tarjan's algorithm on the graph g. Itreturns a partition of the set of the nodes of the graph (i.e. a set of set of nodes), which iscomputed as follows:• empty is the empty partition,• add_class c p adds the class c to the partition p,• singleton nd returns the class with one element nd,• add nd c add the node nd to the class c.

val list : X.graph -> X.node list listlist g computes the SCCs of a graph. The result is a list of list of nodes: each list gives thenodes of one of the SCCs.

val unify : (X.node -> X.node -> unit) -> X.graph -> unitunify unifier graph computes the SCCs of a graph. For every SCC, it chooses aparticular node nd, and for every other node nd' of the SCC, unifier nd nd' is called.

end

5

3 Module Avl_closure : Transitive closure of a directed graph.This module allows computing the transitive closure of a directed graph. Given a graph G = (X,E), the strict transitive closure of G is the graph G' = (X, E') such that there is an edge from x toy in G' if and only if there is a non-empty path from x to y in G.

module type GRAPH = sig end[3.1]

module Make : functor (X : GRAPH) -> sig end[3.2]

3.1 Module type Avl_closure.GRAPH : The client must provide an implementa-tion of graph which full�lls the signature GRAPH.

module type GRAPH = sig

type graphThe type of graphs.

type nodeThe type of nodes.

val iter_nodes :(node -> unit) -> graph -> unit

iter_nodes f g applies f on every nodes of the graph g. The order in which nodes areconsidered does not matter. However, each node must be considered exactly once.

val iter_successors :(node -> unit) -> node -> unit

iter_successors f nd applies f on every successors of the node nd in its graph. The orderin which successors are considere does not matter. Multiple occurences of the same successorare allowed.

val get : node -> intEvery node must carry a transient integer �eld. No assumption is made about the initialcontent. The following functions allows reading and updating this �eld.

val set : node -> int -> unitend

3.2 Module Avl_closure.Make

module Make : sigParameters:• X : Avl_closure.GRAPH

6

val fold : 'a -> (X.node -> X.node -> 'a -> 'a) -> X.graph -> 'afold empty add g computes the strict transitive closure of the graph g. The functionreturns the set of edges of the resulting graph. This set is computed thanks to parametersempty and add:• empty is the empty initial set,• add nd1 nd2 s returns the set obtained by adding the edge nd1 -> nd2 to the set s.

end

4 Module Avl_kernel : Transitive reduction of a directed graph.This module allows computing the transitive reduction of a directed graph. Given a acyclic graph G= (X, E), the transitive reduction of G is the smallest graph G' = (X, E') such that the transitiveclosure of G' is G.

Reference: A.V. Aho, M.R. Garey and J.D. Ullman (HP). The Transitive Reduction of a DirectedGraph. SIAM Journal on Computing, 1(2), pp. 131-137, June 1972.

4.1 Case of acyclic graphs

This �rst implementation handles only acyclic graphs.module type GRAPH_acyclic = sig end

[4.3]module Make_acyclic : functor (X : GRAPH_acyclic) -> sig end

[4.4]

4.2 General case

type 'a sccIn the general case, nodes must provide an additional internal �eld of type 'a scc.

val scc : unit -> 'a sccscc () returns a fresh value of type 'a scc

module type GRAPH = sig end[4.5]

module Make : functor (X : GRAPH) -> sig end[4.6]

4.3 Module type Avl_kernel.GRAPH_acyclic : For this implementation, the clientmust provide an implementation of graph which full�lls the signature GRAPH_acyclic.

module type GRAPH_acyclic = sig

7

type graphThe type of graphs.

type nodeThe type of nodes.

val iter_nodes :(node -> unit) ->graph -> unit

iter_nodes f g applies f on every nodes of the graph g. The order in which nodes areconsidered does not matter. However, each node must be considered exactly once.

val iter_successors :(node -> unit) ->node -> unit

iter_successors f nd applies f on every successors of the node nd in its graph. The orderin which successors are considere does not matter. Multiple occurences of the same successorare allowed.

val get : node -> intEvery node must carry a transient integer �eld. No assumption is made about the initialcontent. The following functions allows reading and updating this �eld.

val set : node -> int -> unitend

4.4 Module Avl_kernel.Make_acyclic

module Make_acyclic : sigParameters:

• X : Avl_kernel.GRAPH_acyclic

exception Cyclicval fold : 'a -> (X.node -> X.node -> 'a -> 'a) -> X.graph -> 'a

fold g computes the transitive reduction of the graph g. The graph g is supposed to beacyclic, otherwise the exception Cyclic is raised. The function returns the set of edges ofthe resulting graph. This set is computed thanks to parameters empty and add:• empty is the empty initial set,• add nd1 nd2 s returns the set obtained by adding the edge nd1 -> nd2 to the set s.

end

8

4.5 Module type Avl_kernel.GRAPH : The client must provide an implementationof graph which full�lls the signature GRAPH.

module type GRAPH = sig

type graphThe type of graphs.

type nodeThe type of nodes.

val iter_nodes :(node -> unit) -> graph -> unit

iter_nodes f g applies f on every nodes of the graph g. The order in which nodes areconsidered does not matter. However, each node must be considered exactly once.

val iter_successors :(node -> unit) -> node -> unit

iter_successors f nd applies f on every successors of the node nd in its graph. The orderin which successors are considere does not matter. Multiple occurences of the same successorare allowed.

val get_scc : node -> node Avl_kernel.sccEvery node must carry a transient �eld of type node scc. The following functions allowsreading and updating this �eld.

val set_scc :node -> node Avl_kernel.scc -> unit

val get : node -> intEvery node must carry a transient integer �eld. No assumption is made about the initialcontent. The following functions allows reading and updating this �eld.

val set : node -> int -> unitend

4.6 Module Avl_kernel.Make

module Make : sigParameters:• X : Avl_kernel.GRAPH

val fold : 'a -> (X.node -> X.node -> 'a -> 'a) -> X.graph -> 'afold g computes the transitive reduction of the graph g.

end

9

5 Module Avl_graphviz : Interface with GraphVizThis module provides a basic interface with dot and neato, two programs of the GraphViz toolbox.These tools are available at the following URLs:

http://www.graphviz.org/

http://www.research.att.com/sw/tools/graphviz/

5.1 Common stu�

Because the neato and dot engines present a lot of common points - in particular in the graphdescription language, large parts of the code is shared. First, the !CommonAttributes modulede�nes attributes of graphs, nodes and edges that are understood by the two engines. Second,given a module (of type !ENGINE) describing an engine the !MakeEngine functor provides suitableinterface function for it.

5.1.1 Common attributes

type color = inttype arrow_style = [ `Dot

| `Inv| `Invdot| `Invodot| `None| `Normal| `Odot]

module CommonAttributes : sig end[5.4]

5.2 Interface with the dot engine

module Dot : sig end[5.5]

5.3 The neato engine

module Neato : sig end[5.6]

5.4 Module Avl_graphviz.CommonAttributes : The CommonAttributes module de-�nes attributes for graphs, nodes and edges that are available in the twoengines, dot and neato.

module CommonAttributes : sig

10

type graph = [ `Center of bool| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontsize of int| `Label of string| `Orientation of [ `Landscape | `Portrait]| `Page of float * float| `Pagedir of [ `LeftToRight | `TopToBottom]| `Size of float * float]

Attributes of graphs.

type node = [ `Color of Avl_graphviz.color| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontsize of int| `Height of float| `Label of string| `Orientation of float| `Peripheries of int| `Regular of bool| `Shape of

[ `Box| `Circle| `Diamond| `Doublecircle| `Ellipse| `Plaintext| `Polygon of int * float| `Record]

| `Style of[ `Bold | `Dashed | `Dotted | `Filled | `Invis | `Solid]

| `Width of float]Attributes of nodes.

type edge = [ `Color of Avl_graphviz.color| `Decorate of bool| `Dir of [ `Back | `Both | `Forward | `None]| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontsize of int| `Label of string| `Labelfontcolor of Avl_graphviz.color| `Labelfontname of string| `Labelfontsize of int| `Style of [ `Bold | `Dashed | `Dotted | `Invis | `Solid]]

Attributes of edges.

end

11

5.5 Module Avl_graphviz.Dot

module Dot : sig

val set_command : string -> unitSeveral functions provided by this module run the external program dot. By default, thiscommand is supposed to be in the default path and is invoked by dot. The functionset_command allows to set an alternative path at run time.

module Attributes : sig end[5.5.1]

module type INPUT = sig end[5.5.2]

module Make : functor (X : INPUT) -> sig end[5.5.3]

end

5.5.1 Module Avl_graphviz.Dot.Attributes

module Attributes : sig

type graph = [ `Bgcolor of Avl_graphviz.color| `Center of bool| `Comment of string| `Concentrate of bool| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontpath of string| `Fontsize of int| `Label of string| `Layers of string list| `Margin of float| `Mclimit of float| `Nodesep of float| `Nslimit of int| `Nslimit1 of int| `Orientation of [ `Landscape | `Portrait]| `Page of float * float| `Pagedir of [ `LeftToRight | `TopToBottom]| `Quantum of float| `Rankdir of [ `LeftToRight | `TopToBottom]| `Ranksep of float| `Ratio of [ `Auto | `Compress | `Fill | `Float of float]| `Samplepoints of int| `Size of float * float| `Url of string]

Attributes of graphs. They include all common graph attributes and several speci�c ones.

12

All attributes described in the "dot User's Manual, February 4, 2002" are handled, excepted:clusterank, color, compound, labeljust, labelloc, ordering, rank, remincross, rotate, searchsizeand style.

type node = [ `Color of Avl_graphviz.color| `Comment of string| `Distortion of float| `Fillcolor of Avl_graphviz.color| `Fixedsize of bool| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontsize of int| `Height of float| `Label of string| `Layer of string| `Orientation of float| `Peripheries of int| `Regular of bool| `Shape of

[ `Box| `Circle| `Diamond| `Doublecircle| `Ellipse| `Plaintext| `Polygon of int * float| `Record]

| `Style of[ `Bold | `Dashed | `Dotted | `Filled | `Invis | `Solid]

| `Url of string| `Width of float| `Z of float]

Attributes of nodes. They include all common node attributes and several speci�c ones. Allattributes described in the "dot User's Manual, February 4, 2002" are handled, excepted:bottomlabel, group, shape�le and toplabel.

type edge = [ `Arrowhead of Avl_graphviz.arrow_style| `Arrowsize of float| `Arrowtail of Avl_graphviz.arrow_style| `Color of Avl_graphviz.color| `Comment of string| `Constraints of bool| `Decorate of bool| `Dir of [ `Back | `Both | `Forward | `None]| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontsize of int

13

| `Headlabel of string| `Headport of [ `E | `N | `NE | `NW | `S | `SE | `SW | `W]| `Headurl of string| `Label of string| `Labelangle of float| `Labeldistance of float| `Labelfloat of bool| `Labelfontcolor of Avl_graphviz.color| `Labelfontname of string| `Labelfontsize of int| `Layer of string| `Minlen of int| `Samehead of string| `Sametail of string| `Style of [ `Bold | `Dashed | `Dotted | `Invis | `Solid]| `Taillabel of string| `Tailport of [ `E | `N | `NE | `NW | `S | `SE | `SW | `W]| `Tailurl of string| `Weight of int]

Attributes of edges. They include all common edge attributes and several speci�c ones. Allattributes described in the "dot User's Manual, February 4, 2002" are handled, excepted:lhead and ltail.

end

5.5.2 Module type Avl_graphviz.Dot.INPUT

module type INPUT = sig

type graphtype nodetype edgeval iter_nodes :(node -> unit) ->graph -> unit

val iter_edges :(edge -> unit) ->graph -> unit

val graph_attributes :graph -> Avl_graphviz.Dot.Attributes.graph list

val default_node_attributes :graph -> Avl_graphviz.Dot.Attributes.node list

val default_edge_attributes :graph -> Avl_graphviz.Dot.Attributes.edge list

val node_name : node -> stringval node_attributes :

14

node -> Avl_graphviz.Dot.Attributes.node listval edge_head : edge -> nodeval edge_tail : edge -> nodeval edge_attributes :edge -> Avl_graphviz.Dot.Attributes.edge list

end

5.5.3 Module Avl_graphviz.Dot.Make

module Make : sigParameters:• X : Avl_graphviz.Dot.INPUT

exception Error of stringval handle_error : ('a -> 'b) -> 'a -> 'bval fprint_graph : Format.formatter -> X.graph -> unit

fprint_graph ppf graph pretty prints the graph graph in the CGL language on theformatter ppf.

val output_graph : Pervasives.out_channel -> X.graph -> unitoutput_graph oc graph pretty prints the graph graph in the dot language on the channeloc.

val run_graph :[ `Gif | `HpGl | `Imap | `Ismap | `Mif | `Plain | `PostScript] ->(Pervasives.in_channel -> 'a) -> X.graph -> 'a

run_graph output_mode f graph runs the engine on the graph graph. The function f isapplied with the input channel where the engine writes its output as argument. Thisfunction must not close the channel. The format of the output is speci�ed by theoutput_mode argument which may be one of the following `PostScript | `Mif | `HpGl| `Gif | `Imap | `Ismap | `Plain .

end

5.6 Module Avl_graphviz.Neato

module Neato : sig

val set_command : string -> unitSeveral functions provided by this module run the external program neato. By default, thiscommand is supposed to be in the default path and is invoked by neato. The functionset_command allows to set an alternative path at run time.

15

module Attributes : sig end[5.6.1]

module type INPUT = sig end[5.6.2]

module Make : functor (X : INPUT) -> sig end[5.6.3]

end

5.6.1 Module Avl_graphviz.Neato.Attributes

module Attributes : sig

type graph = [ `Center of bool| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontsize of int| `Label of string| `Margin of float * float| `Orientation of [ `Landscape | `Portrait]| `Overlap of bool| `Page of float * float| `Pagedir of [ `LeftToRight | `TopToBottom]| `Sep of float| `Size of float * float| `Spline of bool| `Start of int]

Attributes of graphs. They include all common graph attributes and several speci�c ones.All attributes described in the "Neato User's manual, April 10, 2002" are handled.

type node = [ `Color of Avl_graphviz.color| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontsize of int| `Height of float| `Label of string| `Orientation of float| `Peripheries of int| `Pos of float * float| `Regular of bool| `Shape of

[ `Box| `Circle| `Diamond| `Doublecircle| `Ellipse| `Plaintext| `Polygon of int * float

16

| `Record]| `Style of

[ `Bold | `Dashed | `Dotted | `Filled | `Invis | `Solid]| `Width of float]

Attributes of nodes. They include all common node attributes and several speci�c ones. Allattributes described in the "Neato User's manual, April 10, 2002" are handled.

type edge = [ `Color of Avl_graphviz.color| `Decorate of bool| `Dir of [ `Back | `Both | `Forward | `None]| `Fontcolor of Avl_graphviz.color| `Fontname of string| `Fontsize of int| `Id of string| `Label of string| `Labelfontcolor of Avl_graphviz.color| `Labelfontname of string| `Labelfontsize of int| `Len of float| `Style of [ `Bold | `Dashed | `Dotted | `Invis | `Solid]| `Weight of float]

Attributes of edges. They include all common edge attributes and several speci�c ones. Allattributes described in the "Neato User's manual, April 10, 2002" are handled.

end

5.6.2 Module type Avl_graphviz.Neato.INPUT

module type INPUT = sig

type graphtype nodetype edgeval iter_nodes :(node -> unit) ->graph -> unit

val iter_edges :(edge -> unit) ->graph -> unit

val graph_attributes :graph -> Avl_graphviz.Neato.Attributes.graph list

val default_node_attributes :graph -> Avl_graphviz.Neato.Attributes.node list

val default_edge_attributes :graph -> Avl_graphviz.Neato.Attributes.edge list

val node_name : node -> string

17

val node_attributes :node -> Avl_graphviz.Neato.Attributes.node list

val edge_head :edge -> node

val edge_tail :edge -> node

val edge_attributes :edge -> Avl_graphviz.Neato.Attributes.edge list

end

5.6.3 Module Avl_graphviz.Neato.Make

module Make : sigParameters:• X : Avl_graphviz.Neato.INPUT

exception Error of stringval handle_error : ('a -> 'b) -> 'a -> 'bval fprint_graph : Format.formatter -> X.graph -> unit

fprint_graph ppf graph pretty prints the graph graph in the CGL language on theformatter ppf.

val output_graph : Pervasives.out_channel -> X.graph -> unitoutput_graph oc graph pretty prints the graph graph in the dot language on the channeloc.

val run_graph :[ `Gif | `HpGl | `Imap | `Ismap | `Mif | `Plain | `PostScript] ->(Pervasives.in_channel -> 'a) -> X.graph -> 'a

run_graph output_mode f graph runs the engine on the graph graph. The function f isapplied with the input channel where the engine writes its output as argument. Thisfunction must not close the channel. The format of the output is speci�ed by theoutput_mode argument which may be one of the following `PostScript | `Mif | `HpGl| `Gif | `Imap | `Ismap | `Plain .

end

6 Module Avl_draw : Drawing graphs.This module allows drawing a graphical representation of directed graphs. Arbitrary output devicesmay be used, e.g. the Objective Caml graphics library. Arrangements of nodes and edges arecomputed thanks to the GraphViz tools.

18

6.1 Drawing attributesThis sections de�nes datatype for specifying the drawing attributes of the nodes and edges of agraph.type color = int

Colors are represented by integers, using the same encoding than that of the Objective Camlgraphics library.

type point = int * intCoordinates of point are given by a pair of integers.

6.1.1 Nodes attributes

type node_attributes = {nd_label : [ `None | `Text of text_label_attributes] ;

Sets the label to be drawed inside the node. Two options are currently implemented:• `None : no label,• `Text att : textual label, described by att.

nd_shape : [ `Box | `Circle | `Ellipse | `Square] ;Sets the shape of the border of the node. Available shapes are `Box (rectangle), `Square,`Circle and `Ellipse.

nd_size : [ `FitLabel of int * int | `Fixed of int * int] ;Sets the the size of the label. Two options are available:• `FitLabel (hm, vm): the shape will �t the label, with horizontal and vertical margin ofhm and vm pixels, respectively.

• `Fixed (w, h): the label will �t a rectangle of witdth w and height h pixels.

nd_border : [ `NoBorder | `Solid of color * int] ;Sets the style of the border. Available styles are:• `NoBorder: no border will be drawn.• `Solid (c, w): a solid border will be drawn with color c and width w.

nd_background : [ `Solid of color | `Transparent] ;Sets the style of the background of the node. Available styles are:• `Transparent: no background.• `Solid c: the node will be �lled with color c.

}The drawing attributes of a node are speci�ed by a record of type 'a node_attributes.

type text_label_attributes = {tl_text : string ;

The litteral text of the label.

19

tl_fontname : string ;The family font name. If the string is empty, default system font will be kept.

tl_fontsize : int ;The font size.

tl_color : color ;The font color.

}The attributes of a text label are speci�ed by a record of type text_label_attributes.

val default_node : node_attributesdefault_node is a standard record of node attributes.

val default_label : text_label_attributesdefault_text_label is a standard record of text label attributes.

6.1.2 Edges attributes

type edge_attributes = {ed_linestyle : [ `Solid of color * int | `Transparent] ;

Sets the drawing style of the edge line. Available options are:• `Transparent: no line will be traced.• `Solid (c, w): a solid line will be drawn with color c and width w.

ed_originarrow : arrow_style ;The style of the origin arrow.

ed_tailarrow : arrow_style ;The style of the tail arrow.

}The drawing attributes of an edge are speci�ed by a record of type edge_attributes.

type arrow_style = [ `Filled of int * float * color| `Lined of int * float * color * int| `None]

Available arrows styles:

val default_edge : edge_attributesdefault_edge is a standard record of edge attributes.

20

6.2 Client's signatures

module type GRAPH = sig end[6.4]

module type DRAW = sig end[6.5]

module DrawGraphics : DRAW[6.6]

6.3 Make functor

module Make : functor (D : DRAW) -> functor (G : GRAPH) -> sig end[6.7]

module MakeGraphics : functor (G : GRAPH) -> sig end[6.8]

6.4 Module type Avl_draw.GRAPH : The client must provide an implementationof graphs which full�lls the signature GRAPH.

module type GRAPH = sig

type graphtype nodetype edgeval iter_nodes :(node -> unit) -> graph -> unit

val iter_edges :(edge -> unit) -> graph -> unit

val node_hash : node -> intval node_equal : node -> node -> boolval node_attributes : node -> Avl_draw.node_attributesval edge_hash : edge -> intval edge_equal : edge -> edge -> boolval edge_head : edge -> nodeval edge_tail : edge -> nodeval edge_attributes : edge -> Avl_draw.edge_attributesend

6.5 Module type Avl_draw.DRAW : The client must provide drawing functionswhich full�lls the signature DRAW.

module type DRAW = sig

type window

21

val draw_lines :window ->color:Avl_draw.color -> lw:int -> Avl_draw.point list -> unit

val draw_curves :window ->color:Avl_draw.color ->lw:int ->Avl_draw.point ->(Avl_draw.point * Avl_draw.point * Avl_draw.point) list -> unit

val draw_rect :window ->color:Avl_draw.color -> lw:int -> x:int -> y:int -> w:int -> h:int -> unit

val draw_ellipse :window ->color:Avl_draw.color ->lw:int -> x:int -> y:int -> rx:int -> ry:int -> unit

val fill_rect :window ->color:Avl_draw.color -> x:int -> y:int -> w:int -> h:int -> unit

val fill_ellipse :window ->color:Avl_draw.color -> x:int -> y:int -> rx:int -> ry:int -> unit

val fill_poly :window -> color:Avl_draw.color -> Avl_draw.point list -> unit

val draw_text :window ->color:Avl_draw.color ->?name:string -> size:int -> x:int -> y:int -> string -> unit

val text_size :window -> ?name:string -> size:int -> string -> int * int

end

6.6 Module Avl_draw.DrawGraphics : DrawGraphics provides an implementationof signature DRAW for the graphics library of Objective Caml.

module DrawGraphics : sig

end

6.7 Module Avl_draw.Make : Given an implementation of drawing capabilitiesand of graphs structures, the functor Make provide drawing functions forgraphs.

module Make : sigParameters:

22

• D : Avl_draw.DRAW

• G : Avl_draw.GRAPH

type engine = [ `Dot of[ `Nodesep of int| `Rankdir of [ `LeftToRight | `TopToBottom]| `Ranksep of int] list]

Spatial arrangement of nodes and edges is performed by an external engine. Currently, onlyone external engine is supported.

val draw_graph :D.window -> engine -> int -> int -> G.graph -> int * int

draw_graph win a x y g draw the graph g according to the arrangement a. x and y are thecoordinates of the left lower bound of the drawing. The function returns the dimensions ofthe drawing.

end

6.8 Module Avl_draw.MakeGraphics : Given an implementation of graphs struc-tures, the functor MakeGraphics provides drawing functions for the ObjectiveCaml graphics library.

module MakeGraphics : sigSee Make for documentation.Parameters:

• G : Avl_draw.GRAPH

type engine = [ `Dot of[ `Nodesep of int| `Rankdir of [ `LeftToRight | `TopToBottom]| `Ranksep of int] list]

val draw_graph :unit -> engine -> int -> int -> G.graph -> int * int

end

23