From 00f75ba462ed443c998061222a7206dbab167142 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 17 Mar 2020 13:45:07 +0100 Subject: [PATCH] Rename the get_weight() method to get_edge_weight(). --- doc/sphinx/changelog.rst | 2 +- doc/sphinx/docs/cpp/topologies/base_bgl_topology.rst | 2 +- include/pagmo/topologies/base_bgl_topology.hpp | 2 +- src/topologies/base_bgl_topology.cpp | 2 +- tests/base_bgl_topology.cpp | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/sphinx/changelog.rst b/doc/sphinx/changelog.rst index 69197f837..a16b936ca 100644 --- a/doc/sphinx/changelog.rst +++ b/doc/sphinx/changelog.rst @@ -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 `__). diff --git a/doc/sphinx/docs/cpp/topologies/base_bgl_topology.rst b/doc/sphinx/docs/cpp/topologies/base_bgl_topology.rst index fbb27955d..0817afed6 100644 --- a/doc/sphinx/docs/cpp/topologies/base_bgl_topology.rst +++ b/doc/sphinx/docs/cpp/topologies/base_bgl_topology.rst @@ -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 diff --git a/include/pagmo/topologies/base_bgl_topology.hpp b/include/pagmo/topologies/base_bgl_topology.hpp index 20c8a2387..24757d588 100644 --- a/include/pagmo/topologies/base_bgl_topology.hpp +++ b/include/pagmo/topologies/base_bgl_topology.hpp @@ -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, 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.); diff --git a/src/topologies/base_bgl_topology.cpp b/src/topologies/base_bgl_topology.cpp index 27522bc30..2be0794ec 100644 --- a/src/topologies/base_bgl_topology.cpp +++ b/src/topologies/base_bgl_topology.cpp @@ -229,7 +229,7 @@ std::pair, 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 lock(m_mutex); diff --git a/tests/base_bgl_topology.cpp b/tests/base_bgl_topology.cpp index de3d2f477..e8ee8c96e 100644 --- a/tests/base_bgl_topology.cpp +++ b/tests/base_bgl_topology.cpp @@ -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); @@ -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); @@ -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"); });