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

Function calcNodeSort

Applications/NodeSort/NodeSort.cpp:255–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253}
254
255int calcNodeSort(
256 const vector<vector<double>>& graph,
257 int real_size,
258 float lambda,
259 float lambda1,
260 float lambda2,
261 const std::string& filename)
262{
263 NodeSortProblemGenerator gen;
264 gen.setProblemGraph(graph);
265 gen.setLambda1(lambda);
266 gen.setLambda2(lambda1);
267 gen.setLambda3(lambda2);
268 gen.exec();
269
270 std::cout << "Classical Liner result: " << std::endl;
271 auto c_result = gen.getLinearSolverResult();
272 std::vector<double> tmp_result;
273 for (auto i = 0; i < c_result.size(); i++)
274 {
275 tmp_result.push_back(c_result[i]);
276 }
277 auto c_sort_result = quickSort(tmp_result);
278 for (int i = 0; i < c_sort_result.size(); i++)
279 {
280 cout << c_sort_result[i].first << ", " << c_sort_result[i].second << endl;
281 }
282
283 //std::cout << gen.getLinearSolverResult();
284 std::cout << std::endl;
285
286 auto oA = gen.getMatrixA();
287 auto ob = gen.getVectorB();
288
289 auto A = Eigen_to_QStat(oA);
290 std::vector<double> b;
291 for (auto i = 0; i < ob.size(); i++)
292 {
293 b.push_back(ob[i]);
294 }
295
296 std::cout << "HHL:" << std::endl;
297 QStat result = HHL_solve_linear_equations(A, b);
298
299 std::vector<double> result_vec;
300 result_vec.resize(real_size);
301 for (int i = 0; i < real_size; i++)
302 {
303 result_vec[i] = result[i].real();
304 std::cout << result_vec[i] << std::endl;
305 }
306
307 auto sort_result = quickSort(result_vec);
308
309 OriginCollection collection(filename, false);
310 collection = { "sort_index", "value" };
311 for (int i = 0; i < sort_result.size(); i++)
312 {

Callers 1

mainFunction · 0.85

Calls 8

insertValueMethod · 0.80
quickSortFunction · 0.70
execMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
resizeMethod · 0.45
realMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected