From 353d79573149addb7abb6f4405654205b4633a99 Mon Sep 17 00:00:00 2001 From: Tobias Kempf Date: Sun, 1 Dec 2024 03:06:56 +0100 Subject: [PATCH] Fix LocalFM --- .gitignore | 1 + mt-kahypar/dynamic/dynamic_io.h | 4 ++++ mt-kahypar/dynamic/strategies/lokalFM.h | 25 +++++++++++++++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 44067e4e5..2ead21576 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ python/tests/unittest python/tests/*.so python/examples/*.so compile_commands.json +results/ diff --git a/mt-kahypar/dynamic/dynamic_io.h b/mt-kahypar/dynamic/dynamic_io.h index b6a8557a0..3b8cf39a1 100644 --- a/mt-kahypar/dynamic/dynamic_io.h +++ b/mt-kahypar/dynamic/dynamic_io.h @@ -213,6 +213,10 @@ namespace mt_kahypar::dyn { std::tuple, 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, diff --git a/mt-kahypar/dynamic/strategies/lokalFM.h b/mt-kahypar/dynamic/strategies/lokalFM.h index 0eab9a029..54be9a07f 100644 --- a/mt-kahypar/dynamic/strategies/lokalFM.h +++ b/mt-kahypar/dynamic/strategies/lokalFM.h @@ -11,7 +11,6 @@ namespace mt_kahypar::dyn { private: std::optional> partitioned_hypergraph_s; - mt_kahypar_partitioned_hypergraph_t partitioned_hypergraph; int repartition_count = 0; gain_cache_t _gain_cache; std::unique_ptr _fm; @@ -19,27 +18,33 @@ namespace mt_kahypar::dyn { 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::max()); } PartitionID add_node_to_partitioned_hypergraph(ds::StaticHypergraph& hypergraph, Context& context, const HypernodeID& hn) {