MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / _dijkstra_multisource

Function _dijkstra_multisource

cpp_easygraph/functions/path/path.cpp:38–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37}
38py::object _dijkstra_multisource(py::object G,py::object sources, py::object weight, py::object target) {
39 py::list res_lst = py::list();
40 bool is_directed = G.attr("is_directed")().cast<bool>();
41 Graph& G_ = G.cast<Graph&>();
42 node_t target_id = G_.node_to_id.attr("get")(target, -1).cast<node_t>();
43 std::string weight_key = weight_to_string(weight);
44 Graph_L G_l;
45 if(G_.linkgraph_dirty){
46 G_l = graph_to_linkgraph(G_, is_directed, weight_key, true, false);
47 G_.linkgraph_structure=G_l;
48 G_.linkgraph_dirty = false;
49 }
50 else{
51 G_l = G_.linkgraph_structure;
52 }
53
54
55 int N = G_l.n;
56 py::list sources_list = py::list(sources);
57 int sources_list_len = py::len(sources_list);
58 for(register int i = 0; i < sources_list_len; i++){
59 if(G_.node_to_id.attr("get")(sources_list[i],py::none()) == py::none()){
60 printf("The node should exist in the graph!");
61 return py::none();
62 }
63 node_t source_id = G_.node_to_id.attr("get")(sources_list[i]).cast<node_t>();
64 const std::vector<float>& dis = _dijkstra(G_l,source_id,weight_key,target_id);
65 py::list pydist = py::list();
66 for(int i = 1;i<=N;i++){
67 pydist.append(dis[i]);
68 }
69 res_lst.append(pydist);
70 }
71
72 return res_lst;
73}
74
75
76py::object _spfa(py::object G, py::object source, py::object weight) {

Callers

nothing calls this directly

Calls 4

weight_to_stringFunction · 0.85
graph_to_linkgraphFunction · 0.85
_dijkstraFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected