GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
graph.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002 Roberto Micarelli
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/*
20 * best view tabstop=4
21 */
22
23#ifndef _DGL_dglGraph_s_H_
24#define _DGL_dglGraph_s_H_
25
26#ifdef DGL_STATS
27#include <time.h>
28#endif
29
30#include "heap.h"
31#include "tree.h"
32
33/*
34 * Graph State bitmask - returned by dglGet_State() function
35 */
36#define DGL_GS_FLAT 0x1 /* otherwise is TREE */
37
38/*
39 * Graph Family
40 */
41#define DGL_GF_COMPLETE 0x1
42#define DGL_GF_BIPARTITE 0x2
43#define DGL_GF_REGULAR 0x4
44#define DGL_GF_BOUQUET 0x8
45#define DGL_GF_DIPOLE 0x10
46#define DGL_GF_PATH 0x20
47#define DGL_GF_CYCLE 0x40
48
49/*
50 * Graph Options
51 */
52#define DGL_GO_EdgePrioritize_COST 0x10
53#define DGL_GO_EdgePrioritize_ATTR 0x20
54#define DGL_GO_NodePrioritize_ATTR 0x40
55
56/*
57 * Node Status bitmask - returned by dglNodeGet_Status()
58 */
59#define DGL_NS_HEAD 0x1 /* node exists as at least one edge's head (static) */
60#define DGL_NS_TAIL 0x2 /* node exists as at least one edge's tail (static) */
61#define DGL_NS_ALONE 0x4 /* node is a component */
62
63/*
64 * Edge Status bitmask - returned by dglEdgeGet_Status()
65 */
66#define DGL_ES_DIRECTED 0x1 /* force edge to be directed */
67
68/*
69 * Endianness Values - returned by dglGet_Endianess() function
70 */
71#define DGL_ENDIAN_BIG 1
72#define DGL_ENDIAN_LITTLE 2
73
74/*
75 * miscellaneous
76 */
77/* add-edge/add-node flags */
78#define DGL_STRONGCONNECT 0x1
79#define DGL_ALONE 0x2
80#define DGL_MERGE_EDGE 0x4
81/* */
82
83/*
84 * Shortest Path clip definitions
85 */
94
99
100/*
101 * Spanning clip definitions
102 */
109
114
115struct dglGraph;
116
117/*
118 * Node Prioritizer
119 */
120typedef struct {
121 void *pvAVL;
123
124/*
125 * Edge Prioritizer
126 */
133
134/*
135 * The graph context
136 */
137typedef struct _dglGraph {
139
145
152
156
163
166
167 /* so far statistics are only computed by dglAddEdge() */
168#ifdef DGL_STATS
169 clock_t clkAddEdge; /* cycles spent during the last addedge execution */
170 int cAddEdge; /* # of calls to dglAddEdge() */
171 clock_t clkNodeTree; /* cycles spent in accessing the node binary tree */
172 int cNodeTree; /* # of probes in the node tree */
173#endif
175
176/*
177 * Shortest Path clip function type
178 */
180 dglSPClipOutput_s *, void *);
181
182/*
183 * Spanning clip function type
184 */
186 dglSpanClipOutput_s *, void *);
187
188/*
189 * An ARC defined as : from-node, to-node, edge pointer, to-node-distance (from
190 * the path starting node)
191 */
198
199/*
200 * Shortest Path Report
201 */
209
210/*
211 * Shortest Path Cache
212 */
219
220/*
221 * Node Traverser
222 */
228
229/*
230 * Edgeset Traverser
231 */
238
239/*
240 * Edge Traverser
241 */
248
249/*
250 * Error codes returned by dglError
251 */
252#define DGL_ERR_BadVersion 1
253#define DGL_ERR_BadNodeType 2
254#define DGL_ERR_MemoryExhausted 3
255#define DGL_ERR_HeapError 4
256#define DGL_ERR_UndefinedMethod 5
257#define DGL_ERR_Write 6
258#define DGL_ERR_Read 7
259#define DGL_ERR_NotSupported 8
260#define DGL_ERR_UnknownByteOrder 9
261#define DGL_ERR_HeadNodeNotFound 10
262#define DGL_ERR_TailNodeNotFound 11
263#define DGL_ERR_BadEdge 12
264#define DGL_ERR_BadOnFlatGraph 13
265#define DGL_ERR_BadOnTreeGraph 14
266#define DGL_ERR_NodeNotFound 15
267#define DGL_ERR_TreeSearchError 16
268#define DGL_ERR_UnexpectedNullPointer 17
269#define DGL_ERR_VersionNotSupported 18
270#define DGL_ERR_EdgeNotFound 19
271#define DGL_ERR_NodeAlreadyExist 20
272#define DGL_ERR_NodeIsAComponent 21
273#define DGL_ERR_EdgeAlreadyExist 22
274#define DGL_ERR_BadArgument 23
275
276/*
277 * graph context management
278 */
279int dglInitialize(dglGraph_s *pGraph, dglByte_t Version,
280 dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize,
282int dglRelease(dglGraph_s *pGraph);
283int dglUnflatten(dglGraph_s *pGraph);
284int dglFlatten(dglGraph_s *pGraph);
286
287/*
288 * node management
289 */
299void dglNodeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode,
301int dglNodeGet_InDegree(dglGraph_s *pGraph, dglInt32_t *pnNode);
302int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode);
303int dglNodeGet_Valence(dglGraph_s *pGraph, dglInt32_t *pnNode);
304
305/*
306 * edge management
307 */
310
317
319
321
324
328
329/*
330 * graph I/O
331 */
332int dglWrite(dglGraph_s *pGraph, int fd);
333int dglRead(dglGraph_s *pGraph, int fd);
334
335typedef struct {
338 int fSwap;
339 int cb;
340 int ib;
341 unsigned char *pb;
342 unsigned char ab[118]; /* 118 = graph header size */
344
347
348/*
349 * Chunked Write callback function type
350 */
351typedef int (*dglWriteChunk_fn)(dglGraph_s *, unsigned char *pbChunk,
352 int cbChunk, void *pvArg);
353
356
357/*
358 * Algorithms
359 */
361 dglInt32_t nStartNode, dglInt32_t nDestinationNode,
364 dglInt32_t nStartNode, dglInt32_t nDestinationNode,
368 dglInt32_t nStartNode, dglInt32_t nDestinationNode,
372 dglInt32_t nStartNode, dglInt32_t nDestinationNode,
375
379
382 void *pvClipArg);
383
386 void *pvClipArg);
387
390 void *pvClipArg);
391
392/*
393 * error management
394 */
397
398/*
399 * graph property hiders
400 */
401int dglGet_Version(dglGraph_s *pGraph);
402void dglSet_Version(dglGraph_s *pGraph, int Version);
403int dglGet_Endianess(dglGraph_s *pGraph);
406int dglGet_NodeCount(dglGraph_s *pGraph);
410int dglGet_EdgeCount(dglGraph_s *pGraph);
411int dglGet_State(dglGraph_s *pGraph);
414int dglGet_NodeSize(dglGraph_s *pGraph);
415int dglGet_EdgeSize(dglGraph_s *pGraph);
417void dglSet_Cost(dglGraph_s *pGraph, dglInt64_t nnCost);
419void dglSet_Family(dglGraph_s *pGraph, dglInt32_t nFamily);
421void dglSet_Options(dglGraph_s *pGraph, dglInt32_t nOptions);
424
425/*
426 * node traverser
427 */
435
436/*
437 * edgeset traverser
438 */
440 dglGraph_s *pGraph, dglInt32_t *pnEdgeset);
444
445/*
446 * edge traverser
447 */
449 dglEdgePrioritizer_s *pEdgePrioritizer);
453
454#endif
dglInt32_t * dglNode_T_Find(dglNodeTraverser_s *pTraverser, dglInt32_t nNodeId)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
int(* dglSPClip_fn)(dglGraph_s *, dglSPClipInput_s *, dglSPClipOutput_s *, void *)
Definition graph.h:179
int dglRead(dglGraph_s *pGraph, int fd)
int dglNode_T_Initialize(dglNodeTraverser_s *pTraverser, dglGraph_s *pGraph)
void dglSet_Family(dglGraph_s *pGraph, dglInt32_t nFamily)
int dglGet_TailNodeCount(dglGraph_s *pGraph)
dglInt32_t * dglNodeGet_OutEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglEdge_T_Next(dglEdgeTraverser_s *pTraverser)
dglInt32_t dglNodeGet_Status(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglReadChunk(dglIOContext_s *, dglByte_t *pbChunk, int cbChunk)
int dglGet_HeadNodeCount(dglGraph_s *pGraph)
int dglErrno(dglGraph_s *pgraph)
int dglGet_Endianess(dglGraph_s *pGraph)
int dglAddEdge(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_s *pTraverser)
int dglShortestDistanceGraph(dglGraph_s *pGraph, dglGraph_s *pGraphOut, dglInt32_t nStartNode, dglInt32_t nDestinationNode, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
dglInt32_t * dglNodeGet_InEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt64_t dglGet_Cost(dglGraph_s *pGraph)
dglInt32_t dglEdgeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglGet_Version(dglGraph_s *pGraph)
struct _dglGraph dglGraph_s
struct _dglSPClipInput dglSPClipInput_s
int(* dglWriteChunk_fn)(dglGraph_s *, unsigned char *pbChunk, int cbChunk, void *pvArg)
Definition graph.h:351
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pTraverser)
void dglSet_Options(dglGraph_s *pGraph, dglInt32_t nOptions)
int dglShortestPathGraph(dglGraph_s *pGraph, dglGraph_s *pGraphOut, dglInt32_t nStartNode, dglInt32_t nDestinationNode, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
int dglDepthSpanning(dglGraph_s *pgraphInput, dglGraph_s *pgraphOutput, dglInt32_t nVertexNode, dglSpanClip_fn fnClip, void *pvClipArg)
int dglGet_EdgeSize(dglGraph_s *pGraph)
dglInt32_t * dglEdge_T_First(dglEdgeTraverser_s *pTraverser)
int dglInitializeSPCache(dglGraph_s *pgraph, dglSPCache_s *pCache)
void dglNodeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode, dglInt32_t *pnAttr)
int dglRelease(dglGraph_s *pGraph)
void dglSet_Version(dglGraph_s *pGraph, int Version)
int dglGet_AloneNodeCount(dglGraph_s *pGraph)
void dglSet_Cost(dglGraph_s *pGraph, dglInt64_t nnCost)
dglInt32_t * dglNode_T_Prev(dglNodeTraverser_s *pTraverser)
int dglGet_NodeCount(dglGraph_s *pGraph)
dglNodePrioritizer_s * dglGet_NodePrioritizer(dglGraph_s *pGraph)
struct _dglSPArc dglSPArc_s
int dglEdgeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnAttr, dglInt32_t *pnEdge)
struct _dglSpanClipInput dglSpanClipInput_s
dglEdgePrioritizer_s * dglGet_EdgePrioritizer(dglGraph_s *pGraph)
void dglReleaseSPCache(dglGraph_s *pgraph, dglSPCache_s *pCache)
int dglInitialize(dglGraph_s *pGraph, dglByte_t Version, dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize, dglInt32_t *pOpaqueSet)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pTraverser)
dglInt32_t dglEdgesetGet_EdgeCount(dglGraph_s *pGraph, dglInt32_t *pnOutEdgeset)
void dglFreeSPReport(dglGraph_s *pGraph, dglSPReport_s *pSPReport)
int dglShortestPath(dglGraph_s *pGraph, dglSPReport_s **ppReport, dglInt32_t nStartNode, dglInt32_t nDestinationNode, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
int dglGet_NodeSize(dglGraph_s *pGraph)
int dglAddEdgeX(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge, void *pvFnodeAttr, void *pvTnodeAttr, void *pvEdgeAttr, dglInt32_t nFlags)
struct _dglSPReport dglSPReport_s
dglInt32_t * dglNode_T_Last(dglNodeTraverser_s *pTraverser)
void dglIOContextRelease(dglIOContext_s *)
int dglMinimumSpanning(dglGraph_s *pgraphInput, dglGraph_s *pgraphOutput, dglInt32_t nVertexNode, dglSpanClip_fn fnClip, void *pvClipArg)
void dglNode_T_Release(dglNodeTraverser_s *pTraverser)
char * dglStrerror(dglGraph_s *pgraph)
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pTraverser)
dglInt32_t * dglGet_Opaque(dglGraph_s *pGraph)
int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
struct _dglSPClipOutput dglSPClipOutput_s
int dglDelEdge(dglGraph_s *pGraph, dglInt32_t nEdgeId)
struct _dglSpanClipOutput dglSpanClipOutput_s
void dglEdge_T_Release(dglEdgeTraverser_s *pTraverser)
int dglNodeGet_Valence(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglGet_State(dglGraph_s *pGraph)
int dglNodeGet_InDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglNodeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglGetEdge(dglGraph_s *pGraph, dglInt32_t nEdgeId)
int dglIOContextInitialize(dglGraph_s *, dglIOContext_s *)
int dglWriteChunk(dglIOContext_s *, dglWriteChunk_fn, void *pvArg)
int dglShortestDistance(dglGraph_s *pGraph, dglInt32_t *pnDistance, dglInt32_t nStartNode, dglInt32_t nDestinationNode, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
int dglWrite(dglGraph_s *pGraph, int fd)
dglInt32_t * dglEdgeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglEdge_T_Initialize(dglEdgeTraverser_s *pTraverser, dglGraph_s *pGraph, dglEdgePrioritizer_s *pEdgePrioritizer)
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pTraverser)
int dglFlatten(dglGraph_s *pGraph)
dglInt32_t dglGet_Options(dglGraph_s *pGraph)
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglDepthComponents(dglGraph_s *pgraphInput, dglGraph_s *pgraphComponents, int cgraphComponents, dglSpanClip_fn fnClip, void *pvClipArg)
int(* dglSpanClip_fn)(dglGraph_s *, dglGraph_s *, dglSpanClipInput_s *, dglSpanClipOutput_s *, void *)
Definition graph.h:185
void dglSet_Opaque(dglGraph_s *pGraph, dglInt32_t *pOpaque)
int dglUnflatten(dglGraph_s *pGraph)
int dglGet_NodeAttrSize(dglGraph_s *pGraph)
int dglGet_EdgeAttrSize(dglGraph_s *pGraph)
int dglGet_EdgeCount(dglGraph_s *pGraph)
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s *pTraverser, dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
void dglResetStats(dglGraph_s *pgraph)
dglInt32_t dglGet_Family(dglGraph_s *pGraph)
dglInt32_t * dglEdgeGet_Head(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglDelNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglAddNode(dglGraph_s *pGraph, dglInt32_t nNodeId, void *pvNodeAttr, dglInt32_t nFlags)
dglByte_t * pEdgeBuffer
Definition graph.h:161
dglInt32_t NodeAttrSize
Definition graph.h:142
dglInt32_t cTail
Definition graph.h:148
dglInt32_t cEdge
Definition graph.h:150
dglByte_t Endian
Definition graph.h:141
dglInt32_t nOptions
Definition graph.h:155
dglInt32_t EdgeAttrSize
Definition graph.h:143
dglEdgePrioritizer_s edgePrioritizer
Definition graph.h:164
dglInt32_t cAlone
Definition graph.h:149
dglByte_t * pNodeBuffer
Definition graph.h:159
dglInt32_t iEdgeBuffer
Definition graph.h:162
dglInt32_t iNodeBuffer
Definition graph.h:160
dglInt32_t cHead
Definition graph.h:147
dglInt32_t nFamily
Definition graph.h:154
int iErrno
Definition graph.h:138
dglInt32_t cNode
Definition graph.h:146
dglInt32_t aOpaqueSet[16]
Definition graph.h:144
dglByte_t Version
Definition graph.h:140
void * pNodeTree
Definition graph.h:157
dglNodePrioritizer_s nodePrioritizer
Definition graph.h:165
void * pEdgeTree
Definition graph.h:158
dglInt32_t Flags
Definition graph.h:153
dglInt64_t nnCost
Definition graph.h:151
dglInt32_t nDistance
Definition graph.h:196
dglInt32_t nTo
Definition graph.h:194
dglInt32_t * pnEdge
Definition graph.h:195
dglInt32_t nFrom
Definition graph.h:193
dglInt32_t nFromDistance
Definition graph.h:91
dglInt32_t * pnNodeTo
Definition graph.h:90
dglInt32_t * pnNodeFrom
Definition graph.h:88
dglInt32_t * pnPrevEdge
Definition graph.h:87
dglInt32_t * pnEdge
Definition graph.h:89
dglInt32_t nEdgeCost
Definition graph.h:96
dglInt32_t nDistance
Definition graph.h:205
dglInt32_t cArc
Definition graph.h:206
dglSPArc_s * pArc
Definition graph.h:207
dglInt32_t nStartNode
Definition graph.h:203
dglInt32_t nDestinationNode
Definition graph.h:204
dglInt32_t * pnNodeTo
Definition graph.h:106
dglInt32_t * pnNodeFrom
Definition graph.h:104
dglInt32_t * pnEdge
Definition graph.h:105
dglInt32_t * pnReserved
Definition graph.h:111
dglTreeEdgePri32_s * pEdgePri32Item
Definition graph.h:130
dglInt32_t * pnEdge
Definition graph.h:245
dglGraph_s * pGraph
Definition graph.h:243
dglEdgePrioritizer_s * pEdgePrioritizer
Definition graph.h:246
dglInt32_t * pnEdgeset
Definition graph.h:234
dglGraph_s * pGraph
Definition graph.h:233
dglGraph_s * pG
Definition graph.h:336
unsigned char * pb
Definition graph.h:341
dglInt32_t * pnNode
Definition graph.h:226
dglGraph_s * pGraph
Definition graph.h:224
void * pvPredist
Definition graph.h:217
void * pvVisited
Definition graph.h:216
dglHeap_s NodeHeap
Definition graph.h:215
dglInt32_t nStartNode
Definition graph.h:214
long long dglInt64_t
Definition type.h:37
unsigned char dglByte_t
Definition type.h:35
long dglInt32_t
Definition type.h:36