Skip to content

Commit

Permalink
Fix LocalFM
Browse files Browse the repository at this point in the history
  • Loading branch information
T3C42 committed Dec 1, 2024
1 parent 200296d commit 353d795
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ python/tests/unittest
python/tests/*.so
python/examples/*.so
compile_commands.json
results/
4 changes: 4 additions & 0 deletions mt-kahypar/dynamic/dynamic_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ namespace mt_kahypar::dyn {

std::tuple<std::vector<Change>, mt_kahypar_hypergraph_t> generateChanges(Context& context) {

context.partition.instance_type = InstanceType::hypergraph;
context.partition.objective = Objective::km1;
context.partition.gain_policy = GainPolicy::km1;

// Read Hypergraph
mt_kahypar_hypergraph_t hypergraph = io::readInputFile(
context.partition.graph_filename, context.partition.preset_type,
Expand Down
25 changes: 15 additions & 10 deletions mt-kahypar/dynamic/strategies/lokalFM.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,40 @@ namespace mt_kahypar::dyn {

private:
std::optional<ds::PartitionedHypergraph<ds::StaticHypergraph>> partitioned_hypergraph_s;
mt_kahypar_partitioned_hypergraph_t partitioned_hypergraph;
int repartition_count = 0;
gain_cache_t _gain_cache;
std::unique_ptr<IRefiner> _fm;
std::unique_ptr<IRebalancer> _rebalancer;

void repartition(ds::StaticHypergraph& hypergraph_s, Context& context) {
partitioned_hypergraph_s = partition_hypergraph_km1(hypergraph_s, context);
_gain_cache = GainCachePtr::constructGainCache(context);
_rebalancer = RebalancerFactory::getInstance().createObject(
context.refinement.rebalancer, hypergraph_s.initialNumNodes(), context, _gain_cache);

_fm = FMFactory::getInstance().createObject(
context.refinement.fm.algorithm,
hypergraph_s.initialNumNodes(), hypergraph_s.initialNumEdges(), context, _gain_cache, *_rebalancer);
repartition_count++;
}

//use local_fm to refine partitioned_hypergraph_s
void local_fm(ds::StaticHypergraph& hypergraph, Context& context, const HypernodeID& hn) {

GainCachePtr::deleteGainCache(_gain_cache);
//GainCachePtr::deleteGainCache(_gain_cache);
//TODO maybe
GainCachePtr::resetGainCache(_gain_cache);

_gain_cache = GainCachePtr::constructGainCache(context);
_rebalancer = RebalancerFactory::getInstance().createObject(
context.refinement.rebalancer, hypergraph.initialNumNodes(), context, _gain_cache);
// _gain_cache = GainCachePtr::constructGainCache(context);

_fm = FMFactory::getInstance().createObject(
context.refinement.fm.algorithm,
hypergraph.initialNumNodes(), hypergraph.initialNumEdges(), context, _gain_cache, *_rebalancer);
mt_kahypar_partitioned_hypergraph_t partitioned_hypergraph = utils::partitioned_hg_cast(*partitioned_hypergraph_s);

_fm->initialize(partitioned_hypergraph);

Metrics best_Metrics = {0, 0};
Metrics best_Metrics = {mt_kahypar::metrics::quality(*partitioned_hypergraph_s, Objective::km1),
mt_kahypar::metrics::imbalance(*partitioned_hypergraph_s, context)};

_fm->refine(partitioned_hypergraph, {hn}, best_Metrics, context.refinement.fm.time_limit_factor);
_fm->refine(partitioned_hypergraph, {hn}, best_Metrics, std::numeric_limits<double>::max());
}

PartitionID add_node_to_partitioned_hypergraph(ds::StaticHypergraph& hypergraph, Context& context, const HypernodeID& hn) {
Expand Down

0 comments on commit 353d795

Please sign in to comment.