Skip to content

Commit

Permalink
Merge pull request #408 from bluescarni/pr/topo_fix
Browse files Browse the repository at this point in the history
Rename the get_weight() method to get_edge_weight().
  • Loading branch information
bluescarni authored Mar 17, 2020
2 parents 9030bdf + 00f75ba commit 64f4365
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Changelog
New
~~~

- Add a :cpp:func:`pagmo::base_bgl_topology::get_weight()`
- Add a :cpp:func:`pagmo::base_bgl_topology::get_edge_weight()`
function to fetch the weight of an edge in a BGL topology
(`#407 <https://github.com/esa/pagmo2/pull/407>`__).

Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx/docs/cpp/topologies/base_bgl_topology.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Base BGL topology
:exception std\:\:invalid_argument: if *i* is not smaller than the number of vertices.
:exception unspecified: any exception thrown by the public BGL API.

.. cpp:function:: double get_weight(std::size_t i, std::size_t j) const
.. cpp:function:: double get_edge_weight(std::size_t i, std::size_t j) const

.. versionadded:: 2.15

Expand Down
2 changes: 1 addition & 1 deletion include/pagmo/topologies/base_bgl_topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class PAGMO_DLL_PUBLIC base_bgl_topology
std::size_t num_vertices() const;
bool are_adjacent(std::size_t, std::size_t) const;
std::pair<std::vector<std::size_t>, vector_double> get_connections(std::size_t) const;
double get_weight(std::size_t, std::size_t) const;
double get_edge_weight(std::size_t, std::size_t) const;

void add_vertex();
void add_edge(std::size_t, std::size_t, double = 1.);
Expand Down
2 changes: 1 addition & 1 deletion src/topologies/base_bgl_topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ std::pair<std::vector<std::size_t>, vector_double> base_bgl_topology::get_connec
return retval;
}

double base_bgl_topology::get_weight(std::size_t i, std::size_t j) const
double base_bgl_topology::get_edge_weight(std::size_t i, std::size_t j) const
{
std::lock_guard<std::mutex> lock(m_mutex);

Expand Down
12 changes: 6 additions & 6 deletions tests/base_bgl_topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ BOOST_AUTO_TEST_CASE(basic_test)

t0.add_edge(1, 0);
t0.add_edge(2, 0);
BOOST_CHECK(t0.get_weight(1, 0) == 1.);
BOOST_CHECK(t0.get_weight(2, 0) == 1.);
BOOST_CHECK(t0.get_edge_weight(1, 0) == 1.);
BOOST_CHECK(t0.get_edge_weight(2, 0) == 1.);

auto conns = t0.get_connections(0);
using c_vec = decltype(conns.first);
Expand All @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(basic_test)
BOOST_CHECK(t0.get_connections(2).second.empty());

t0.set_weight(0, 1, .5);
BOOST_CHECK(t0.get_weight(0, 1) == .5);
BOOST_CHECK(t0.get_edge_weight(0, 1) == .5);

conns = t0.get_connections(1);

Expand Down Expand Up @@ -198,15 +198,15 @@ BOOST_AUTO_TEST_CASE(error_handling)
ia.what(), "cannot set the weight of an edge in a BGL topology: the vertex 0 is not connected to vertex 1");
});

BOOST_CHECK_EXCEPTION(t0.get_weight(0, 1), std::invalid_argument, [](const std::invalid_argument &ia) {
BOOST_CHECK_EXCEPTION(t0.get_edge_weight(0, 1), std::invalid_argument, [](const std::invalid_argument &ia) {
return boost::contains(
ia.what(), "cannot get the weight of an edge in a BGL topology: the vertex 0 is not connected to vertex 1");
});
BOOST_CHECK_EXCEPTION(t0.get_weight(0, 10), std::invalid_argument, [](const std::invalid_argument &ia) {
BOOST_CHECK_EXCEPTION(t0.get_edge_weight(0, 10), std::invalid_argument, [](const std::invalid_argument &ia) {
return boost::contains(
ia.what(), "invalid vertex index in a BGL topology: the index is 10, but the number of vertices is only 3");
});
BOOST_CHECK_EXCEPTION(t0.get_weight(11, 10), std::invalid_argument, [](const std::invalid_argument &ia) {
BOOST_CHECK_EXCEPTION(t0.get_edge_weight(11, 10), std::invalid_argument, [](const std::invalid_argument &ia) {
return boost::contains(
ia.what(), "invalid vertex index in a BGL topology: the index is 11, but the number of vertices is only 3");
});
Expand Down

0 comments on commit 64f4365

Please sign in to comment.