13
13
<!-- = incidental or special damages arising in any way out of the use = -->
14
14
<!-- = of this software. = -->
15
15
<!-- ====================================================================== -->
16
<!-- = copyright (c) 1999-2007 - amaury darsch = -->
16
<!-- = copyright (c) 1999-2011 - amaury darsch = -->
17
17
<!-- ====================================================================== -->
19
19
<chapter module="gfx" number="1">
20
<title>Standard graph services</title>
23
This chapter covers the graph facilities available in the
24
<em>standard graph</em> module. The basic operations are related to
25
edge, vertices and graph manipulations.
29
All <afnix/> standard graph objects are located in the
30
<code>afnix-gfx</code> module. This module must be loaded prior
31
any operation. Multiple calls to the module initialization routine
32
are harmless. The interpreter method <code>module</code> loads a
33
specific module by name. When the module has been loaded, the
34
object are available in the <code>afnix:gfx</code> nameset.
38
interp:library "afnix-gfx"
20
<title>Standard graph module</title>
23
This chapter covers the graph facilities available in the
24
<em>standard graph</em> module. The basic operations are related to
25
edge, vertices and graph manipulations.
41
28
<!-- graph concepts -->
43
30
<title>Graph concepts</title>
46
The <code>afnix-gfx</code> provides the support for manipulating
47
graphs. Formally a graph is a collection of edges and vertices. In
48
a normal graph, an edge connects two vertices. On the other hand,
49
a vertex can have several edges. When an edge connects several
50
vertices, it is called an hyperedge and the resulting structure is
33
The <code>afnix-gfx</code> module provides the support for manipulating
34
graphs. Formally a graph is a collection of edges and vertices. In
35
a normal graph, an edge connects two vertices. On the other hand,
36
a vertex can have several edges. When an edge connects several
37
vertices, it is called an hyperedge and the resulting structure is
54
41
<!-- edge class -->
56
43
<title>Edge class</title>
59
The <code>Edge</code> class is a class used for a graph
60
construction in association with the <code>Vertex</code> class.
61
An edge is used to connect vertices. Normally, an edge connects
62
two vertices. The number of vertices attached to an edge is
63
called the cardinality of that edge. When the edge cardinality
64
is one, the edge is called a self-loop. This mean that the edge
65
connects the vertex to itself. This last point is merely a
66
definition but present the advantage of defining an hyperedge as
46
The <code>Edge</code> class is a class used for a graph
47
construction in association with the <code>Vertex</code> class.
48
An edge is used to connect vertices. Normally, an edge connects
49
two vertices. The number of vertices attached to an edge is
50
called the cardinality of that edge. When the edge cardinality
51
is one, the edge is called a self-loop. This mean that the edge
52
connects the vertex to itself. This last point is merely a
53
definition but present the advantage of defining an hyperedge as
73
60
<title>Vertex class </title>
76
The <code>Vertex</code> is the other class used for the
77
graph construction. and operates with the <code>edge</code>
78
class. A vertex is used to reference edges. the number of edges
79
referenced by a vertex is called the degree of that vertex.
63
The <code>Vertex</code> is the other class used for the
64
graph construction. and operates with the <code>edge</code>
65
class. A vertex is used to reference edges. the number of edges
66
referenced by a vertex is called the degree of that vertex.
85
72
<title>Graph</title>
88
The <code>Graph</code> class is class that represent either a
89
graph or a hypergraph. By definition, a graph is collection of
90
edges and vertices. There are numerous property attached to
91
graph. Formally, a graph consists of a set of edges, a set of
92
vertices and the associated endpoints. However, the implementation
93
is designed in a way so that each edge and vertex carry its
94
associated objects. This method ensures that the graph is fully
95
defined by only its two sets.
75
The <code>Graph</code> class is class that represent either a
76
graph or a hypergraph. By definition, a graph is collection of
77
edges and vertices. There are numerous property attached to
78
graph. Formally, a graph consists of a set of edges, a set of
79
vertices and the associated endpoints. However, the implementation
80
is designed in a way so that each edge and vertex carry its
81
associated objects. This method ensures that the graph is fully
82
defined by only its two sets.
102
89
<title>Graph construction</title>
105
The graph construction is quite simple and proceed by adding edges
106
and vertices. The base system does not enforce rules on the graph
107
structure. it is possible to add con connected vertices as well as
92
The graph construction is quite simple and proceed by adding edges
93
and vertices. The base system does not enforce rules on the graph
94
structure. it is possible to add con connected vertices as well as
111
98
<!-- edge construction -->
113
100
<title>Edge construction</title>
116
An edge is constructed by simply invoking the default
117
constructor. Optionally, a client object can be attached to the
103
An edge is constructed by simply invoking the default
104
constructor. Optionally, a client object can be attached to the
122
# create a default edge
123
const edge (afnix:gfx:Edge)
125
# create an edge with a client object
126
const hello (afnix:gfx:Edge "hello")
109
# create a default edge
110
const edge (afnix:gfx:Edge)
112
# create an edge with a client object
113
const hello (afnix:gfx:Edge "hello")
130
The <code>edge-p</code> predicate can be used to check for the
131
object type. When an edge is created with client object, the
132
<code>get-client</code> method can be used to access that object.
117
The <code>edge-p</code> predicate can be used to check for the
118
object type. When an edge is created with client object, the
119
<code>get-client</code> method can be used to access that object.
138
125
<title>Vertex construction</title>
141
A vertex is constructed a way similar to the <code>Edge></code>
142
object. The vertex is constructed by simply invoking the default
143
constructor. Optionally, a client object can be attached to the
128
A vertex is constructed a way similar to the <code>Edge></code>
129
object. The vertex is constructed by simply invoking the default
130
constructor. Optionally, a client object can be attached to the
148
# create a default vertex
149
const vrtx (afnix:gfx:Vertex)
151
# create an vertex with a client object
152
const world (afnix:gfx:Vertex "world")
135
# create a default vertex
136
const vrtx (afnix:gfx:Vertex)
138
# create an vertex with a client object
139
const world (afnix:gfx:Vertex "world")
156
The <code>vertex-p</code> predicate can be used to check for the
157
object type. When a vertex is created with a client object, the
158
<code>get-client</code> method can be used to access that object.
143
The <code>vertex-p</code> predicate can be used to check for the
144
object type. When a vertex is created with a client object, the
145
<code>get-client</code> method can be used to access that object.
164
151
<title>Graph construction</title>
167
A graph is constructed by simply adding edges and vertices to
168
it. The <code>graph-p</code> predicate can be use to assert the
169
graph type. the graph class also supports the concept of client
170
object which can be attached at construction or with the
171
<code>set-client</code> method.
154
A graph is constructed by simply adding edges and vertices to
155
it. The <code>graph-p</code> predicate can be use to assert the
156
graph type. the graph class also supports the concept of client
157
object which can be attached at construction or with the
158
<code>set-client</code> method.
175
const graph (afnix:gfx:Graph)
162
const graph (afnix:gfx:Graph)
179
The <code>add</code> method can be used to add edges or vertices
180
to the graph. The important point is that during the
181
construction process, the graph structure is updated with the
182
proper number of edge and vertices.
166
The <code>add</code> method can be used to add edges or vertices
167
to the graph. The important point is that during the
168
construction process, the graph structure is updated with the
169
proper number of edge and vertices.
187
const g (afnix:gfx:Graph)
188
assert true (afnix:gfx:graph-p g)
190
# create an edge and add vertices
191
const edge (afnix:gfx:Edge)
192
edge:add (afnix:gfx:Vertex "hello")
193
edge:add (afnix:gfx:Vertex "world")
194
assert 2 (edge:degree)
196
# add the edge to the graph and check
198
assert 1 (g:number-of-edges)
199
assert 2 (g:number-of-vertices)
201
# check for nodes and edges
202
assert true (afnix:gfx:edge-p (g:get-edge 0))
203
assert true (afnix:gfx:vertex-p (g:get-vertex 0))
204
assert true (afnix:gfx:vertex-p (g:get-vertex 1))
174
const g (afnix:gfx:Graph)
175
assert true (afnix:gfx:graph-p g)
177
# create an edge and add vertices
178
const edge (afnix:gfx:Edge)
179
edge:add (afnix:gfx:Vertex "hello")
180
edge:add (afnix:gfx:Vertex "world")
181
assert 2 (edge:degree)
183
# add the edge to the graph and check
185
assert 1 (g:number-of-edges)
186
assert 2 (g:number-of-vertices)
188
# check for nodes and edges
189
assert true (afnix:gfx:edge-p (g:get-edge 0))
190
assert true (afnix:gfx:vertex-p (g:get-vertex 0))
191
assert true (afnix:gfx:vertex-p (g:get-vertex 1))