From 1922396b71bee936570b103000b3a1a629f7323b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Wed, 20 Nov 2024 11:50:36 +0100 Subject: [PATCH] bug fix --- src/SOCgen.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/SOCgen.c b/src/SOCgen.c index 2b03cb0..feeae56 100644 --- a/src/SOCgen.c +++ b/src/SOCgen.c @@ -339,23 +339,25 @@ int find_cycles(int *cycles, int *cyclescnt, int n, const int *children, \ * 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. + * 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; - const int hastwocycles = cyclescnt[2]; for (int clen=n; clen>2; clen--) { if (!cyclescnt[clen]) continue; - if (!hastwocycles && !cyclescnt[clen-1]) 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