3737
3838#include " graph_partitioner.hpp"
3939#include < algorithms/partitioner/build_sb_graph.hpp>
40+ #include < algorithms/partitioner/kernighan_lin_partitioner.hpp>
41+ #include < algorithms/partitioner/partition_graph.hpp>
4042#include < algorithms/partitioner/weighted_sb_graph.hpp>
4143
42- constexpr const char *VALID_PARTITION_METHODS = " { Scotch, Metis, HMetis, Kahip}" ;
44+ constexpr const char *VALID_PARTITION_METHODS = " { Scotch, Metis, HMetis, Kahip, SBG }" ;
4345
4446// Initialize the map outside the function
4547static const std::unordered_map<std::string, PartitionMethod> PARTITION_METHOD_MAP = {{" Metis" , PartitionMethod::Metis},
4648 {" HMetis" , PartitionMethod::HMetis},
4749 {" Scotch" , PartitionMethod::Scotch},
48- {" Kahip" , PartitionMethod::Kahip}};
50+ {" Kahip" , PartitionMethod::Kahip},
51+ {" SBG" , PartitionMethod::SBG}};
52+
53+ static std::unique_ptr<SBG::LIB::WeightedSBGraph> sbg_graph;
4954
5055GraphPartitioner::GraphPartitioner (const std::string &name) : _name(name) { generateInputGraph (); }
5156
@@ -95,6 +100,9 @@ Partition GraphPartitioner::createPartition(const std::string &partition_method_
95100 case PartitionMethod::Kahip:
96101 partitionUsingKaHip (partition);
97102 break ;
103+ case PartitionMethod::SBG:
104+ partitionUsingSBG ();
105+ break ;
98106 default :
99107 break ;
100108 }
@@ -122,8 +130,9 @@ void GraphPartitioner::generateInputGraph()
122130
123131void GraphPartitioner::readGraphFromJson ()
124132{
125- auto sb_graph = sbg_partitioner::build_sb_graph (_name);
126- readGraphFromSBG (sb_graph);
133+ auto temp_sbg_graph = sbg_partitioner::build_sb_graph (_name);
134+ sbg_graph.reset (new SBG::LIB::WeightedSBGraph (temp_sbg_graph));
135+ readGraphFromSBG ();
127136}
128137
129138void GraphPartitioner::readGraph ()
@@ -314,13 +323,23 @@ void GraphPartitioner::partitionUsingKaHip(Partition &partition)
314323 partition.values .data ());
315324}
316325
317- void GraphPartitioner::readGraphFromSBG (const SBG::LIB::WeightedSBGraph &sbg_graph)
326+ void GraphPartitioner::partitionUsingSBG ()
327+ {
328+ std::cout << " partitionUsingSBG" << std::endl;
329+
330+ auto partitions = sbg_partitioner::best_initial_partition (*sbg_graph, _nbr_parts, sbg_partitioner::InitialPartitionStrategy::ALL, false );
331+ // std::cout << "chosen partition " << partitions << std::endl;
332+
333+ sbg_partitioner::kl_sbg_imbalance_partitioner (*sbg_graph, partitions, _imbalance, false );
334+ }
335+
336+ void GraphPartitioner::readGraphFromSBG ()
318337{
319- _nbr_vtxs = sbg_graph. V ().cardinal ();
320- _edges = sbg_graph. E ().cardinal ();
338+ _nbr_vtxs = sbg_graph-> V ().cardinal ();
339+ _edges = sbg_graph-> E ().cardinal ();
321340 // asumming all setpiece are unidimensional and have step 1
322341 int max_node = -1 ;
323- for (const auto &v : sbg_graph. V ()) {
342+ for (const auto &v : sbg_graph-> V ()) {
324343 if (int (v.begin ()[0 ].end ()) > max_node) {
325344 max_node = int (v.begin ()[0 ].end ());
326345 }
@@ -330,11 +349,11 @@ void GraphPartitioner::readGraphFromSBG(const SBG::LIB::WeightedSBGraph &sbg_gra
330349
331350 for (int i = 0 ; i <= max_node; i++) {
332351 auto s = SBG::LIB::SET_FACT.createSet (SBG::LIB::Interval (i, 1 , i));
333- auto edges1 = sbg_graph. map1 ().preImage (s);
334- auto nodes1 = sbg_graph. map2 ().image (edges1);
352+ auto edges1 = sbg_graph-> map1 ().preImage (s);
353+ auto nodes1 = sbg_graph-> map2 ().image (edges1);
335354
336- auto edges2 = sbg_graph. map2 ().preImage (s);
337- auto nodes2 = sbg_graph. map1 ().image (edges2);
355+ auto edges2 = sbg_graph-> map2 ().preImage (s);
356+ auto nodes2 = sbg_graph-> map1 ().image (edges2);
338357
339358 auto nodes = nodes1.cup (nodes2);
340359 auto nodes_vector = std::vector<int >();
0 commit comments