This repository was archived by the owner on Dec 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsc_problem.cpp
More file actions
71 lines (61 loc) · 2.4 KB
/
Copy pathcsc_problem.cpp
File metadata and controls
71 lines (61 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "common/csc_problem.hpp"
#include <common/cut_vertex.hpp>
#include <common/embedding_base.hpp>
#include <common/embedding_manager.hpp>
#include <common/debug_utils.hpp>
#include <common/random_gen.hpp>
using namespace majorminer;
adjacency_list_t majorminer::extractSubgraph(const EmbeddingBase& base, fuint32_t sourceNode)
{
adjacency_list_t subgraph{};
const auto& targetGraph = *base.getTargetGraph();
base.iterateSourceMappingPair(sourceNode,
[&subgraph, &targetGraph](fuint32_t targetNodeA, fuint32_t targetNodeB){
edge_t uv{targetNodeA, targetNodeB};
edge_t vu{targetNodeB, targetNodeA};
if (targetGraph.contains(uv) || targetGraph.contains(vu))
{
subgraph.insert(uv);
subgraph.insert(vu);
}
});
return subgraph;
}
nodeset_t majorminer::getEmbeddedAdjacentSourceVertices(const EmbeddingBase& base, fuint32_t sourceVertex)
{
const auto& mapping = base.getMapping();
nodeset_t connections{};
base.iterateSourceGraphAdjacent(sourceVertex, [&](fuint32_t adjSourceNode){
if (mapping.contains(adjSourceNode)) connections.insert(adjSourceNode);
});
return connections;
}
bool majorminer::isNodeCrucial(const EmbeddingBase& base, fuint32_t sourceNode, fuint32_t targetNode, fuint32_t conqueror)
{
// 1. Check whether targetNode is crucial due to it being a cut vertex
// std::cout << "Checking whether cut vertex " << std::endl;
if (isCutVertex(base, sourceNode, targetNode)) return true;
// std::cout << "Is no cut vertex" << std::endl;
// 2. Check whether targetNode is crucial connections to other super vertices
nodeset_t connections = getEmbeddedAdjacentSourceVertices(base, sourceNode);
connections.unsafe_erase(conqueror);
base.iterateSourceMappingAdjacentReverse(sourceNode, targetNode, [&](fuint32_t adjSourceNode){
connections.unsafe_erase(adjSourceNode);
return connections.empty();
});
// std::cout << "Connections empty? " << connections.empty() << std::endl;
return !connections.empty();
}
bool majorminer::connectsToAdjacentVertices(const EmbeddingManager& base,
const nodeset_t& placement, fuint32_t sourceVertex)
{
nodeset_t connections = getEmbeddedAdjacentSourceVertices(base, sourceVertex);
for (auto target : placement)
{
base.iterateTargetAdjacentReverseMapping(target,
[&connections](fuint32_t sourceAdj){
connections.unsafe_erase(sourceAdj);
});
}
return connections.empty();
}