@@ -1180,6 +1180,8 @@ vertex_idx_t<Graph_t_in> Sarkar<Graph_t_in, Graph_t_out>::out_buffer_merge(v_wor
11801180 }
11811181 }
11821182
1183+ vertex_idx_t <Graph_t_in> counter = 0 ;
1184+ std::vector<bool > partitionedFlag (graph.num_vertices (), false );
11831185
11841186 std::vector<bool > consideredVertices (graph.num_vertices (), false );
11851187 for (const VertexType &vert : graph.vertices ()) {
@@ -1213,7 +1215,12 @@ vertex_idx_t<Graph_t_in> Sarkar<Graph_t_in, Graph_t_out>::out_buffer_merge(v_wor
12131215 }
12141216 if (secureOrb.size () <= 1U ) continue ;
12151217
1216-
1218+ const v_workw_t <Graph_t_in> desiredVerticesInGroup = graph.vertex_work_weight (vert) == 0 ? std::numeric_limits<v_workw_t <Graph_t_in>>::lowest () : params.smallWeightThreshold / graph.vertex_work_weight (vert);
1219+ const v_workw_t <Graph_t_in> maxVerticesInGroup = graph.vertex_work_weight (vert) == 0 ? std::numeric_limits<v_workw_t <Graph_t_in>>::max () : params.maxWeight / graph.vertex_work_weight (vert);
1220+
1221+ const std::size_t minDesiredSize = desiredVerticesInGroup < 2 ? 2U : static_cast <std::size_t >(desiredVerticesInGroup);
1222+ const std::size_t maxDesiredSize = std::max (minDesiredSize, std::min (minDesiredSize * 2U , static_cast <std::size_t >(maxVerticesInGroup)));
1223+
12171224 auto descendantsCmp = [&vertexPoset](const VertexType &lhs, const VertexType &rhs) {
12181225 return (vertexPoset[lhs] < vertexPoset[rhs])
12191226 || ((vertexPoset[lhs] == vertexPoset[rhs]) && (lhs < rhs));
@@ -1238,98 +1245,87 @@ vertex_idx_t<Graph_t_in> Sarkar<Graph_t_in, Graph_t_out>::out_buffer_merge(v_wor
12381245
12391246 // todo make me a parameter
12401247 constexpr vertex_idx_t <Graph_t_in> groupingSearchDepth = static_cast < vertex_idx_t <Graph_t_in> >(5 );
1248+
12411249 for (vertex_idx_t <Graph_t_in> i = 0 ; i < groupingSearchDepth; ++i) {
12421250 if (descendantQueue.empty ()) continue ;
1251+
1252+ Union_Find_Universe<VertexType, VertexType, v_workw_t <Graph_t_in>, unsigned > similarityGroupingsPrevious = similarityGroupings;
1253+
12431254 const vertex_idx_t <Graph_t_in> level = vertexPoset[ descendantQueue.cbegin ()->first ];
12441255 while ((!descendantQueue.empty ()) && vertexPoset[ descendantQueue.cbegin ()->first ] == level) {
12451256 const VertexType &descendant = descendantQueue.cbegin ()->first ;
12461257 const std::set<VertexType> &orbSubset = descendantQueue.cbegin ()->second ;
12471258
1248- const VertexType firstVert = *orbSubset.begin ();
1249- for (const VertexType otherVert : orbSubset) {
1250- similarityGroupings.join_by_name (firstVert, otherVert);
1259+ auto firstVertIter = orbSubset.begin ();
1260+ while ((firstVertIter != orbSubset.end ()) && partitionedFlag[*firstVertIter]) {
1261+ ++firstVertIter;
1262+ }
1263+
1264+ for (auto otherVertIter = firstVertIter; otherVertIter != orbSubset.end (); ++otherVertIter) {
1265+ if (! partitionedFlag[*otherVertIter]) {
1266+ similarityGroupings.join_by_name (*firstVertIter, *otherVertIter);
1267+ }
12511268 }
12521269
12531270 for (const VertexType chld : graph.children (descendant)) {
12541271 auto it = descendantQueue.find (chld);
12551272 if (it == descendantQueue.end ()) {
1256- descendantQueue.emplace (chld, std::initializer_list< vertex_idx_t <Graph_t_in> >{*orbSubset. cbegin () });
1273+ descendantQueue.emplace (chld, std::initializer_list< vertex_idx_t <Graph_t_in> >{*firstVertIter });
12571274 } else {
1258- it->second .insert (*orbSubset. cbegin () );
1275+ it->second .insert (*firstVertIter );
12591276 }
12601277 }
12611278
12621279 descendantQueue.erase (descendantQueue.begin ());
12631280 }
12641281
1265- // TODO stuff
1266- }
1267-
1268- // Union_Find_Universe<VertexType, VertexType, v_workw_t<Graph_t_in>, unsigned> bestSimilarGrouping = similarityGroupings;
1269- // todo
1270-
1282+ for (const auto &similarGroup : similarityGroupings.get_connected_components ()) {
1283+ if (partitionedFlag[*similarGroup.begin ()]) continue ;
12711284
1285+ if (similarGroup.size () < minDesiredSize) continue ;
12721286
1287+ if (similarGroup.size () < maxDesiredSize) {
1288+ expansionMapOutput.emplace_back (similarGroup);
1289+ for (const VertexType &mergedVert : similarGroup) {
1290+ partitionedFlag[mergedVert] = true ;
1291+ }
1292+ counter += static_cast <VertexType>( similarGroup.size () ) - 1 ;
12731293
1294+ } else {
1295+ std::map<VertexType, std::vector<VertexType>> prevGrouping;
1296+ for (const VertexType &simVert : similarGroup) {
1297+ const VertexType prevGroupIndx = similarityGroupingsPrevious.find_origin_by_name (simVert);
1298+
1299+ auto prevGroupingIter = prevGrouping.find (prevGroupIndx);
1300+ if (prevGroupingIter != prevGrouping.end ()) {
1301+ prevGroupingIter->second .emplace_back (simVert);
1302+ } else {
1303+ prevGrouping.emplace (prevGroupIndx, std::initializer_list<VertexType>{simVert});
1304+ }
1305+ }
12741306
1307+ std::vector<std::size_t > prevGroupSizes;
1308+ for (const auto &prevGroup : prevGrouping) {
1309+ prevGroupSizes.emplace_back (prevGroup.second .size ());
1310+ }
12751311
12761312
1277- for (const VertexType &touchedVertex : secureOrb) {
1278- consideredVertices[touchedVertex] = true ;
1313+ // look at previous step and figure out merging
1314+ }
1315+ }
1316+ // deal with non-merged
12791317 }
1280- }
1281-
1282-
1283-
1284-
12851318
12861319
12871320
12881321
12891322
12901323
1291- // todo
12921324
1293- std::vector<bool > partitionedFlag (graph.num_vertices (), false );
1294-
1295- // vertex_idx_t<Graph_t_in> maxCorseningNum = graph.num_vertices() - static_cast<vertex_idx_t<Graph_t_in>>(static_cast<double>(graph.num_vertices()) * params.geomDecay);
1296-
1297- vertex_idx_t <Graph_t_in> counter = 0 ;
1298- // long minSave = std::numeric_limits<long>::lowest();
1299- // for (auto prioIter = vertPriority.begin(); prioIter != vertPriority.end(); prioIter++) {
1300- // const long &vertSave = prioIter->first;
1301- // const VertexType &groupHead = prioIter->second;
1302-
1303- // // Iterations halt
1304- // if (vertSave < minSave) break;
1305-
1306- // // Check whether we can glue
1307- // bool shouldSkip = false;
1308- // for (const VertexType &groupFoot : graph.children(groupHead)) {
1309- // if (partitionedFlag[groupFoot]) {
1310- // shouldSkip = true;
1311- // break;
1312- // }
1313- // }
1314- // if (shouldSkip) continue;
1315-
1316- // // Adding to partition
1317- // std::vector<VertexType> part;
1318- // part.reserve(graph.out_degree(groupHead));
1319- // for (const VertexType &groupFoot : graph.children(groupHead)) {
1320- // part.emplace_back(groupFoot);
1321- // }
1322-
1323- // expansionMapOutput.emplace_back( std::move(part) );
1324- // counter += graph.out_degree(groupHead) - 1;
1325- // if (counter > maxCorseningNum) {
1326- // minSave = vertSave;
1327- // }
1328-
1329- // for (const VertexType &groupFoot : graph.children(groupHead)) {
1330- // partitionedFlag[groupFoot] = true;
1331- // }
1332- // }
1325+ for (const VertexType &touchedVertex : secureOrb) {
1326+ consideredVertices[touchedVertex] = true ;
1327+ }
1328+ }
13331329
13341330 for (const VertexType &vert : graph.vertices ()) {
13351331 if (partitionedFlag[vert]) continue ;
0 commit comments