Skip to content

Commit 2936740

Browse files
committed
update merge rules
1 parent 9df102c commit 2936740

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

include/osp/dag_divider/isomorphism_divider/OrbitGraphProcessor.hpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ class OrbitGraphProcessor {
8686
};
8787

8888
std::unordered_set<std::pair<VertexType, VertexType>, PairHasher> non_viable_edges_cache_;
89-
90-
89+
std::unordered_set<std::pair<VertexType, VertexType>, PairHasher> non_viable_crit_path_edges_cache_;
9190

9291
/**
9392
* @brief Simulates the merge of node v into u and returns the resulting temporary graph.
@@ -147,6 +146,22 @@ class OrbitGraphProcessor {
147146
}
148147
non_viable_edges_cache_ = std::move(next_non_viable_edges);
149148

149+
150+
std::unordered_set<std::pair<VertexType, VertexType>, PairHasher> next_non_viable_crit_path_edges;
151+
for (const auto &non_viable_edge : non_viable_crit_path_edges_cache_) {
152+
VertexType old_u = non_viable_edge.first;
153+
VertexType old_v = non_viable_edge.second;
154+
// If an edge involved the removed vertex `v`, it's gone. Otherwise, remap its endpoints.
155+
if (old_u != v && old_v != v) {
156+
VertexType new_u = group_remap[old_u];
157+
VertexType new_v = group_remap[old_v];
158+
if (new_u != new_v) {
159+
next_non_viable_crit_path_edges.insert({new_u, new_v});
160+
}
161+
}
162+
}
163+
non_viable_crit_path_edges_cache_ = std::move(next_non_viable_crit_path_edges);
164+
150165
std::vector<Group> next_groups(current_coarse_graph.num_vertices());
151166
for (VertexType i = 0; i < current_groups.size(); ++i) {
152167
if (i != u && i != v) {
@@ -243,7 +258,7 @@ class OrbitGraphProcessor {
243258
}
244259
}
245260

246-
void contract_edges(const Graph_t &original_dag, Constr_Graph_t& current_coarse_graph, std::vector<Group>& current_groups, std::vector<VertexType>& current_contraction_map, const bool merge_symmetry_narrowing, const bool merge_different_node_types) {
261+
void contract_edges(const Graph_t &original_dag, Constr_Graph_t& current_coarse_graph, std::vector<Group>& current_groups, std::vector<VertexType>& current_contraction_map, const bool merge_symmetry_narrowing, const bool merge_different_node_types, const v_workw_t<Constr_Graph_t> work_threshold = 0) {
247262

248263
bool changed = true;
249264
while (changed) {
@@ -258,7 +273,7 @@ class OrbitGraphProcessor {
258273
VertexType v = target(edge, current_coarse_graph);
259274

260275
// Check memoization cache first
261-
if (non_viable_edges_cache_.count({u, v})) {
276+
if (non_viable_edges_cache_.count({u, v}) || non_viable_crit_path_edges_cache_.count({u, v})) {
262277
continue;
263278
}
264279

@@ -290,8 +305,8 @@ class OrbitGraphProcessor {
290305
const bool merge_viable = is_merge_viable(original_dag, current_groups[u], current_groups[v], new_subgraphs, error);
291306
const bool both_below_symmetry_threshold =
292307
(u_size < symmetry_threshold_) &&
293-
(v_size < symmetry_threshold_) &&
294-
(not ((u_size == 1 && v_size > 1) || (u_size > 1 && v_size == 1)));
308+
(v_size < symmetry_threshold_);// &&
309+
// (not ((u_size == 1 && v_size > 1) || (u_size > 1 && v_size == 1)));
295310

296311
if (error) {
297312
if constexpr (verbose) {
@@ -333,11 +348,12 @@ class OrbitGraphProcessor {
333348
// }
334349
// continue;
335350
// }
336-
if (critical_path_weight(temp_coarse_graph) > critical_path_weight(current_coarse_graph)) {
351+
if (critical_path_weight(temp_coarse_graph) > (work_threshold * static_cast<v_workw_t<Constr_Graph_t>>(new_subgraphs.size()) + critical_path_weight(current_coarse_graph))) {
352+
//if (critical_path_weight(temp_coarse_graph) > critical_path_weight(current_coarse_graph)) {
337353
if constexpr (verbose) {
338354
std::cout << " - Merge of " << u << " and " << v << " increases critical path. Skipping.\n";
339355
}
340-
non_viable_edges_cache_.insert({u, v});
356+
non_viable_crit_path_edges_cache_.insert({u, v});
341357
continue;
342358
}
343359

@@ -378,6 +394,7 @@ class OrbitGraphProcessor {
378394
final_contraction_map_.clear();
379395
final_groups_.clear();
380396
non_viable_edges_cache_.clear();
397+
non_viable_crit_path_edges_cache_.clear();
381398

382399
if (dag.num_vertices() == 0) {
383400
return;
@@ -436,7 +453,9 @@ class OrbitGraphProcessor {
436453
if constexpr (verbose) {
437454
std::cout << "Attempting to merge small orbits.\n";
438455
}
439-
merge_small_orbits(original_dag, current_coarse_graph, current_groups, current_contraction_map, work_threshold_);
456+
non_viable_crit_path_edges_cache_.clear();
457+
contract_edges(original_dag, current_coarse_graph, current_groups, current_contraction_map, true, true, work_threshold_);
458+
// merge_small_orbits(original_dag, current_coarse_graph, current_groups, current_contraction_map, work_threshold_);
440459

441460
// --- Finalize ---
442461
final_coarse_graph_ = std::move(current_coarse_graph);

0 commit comments

Comments
 (0)