Compare commits

...

3 Commits
main ... dev

Author SHA1 Message Date
d35206c2b9 --chordless option in readme 2024-11-20 11:52:31 +01:00
1922396b71 bug fix 2024-11-20 11:50:36 +01:00
e953d8aa1f chordless filter 2024-11-20 11:26:27 +01:00
2 changed files with 69 additions and 0 deletions

View File

@ -43,6 +43,7 @@ Usage: ./SOCgen -n <order> [-r <num>] [--graphviz] [FILTER ...]
-c ... that are cyclic (i.e., not DAGs)
--no-sink ... without sink nodes (this logically implies -c)
--no-source ... without source nodes (also this logically implies -c)
--chordless ... without cycles that have chords (this is incompatible with --no-source, see paper)
This program prints the found SOCs as adjacency matrices to stdout, unless --graphviz has been specified.
To exclude (some) of the isomorphic SOCs, it uses a degree-order filter, unless --all is specified.

View File

@ -324,6 +324,65 @@ int find_cycles(int *cycles, int *cyclescnt, int n, const int *children, \
return found;
}
/***
* gischordless tests wheter the graph provided has chordless cycles only
* Parameter `n': Number of nodes
* Parameter `parents': Pointer to list of parents per node
* Parameter `parentslen': Pointer to list of number of parents per node
* Parameter `children': Pointer to list of children per node
* Parameter `childrenlen': Pointer to list of number of children per node
* Parameter `cycles': Pointer to list of cycles in the graph
* Parameter `cyclescnt': Pointer to list of cycles count
* Parameter `num_cycles' Total number of cycles
*
* This function retruns 0 if the graph has a directed cycle with a chord, and
* 1 otherwise.
*
* If there is no cycle, then the graph trivially satisfy this condition.
* Cycles of length two are trivially chordless.
* If there is a k-cycle, then a chord implies the existance of an l-cycle
* with l < k.
***/
int gischordless(int n, const int *parents, const int *parentslen, \
const int *children, const int *childrenlen, const int *cycles, \
const int *cyclescnt, int num_cycles) {
if (!num_cycles) return 1;
for (int clen=n; clen>2; clen--) {
if (!cyclescnt[clen]) continue;
// A chord can only exist if there is a cycle of length < clen
int shortercycleexists = 0;
for (int sclen = 2; sclen < clen; sclen++) {
if (cyclescnt[sclen]) {
shortercycleexists = 1;
break;
}
}
if (!shortercycleexists) return 1;
for (int i=0; i<cyclescnt[clen]; i++) {
const int bs = blocksize(n);
const int startidx = clen*bs + i*clen; // Cycle starts here
int v = cycles[startidx+clen-1];
for (int pos=0; pos<clen; pos++) {
const int u = v;
v = cycles[startidx+pos];
// Cycle has arc u -> v
// Is there a chord, i.e., A) reverse arc u <- v or B) u -> v' for v'
// on the cycle? We test only B), but for all vertices on the cycle.
for (int cidx=0; cidx<childrenlen[u]; cidx++) {
const int child = children[n*u+cidx];
if (child == v) continue;
// Is `child` on the cycle?
for (int j=0; j<clen; j++) {
const int w = cycles[startidx+j];
if (child == w) return 0;
}
}
}
}
}
return 1;
}
/***
* gissoc tests wheter the graph provided is a SOC or not.
* Parameter `n': Number of nodes
@ -485,6 +544,7 @@ int main(int argc, char *argv[]) {
int RANDOM = 0;
int GRAPHVIZ = 0;
int VECTOR = 0;
int CHORDLESS = 0;
int UNKOPTION = 0;
int ALL = 0;
for (int i = 1; i < argc; i++) {
@ -506,6 +566,8 @@ int main(int argc, char *argv[]) {
ALL = 1;
} else if (strcmp(argv[i], "--vector") == 0) {
VECTOR = 1;
} else if (strcmp(argv[i], "--chordless") == 0) {
CHORDLESS = 1;
} else {
UNKOPTION = 1;
break;
@ -523,6 +585,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, " -c ... that are cyclic (i.e., not DAGs)\n");
fprintf(stderr, " --no-sink ... without sink nodes (this logically implies -c)\n");
fprintf(stderr, " --no-source ... without source nodes (also this logically implies -c)\n");
fprintf(stderr, " --chordless ... without cycles that have chords (this is incompatible with --no-source, see paper)\n");
fprintf(stderr, "\n");
fprintf(stderr, "This program prints the found SOCs as adjacency matrices to stdout, unless --graphviz has been specified.\n");
fprintf(stderr, "To exclude (some) of the isomorphic SOCs, it uses a degree-order filter, unless --all is specified.\n");
@ -566,6 +629,8 @@ int main(int argc, char *argv[]) {
fprintf(stderr, " Filter: Omitting graphs with sink nodes\n");
if (NOSOURCE)
fprintf(stderr, " Filter: Omitting graphs with source nodes\n");
if (CHORDLESS)
fprintf(stderr, " Filter: Omitting graphs with chords in directed cycles\n");
// We will always omit the graph with `graphnumber' 0;
// it is unintersting anyway
unsigned long long graphnumber = 0;
@ -630,6 +695,9 @@ int main(int argc, char *argv[]) {
if (num_cycles > 0 && !gissoc(n, parents, parentslen, children, \
childrenlen, cycles, cyclescnt)) continue;
// We have found a SOC
// If enabled, test chordless property
if (CHORDLESS && !gischordless(n, parents, parentslen, children, \
childrenlen, cycles, cyclescnt, num_cycles)) continue;
len++;
if (GRAPHVIZ)
dumpgv(n, graphnumber, children, childrenlen);