void
degstats(graph *g, int m, int n, unsignedlong *edges, int *mindeg, int *mincount, int *maxdeg, int *maxcount, boolean *eulerian) /* Compute degree-related graph properties. *edges = number of edges *mindeg, *mincount = minimum degree and how many there are *maxdeg, *maxcount = maximum degree and how many there are *eulerian = whether the graph has only even degrees
*/
{
setword *pg; int i,j,d,dor; int mind,mindc,maxd,maxdc; unsignedlong ned;
mind = n;
mindc = 0;
maxd = 0;
maxdc = 0;
ned = 0;
dor = 0;
pg = (setword*)g; for (i = 0; i < n; ++i)
{
d = 0; for (j = 0; j < m; ++j, ++pg) if (*pg) d += POPCOUNT(*pg);
if (d == mind)
++mindc; elseif (d < mind)
{
mind = d;
mindc = 1;
}
void
degstats3(graph *g, int m, int n, unsignedlong *edges, int *mindeg, int *mincount, int *maxdeg, int *maxcount, int *odddeg) /* Compute degree-related graph properties. *edges = number of edges *mindeg, *mincount = minimum degree and how many there are *maxdeg, *maxcount = maximum degree and how many there are *odddeg = number of vertices of odd degree
*/
{
setword *pg; int i,j,d,dodd; int mind,mindc,maxd,maxdc; unsignedlong ned;
mind = n;
mindc = 0;
maxd = 0;
maxdc = 0;
ned = 0;
dodd = 0;
pg = (setword*)g; for (i = 0; i < n; ++i)
{
d = 0; for (j = 0; j < m; ++j, ++pg) if (*pg) d += POPCOUNT(*pg);
if (d == mind)
++mindc; elseif (d < mind)
{
mind = d;
mindc = 1;
}
void
degstats2(graph *g, boolean digraph, int m, int n, unsignedlong *edges, int *loops, int *minindeg, int *minincount, int *maxindeg, int *maxincount, int *minoutdeg, int *minoutcount, int *maxoutdeg, int *maxoutcount,
boolean *eulerian) /* Compute degree-related graph properties. *edges = number of edges (including loops), directed edges for digraphs *loops = number of loops *minindeg, *minincount = minimum in-degree and how many there are *maxindeg, *maxincount = maximum in-degree and how many there are *minoutdeg,*minoutcount,*maxoutdeg,*maxoutcount = similarly for out-degree *eulerian = whether the undirected graph has only even degrees, or the directed graph has indegree=outdegree at each vertex. A loop contributes 2 to the degrees of an undirected graph and 1 to each degree for a directed graph.
*/
{
setword *pg; int i,j,d,dor; int mind,mindc,maxd,maxdc; unsignedlong ned; int nloops; #if MAXN int indeg[MAXN]; int outdeg[MAXN]; #else
DYNALLSTAT(int,indeg,indeg_sz);
DYNALLSTAT(int,outdeg,outdeg_sz); #endif
void
sources_sinks(graph *g, int m, int n, int *sources, int *sinks) /* Count the sources and sinks. For an undirected graph, these are just the isolated vertices. For a directed graph, they have their usual meanings. A vertex with a loop is neither a source nor a sink.
*/
{
setword rowor,wk; int i,j,nsource,nsink;
set *gi; #if MAXM
setword work[MAXM+1]; #else
DYNALLSTAT(setword,work,work_sz);
DYNALLOC1(setword,work,work_sz,m,"sources_sinks"); #endif
if (n == 0) { *sources = *sinks = 0; return; }
if (m == 1)
{
nsink = 0;
wk = 0; for (i = 0; i < n; ++i)
{ if (g[i] == 0) ++nsink;
wk |= g[i];
}
*sinks = nsink;
*sources = n - POPCOUNT(wk); return;
}
for (i = 0; i < m; ++i) work[i] = 0;
nsink = 0; for (i = 0, gi = g; i < n; ++i, gi += m)
{
rowor = 0; for (j = 0; j < m; ++j)
{
rowor |= gi[j];
work[j] |= gi[j];
} if (rowor == 0) ++nsink;
}
*sinks = nsink;
nsource = n; for (j = 0; j < m; ++j)
nsource -= POPCOUNT(work[j]);
*sources = nsource;
}
boolean
isconnected(graph *g, int m, int n) /* Test if g is connected */
{ int i,head,tail,w;
set *gw; #if MAXN int queue[MAXN],visited[MAXN]; #else
DYNALLSTAT(int,queue,queue_sz);
DYNALLSTAT(int,visited,visited_sz); #endif
if (n == 0) returnFALSE; if (m == 1) return isconnected1(g,n);
boolean
issubconnected(graph *g, set *sub, int m, int n) /* Test if the subset of g induced by sub is connected. Empty is connected. */ /* Note that the value for empty subgraphs disagrees with isconnected() */
{ int i,head,tail,w,subsize;
set *gw; #if MAXN int queue[MAXN],visited[MAXN];
setword subw[MAXM]; #else
DYNALLSTAT(int,queue,queue_sz);
DYNALLSTAT(int,visited,visited_sz);
DYNALLSTAT(set,subw,subw_sz);
boolean
isbiconnected1(graph *g, int n) /* Test if g is biconnected; version for m=1. */
{ int sp,v,w;
setword sw; int numvis;
setword visited; int num[WORDSIZE],lp[WORDSIZE],stack[WORDSIZE];
boolean
isbiconnected(graph *g, int m, int n) /* test if g is biconnected */
{ int sp,v,vc; int numvis;
set *gv; #if MAXN int num[MAXN],lp[MAXN],stack[MAXN]; #else
DYNALLSTAT(int,num,num_sz);
DYNALLSTAT(int,lp,lp_sz);
DYNALLSTAT(int,stack,stack_sz); #endif
if (n <= 2) returnFALSE; if (m == 1) return isbiconnected1(g,n);
boolean
twocolouring(graph *g, int *colour, int m, int n) /* If g is bipartite, set colour[*] to 0 or 1 to indicate an example of 2-colouring and return TRUE. Otherwise return FALSE.
Colour 0 is assigned to the first vertex of each component. */
{ int i,head,tail,v,w,need;
set *gw;
setword xg; #if MAXN int queue[MAXN]; #else
DYNALLSTAT(int,queue,queue_sz); #endif
int
bipartiteside(graph *g, int m, int n) /* If g is not bipartite, return 0. Otherwise return the size of the smallest of the two parts
of a 2-coluring for which this value is smallest. */
{ int i,head,tail,v,w,need;
set *gw;
setword xg; int ans,col[2]; #if MAXN int queue[MAXN]; int colour[MAXN]; #else
DYNALLSTAT(int,queue,queue_sz);
DYNALLSTAT(int,colour,colour_sz); #endif
int
girth(graph *g, int m, int n) /* Find the girth of graph g. 0 means acyclic. */
{ int i,head,tail,v,w; int best,c,dw1;
set *gw; #if MAXN int dist[MAXN],queue[MAXN]; #else
DYNALLSTAT(int,queue,queue_sz);
DYNALLSTAT(int,dist,dist_sz);
void
find_dist(graph *g, int m, int n, int v, int *dist) /* Put in dist[0..n-1] the distance of each vertex from v.
Vertices in a different component are given the distance n. */
{ int i,head,tail,w;
set *gw; #if MAXN int queue[MAXN]; #else
DYNALLSTAT(int,queue,queue_sz); #endif
void
find_dist2(graph *g, int m, int n, int v, int w, int *dist) /* Put in dist[0..n-1] the distance of each vertex from {v,w}.
Vertices in a different component are given the distance n. */
{ int i,head,tail,x;
set *gx; #if MAXN int queue[MAXN]; #else
DYNALLSTAT(int,queue,queue_sz); #endif
int
numcomponents(graph *g, int m, int n) /* Find number of components of undirected graph */
{ int i,nc,head,tail,v,w;
set *gw; #if MAXN int queue[MAXN];
set notvisited[MAXM+1]; /* +1 to satisfy gcc12 on ARM */ #else
DYNALLSTAT(int,queue,queue_sz);
DYNALLSTAT(set,notvisited,notvisited_sz); #endif
if (n == 0) return 0; if (m == 1) return numcomponents1(g,n);
void
diamstats(graph *g, int m, int n, int *radius, int *diameter) /* Find the radius and diameter. Both -1 if g is disconnected.
We use an O(mn) algorithm, which is pretty disgraceful. */
{ int v,i,head,tail,w; int ecc,diam,rad;
set *gw; #if MAXN int queue[MAXN],dist[MAXN]; #else
DYNALLSTAT(int,queue,queue_sz);
DYNALLSTAT(int,dist,dist_sz); #endif
/* if (m == 1) {diamstats1(g,n,radius,diameter); return; } */
staticlong
maxclnode1(graph *g, setword cliq, setword cov, int maxv) /* Internal search node. cov has all the vertices outside cliq that * cover all of cliq. maxv is the last vertex of cliq.
*/
{ long ans; int i;
setword w;
if (cov == 0) return 1;
ans = 0;
w = cov & BITMASK(maxv); while (w)
{
TAKEBIT(i,w);
ans += maxclnode1(g,cliq|bit[i],cov&g[i]&~bit[i],i);
} return ans;
}
long
maxcliques(graph *g, int m, int n) /* Find the number of maximal cliques */
{ int i; long ans;
if (n == 0) return 0;
if (m == 1)
{
ans = 0; for (i = 0; i < n; ++i)
ans += maxclnode1(g,bit[i],g[i],i);
} else
{
fprintf(stderr,">E maxcliques() is only implemented for m=1\n"); exit(1);
}
staticvoid
maxcsnode1(int *best, graph *g, setword cliq, setword cov, int maxv) /* Internal search node. cov has all the vertices outside cliq that * cover all of cliq. maxv is the last vertex of cliq. * *best is the largest clique known so far.
*/
{ int i,s;
setword w;
if (cov == 0) return;
w = cov & BITMASK(maxv);
s = POPCOUNT(cliq); if (s + POPCOUNT(w) <= *best) return; if (w)
{ if (s + 1 > *best) *best = s + 1; while (w)
{
TAKEBIT(i,w);
maxcsnode1(best,g,cliq|bit[i],cov&g[i]&~bit[i],i);
}
}
}
int
maxcliquesize(graph *g, int m, int n) /* Find the largest clique size */
{ int i,best;
if (n == 0) return 0;
if (m == 1)
{
best = 1; for (i = 0; i < n; ++i)
maxcsnode1(&best,g,bit[i],g[i],i);
} else
{
fprintf(stderr,">E maxcliquesize() is only implemented for m=1\n"); exit(1);
}
return best;
}
int
maxindsetsize(graph *g, int m, int n) /* Find the largest independent set size */
{ int i,best;
graph gc[WORDSIZE];
setword all;
if (n == 0) return 0;
if (m == 1)
{
all = ALLMASK(n); for (i = 0; i < n; ++i) gc[i] = g[i] ^ all ^ bit[i];
best = 1; for (i = 0; i < n; ++i)
maxcsnode1(&best,gc,bit[i],gc[i],i);
} else
{
fprintf(stderr,">E maxindsetsize() is only implemented for m=1\n"); exit(1);
}
return best;
}
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.