Skip to content

Commit

Permalink
network_base: Function for checking connection
Browse files Browse the repository at this point in the history
Added a function `connection_exists` that checks if agents with indices
`i_idx` and `j_idx` are connected or not.
  • Loading branch information
amritagos committed Jul 29, 2024
1 parent 9e569e1 commit f2122d8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions graph_lib/include/network_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ template <typename WeightType = double> class NetworkBase {
return weight_list[agent_idx][index_neighbour];
}

/*
Checks if a connection exists between two agents i_idx and j_idx
*/
bool connection_exists(size_t i_idx, size_t j_idx) const {
auto i_neighbours = get_neighbours(i_idx);
if (std::find(i_neighbours.begin(), i_neighbours.end(), j_idx) ==
std::end(i_neighbours)) {
return false;
} else {
return true;
}
}

/*
Clears the network
*/
Expand Down

0 comments on commit f2122d8

Please sign in to comment.