From a27b46106d30c599632cf8b5715c9aae403acff1 Mon Sep 17 00:00:00 2001 From: Yichen Wang Date: Mon, 14 Aug 2023 16:33:05 -0400 Subject: [PATCH] Add iteration stop criteria --- src/leidenbase/leidenFindPartition.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/leidenbase/leidenFindPartition.cpp b/src/leidenbase/leidenFindPartition.cpp index bddfb70..8f861b7 100644 --- a/src/leidenbase/leidenFindPartition.cpp +++ b/src/leidenbase/leidenFindPartition.cpp @@ -135,7 +135,7 @@ int leidenFindPartition( igraph_t *pigraph, { int correctSelfLoops; int status; - std::int32_t iiter; + std::int32_t iiter = 0; size_t numVertex; size_t numEdge; @@ -207,9 +207,11 @@ int leidenFindPartition( igraph_t *pigraph, /* * Run optimiser. */ - for( iiter = 0; iiter < numIter; ++iiter ) + double update = 1; + while (iiter < numIter && update > 0) { - optimiser.optimise_partition( ppartition ); + update = optimiser.optimise_partition( ppartition ); + iiter++; } /*