'\" t .\" This documentation, which is part of the afnix writing .\" system distribution, is free and can be distributed as .\" long as this copyright notice is left intact. .\" .\" This documentation is distributed in the hope that it .\" will be useful, but without any warranty; without even .\" the implied warranty of merchantability and fitness .\" for a particular purpose. In no event, shall the .\" copyright holder be liable for any direct, incident .\" incidental or special damages arising in any way out .\" of the use of this documentation. .\" .\" Copyright (c) 1999-2022 Amaury Darsch .\" .TH gfx 3 AFNIX "AFNIX Module" .SH NAME gfx - standard graph module .SH STANDARD GRAPH MODULE The Standard Graph module is an original implementation dedicated to the graph modeling and manipulation. At the heart of this module is the concept of edges and vertices. The module also provides support for automaton. .PP .B Graph concepts .br The afnix-gfx module provides the support for manipulating graphs. Formally a graph is a collection of edges and vertices. In a normal graph, an edge connects two vertices. On the other hand, a vertex can have several edges. When an edge connects several vertices, it is called an hyperedge and the resulting structure is called an hypergraph. .PP .I Edge class .br The Edge class is a class used for a graph construction in association with the Vertex class. An edge is used to connect vertices. Normally, an edge connects two vertices. The number of vertices attached to an edge is called the cardinality of that edge. When the edge cardinality is one, the edge is called a self-loop. This mean that the edge connects the vertex to itself. This last point is merely a definition but present the advantage of defining an hyperedge as a set of vertices. .PP .I Vertex class .br The Vertex is the other class used for the graph construction. and operates with the edge class. A vertex is used to reference edges. the number of edges referenced by a vertex is called the degree of that vertex. .PP .I Graph .br The Graph class is class that represent either a graph or a hypergraph. By definition, a graph is collection of edges and vertices. There are numerous property attached to graph. Formally, a graph consists of a set of edges, a set of vertices and the associated endpoints. However, the implementation is designed in a way so that each edge and vertex carry its associated objects. This method ensures that the graph is fully defined by only its two sets. .PP .B Graph construction .br The graph construction is quite simple and proceed by adding edges and vertices. The base system does not enforce rules on the graph structure. it is possible to add con connected vertices as well as unreferenced edges. .PP .I Edge construction .br An edge is constructed by simply invoking the default constructor. Optionally, a client object can be attached to the edge. .sp .nf # create a default edge const edge (afnix:gfx:Edge) # create an edge with a client object const hello (afnix:gfx:Edge "hello") .fi .sp The edge-p predicate can be used to check for the object type. When an edge is created with client object, the get-client method can be used to access that object. .PP .I Vertex construction .br A vertex is constructed a way similar to the Edge> object. The vertex is constructed by simply invoking the default constructor. Optionally, a client object can be attached to the edge. .sp .nf # create a default vertex const vrtx (afnix:gfx:Vertex) # create an vertex with a client object const world (afnix:gfx:Vertex "world") .fi .sp The vertex-p predicate can be used to check for the object type. When a vertex is created with a client object, the get-client method can be used to access that object. .PP .I Graph construction .br A graph is constructed by simply adding edges and vertices to it. The graph-p predicate can be use to assert the graph type. the graph class also supports the concept of client object which can be attached at construction or with the set-client method. .sp .nf const graph (afnix:gfx:Graph) .fi .sp The add method can be used to add edges or vertices to the graph. The important point is that during the construction process, the graph structure is updated with the proper number of edge and vertices. .sp .nf # create a graph const g (afnix:gfx:Graph) assert true (afnix:gfx:graph-p g) # create an edge and add vertices const edge (afnix:gfx:Edge) edge:add (afnix:gfx:Vertex "hello") edge:add (afnix:gfx:Vertex "world") assert 2 (edge:degree) # add the edge to the graph and check g:add edge assert 1 (g:number-of-edges) assert 2 (g:number-of-vertices) # check for nodes and edges assert true (afnix:gfx:edge-p (g:get-edge 0)) assert true (afnix:gfx:vertex-p (g:get-vertex 0)) assert true (afnix:gfx:vertex-p (g:get-vertex 1)) .fi .sp .SH STANDARD GRAPH REFERENCE .PP .B State .br The State class is a class the graph object library. The state is used to model vertex and edge and can be used seldom in structure like finite automaton. .PP .I Predicate .br .sp .RS state-p .RE .PP .I Inheritance .br .sp .RS Serial .RE .PP .I Constructors .br .sp .RS .B State (none) .br The State constructor create an empty state. .RE .sp .RS .B State (Object) .br The State constructor create a state edge with a client object. .RE .PP .I Methods .br .sp .RS .B clear -> none (none) .br The clear method clear the state marker. .RE .sp .RS .B get-index -> Integer (none) .br The get-idex method returns the state index. .RE .sp .RS .B set-idnex -> none (Integer) .br The set-index method sets the state index. .RE .sp .RS .B get-client -> Object (none) .br The get-client method returns the state client object. If the client object is not set, nil is returned. .RE .sp .RS .B set-client -> Object (Object) .br The set-client method sets the state client object. The object is returned by this method. .RE .PP .B Edge .br The Edge class is a class used for a graph construction in association with the Vertex class. An edge is used to connect vertices. Normally, an edge connects two vertices. The number of vertices attached to an edge is called the cardinality of that edge. A client object can also be attached to the class. .PP .I Predicate .br .sp .RS edge-p .RE .PP .I Inheritance .br .sp .RS State, Collectable .RE .PP .I Constructors .br .sp .RS .B Edge (none) .br The Edge constructor create an empty edge. .RE .sp .RS .B Edge (Object) .br The Edge constructor create an edge with a client object. .RE .PP .I Methods .br .sp .RS .B reset -> none (none) .br The reset method reset all vertices attached to the edge. .RE .sp .RS .B cardinality -> Integer (none) .br The cardinality method returns the cardinality of the edge. The cardinality of an edge is the number of attached vertices. .RE .sp .RS .B add -> Vertex (Vertex) .br The add method attach a vertex to this edge. The method return the argument vertex. .RE .sp .RS .B get -> Vertex (Integer) .br The get method returns the attached vertex by index. If the index is out-of range, and exception is raised. .RE .PP .B Vertex .br The Vertex class is a class used for a graph construction in association with the Edge class. An vertex is an edge node. The number of edges referenced by a vertex is called the degree of that vertex. A client object can also be attached to the object. .PP .I Predicate .br .sp .RS vertex-p .RE .PP .I Inheritance .br .sp .RS State, Collectable .RE .PP .I Constructors .br .sp .RS .B Vertex (none) .br The Vertex constructor create an empty vertex. .RE .sp .RS .B Vertex (Object) .br The Vertex constructor create a vertex with a client object. .RE .PP .I Methods .br .sp .RS .B reset -> none (none) .br The reset method reset all edges attached to the vertex. .RE .sp .RS .B degree -> Integer (none) .br The degree method returns the degree of the vertex. The degree of a vertex is the number of referenced edges. .RE .sp .RS .B add -> Edge (Edge) .br The add method references an edge with this vertex. The method return the argument edge. .RE .sp .RS .B get -> Edge (Integer) .br The get method returns the referenced edge by index. If the index is out-of range, and exception is raised. .RE .PP .B Graph .br The Graph object is a general graph class that manages a set of edges and vertices. The graph operates by adding edges and vertices to it. .PP .I Predicate .br .sp .RS graph-p .RE .PP .I Inheritance .br .sp .RS Object .RE .PP .I Constructors .br .sp .RS .B Graph (none) .br The Graph constructor create an empty graph. .RE .PP .I Methods .br .sp .RS .B reset -> none (none) .br The reset method reset the graph .RE .sp .RS .B clear -> none (none) .br The clear method clear the graph .RE .sp .RS .B add -> Object (Vertex|Edge) .br The add method adds a vertex or an edge to the graph. When adding an edge, the methods check that the source and target vertices are also part of the graph. .RE