Skip to content

Commit de59faa

Browse files
committed
revise bwd merkle hash computer, orbit error
1 parent f6b0794 commit de59faa

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

include/osp/dag_divider/isomorphism_divider/MerkleHashComputer.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ limitations under the License.
2424
#include <stdexcept>
2525
#include "osp/concepts/computational_dag_concept.hpp"
2626
#include "osp/graph_algorithms/directed_graph_top_sort.hpp"
27+
#include "osp/graph_algorithms/directed_graph_util.hpp"
2728
#include "osp/auxiliary/hash_util.hpp"
2829

2930
namespace osp {
@@ -160,19 +161,15 @@ template<typename Graph_t>
160161
struct bwd_merkle_node_hash_func {
161162

162163
MerkleHashComputer<Graph_t, uniform_node_hash_func<vertex_idx_t<Graph_t>>, false> bw_merkle_hash;
164+
std::vector<std::size_t> vertex_components;
163165

164-
const Graph_t & graph_;
165-
166-
bwd_merkle_node_hash_func(const Graph_t & graph) : bw_merkle_hash(graph), graph_(graph) {}
166+
bwd_merkle_node_hash_func(const Graph_t & graph) : bw_merkle_hash(graph) {
167+
compute_weakly_connected_components(graph, vertex_components);
168+
}
167169

168170
std::size_t operator()(const vertex_idx_t<Graph_t> & v) const {
169171
std::size_t hash = bw_merkle_hash.get_vertex_hash(v);
170-
hash_combine(hash, graph_.vertex_work_weight(v));
171-
172-
if constexpr (has_typed_vertices_v<Graph_t>) {
173-
hash_combine(hash, graph_.vertex_type(v));
174-
}
175-
172+
hash_combine(hash, static_cast<size_t>((vertex_components[v] + 3) * 7));
176173
return hash;
177174
}
178175
};

include/osp/dag_divider/isomorphism_divider/OrbitGraphProcessor.hpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,15 @@ class OrbitGraphProcessor {
163163

164164
// --- Check Constraints ---
165165
// Symmetry Threshold
166-
const bool merge_viable = is_merge_viable(original_dag, current_groups[u], current_groups[v], new_subgraphs);
166+
bool error = false;
167+
const bool merge_viable = is_merge_viable(original_dag, current_groups[u], current_groups[v], new_subgraphs, error);
167168
const bool both_below_symmetry_threshold = (current_groups[u].size() < symmetry_threshold_) && (current_groups[v].size() < symmetry_threshold_);// && (not ((current_groups[u].size() == 1 && current_groups[v].size() > 1) || (current_groups[u].size() > 1 && current_groups[v].size() == 1)));
168169

170+
if (error) {
171+
if constexpr (verbose) { std::cout << " - Merge of " << u << " and " << v << " and " << v << " not viable (error in is_merge_viable)\n"; }
172+
continue;
173+
}
174+
169175
if (!merge_viable && !both_below_symmetry_threshold) {
170176
if constexpr (verbose) { std::cout << " - Merge of " << u << " and " << v << " not viable (symmetry threshold)\n"; }
171177
continue;
@@ -261,7 +267,7 @@ class OrbitGraphProcessor {
261267
* If viable, it populates the `out_new_subgraphs` with the structure of the merged group.
262268
*/
263269
bool is_merge_viable(const Graph_t& original_dag, const Group& group_u, const Group& group_v,
264-
std::vector<std::vector<VertexType>>& out_new_subgraphs) const {
270+
std::vector<std::vector<VertexType>>& out_new_subgraphs, bool & error) const {
265271

266272
std::vector<VertexType> all_nodes;
267273
all_nodes.reserve(group_u.subgraphs.size() + group_v.subgraphs.size());
@@ -281,13 +287,19 @@ class OrbitGraphProcessor {
281287
std::sort(all_nodes.begin(), all_nodes.end());
282288

283289
Constr_Graph_t induced_subgraph;
284-
auto map = create_induced_subgraph_map(original_dag, induced_subgraph, all_nodes);
285290

291+
// create_induced_subgraph(original_dag, induced_subgraph, all_nodes);
292+
// std::vector<VertexType> components; // local -> component_id
293+
// size_t num_components = compute_weakly_connected_components(induced_subgraph, components);
294+
// out_new_subgraphs.assign(num_components, std::vector<VertexType>());
295+
// for (VertexType i = 0; i < induced_subgraph.num_vertices(); ++i) {
296+
// out_new_subgraphs[components[i]].push_back(all_nodes[i]);
297+
// }
298+
299+
auto map = create_induced_subgraph_map(original_dag, induced_subgraph, all_nodes);
286300
std::vector<VertexType> components; // local -> component_id
287301
size_t num_components = compute_weakly_connected_components(induced_subgraph, components);
288-
289302
out_new_subgraphs.assign(num_components, std::vector<VertexType>());
290-
291303
for (const auto & node : all_nodes) {
292304
out_new_subgraphs[components[map[node]]].push_back(node);
293305
}
@@ -303,12 +315,14 @@ class OrbitGraphProcessor {
303315

304316
for (size_t i = 1; i < num_components; ++i) {
305317
if (out_new_subgraphs[i].size() != first_sg_size) {
318+
error = true;
306319
return false;
307320
}
308321

309322
Constr_Graph_t current_sg;
310323
create_induced_subgraph(original_dag, current_sg, out_new_subgraphs[i]);
311324
if (!are_isomorphic_by_merkle_hash(rep_sg, current_sg)) {
325+
error = true;
312326
return false;
313327
}
314328
}

0 commit comments

Comments
 (0)