// Copyright (c) 2018-2019 GeometryFactory (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL: https://github.com/CGAL/cgal/blob/v5.2/Optimal_bounding_box/include/CGAL/Optimal_bounding_box/internal/population.h $ // $Id: population.h e9d41d7 2020-04-21T10:03:00+02:00 Maxime Gimeno // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // // Author(s) : Mael Rouxel-Labbé // Konstantinos Katrioplas // #ifndef CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H #define CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H #include #include #include #include #include #include namespace CGAL { namespace Optimal_bounding_box { namespace internal { template struct Vertex_with_fitness { typedef typename Traits::FT FT; typedef typename Traits::Matrix Matrix; Vertex_with_fitness() { CGAL_assertion_code(m_is_val_initialized = false;) } Vertex_with_fitness(const Matrix m, const FT v) : m_mat(std::move(m)), m_val(v) { CGAL_assertion_code(m_is_val_initialized = true;) } template Vertex_with_fitness(const Matrix m, const PointRange& points, const Traits& traits) : m_mat(std::move(m)) { m_val = compute_fitness(m, points, traits); CGAL_assertion_code(m_is_val_initialized = true;) } Matrix& matrix() { return m_mat; } const Matrix& matrix() const { return m_mat; } FT& fitness() { return m_val; } FT fitness() const { CGAL_assertion(m_is_val_initialized); return m_val; } private: Matrix m_mat; FT m_val; CGAL_assertion_code(bool m_is_val_initialized;) }; template class Population { public: typedef typename Traits::FT FT; typedef typename Traits::Matrix Matrix; typedef Vertex_with_fitness Vertex; typedef std::array Simplex; typedef std::vector Simplex_container; public: Population(const Traits& traits) : m_traits(traits) { } // Access std::size_t size() const { return m_simplices.size(); } Simplex& operator[](const std::size_t i) { CGAL_assertion(i < m_simplices.size()); return m_simplices[i]; } const Simplex& operator[](const std::size_t i) const { CGAL_assertion(i < m_simplices.size()); return m_simplices[i]; } Simplex_container& simplices() { return m_simplices; } private: Matrix create_random_matrix(CGAL::Random& rng) const { Matrix m; for(std::size_t i=0; i<3; ++i) for(std::size_t j=0; j<3; ++j) m.set(i, j, FT(rng.get_double())); return m; } public: template Simplex create_simplex(const PointRange& points, CGAL::Random& rng) const { Simplex s; for(std::size_t i=0; i<4; ++i) s[i] = Vertex{m_traits.get_Q(create_random_matrix(rng)), points, m_traits}; return s; } // create random population template void initialize(const std::size_t population_size, const PointRange& points, CGAL::Random& rng) { m_simplices.clear(); m_simplices.reserve(population_size); for(std::size_t i=0; i(-1), vertex_id = static_cast(-1); FT best_fitness = FT{(std::numeric_limits::max)()}; for(std::size_t i=0, ps=m_simplices.size(); i m_simplices; const Traits& m_traits; }; } // namespace internal } // namespace Optimal_bounding_box } // namespace CGAL #endif // CGAL_OPTIMAL_BOUNDING_BOX_POPULATION_H