* @brief 广度优先算法: Gets the connected subgraph of the specified number of nodes in the graph * @param[in, out] matched_subgraph : 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
| 135 | * @param[in] target_num : The number of nodes of the target connected subgraph |
| 136 | */ |
| 137 | void search_bfs(std::map<double, std::vector<std::vector<uint32_t>>, greater<double>>& matched_subgraph, |
| 138 | std::vector<uint32_t>& temp, std::vector<bool>& visited, const ArchGraph::sRef g, |
| 139 | std::vector<std::vector<double>>& fidelity, |
| 140 | double weight, uint32_t u, int& quantum_num, int target_num) |
| 141 | { |
| 142 | auto handle_new_node_func = [&](const uint32_t new_node)->bool { |
| 143 | temp.emplace_back(new_node); |
| 144 | ++quantum_num; |
| 145 | visited[new_node] = true; |
| 146 | if (quantum_num == target_num) |
| 147 | { |
| 148 | /* 基于子图进行最短路径搜索 */ |
| 149 | ShortestDistanceByBFS sub_graph_shortest_distance; |
| 150 | ArchGraph::sRef tmp_graph = build_sub_graph(temp, g); |
| 151 | //ArchGraph::sRef tmp_graph = mArchGraph; |
| 152 | //std::cout << "Got temp_graph: \n" << tmp_graph->dotify() << "\n------ graph_text end ------" << std::endl; |
| 153 | sub_graph_shortest_distance.init(tmp_graph.get()); |
| 154 | |
| 155 | /* Combine quantum circuit fidelity and quantum dispersion as weights */ |
| 156 | //const double res = /*sum * 0.2 +*/ m_shortest_distance.get_overall_dispersion(temp) * 10/*0.8*/; |
| 157 | const double res = sub_graph_shortest_distance.get_overall_dispersion(temp); |
| 158 | //std::cout << "Got sub graph_" << matched_subgraph.size() << " fidelity-res: " << res << std::endl; |
| 159 | matched_subgraph[res].emplace_back(temp); |
| 160 | return true; /* 找到合适子图,返回true */ |
| 161 | } |
| 162 | |
| 163 | return false; /* 未找到合适子图 */ |
| 164 | }; |
| 165 | |
| 166 | bool b_find_sub_graph = false; |
| 167 | std::vector<uint32_t> new_node_vec; |
| 168 | for (uint32_t v : g->adj(u)) |
| 169 | { |
| 170 | if (!visited[v]) |
| 171 | { |
| 172 | /* 将每个相邻的点加入子图 */ |
| 173 | new_node_vec.emplace_back(v); |
| 174 | |
| 175 | /* 如果找到子图,就不再搜索,其他的子图组合会在对应的节点的子图搜索过程中,被发现 */ |
| 176 | if (handle_new_node_func(v)) |
| 177 | { |
| 178 | b_find_sub_graph = true; |
| 179 | |
| 180 | for (const uint32_t& new_v : new_node_vec) |
| 181 | { |
| 182 | visited[temp.back()] = false; |
| 183 | temp.pop_back(); |
| 184 | --quantum_num; |
| 185 | } |
| 186 | |
| 187 | new_node_vec.clear(); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /* 如果本次搜索已经找到合适子图,就不再递归搜索 */ |
| 193 | if (b_find_sub_graph) |
| 194 | { |
nothing calls this directly
no test coverage detected