MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / search_dfs

Method search_dfs

Extensions/QMapping/SabreQMapping.cpp:91–123  ·  view source on GitHub ↗

* @brief Gets the connected subgraph of the specified number of nodes in the graph * @param[in, out] sub_archgraph : Holds the sum of the weights of the connected subgraph and the set of connected subgraphs * @param[in, out] temp : Holds the set of connected subgraph * @param[in, out] visited : Holds the flag for whether a node in the graph is accessed * @param[in] g : archgraph * @param

Source from the content-addressed store, hash-verified

89 * @param[in] target_num : The number of nodes of the target connected subgraph
90 */
91 void search_dfs(std::map<double, std::vector<std::vector<uint32_t>>, greater<double>>& sub_archgraph, std::vector<uint32_t>& temp,
92 std::vector<bool>& visited, ArchGraph::sRef g, std::vector<std::vector<double>>& fidelity, double sum, uint32_t u,
93 int& quantum_num, int target_num)
94 {
95 temp.emplace_back(u);
96 quantum_num++;
97 visited[u] = true;
98 if (quantum_num == target_num)
99 {
100 /* 基于子图进行最短路径搜索 */
101 ShortestDistanceByBFS sub_graph_shortest_distance;
102 ArchGraph::sRef tmp_graph = build_sub_graph(temp, g);
103 sub_graph_shortest_distance.init(tmp_graph.get());
104
105 /* Combine quantum circuit fidelity and quantum dispersion as weights */
106 //const double res = /*sum * 0.2 +*/ m_shortest_distance.get_overall_dispersion(temp) * 10/*0.8*/;
107 const double res = sub_graph_shortest_distance.get_overall_dispersion(temp);
108 //std::cout << "get sub graph fidelity-res: " << res << std::endl;
109 sub_archgraph[res].emplace_back(temp);
110 return;
111 }
112
113 for (uint32_t v : g->adj(u))
114 {
115 if (!visited[v])
116 {
117 search_dfs(sub_archgraph, temp, visited, g, fidelity, sum + fidelity[u][v] * 10, v, quantum_num, target_num);
118 /*temp.pop_back();
119 quantum_num--;
120 visited[v] = false;*/
121 }
122 }
123 }
124
125 /*
126 * @brief 广度优先算法: Gets the connected subgraph of the specified number of nodes in the graph

Callers

nothing calls this directly

Calls 6

build_sub_graphFunction · 0.85
adjMethod · 0.80
emplace_backMethod · 0.45
initMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected