#ifndef GRAPH_H
#define GRAPH_H
#ifdef __cplusplus
extern "C" {
#endif
#include "graphStructures.h"
#include "graphExtensions.h"
graphP gp_New(void);
int gp_InitGraph(graphP theGraph, int N);
void gp_ReinitializeGraph(graphP theGraph);
int gp_CopyGraph(graphP dstGraph, graphP srcGraph);
graphP gp_DupGraph(graphP theGraph);
int gp_CreateRandomGraph(graphP theGraph);
int gp_CreateRandomGraphEx(graphP theGraph, int numEdges);
void gp_Free(graphP *pGraph);
int gp_Read(graphP theGraph, char *FileName);
#define WRITE_ADJLIST 1
#define WRITE_ADJMATRIX 2
#define WRITE_DEBUGINFO 3
int gp_Write(graphP theGraph, char *FileName, int Mode);
#define EDGEFLAG_DIRECTION_INONLY 1
#define EDGEFLAG_DIRECTION_OUTONLY 2
#define gp_GetDirection(theGraph, e, edgeFlag_Direction) (theGraph->G[e].flags & edgeFlag_Direction)
void gp_SetDirection(graphP theGraph, int e, int edgeFlag_Direction);
#define gp_GetTwinArc(theGraph, Arc) (((Arc) & 1) ? (Arc)-1 : (Arc)+1)
#define gp_GetFirstArc(theGraph, v) (theGraph->G[v].link[0])
#define gp_GetLastArc(theGraph, v) (theGraph->G[v].link[1])
#define gp_GetNextArc(theGraph, e) (theGraph->G[e].link[0])
#define gp_GetPrevArc(theGraph, e) (theGraph->G[e].link[1])
#ifdef CIRCULAR
#define gp_IsArc(theGraph, e) ((e) >= theGraph->edgeOffset)
#else
#define gp_IsArc(theGraph, e) ((e) != NIL)
#endif
#define gp_GetArc(theGraph, v, theLink) (theGraph->G[v].link[theLink])
#define gp_GetAdjacentArc(theGraph, e, theLink) (theGraph->G[e].link[theLink])
#define gp_GetNextArcCircular(theGraph, e) \
(gp_IsArc(theGraph, theGraph->G[e].link[0]) ? \
theGraph->G[e].link[0] : \
gp_GetFirstArc(theGraph, theGraph->G[gp_GetTwinArc(theGraph, e)].v))
#define gp_GetPrevArcCircular(theGraph, e) \
(gp_IsArc(theGraph, theGraph->G[e].link[1]) ? \
theGraph->G[e].link[1] : \
gp_GetLastArc(theGraph, theGraph->G[gp_GetTwinArc(theGraph, e)].v))
#ifdef CIRCULAR
#define gp_AdjacencyListEndMark(v) (v)
#else
#define gp_AdjacencyListEndMark(v) (NIL)
#endif
#define gp_SetFirstArc(theGraph, v, newFirstArc) (theGraph->G[v].link[0] = newFirstArc)
#define gp_SetLastArc(theGraph, v, newLastArc) (theGraph->G[v].link[1] = newLastArc)
#define gp_SetNextArc(theGraph, e, newNextArc) (theGraph->G[e].link[0] = newNextArc)
#define gp_SetPrevArc(theGraph, e, newPrevArc) (theGraph->G[e].link[1] = newPrevArc)
#define gp_SetArc(theGraph, v, theLink, newArc) (theGraph->G[v].link[theLink] = newArc)
#define gp_SetAdjacentArc(theGraph, e, theLink, newArc) (theGraph->G[e].link[theLink] = newArc)
#define gp_BindFirstArc(theGraph, v, arc) \
{ \
gp_SetPrevArc(theGraph, arc, gp_AdjacencyListEndMark(v)); \
gp_SetFirstArc(theGraph, v, arc); \
}
#define gp_BindLastArc(theGraph, v, arc) \
{ \
gp_SetNextArc(theGraph, arc, gp_AdjacencyListEndMark(v)); \
gp_SetLastArc(theGraph, v, arc); \
}
#define gp_AttachFirstArc(theGraph, v, arc) \
{ \
if (gp_IsArc(theGraph, gp_GetFirstArc(theGraph, v))) \
{ \
gp_SetNextArc(theGraph, arc, gp_GetFirstArc(theGraph, v)); \
gp_SetPrevArc(theGraph, gp_GetFirstArc(theGraph, v), arc); \
} \
else gp_BindLastArc(theGraph, v, arc); \
gp_BindFirstArc(theGraph, v, arc); \
}
#define gp_AttachLastArc(theGraph, v, arc) \
{ \
if (gp_IsArc(theGraph, gp_GetLastArc(theGraph, v))) \
{ \
gp_SetPrevArc(theGraph, arc, gp_GetLastArc(theGraph, v)); \
gp_SetNextArc(theGraph, gp_GetLastArc(theGraph, v), arc); \
} \
else gp_BindFirstArc(theGraph, v, arc); \
gp_BindLastArc(theGraph, v, arc); \
}
#define gp_MoveArcToFirst(theGraph, v, arc) \
if (arc != gp_GetFirstArc(theGraph, v)) \
{ \
\
if (arc == gp_GetLastArc(theGraph, v)) \
{ \
gp_SetNextArc(theGraph, gp_GetPrevArc(theGraph, arc), gp_AdjacencyListEndMark(v)); \
gp_SetLastArc(theGraph, v, gp_GetPrevArc(theGraph, arc)); \
} \
\
else \
{ \
gp_SetNextArc(theGraph, gp_GetPrevArc(theGraph, arc), gp_GetNextArc(theGraph, arc)); \
gp_SetPrevArc(theGraph, gp_GetNextArc(theGraph, arc), gp_GetPrevArc(theGraph, arc)); \
} \
\
\
gp_SetNextArc(theGraph, arc, gp_GetFirstArc(theGraph, v)); \
gp_SetPrevArc(theGraph, gp_GetFirstArc(theGraph, v), arc); \
gp_BindFirstArc(theGraph, v, arc); \
}
#define gp_MoveArcToLast(theGraph, v, arc) \
if (arc != gp_GetLastArc(theGraph, v)) \
{ \
\
if (arc == gp_GetFirstArc(theGraph, v)) \
{ \
gp_SetPrevArc(theGraph, gp_GetNextArc(theGraph, arc), gp_AdjacencyListEndMark(v)); \
gp_SetFirstArc(theGraph, v, gp_GetNextArc(theGraph, arc)); \
} \
\
else \
{ \
gp_SetNextArc(theGraph, gp_GetPrevArc(theGraph, arc), gp_GetNextArc(theGraph, arc)); \
gp_SetPrevArc(theGraph, gp_GetNextArc(theGraph, arc), gp_GetPrevArc(theGraph, arc)); \
} \
\
\
gp_SetPrevArc(theGraph, arc, gp_GetLastArc(theGraph, v)); \
gp_SetNextArc(theGraph, gp_GetLastArc(theGraph, v), arc); \
gp_BindLastArc(theGraph, v, arc); \
}
void gp_AttachArc(graphP theGraph, int v, int e, int link, int newArc);
void gp_DetachArc(graphP theGraph, int arc);
int gp_IsNeighbor(graphP theGraph, int u, int v);
int gp_GetNeighborEdgeRecord(graphP theGraph, int u, int v);
int gp_GetVertexDegree(graphP theGraph, int v);
int gp_GetVertexInDegree(graphP theGraph, int v);
int gp_GetVertexOutDegree(graphP theGraph, int v);
int gp_GetArcCapacity(graphP theGraph);
int gp_EnsureArcCapacity(graphP theGraph, int requiredArcCapacity);
int gp_AddEdge(graphP theGraph, int u, int ulink, int v, int vlink);
int gp_InsertEdge(graphP theGraph, int u, int e_u, int e_ulink,
int v, int e_v, int e_vlink);
void gp_HideEdge(graphP theGraph, int e);
void gp_RestoreEdge(graphP theGraph, int e);
int gp_HideVertex(graphP theGraph, int vertex);
int gp_DeleteEdge(graphP theGraph, int e, int nextLink);
int gp_ContractEdge(graphP theGraph, int e);
int gp_IdentifyVertices(graphP theGraph, int u, int v, int eBefore);
int gp_RestoreVertices(graphP theGraph);
int gp_CreateDFSTree(graphP theGraph);
int gp_SortVertices(graphP theGraph);
int gp_LowpointAndLeastAncestor(graphP theGraph);
int gp_Embed(graphP theGraph, int embedFlags);
int gp_TestEmbedResultIntegrity(graphP theGraph, graphP origGraph, int embedResult);
#ifdef LOGGING
#define gp_LogLine _LogLine
#define gp_Log _Log
void _LogLine(char *Line);
void _Log(char *Line);
#define gp_MakeLogStr1 _MakeLogStr1
#define gp_MakeLogStr2 _MakeLogStr2
#define gp_MakeLogStr3 _MakeLogStr3
#define gp_MakeLogStr4 _MakeLogStr4
#define gp_MakeLogStr5 _MakeLogStr5
char *_MakeLogStr1(char *format, int);
char *_MakeLogStr2(char *format, int, int);
char *_MakeLogStr3(char *format, int, int, int);
char *_MakeLogStr4(char *format, int, int, int, int);
char *_MakeLogStr5(char *format, int, int, int, int, int);
#else
#define gp_LogLine(Line)
#define gp_Log(Line)
#define gp_MakeLogStr1(format, one)
#define gp_MakeLogStr2(format, one, two)
#define gp_MakeLogStr3(format, one, two, three)
#define gp_MakeLogStr4(format, one, two, three, four)
#define gp_MakeLogStr5(format, one, two, three, four, five)
#endif
#define EMBEDFLAGS_PLANAR 1
#define EMBEDFLAGS_OUTERPLANAR 2
#define EMBEDFLAGS_DRAWPLANAR (4|EMBEDFLAGS_PLANAR)
#define EMBEDFLAGS_SEARCHFORK23 (16|EMBEDFLAGS_OUTERPLANAR)
#define EMBEDFLAGS_SEARCHFORK4 (32|EMBEDFLAGS_OUTERPLANAR)
#define EMBEDFLAGS_SEARCHFORK33 (64|EMBEDFLAGS_PLANAR)
#define EMBEDFLAGS_SEARCHFORK5 (128|EMBEDFLAGS_PLANAR)
#define EMBEDFLAGS_MAXIMALPLANARSUBGRAPH 256
#define EMBEDFLAGS_PROJECTIVEPLANAR 512
#define EMBEDFLAGS_TOROIDAL 1024
#ifdef __cplusplus
}
#endif
#endif