diff --git a/src/SOCgen.c b/src/SOCgen.c index fe9398b..2b03cb0 100644 --- a/src/SOCgen.c +++ b/src/SOCgen.c @@ -324,6 +324,63 @@ 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. + * + * If there are k-cycles, then a chord + * A) introduces a two-cycle, or + * B) introduces a (k-1)-cycle. + * So, if there are no two-cycles, then we must only test the cycles of length + * k where cyclescnt[k-1] is nonzero. + * + * Cycles of length two are trivially chordless. + ***/ +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; + const int hastwocycles = cyclescnt[2]; + for (int clen=n; clen>2; clen--) { + if (!cyclescnt[clen]) continue; + if (!hastwocycles && !cyclescnt[clen-1]) continue; + for (int i=0; i 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 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);