From 2b876b256a919446e08ccda260a68dfc5dbc26be Mon Sep 17 00:00:00 2001 From: Vissarion Fisikopoulos Date: Sat, 11 Feb 2023 20:19:19 +0100 Subject: [PATCH] Enable github actions to build examples. Avoid passing a polytope as a const reference. --- .github/workflows/cmake-clang.yml | 4 +- .github/workflows/cmake-examples.yml | 40 +++++++++++++ examples/hpolytope-volume/hpolytopeVolume.cpp | 2 +- examples/mmcs_method/CMakeLists.txt | 2 +- examples/multithread_sampling/CMakeLists.txt | 6 +- .../sampling_multithread_walks.cpp | 11 ++-- .../optimization_spectrahedra/CMakeLists.txt | 9 +-- .../sampler.cpp | 6 +- examples/vpolytope-volume/CMakeLists.txt | 4 +- examples/vpolytope-volume/vpolytopevolume.cpp | 2 +- include/convex_bodies/ballintersectconvex.h | 2 +- include/random_walks/boundary_cdhr_walk.hpp | 2 +- include/random_walks/boundary_rdhr_walk.hpp | 2 +- include/random_walks/compute_diameter.hpp | 4 +- ...ial_hamiltonian_monte_carlo_exact_walk.hpp | 26 ++++----- .../gaussian_accelerated_billiard_walk.hpp | 8 +-- include/random_walks/gaussian_ball_walk.hpp | 6 +- include/random_walks/gaussian_cdhr_walk.hpp | 4 +- ...ian_hamiltonian_monte_carlo_exact_walk.hpp | 26 ++++----- include/random_walks/gaussian_rdhr_walk.hpp | 4 +- include/random_walks/multithread_walks.hpp | 58 +++++++++---------- include/random_walks/uniform_ball_walk.hpp | 6 +- include/random_walks/uniform_cdhr_walk.hpp | 4 +- include/random_walks/uniform_rdhr_walk.hpp | 8 +-- include/sampling/random_point_generators.hpp | 10 ++-- include/volume/volume_cooling_balls.hpp | 2 +- include/volume/volume_cooling_gaussians.hpp | 10 ++-- include/volume/volume_cooling_hpoly.hpp | 4 +- include/volume/volume_sequence_of_balls.hpp | 4 +- 29 files changed, 158 insertions(+), 118 deletions(-) create mode 100644 .github/workflows/cmake-examples.yml diff --git a/.github/workflows/cmake-clang.yml b/.github/workflows/cmake-clang.yml index 5386c3963..caa22fff2 100644 --- a/.github/workflows/cmake-clang.yml +++ b/.github/workflows/cmake-clang.yml @@ -1,5 +1,5 @@ ############################################################################## -# GitHub Actions Workflow for volesti to build tests with GCC +# GitHub Actions Workflow for volesti to build tests with Clang # # Copyright (c) 2020-2022 Vissarion Fisikopoulos # @@ -36,4 +36,4 @@ jobs: cd build; cmake -D CMAKE_CXX_COMPILER=${{ matrix.config.compiler }} -D CMAKE_CXX_FLAGS=-fsanitize=memory -D CMAKE_CXX_FLAGS=-fsanitize=undefined -D CMAKE_CXX_FLAGS=-g -D DISABLE_NLP_ORACLES=ON -D USE_MKL=OFF ../test; make; - ctest --verbose; + ctest --verbose; \ No newline at end of file diff --git a/.github/workflows/cmake-examples.yml b/.github/workflows/cmake-examples.yml new file mode 100644 index 000000000..b7784fa30 --- /dev/null +++ b/.github/workflows/cmake-examples.yml @@ -0,0 +1,40 @@ +############################################################################## +# GitHub Actions Workflow for volesti to build tests with GCC +# +# Copyright (c) 2020-2022 Vissarion Fisikopoulos +# +# Licensed under GNU LGPL.3, see LICENCE file +############################################################################## +name: cmake-examples + +on: [push, pull_request] + +jobs: + build: + name: ${{ matrix.config.os }} - ${{ matrix.config.compiler }} + strategy: + fail-fast: false + matrix: + config: + - {os: ubuntu-22.04, compiler_pkg: clang-11, compiler: clang++-11} + - {os: ubuntu-22.04, compiler_pkg: g++-11, compiler: g++-11} + runs-on: ${{ matrix.config.os }} + steps: + - uses: actions/checkout@v1 + - run: sudo apt-get update || true; + sudo apt-get install ${{ matrix.config.compiler_pkg }} lp-solve libomp-dev libopenblas-dev libarpack2-dev; + - name: Build examples + run: | + cd examples + for dir in */; do + if [ "$dir" != "EnvelopeProblemSOS/" ] && [ "$dir" != "python_utilities/" ]; then + echo + echo "Building examples in $dir ....................." + cd "$dir" + mkdir build && cd build + cmake -DCMAKE_CXX_COMPILER=${{ matrix.config.compiler }} -DUSE_MKL=OFF .. + make + cd ../.. + fi + done + diff --git a/examples/hpolytope-volume/hpolytopeVolume.cpp b/examples/hpolytope-volume/hpolytopeVolume.cpp index 487ce98f4..b61190de9 100644 --- a/examples/hpolytope-volume/hpolytopeVolume.cpp +++ b/examples/hpolytope-volume/hpolytopeVolume.cpp @@ -29,7 +29,7 @@ typedef typename Kernel::Point Point; typedef BoostRandomNumberGenerator RNGType; typedef HPolytope HPOLYTOPE; -void calculateVolumes(const HPOLYTOPE &HP) { +void calculateVolumes(HPOLYTOPE &HP) { // Setup parameters for calculating volume int walk_len = 10 + HP.dimension()/10; NT e=0.1; diff --git a/examples/mmcs_method/CMakeLists.txt b/examples/mmcs_method/CMakeLists.txt index 1ee6ce0a5..01b8a040c 100644 --- a/examples/mmcs_method/CMakeLists.txt +++ b/examples/mmcs_method/CMakeLists.txt @@ -105,7 +105,7 @@ else () add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR") #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") #add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) - + find_package(OpenMP REQUIRED) add_executable (skinny_cube_10_dim skinny_cube_10_dim.cpp) diff --git a/examples/multithread_sampling/CMakeLists.txt b/examples/multithread_sampling/CMakeLists.txt index fe4d5ee75..ded4b4dbb 100644 --- a/examples/multithread_sampling/CMakeLists.txt +++ b/examples/multithread_sampling/CMakeLists.txt @@ -97,7 +97,7 @@ else () endif () - add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + #add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl") add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm") @@ -105,11 +105,11 @@ else () add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR") #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") #add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) - + find_package(OpenMP REQUIRED) add_executable (sampling_multithread_walks sampling_multithread_walks.cpp) - + TARGET_LINK_LIBRARIES(sampling_multithread_walks ${LP_SOLVE} OpenMP::OpenMP_CXX) diff --git a/examples/multithread_sampling/sampling_multithread_walks.cpp b/examples/multithread_sampling/sampling_multithread_walks.cpp index 191b8e6c5..cb416c72c 100644 --- a/examples/multithread_sampling/sampling_multithread_walks.cpp +++ b/examples/multithread_sampling/sampling_multithread_walks.cpp @@ -48,12 +48,12 @@ MT get_uniform_samples(Polytope &P, std::list randPoints; typedef RandomPointGeneratorMultiThread _RandomPointGeneratorMultiThread; - + _RandomPointGeneratorMultiThread::apply(P, p, N, walk_len, num_threads, randPoints, push_back_policy, rng); unsigned int d = P.dimension(); - + MT samples(d, N); unsigned int jj = 0; @@ -92,7 +92,7 @@ MT get_gaussian_samples(Polytope &P, std::list randPoints; typedef GaussianPointGeneratorMultiThread _GaussianPointGeneratorMultiThread; - + _GaussianPointGeneratorMultiThread::apply(P, p, a_i, N, walk_len, num_threads, randPoints, push_back_policy, rng); @@ -118,11 +118,10 @@ void test_uniform_random_walk(std::string random_walk, unsigned int const& num_t typedef Eigen::Matrix MT; typedef Eigen::Matrix VT; typedef BoostRandomNumberGenerator RNGType; - Hpolytope P; unsigned int d = 10, walk_len = 5, N = 5000; std::cout << "--- Sampling with " + random_walk + " walk from H-cube10" << std::endl; - P = generate_cube(d, false); + Hpolytope P = generate_cube(d, false); RNGType rng(P.dimension()); MT samples = get_uniform_samples(P, rng, walk_len, N, num_threads); @@ -155,7 +154,7 @@ void test_gaussian_random_walk(std::string random_walk, unsigned int const& num_ int main() { - + unsigned int num_threads = 2; test_uniform_random_walk("BRDHR", num_threads); diff --git a/examples/optimization_spectrahedra/CMakeLists.txt b/examples/optimization_spectrahedra/CMakeLists.txt index 356a3e6ac..a35aee4c7 100644 --- a/examples/optimization_spectrahedra/CMakeLists.txt +++ b/examples/optimization_spectrahedra/CMakeLists.txt @@ -78,11 +78,12 @@ IF (OPENBLAS_LIB) IF (GFORTRAN_LIB) message( STATUS "GFORTRAN_LIB found: ${GFORTRAN_LIB}" ) - add_executable (boltzmann_hmc_walk boltzmann_hmc_walk.cpp) - TARGET_LINK_LIBRARIES(boltzmann_hmc_walk ${ARPACK_LIB} ${LAPACK_LIBRARIES} ${GFORTRAN_LIB}) + # These are not compiling, see issue https://github.com/GeomScale/volesti/issues/264 + #add_executable (boltzmann_hmc_walk boltzmann_hmc_walk.cpp) + #TARGET_LINK_LIBRARIES(boltzmann_hmc_walk ${ARPACK_LIB} ${LAPACK_LIBRARIES} ${GFORTRAN_LIB}) - add_executable (solve_sdp solve_sdp.cpp) - TARGET_LINK_LIBRARIES(solve_sdp ${GFORTRAN_LIB} ${LAPACK_LIBRARIES} ${ARPACK_LIB}) + #add_executable (solve_sdp solve_sdp.cpp) + #TARGET_LINK_LIBRARIES(solve_sdp ${GFORTRAN_LIB} ${LAPACK_LIBRARIES} ${ARPACK_LIB}) ELSE() MESSAGE(STATUS "gfortran is required but it could not be found") diff --git a/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp b/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp index 16b6f2367..22dd6d9e5 100644 --- a/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp +++ b/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp @@ -37,7 +37,7 @@ void write_to_file(std::string filename, std::vector const& randPoints) { } -void sample_using_uniform_billiard_walk(HPOLYTOPE const& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) { +void sample_using_uniform_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) { std::string filename = "uniform_billiard_walk.txt"; typedef RandomPointGenerator Generator; @@ -49,7 +49,7 @@ void sample_using_uniform_billiard_walk(HPOLYTOPE const& HP, RNGType& rng, unsig } -void sample_using_uniform_accelerated_billiard_walk(HPOLYTOPE const& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) { +void sample_using_uniform_accelerated_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) { std::string filename = "uniform_accelerated_billiard_walk.txt"; typedef RandomPointGenerator Generator; @@ -61,7 +61,7 @@ void sample_using_uniform_accelerated_billiard_walk(HPOLYTOPE const& HP, RNGType } -void sample_using_gaussian_billiard_walk(HPOLYTOPE const& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) { +void sample_using_gaussian_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) { std::string filename = "gaussian_billiard_walk.txt"; typedef MultivariateGaussianRandomPointGenerator Generator; diff --git a/examples/vpolytope-volume/CMakeLists.txt b/examples/vpolytope-volume/CMakeLists.txt index fdcb3095f..5ffd4784b 100644 --- a/examples/vpolytope-volume/CMakeLists.txt +++ b/examples/vpolytope-volume/CMakeLists.txt @@ -106,7 +106,7 @@ else () add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl") add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR") - add_executable (vpolytopeVolume vpolytopeVolume.cpp) - TARGET_LINK_LIBRARIES(vpolytopeVolume ${LP_SOLVE}) + add_executable (vpolytopevolume vpolytopevolume.cpp) + TARGET_LINK_LIBRARIES(vpolytopevolume ${LP_SOLVE}) endif() diff --git a/examples/vpolytope-volume/vpolytopevolume.cpp b/examples/vpolytope-volume/vpolytopevolume.cpp index e814b5875..007964232 100644 --- a/examples/vpolytope-volume/vpolytopevolume.cpp +++ b/examples/vpolytope-volume/vpolytopevolume.cpp @@ -28,7 +28,7 @@ typedef typename Kernel::Point Point; typedef BoostRandomNumberGenerator RNGType; typedef VPolytope VPOLYTOPE; -void calculateVolumes(const VPOLYTOPE &VP) { +void calculateVolumes(VPOLYTOPE &VP) { // Setup parameters for calculating volume int walk_len = 10 + VP.dimension()/10; NT e=0.1; diff --git a/include/convex_bodies/ballintersectconvex.h b/include/convex_bodies/ballintersectconvex.h index 12965d08c..b61ae5324 100644 --- a/include/convex_bodies/ballintersectconvex.h +++ b/include/convex_bodies/ballintersectconvex.h @@ -28,7 +28,7 @@ class BallIntersectPolytope { BallIntersectPolytope() {} - BallIntersectPolytope(Polytope const& PP, CBall &BB) : P(PP), B(BB) {}; + BallIntersectPolytope(Polytope& PP, CBall &BB) : P(PP), B(BB) {}; Polytope first() const { return P; } CBall second() const { return B; } diff --git a/include/random_walks/boundary_cdhr_walk.hpp b/include/random_walks/boundary_cdhr_walk.hpp index 40d35df2d..5e6b5224c 100644 --- a/include/random_walks/boundary_cdhr_walk.hpp +++ b/include/random_walks/boundary_cdhr_walk.hpp @@ -26,7 +26,7 @@ struct BCDHRWalk typedef typename Point::FT NT; template - Walk(GenericPolytope const& P, Point const& p, RandomNumberGenerator& rng) + Walk(GenericPolytope& P, Point const& p, RandomNumberGenerator& rng) { initialize(P, p, rng); } diff --git a/include/random_walks/boundary_rdhr_walk.hpp b/include/random_walks/boundary_rdhr_walk.hpp index 0cf582957..29d500b6c 100644 --- a/include/random_walks/boundary_rdhr_walk.hpp +++ b/include/random_walks/boundary_rdhr_walk.hpp @@ -27,7 +27,7 @@ struct BRDHRWalk typedef typename Point::FT NT; template - Walk(GenericPolytope const& P, Point const& p, RandomNumberGenerator& rng) + Walk(GenericPolytope& P, Point const& p, RandomNumberGenerator& rng) { initialize(P, p, rng); } diff --git a/include/random_walks/compute_diameter.hpp b/include/random_walks/compute_diameter.hpp index e3ec0f441..b20aa839a 100644 --- a/include/random_walks/compute_diameter.hpp +++ b/include/random_walks/compute_diameter.hpp @@ -205,7 +205,7 @@ template struct compute_diameter> { template - static NT compute(OrderPolytope const& P) + static NT compute(OrderPolytope& P) { return std::sqrt(NT(P.dimension())); } @@ -215,7 +215,7 @@ template struct compute_diameter, Ellipsoid > > { template - static NT compute(BallIntersectPolytope, Ellipsoid> const& P) + static NT compute(BallIntersectPolytope, Ellipsoid>& P) { NT polytope_diameter = std::sqrt(NT(P.dimension())); return std::min(polytope_diameter, (NT(2) * P.radius())); diff --git a/include/random_walks/exponential_hamiltonian_monte_carlo_exact_walk.hpp b/include/random_walks/exponential_hamiltonian_monte_carlo_exact_walk.hpp index 0d1199410..6e5d2e000 100644 --- a/include/random_walks/exponential_hamiltonian_monte_carlo_exact_walk.hpp +++ b/include/random_walks/exponential_hamiltonian_monte_carlo_exact_walk.hpp @@ -84,7 +84,7 @@ struct Walk < typename GenericPolytope > - inline bool apply(GenericPolytope const& P, + inline bool apply(GenericPolytope& P, Point& p, // a point to start unsigned int const& walk_length, RandomNumberGenerator &rng) @@ -104,7 +104,7 @@ struct Walk } T = rng.sample_urdist() * _Len; _v = GetDirection::apply(n, rng, false); - + it = 0; while (it < _rho) { @@ -122,7 +122,7 @@ struct Walk P.compute_reflection(_v, _p, pbpair.second); it++; } - + } while (P.is_in(_p, INSIDE_BODY_TOLLERANCE) == 0); if (it == _rho) { _p = p0; @@ -137,7 +137,7 @@ struct Walk < typename GenericPolytope > - inline void get_starting_point(GenericPolytope const& P, + inline void get_starting_point(GenericPolytope& P, Point const& center, Point &q, unsigned int const& walk_length, @@ -158,7 +158,7 @@ struct Walk < typename GenericPolytope > - inline void parameters_burnin(GenericPolytope const& P, + inline void parameters_burnin(GenericPolytope& P, Point const& center, unsigned int const& num_points, unsigned int const& walk_length, @@ -171,7 +171,7 @@ struct Walk pointset.push_back(_p); NT rad = NT(0), max_dist, Lmax = NT(0), radius = P.InnerBall().second; - for (int i = 0; i < num_points; i++) + for (int i = 0; i < num_points; i++) { p = GetPointInDsphere::apply(n, radius, rng); p += center; @@ -179,18 +179,18 @@ struct Walk apply(P, p, walk_length, rng); max_dist = get_max_distance(pointset, p, rad); - if (max_dist > Lmax) + if (max_dist > Lmax) { Lmax = max_dist; } - if (2.0 * rad > Lmax) + if (2.0 * rad > Lmax) { Lmax = 2.0 * rad; } pointset.push_back(p); } - if (Lmax > _Len) + if (Lmax > _Len) { update_delta(Lmax); } @@ -210,7 +210,7 @@ private : < typename GenericPolytope > - inline void initialize(GenericPolytope const& P, + inline void initialize(GenericPolytope& P, Point const& p, RandomNumberGenerator &rng) { @@ -219,7 +219,7 @@ private : _lambdas.setZero(P.num_of_hyperplanes()); _Av.setZero(P.num_of_hyperplanes()); _v = GetDirection::apply(n, rng, false); - + do { _p = p; T = rng.sample_urdist() * _Len; @@ -262,11 +262,11 @@ private : } - inline double get_max_distance(std::vector &pointset, Point const& q, double &rad) + inline double get_max_distance(std::vector &pointset, Point const& q, double &rad) { double dis = -1.0, temp_dis; int jj = 0; - for (auto vecit = pointset.begin(); vecit!=pointset.end(); vecit++, jj++) + for (auto vecit = pointset.begin(); vecit!=pointset.end(); vecit++, jj++) { temp_dis = (q.getCoefficients() - (*vecit).getCoefficients()).norm(); if (temp_dis > dis) { diff --git a/include/random_walks/gaussian_accelerated_billiard_walk.hpp b/include/random_walks/gaussian_accelerated_billiard_walk.hpp index a44608fb2..fbf43f443 100644 --- a/include/random_walks/gaussian_accelerated_billiard_walk.hpp +++ b/include/random_walks/gaussian_accelerated_billiard_walk.hpp @@ -68,7 +68,7 @@ struct GaussianAcceleratedBilliardWalk typedef typename Point::FT NT; template - Walk(GenericPolytope const& P, + Walk(GenericPolytope& P, Point const& p, Ellipsoid const& E, // ellipsoid representing the Gaussian distribution RandomNumberGenerator &rng) @@ -83,7 +83,7 @@ struct GaussianAcceleratedBilliardWalk } template - Walk(GenericPolytope const& P, + Walk(GenericPolytope& P, Point const& p, Ellipsoid const& E, // ellipsoid representing the Gaussian distribution RandomNumberGenerator &rng, @@ -104,7 +104,7 @@ struct GaussianAcceleratedBilliardWalk typename GenericPolytope, typename Ellipsoid > - inline void apply(GenericPolytope const& P, + inline void apply(GenericPolytope& P, Point &p, // a point to return the result Ellipsoid const& E, // ellipsoid representing the Gaussian distribution unsigned int const& walk_length, @@ -181,7 +181,7 @@ struct GaussianAcceleratedBilliardWalk typename GenericPolytope, typename Ellipsoid > - inline void initialize(GenericPolytope const& P, + inline void initialize(GenericPolytope& P, Point const& p, // a point to start Ellipsoid const& E, // ellipsoid representing the Gaussian distribution RandomNumberGenerator &rng) diff --git a/include/random_walks/gaussian_ball_walk.hpp b/include/random_walks/gaussian_ball_walk.hpp index c641b7344..8c267e0f9 100644 --- a/include/random_walks/gaussian_ball_walk.hpp +++ b/include/random_walks/gaussian_ball_walk.hpp @@ -46,19 +46,19 @@ struct Walk typedef typename Point::FT NT; template - static inline NT compute_delta(GenericPolytope const& P, NT const& a) + static inline NT compute_delta(GenericPolytope& P, NT const& a) { //return ((P.InnerBall()).second * NT(4)) / NT(P.dimension()); return (NT(4) * (P.InnerBall()).second) / std::sqrt(std::max(NT(1), a) * NT(P.dimension())); } - Walk (Polytope const& P, Point const& p, NT const& a, + Walk (Polytope& P, Point const& p, NT const& a, RandomNumberGenerator &rng) { _delta = compute_delta(P, a); } - Walk (Polytope const& P, + Walk (Polytope& P, Point const& p, NT const& a, RandomNumberGenerator &rng, diff --git a/include/random_walks/gaussian_cdhr_walk.hpp b/include/random_walks/gaussian_cdhr_walk.hpp index 8962ce413..04ebedbc4 100644 --- a/include/random_walks/gaussian_cdhr_walk.hpp +++ b/include/random_walks/gaussian_cdhr_walk.hpp @@ -75,7 +75,7 @@ struct Walk typedef typename Polytope::PointType Point; typedef typename Point::FT NT; - Walk(Polytope const& P, + Walk(Polytope& P, Point const& p, NT const& a_i, RandomNumberGenerator &rng) @@ -83,7 +83,7 @@ struct Walk initialize(P, p, a_i, rng); } - Walk(Polytope const& P, + Walk(Polytope& P, Point const& p, NT const& a_i, RandomNumberGenerator& rng, diff --git a/include/random_walks/gaussian_hamiltonian_monte_carlo_exact_walk.hpp b/include/random_walks/gaussian_hamiltonian_monte_carlo_exact_walk.hpp index 954fda731..8b83b053b 100644 --- a/include/random_walks/gaussian_hamiltonian_monte_carlo_exact_walk.hpp +++ b/include/random_walks/gaussian_hamiltonian_monte_carlo_exact_walk.hpp @@ -19,7 +19,7 @@ struct GaussianHamiltonianMonteCarloExactWalk GaussianHamiltonianMonteCarloExactWalk(double L, unsigned int _rho) : param(L, true, _rho, true) {} - + GaussianHamiltonianMonteCarloExactWalk(double L) : param(L, true, 0, false) {} @@ -28,7 +28,7 @@ struct GaussianHamiltonianMonteCarloExactWalk : param(0, false, 0, false) {} - + struct parameters { parameters(double L, bool set, unsigned int _rho, bool _set_rho) @@ -80,7 +80,7 @@ struct Walk < typename GenericPolytope > - inline void apply(GenericPolytope const& P, + inline void apply(GenericPolytope& P, Point& p, NT const& a_i, unsigned int const& walk_length, @@ -120,7 +120,7 @@ struct Walk < typename GenericPolytope > - inline void get_starting_point(GenericPolytope const& P, + inline void get_starting_point(GenericPolytope& P, Point const& center, Point &q, unsigned int const& walk_length, @@ -141,7 +141,7 @@ struct Walk < typename GenericPolytope > - inline void parameters_burnin(GenericPolytope const& P, + inline void parameters_burnin(GenericPolytope& P, Point const& center, unsigned int const& num_points, unsigned int const& walk_length, @@ -154,7 +154,7 @@ struct Walk pointset.push_back(_p); NT rad = NT(0), max_dist, Lmax = NT(0), radius = P.InnerBall().second; - for (int i = 0; i < num_points; i++) + for (int i = 0; i < num_points; i++) { p = GetPointInDsphere::apply(n, radius, rng); p += center; @@ -162,18 +162,18 @@ struct Walk apply(P, p, walk_length, rng); max_dist = get_max_distance(pointset, p, rad); - if (max_dist > Lmax) + if (max_dist > Lmax) { Lmax = max_dist; } - if (2.0*rad > Lmax) + if (2.0*rad > Lmax) { Lmax = 2.0 * rad; } pointset.push_back(p); } - if (Lmax > _Len) + if (Lmax > _Len) { update_delta(Lmax); } @@ -191,7 +191,7 @@ private : < typename GenericPolytope > - inline void initialize(GenericPolytope const& P, + inline void initialize(GenericPolytope& P, Point const& p, NT const& a_i, RandomNumberGenerator &rng) @@ -239,14 +239,14 @@ private : p.set_coord(i, C * std::cos(omega * T + Phi)); v.set_coord(i, -C * omega * std::sin(omega * T + Phi)); } - + } - inline double get_max_distance(std::vector &pointset, Point const& q, double &rad) + inline double get_max_distance(std::vector &pointset, Point const& q, double &rad) { double dis = -1.0, temp_dis; int jj = 0; - for (auto vecit = pointset.begin(); vecit!=pointset.end(); vecit++, jj++) + for (auto vecit = pointset.begin(); vecit!=pointset.end(); vecit++, jj++) { temp_dis = (q.getCoefficients() - (*vecit).getCoefficients()).norm(); if (temp_dis > dis) { diff --git a/include/random_walks/gaussian_rdhr_walk.hpp b/include/random_walks/gaussian_rdhr_walk.hpp index de7fd7bf9..b7a53abe7 100644 --- a/include/random_walks/gaussian_rdhr_walk.hpp +++ b/include/random_walks/gaussian_rdhr_walk.hpp @@ -80,10 +80,10 @@ struct Walk typedef typename Polytope::PointType Point; typedef typename Point::FT NT; - Walk(Polytope const&, Point const&, NT const&, RandomNumberGenerator&) + Walk(Polytope&, Point const&, NT const&, RandomNumberGenerator&) {} - Walk(Polytope const&, Point const&, NT const&, RandomNumberGenerator&, + Walk(Polytope&, Point const&, NT const&, RandomNumberGenerator&, parameters&) {} diff --git a/include/random_walks/multithread_walks.hpp b/include/random_walks/multithread_walks.hpp index 45b2b67cb..c42fba1fa 100644 --- a/include/random_walks/multithread_walks.hpp +++ b/include/random_walks/multithread_walks.hpp @@ -58,7 +58,7 @@ struct BCDHRWalk_multithread //typedef thread_params thread_parameters_; template - Walk(GenericPolytope const& P, thread_parameters_ ¶meters, RandomNumberGenerator& rng) + Walk(GenericPolytope& P, thread_parameters_ ¶meters, RandomNumberGenerator& rng) { initialize(P, parameters, rng); } @@ -68,7 +68,7 @@ struct BCDHRWalk_multithread typename BallPolytope > inline void apply(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters unsigned int const& walk_length, RandomNumberGenerator& rng) { @@ -97,13 +97,13 @@ struct BCDHRWalk_multithread template inline void initialize(GenericBody const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters RandomNumberGenerator& rng) { params.lambdas.setZero(P.num_of_hyperplanes()); params.rand_coord = rng.sample_uidist(); NT kapa = rng.sample_urdist(); - + std::pair bpair = P.line_intersect_coord(params.p, params.rand_coord, params.lambdas); params.p_prev = params.p; @@ -158,7 +158,7 @@ struct BRDHRWalk_multithread //typedef thread_params thread_parameters_; template - Walk(GenericPolytope const& P, thread_parameters_ ¶meters, RandomNumberGenerator& rng) + Walk(GenericPolytope& P, thread_parameters_ ¶meters, RandomNumberGenerator& rng) { initialize(P, parameters, rng); } @@ -168,7 +168,7 @@ struct BRDHRWalk_multithread typename BallPolytope > inline void apply(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters unsigned int const& walk_length, RandomNumberGenerator& rng) { @@ -191,7 +191,7 @@ struct BRDHRWalk_multithread template inline void initialize(GenericBody const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters RandomNumberGenerator& rng) { params.lambdas.setZero(P.num_of_hyperplanes()); @@ -243,7 +243,7 @@ struct Walk typedef thread_parameters thread_parameters_; //typedef thread_params thread_parameters_; - Walk(Polytope const& P, + Walk(Polytope& P, thread_parameters_ ¶ms, NT const& a_i, RandomNumberGenerator &rng) @@ -252,7 +252,7 @@ struct Walk } template - Walk(Polytope const& P, + Walk(Polytope& P, thread_parameters_ ¶ms, NT const& a_i, RandomNumberGenerator &rng, @@ -260,14 +260,14 @@ struct Walk { initialize(P, params, a_i, rng); } - + template < typename BallPolytope > inline void apply(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters NT const& a_i, unsigned int const& walk_length, RandomNumberGenerator &rng) @@ -293,7 +293,7 @@ private : template inline void initialize(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters NT const& a_i, RandomNumberGenerator &rng) { @@ -345,11 +345,11 @@ struct Walk typedef thread_parameters thread_parameters_; //typedef thread_params thread_parameters_; - Walk(Polytope const&, thread_parameters_ &, NT const&, RandomNumberGenerator&) + Walk(Polytope&, thread_parameters_ &, NT const&, RandomNumberGenerator&) {} template - Walk(Polytope const&, thread_parameters_ &, NT const&, RandomNumberGenerator&, + Walk(Polytope&, thread_parameters_ &, NT const&, RandomNumberGenerator&, parameters&) {} @@ -358,7 +358,7 @@ struct Walk typename BallPolytope > inline void apply(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters NT const& a_i, unsigned int const& walk_length, RandomNumberGenerator &rng) @@ -440,7 +440,7 @@ struct Walk //typedef thread_params thread_parameters_; template - Walk(GenericPolytope const& P, thread_parameters_ ¶meters, RandomNumberGenerator &rng) + Walk(GenericPolytope& P, thread_parameters_ ¶meters, RandomNumberGenerator &rng) { _Len = compute_diameter ::template compute(P); @@ -448,7 +448,7 @@ struct Walk } template - Walk(GenericPolytope const& P, thread_parameters_ ¶meters, RandomNumberGenerator &rng, + Walk(GenericPolytope& P, thread_parameters_ ¶meters, RandomNumberGenerator &rng, parameters_ const& params) { _Len = params.set_L ? params.m_L @@ -461,7 +461,7 @@ struct Walk < typename GenericPolytope > - inline void apply(GenericPolytope const& P, + inline void apply(GenericPolytope& P, thread_parameters_ ¶meters, unsigned int const& walk_length, RandomNumberGenerator &rng) @@ -491,7 +491,7 @@ struct Walk P.compute_reflection(parameters.v, parameters.p, pbpair.second); it++; } - if (it == 50*n) + if (it == 50*n) { parameters.p = parameters.p0; } @@ -509,7 +509,7 @@ private : < typename GenericPolytope > - inline void initialize(GenericPolytope const& P, + inline void initialize(GenericPolytope& P, thread_parameters_ ¶meters, RandomNumberGenerator &rng) { @@ -524,7 +524,7 @@ private : std::pair pbpair = P.line_positive_intersect(parameters.p, parameters.v, parameters.lambdas, parameters.Av); - if (T <= pbpair.first) + if (T <= pbpair.first) { parameters.p += (T * parameters.v); parameters.lambda_prev = T; @@ -538,9 +538,9 @@ private : while (it <= 50*n) { std::pair pbpair - = P.line_positive_intersect(parameters.p, parameters.v, parameters.lambdas, + = P.line_positive_intersect(parameters.p, parameters.v, parameters.lambdas, parameters.Av, parameters.lambda_prev); - if (T <= pbpair.first) + if (T <= pbpair.first) { parameters.p += (T * parameters.v); parameters.lambda_prev = T; @@ -599,7 +599,7 @@ struct Walk //typedef thread_params thread_parameters_; template - Walk(GenericPolytope const& P, thread_parameters_ ¶meters, RandomNumberGenerator& rng) + Walk(GenericPolytope& P, thread_parameters_ ¶meters, RandomNumberGenerator& rng) { initialize(P, parameters, rng); } @@ -610,7 +610,7 @@ struct Walk typename BallPolytope > inline void apply(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters unsigned int const& walk_length, RandomNumberGenerator &rng) { @@ -634,7 +634,7 @@ private : template inline void initialize(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters RandomNumberGenerator &rng) { params.lambdas.setZero(P.num_of_hyperplanes()); @@ -690,7 +690,7 @@ struct Walk //typedef thread_params thread_parameters_; template - Walk(GenericPolytope const& P, thread_parameters_ ¶meters, RandomNumberGenerator& rng) + Walk(GenericPolytope& P, thread_parameters_ ¶meters, RandomNumberGenerator& rng) { initialize(P, parameters, rng); } @@ -700,7 +700,7 @@ struct Walk typename BallPolytope > inline void apply(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters unsigned int const& walk_length, RandomNumberGenerator& rng) { @@ -719,7 +719,7 @@ private : template inline void initialize(BallPolytope const& P, - thread_parameters_ ¶ms, // parameters + thread_parameters_ ¶ms, // parameters RandomNumberGenerator &rng) { params.lambdas.setZero(P.num_of_hyperplanes()); diff --git a/include/random_walks/uniform_ball_walk.hpp b/include/random_walks/uniform_ball_walk.hpp index aeee06537..77c608b72 100644 --- a/include/random_walks/uniform_ball_walk.hpp +++ b/include/random_walks/uniform_ball_walk.hpp @@ -46,14 +46,14 @@ struct BallWalk typedef typename Point::FT NT; template - Walk(GenericPolytope const& P, Point const& /*p*/, + Walk(GenericPolytope& P, Point const& /*p*/, RandomNumberGenerator& /*rng*/) { _delta = compute_delta(P); } template - Walk(GenericPolytope const& P, Point const& /*p*/, + Walk(GenericPolytope& P, Point const& /*p*/, RandomNumberGenerator& /*rng*/, parameters const& params) { _delta = params.set_delta ? params.m_L @@ -61,7 +61,7 @@ struct BallWalk } template - static inline NT compute_delta(GenericPolytope const& P) + static inline NT compute_delta(GenericPolytope& P) { //return ((P.InnerBall()).second * NT(4)) / NT(P.dimension()); return (NT(4) * (P.InnerBall()).second) / std::sqrt(NT(P.dimension())); diff --git a/include/random_walks/uniform_cdhr_walk.hpp b/include/random_walks/uniform_cdhr_walk.hpp index b1a1a5386..12d2ff78e 100644 --- a/include/random_walks/uniform_cdhr_walk.hpp +++ b/include/random_walks/uniform_cdhr_walk.hpp @@ -30,13 +30,13 @@ struct Walk typedef typename Point::FT NT; template - Walk(GenericPolytope const& P, Point const& p, RandomNumberGenerator& rng) + Walk(GenericPolytope& P, Point const& p, RandomNumberGenerator& rng) { initialize(P, p, rng); } template - Walk(GenericPolytope const& P, Point const& p, + Walk(GenericPolytope& P, Point const& p, RandomNumberGenerator& rng, parameters const& params) { initialize(P, p, rng); diff --git a/include/random_walks/uniform_rdhr_walk.hpp b/include/random_walks/uniform_rdhr_walk.hpp index a322fe12c..5e0eb4750 100644 --- a/include/random_walks/uniform_rdhr_walk.hpp +++ b/include/random_walks/uniform_rdhr_walk.hpp @@ -31,13 +31,13 @@ struct Walk typedef typename Point::FT NT; template - Walk(GenericPolytope const& P, Point const& p, RandomNumberGenerator& rng) + Walk(GenericPolytope& P, Point const& p, RandomNumberGenerator& rng) { initialize(P, p, rng); } template - Walk(GenericPolytope const& P, Point const& p, + Walk(GenericPolytope& P, Point const& p, RandomNumberGenerator& rng, parameters const& params) { initialize(P, p, rng); @@ -47,7 +47,7 @@ struct Walk < typename BallPolytope > - inline void apply(BallPolytope const& P, + inline void apply(BallPolytope& P, Point& p, // a point to start unsigned int const& walk_length, RandomNumberGenerator& rng) @@ -67,7 +67,7 @@ struct Walk private : template - inline void initialize(BallPolytope const& P, + inline void initialize(BallPolytope& P, Point const& p, RandomNumberGenerator &rng) { diff --git a/include/sampling/random_point_generators.hpp b/include/sampling/random_point_generators.hpp index abc7677e7..86b10666c 100644 --- a/include/sampling/random_point_generators.hpp +++ b/include/sampling/random_point_generators.hpp @@ -143,7 +143,7 @@ struct GaussianRandomPointGenerator typename WalkPolicy, typename RandomNumberGenerator > - static void apply(Polytope const& P, + static void apply(Polytope& P, Point &p, // a point to start NT const& a_i, unsigned int const& rnum, @@ -170,7 +170,7 @@ struct GaussianRandomPointGenerator typename RandomNumberGenerator, typename Parameters > - static void apply(Polytope const& P, + static void apply(Polytope& P, Point &p, // a point to start NT const& a_i, unsigned int const& rnum, @@ -203,7 +203,7 @@ struct BoundaryRandomPointGenerator typename WalkPolicy, typename RandomNumberGenerator > - static void apply(Polytope const& P, + static void apply(Polytope& P, Point &p, // a point to start unsigned int const& rnum, unsigned int const& walk_length, @@ -282,7 +282,7 @@ struct ExponentialRandomPointGenerator typename WalkPolicy, typename RandomNumberGenerator > - static void apply(Polytope const& P, + static void apply(Polytope& P, Point &p, // a point to start Point const& c, // bias function NT const& T, // temperature/variance @@ -315,7 +315,7 @@ struct ExponentialRandomPointGenerator typename RandomNumberGenerator, typename Parameters > - static void apply(Polytope const& P, + static void apply(Polytope& P, Point &p, // a point to start Point const& c, // bias function NT const& T, // temperature/variance diff --git a/include/volume/volume_cooling_balls.hpp b/include/volume/volume_cooling_balls.hpp index 29731a2e9..d90604fa4 100644 --- a/include/volume/volume_cooling_balls.hpp +++ b/include/volume/volume_cooling_balls.hpp @@ -694,7 +694,7 @@ template typename RandomNumberGenerator = BoostRandomNumberGenerator > -std::pair volume_cooling_balls(Polytope const& Pin, +std::pair volume_cooling_balls(Polytope& Pin, RandomNumberGenerator &rng, double const& error = 0.1, unsigned int const& walk_length = 1, diff --git a/include/volume/volume_cooling_gaussians.hpp b/include/volume/volume_cooling_gaussians.hpp index ef7ab0f70..ca06ce315 100644 --- a/include/volume/volume_cooling_gaussians.hpp +++ b/include/volume/volume_cooling_gaussians.hpp @@ -57,7 +57,7 @@ struct update_delta> // Compute the first variance a_0 for the starting gaussian template -void get_first_gaussian(Polytope const& P, +void get_first_gaussian(Polytope& P, NT const& frac, NT const& chebychev_radius, NT const& error, @@ -125,7 +125,7 @@ template typename NT, typename RandomNumberGenerator > -NT get_next_gaussian(Polytope const& P, +NT get_next_gaussian(Polytope& P, Point &p, NT const& a, const unsigned int &N, @@ -186,7 +186,7 @@ template typename NT, typename RandomNumberGenerator > -void compute_annealing_schedule(Polytope const& P, +void compute_annealing_schedule(Polytope& P, NT const& ratio, NT const& C, NT const& frac, @@ -289,7 +289,7 @@ template typename RandomNumberGenerator > -double volume_cooling_gaussians(Polytope const& Pin, +double volume_cooling_gaussians(Polytope& Pin, RandomNumberGenerator& rng, double const& error = 0.1, unsigned int const& walk_length = 1) @@ -483,7 +483,7 @@ double volume_cooling_gaussians(Polytope &Pin, { RandomNumberGenerator rng(Pin.dimension()); Pin.set_interior_point(interior_point); - + return volume_cooling_gaussians(Pin, rng, error, walk_length); } diff --git a/include/volume/volume_cooling_hpoly.hpp b/include/volume/volume_cooling_hpoly.hpp index 1175d9b64..c8183384c 100644 --- a/include/volume/volume_cooling_hpoly.hpp +++ b/include/volume/volume_cooling_hpoly.hpp @@ -135,7 +135,7 @@ bool get_next_zonoball(std::vector &HPolySet, return false; } -template +template < typename RandomPointGenerator, typename ZonoHP, @@ -374,7 +374,7 @@ template typename HPolytope, typename Polytope > -double volume_cooling_hpoly(Polytope const& Pin, +double volume_cooling_hpoly(Polytope& Pin, double const& error = 0.1, unsigned int const& walk_length = 1) { diff --git a/include/volume/volume_sequence_of_balls.hpp b/include/volume/volume_sequence_of_balls.hpp index fc1342cee..b79358a6e 100644 --- a/include/volume/volume_sequence_of_balls.hpp +++ b/include/volume/volume_sequence_of_balls.hpp @@ -44,7 +44,7 @@ template typename RandomNumberGenerator > -double volume_sequence_of_balls(Polytope const& Pin, +double volume_sequence_of_balls(Polytope& Pin, RandomNumberGenerator &rng, double const& error = 1.0, unsigned int const& walk_length = 1, @@ -258,7 +258,7 @@ double volume_sequence_of_balls(Polytope &Pin, { RandomNumberGenerator rng(Pin.dimension()); Pin.set_interior_point(interior_point); - + return volume_sequence_of_balls(Pin, rng, error, walk_length, n_threads); }