Skip to content

Commit

Permalink
Merge pull request #142 from constantinpape/master
Browse files Browse the repository at this point in the history
Fix issues in bfs graph api
  • Loading branch information
constantinpape authored Dec 20, 2021
2 parents 00119fd + 7528de9 commit c4bd4cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions include/nifty/graph/detail/search_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace detail_graph{

public:
typedef GRAPH GraphType;
typedef typename GraphType:: template NodeMap<int64_t> PredecessorsMap;
typedef typename GraphType:: template NodeMap<int64_t> PredecessorsMap;
typedef typename GraphType:: template NodeMap<int64_t> DistanceMap;
private:
typedef QUEUE Queue;
Expand Down Expand Up @@ -165,7 +165,7 @@ namespace detail_graph{
VISITOR && visitor
){
this->initializeMaps(sourceBegin, sourceEnd);
this->runImpl(subgraphMask,visitor);
this->runImpl(subgraphMask, visitor);
}

const DistanceMap & distances()const{
Expand All @@ -181,7 +181,7 @@ namespace detail_graph{
class VISITOR
>
void runImpl(
const SUBGRAPH_MASK & subgraphMask,
const SUBGRAPH_MASK & subgraphMask,
VISITOR && visitor
){
auto continueSeach = true;
Expand Down
20 changes: 13 additions & 7 deletions src/python/lib/graph/export_undirected_graph_class_api.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -243,30 +243,36 @@ namespace graph{
" tuple : pair of node indexes / enpoints of the edge."
)

.def("bfsEdges",[](G & g, const std::size_t maxDistance){
.def("bfsEdges",[](G & g, const std::size_t maxDistance, const bool exactDistance){

BreadthFirstSearch<G> bfs(g);
std::vector<std::pair<uint64_t, uint64_t>> pairs;
g.forEachNode([&](const uint64_t sourceNode){
bfs.graphNeighbourhood(sourceNode, maxDistance,

[&](const uint64_t targetNode, const uint64_t ){
[&](const uint64_t targetNode, const uint64_t distance){
if(targetNode < sourceNode){
return;
}
if(exactDistance && (distance != maxDistance)){
return;
}
pairs.emplace_back(sourceNode, targetNode);
}
);
});

xt::pytensor<uint64_t, 2> out({int64_t(pairs.size()), int64_t(2)});

auto c=0;
auto c = 0;
for(const auto & uv : pairs){
out(c,0) = uv.first;
out(c,1) = uv.second;
out(c, 0) = uv.first;
out(c, 1) = uv.second;
++c;
}
return out;

},
py::arg("maxDistance")
py::arg("maxDistance"), py::arg("exactDistance")=false
)
.def("uvIds",
[](G & g) {
Expand Down

0 comments on commit c4bd4cd

Please sign in to comment.