Skip to content

Commit d344520

Browse files
author
Anton Eriksson
committed
refactor: Extract aggregateModuleLinks from writeTreeLinks
1 parent 7db19f2 commit d344520

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/core/InfomapBase.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,10 +2381,8 @@ void InfomapBase::writeTree(std::ostream& outStream, bool states)
23812381
outStream << std::setprecision(oldPrecision);
23822382
}
23832383

2384-
void InfomapBase::writeTreeLinks(std::ostream& outStream, bool states)
2384+
std::map<std::string, std::map<std::pair<unsigned int, unsigned int>, double>> InfomapBase::aggregateModuleLinks(bool states)
23852385
{
2386-
auto oldPrecision = outStream.precision();
2387-
outStream << std::setprecision(6);
23882386
// Aggregate links between each module. Rest is aggregated as exit flow
23892387

23902388
// Links on nodes within sub infomap instances doesn't have links outside the root
@@ -2477,6 +2475,16 @@ void InfomapBase::writeTreeLinks(std::ostream& outStream, bool states)
24772475
}
24782476
}
24792477

2478+
return moduleLinks;
2479+
}
2480+
2481+
void InfomapBase::writeTreeLinks(std::ostream& outStream, bool states)
2482+
{
2483+
auto oldPrecision = outStream.precision();
2484+
outStream << std::setprecision(6);
2485+
2486+
auto moduleLinks = aggregateModuleLinks(states);
2487+
24802488
outStream << "*Links " << (isUndirectedFlow() ? "undirected" : "directed") << "\n";
24812489
outStream << "#*Links path enterFlow exitFlow numEdges numChildren\n";
24822490

src/core/InfomapBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ class InfomapBase : public InfomapConfig<InfomapBase> {
502502
*/
503503
void writeCsvTree(std::ostream& outStream, bool states = false);
504504

505+
std::map<std::string, std::map<std::pair<unsigned int, unsigned int>, double>> aggregateModuleLinks(bool states = false);
506+
505507
InfoNode m_root;
506508
std::vector<InfoNode*> m_leafNodes;
507509
std::vector<InfoNode*> m_moduleNodes;

0 commit comments

Comments
 (0)