Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions tests/hypervolume.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2017-2021 PaGMO development team
/* Copyright 2017-2026 PaGMO development team

This file is part of the PaGMO library.

Expand Down Expand Up @@ -63,16 +63,16 @@ void assertContribs(const std::vector<vector_double> &points, std::vector<double
hypervolume hv = hypervolume(points, true);
BOOST_CHECK((hv.contributions(ref) == answers));
for (unsigned i = 0u; i < answers.size(); i++) {
BOOST_CHECK((hv.exclusive(i, ref) == answers[i]));
BOOST_CHECK_SMALL(hv.exclusive(i, ref) - answers[i], 1e-12);
}
hv = hypervolume(points, false);
BOOST_CHECK((hv.contributions(ref) == answers));
for (unsigned i = 0u; i < answers.size(); i++) {
BOOST_CHECK((hv.exclusive(i, ref) == answers[i]));
BOOST_CHECK_SMALL(hv.exclusive(i, ref) - answers[i], 1e-12);
}
hv.set_copy_points(false);
BOOST_CHECK((hv.contributions(ref) == answers));
BOOST_CHECK((hv.exclusive(0, ref) == answers[0]));
BOOST_CHECK_SMALL(hv.exclusive(0, ref) - answers[0], 1e-13);
}

class hypervolume_test
Expand Down Expand Up @@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE(hypervolume_compute_test)

// 4d duplicate and dominated
hv = hypervolume({{1.0, 1.0, 1.0, 1.0}, {1.0, 1.0, 1.0, 1.0}, {0.0, 0.0, 0.0, 0.0}});
BOOST_CHECK((hv.compute({2.0, 2.0, 2.0, 2.0}) == 16.0));
BOOST_CHECK_SMALL(hv.compute({2.0, 2.0, 2.0, 2.0}) - 16.0, 1e-12);

// test for flags
hv = hypervolume({{1, 1, 1}, {2, 2, 2}}, false);
Expand All @@ -281,32 +281,32 @@ BOOST_AUTO_TEST_CASE(hypervolume_compute_test)
hvwfg hv_algo_nd2 = hvwfg(3u); // stop-dimension 3

hv = hypervolume({{2.3, 4.5}, {3.4, 3.4}, {6.0, 1.2}});
BOOST_CHECK((hv.compute({7.0, 7.0}) == 17.91));
BOOST_CHECK((hv.compute({7.0, 7.0}, hv_algo_2d) == 17.91));
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0}) - 17.91, 1e-12);
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0}, hv_algo_2d) - 17.91, 1e-12);
BOOST_CHECK_THROW(hv.compute({7.0, 7.0}, hv_algo_3d), std::invalid_argument);
BOOST_CHECK((hv.compute({7.0, 7.0}, hv_algo_nd) == 17.91));
BOOST_CHECK((hv.compute({7.0, 7.0}, hv_algo_nd2) == 17.91));
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0}, hv_algo_nd) - 17.91, 1e-12);
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0}, hv_algo_nd2) - 17.91, 1e-12);

hv = hypervolume({{2.3, 4.5, 3.2}, {3.4, 3.4, 3.4}, {6.0, 1.2, 3.6}});
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0}) == 66.386));
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0}) - 66.386, 1e-12);
BOOST_CHECK_THROW(hv.compute({7.0, 7.0, 7.0}, hv_algo_2d), std::invalid_argument);
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0}, hv_algo_3d) == 66.386));
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0}, hv_algo_nd) == 66.386));
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0}, hv_algo_nd2) == 66.386));
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0}, hv_algo_3d) - 66.386, 1e-12);
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0}, hv_algo_nd) - 66.386, 1e-12);
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0}, hv_algo_nd2) - 66.386, 1e-12);

hv = hypervolume({{2.3, 4.5, 3.2}, {3.4, 3.4, 3.4}, {6.0, 1.2, 3.6}});
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0}) == 66.386));
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0}) - 66.386, 1e-12);
BOOST_CHECK_THROW(hv.compute({7.0, 7.0, 7.0}, hv_algo_2d), std::invalid_argument);
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0}, hv_algo_3d) == 66.386));
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0}, hv_algo_nd) == 66.386));
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0}, hv_algo_nd2) == 66.386));
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0}, hv_algo_3d) - 66.386, 1e-12);
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0}, hv_algo_nd) - 66.386, 1e-12);
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0}, hv_algo_nd2) - 66.386, 1e-12);

hv = hypervolume({{2.3, 4.5, 3.2, 1.9, 6.0}, {3.4, 3.4, 3.4, 2.1, 5.8}, {6.0, 1.2, 3.6, 3.0, 6.0}});
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0, 7.0, 7.0}) == 373.21228));
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0, 7.0, 7.0}) - 373.21228, 1e-12);
BOOST_CHECK_THROW(hv.compute({7.0, 7.0, 7.0, 7.0, 7.0}, hv_algo_2d), std::invalid_argument);
BOOST_CHECK_THROW(hv.compute({7.0, 7.0, 7.0, 7.0, 7.0}, hv_algo_3d), std::invalid_argument);
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0, 7.0, 7.0}, hv_algo_nd) == 373.21228));
BOOST_CHECK((hv.compute({7.0, 7.0, 7.0, 7.0, 7.0}, hv_algo_nd2) == 373.21228));
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0, 7.0, 7.0}, hv_algo_nd) - 373.21228, 1e-12);
BOOST_CHECK_SMALL(hv.compute({7.0, 7.0, 7.0, 7.0, 7.0}, hv_algo_nd2) - 373.21228, 1e-12);

BOOST_CHECK_THROW(hvwfg(0), std::invalid_argument);
BOOST_CHECK_THROW(hvwfg(1), std::invalid_argument);
Expand Down Expand Up @@ -813,4 +813,4 @@ BOOST_AUTO_TEST_CASE(hypervolume_bf_pras_test)
BOOST_CHECK_THROW(al.contributions(points, ref), std::invalid_argument);
auto al_clone = al.clone();
BOOST_CHECK(al_clone->get_name().find("bf_fpras") != std::string::npos);
}
}
Loading