~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/mod/gfx/doc/chapter-1.xml

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
<!-- ====================================================================== -->
18
18
 
19
19
<chapter module="gfx" number="1">
20
 
  <title>Standard graph services</title>
21
 
  
22
 
  <p>
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.
26
 
  </p>
27
 
 
28
 
  <p>
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.
35
 
  </p>
36
 
  
37
 
  <example>
38
 
  interp:library "afnix-gfx"
39
 
  </example>
 
20
  <title>Standard graph module</title>
 
21
  
 
22
  <p>
 
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.
 
26
  </p>
40
27
 
41
28
  <!-- graph concepts -->
42
29
  <section>
43
30
    <title>Graph concepts</title>
44
31
 
45
32
    <p>
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
51
 
    called an hypergraph.
 
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
 
38
      called an hypergraph.
52
39
    </p>
53
40
 
54
41
    <!-- edge class -->
56
43
      <title>Edge class</title>
57
44
 
58
45
      <p>
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
67
 
      a set of vertices.
 
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
 
54
        a set of vertices.
68
55
      </p>
69
56
    </subsect>
70
57
 
73
60
      <title>Vertex class </title>
74
61
 
75
62
      <p>
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.
80
67
      </p>
81
68
    </subsect>
82
69
 
85
72
      <title>Graph</title>
86
73
 
87
74
      <p>
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.
96
83
      </p>
97
84
    </subsect>
98
85
  </section>
102
89
    <title>Graph construction</title>
103
90
 
104
91
    <p>
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
108
 
    unreferenced edges.
 
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
 
95
      unreferenced edges.
109
96
    </p>
110
97
 
111
98
    <!-- edge construction -->
113
100
      <title>Edge construction</title>
114
101
 
115
102
      <p>
116
 
      An edge is constructed by simply invoking the default
117
 
      constructor. Optionally, a client object can be attached to the
118
 
      edge.
 
103
        An edge is constructed by simply invoking the default
 
104
        constructor. Optionally, a client object can be attached to the
 
105
        edge.
119
106
      </p>
120
107
 
121
108
      <example>
122
 
      # create a default edge
123
 
      const edge (afnix:gfx:Edge)
124
 
      
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)
 
111
        
 
112
        # create an edge with a client object
 
113
        const hello (afnix:gfx:Edge "hello")
127
114
      </example>
128
115
 
129
116
      <p>
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.
133
120
      </p>
134
121
    </subsect>
135
122
 
138
125
      <title>Vertex construction</title>
139
126
 
140
127
      <p>
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
144
 
      edge.
 
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
 
131
        edge.
145
132
      </p>
146
133
 
147
134
      <example>
148
 
      # create a default vertex
149
 
      const vrtx (afnix:gfx:Vertex)
150
 
      
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)
 
137
        
 
138
        # create an vertex with a client object
 
139
        const world (afnix:gfx:Vertex "world")
153
140
      </example>
154
141
 
155
142
      <p>
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.
159
146
      </p>
160
147
    </subsect>
161
148
 
164
151
      <title>Graph construction</title>
165
152
 
166
153
      <p>
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.
172
159
      </p>
173
160
 
174
161
      <example>
175
 
      const graph (afnix:gfx:Graph)
 
162
        const graph (afnix:gfx:Graph)
176
163
      </example>
177
164
      
178
165
      <p>
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.
183
170
      </p>
184
171
 
185
172
      <example>
186
 
      # create a graph
187
 
      const  g    (afnix:gfx:Graph)
188
 
      assert true (afnix:gfx:graph-p g)
189
 
 
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)
195
 
 
196
 
      # add the edge to the graph and check
197
 
      g:add edge
198
 
      assert 1 (g:number-of-edges)
199
 
      assert 2 (g:number-of-vertices)
200
 
 
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))
 
173
        # create a graph
 
174
        const  g    (afnix:gfx:Graph)
 
175
        assert true (afnix:gfx:graph-p g)
 
176
 
 
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)
 
182
 
 
183
        # add the edge to the graph and check
 
184
        g:add edge
 
185
        assert 1 (g:number-of-edges)
 
186
        assert 2 (g:number-of-vertices)
 
187
 
 
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))
205
192
      </example>
206
193
    </subsect>
207
194
  </section>