From 93f41a9063929f5195ff636bf9cfea6154176bdd Mon Sep 17 00:00:00 2001 From: kalmarek Date: Thu, 30 Jul 2020 11:57:39 +0200 Subject: [PATCH 01/12] move `include("meta.jl")` to main Polymake.jl file --- src/Polymake.jl | 6 ++++++ src/generate_applications.jl | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Polymake.jl b/src/Polymake.jl index 70be81cc..1bb7f5f7 100644 --- a/src/Polymake.jl +++ b/src/Polymake.jl @@ -145,6 +145,12 @@ include("polynomial.jl") include("polymake_direct_calls.jl") +using Base.Docs +using Markdown +include("meta.jl") + +using Polymake.Meta + include("generate_applications.jl") include("polydb.jl") diff --git a/src/generate_applications.jl b/src/generate_applications.jl index 79fd9704..43c75f92 100644 --- a/src/generate_applications.jl +++ b/src/generate_applications.jl @@ -1,9 +1,3 @@ -using Base.Docs -using Markdown -include("meta.jl") - -using Polymake.Meta - json_dir = joinpath(@__DIR__, "..", "deps", "json") generated_dir = joinpath(@__DIR__, "generated") isdir(generated_dir) || mkpath(generated_dir) From 51b2105e42493c98213323901c004e072a572f5f Mon Sep 17 00:00:00 2001 From: kalmarek Date: Thu, 30 Jul 2020 12:55:13 +0200 Subject: [PATCH 02/12] first try at direct interface to beneath_beyond --- deps/src/beneath_beyond.cpp | 238 +++++++++++++++++++++++++++++ deps/src/polymake.cpp | 1 + deps/src/polymake_direct_calls.cpp | 2 +- deps/src/polymake_includes.h | 1 - deps/src/polymake_type_modules.h | 3 +- 5 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 deps/src/beneath_beyond.cpp diff --git a/deps/src/beneath_beyond.cpp b/deps/src/beneath_beyond.cpp new file mode 100644 index 00000000..8b62822c --- /dev/null +++ b/deps/src/beneath_beyond.cpp @@ -0,0 +1,238 @@ +#include "polymake_includes.h" +#include +#include "polymake_type_modules.h" + +namespace polymake { namespace polytope { + +template +class beneath_beyond_algo_for_ml: public beneath_beyond_algo{ + public: + typedef E value_type; + typedef const beneath_beyond_algo Base; + + beneath_beyond_algo_for_ml(): Base() + { + initialized = false; + }; + + void initialize(const Matrix& rays, const Matrix& lins){ + initialize(rays, lins, entire(sequence(0, rays.rows()))); + }; + + template + void initialize(const Matrix& rays, const Matrix& lins, Iterator perm); + + void process_point(Int p); + + void finalize(); + + void compute(const Matrix& rays, const Matrix& lins) + { + #if POLYMAKE_DEBUG + enable_debug_output(); + #endif + compute(rays, lins, entire(sequence(0, rays.rows()))); + } + + // TODO: bundle all results in a structure, move all numbers into it + template + void compute(const Matrix& rays, const Matrix& lins, Iterator perm); + + protected: + void stop_cleanup(); + + using Base::source_points; + using Base::source_linealities; + using Base::linealities_so_far; + using Base::expect_redundant; + using Base::source_lineality_basis; + using Base::linealities; + using Base::transform_points; + using Base::points; + using Base::generic_position; + using Base::triang_size; + using Base::AH; + using Base::interior_points; + using Base::vertices_this_step; + using Base::interior_points_this_step; + using Base::facet_normals_valid; + using Base::facet_normals_low_dim; + using Base::dual_graph; + using Base::vertices_so_far; + using Base::make_triangulation; + using Base::triangulation; + using Base::is_cone; + using Base::facets; + + class stop_calculation {}; + + enum class compute_state { zero, one, low_dim, full_dim }; + compute_state state; + + private: + bool initialized; + std::vector points_added; +}; + +template +template +void beneath_beyond_algo_for_ml::initialize(const Matrix& rays, const Matrix& lins, Iterator perm) +{ + assert(initialized == false); + + source_points = &rays; + source_linealities = &lins; + + linealities_so_far.resize(0,rays.cols()); + + try { + if (lins.rows() != 0) { + if (expect_redundant) { + source_lineality_basis = basis_rows(lins); + linealities_so_far = lins.minor(source_lineality_basis, All); + linealities = &linealities_so_far; + } else { + linealities = source_linealities; + } + transform_points(); // the only place where stop_calculation could be thrown + } else { + points = source_points; + linealities = expect_redundant ? &linealities_so_far : source_linealities; + } + + generic_position = !expect_redundant; + triang_size = 0; + AH = unit_matrix(points->cols()); + if (expect_redundant) { + interior_points.resize(points->rows()); + vertices_this_step.resize(points->rows()); + interior_points_this_step.resize(points->rows()); + } + + points_added = std::vector(perm.size(), false); + initialized = true; + } + catch (const stop_calculation&) { +#if POLYMAKE_DEBUG + if (debug >= do_dump) cout << "stop: failed to initialize beneath_beyond_algo" << endl; +#endif + // TODO: some cleanup?? + } +}; + +template +void beneath_beyond_algo_for_ml::process_point(Int p){ + if ( !points_added[p] ) + Base::process_point(p); + points_added[p] = true; +}; + +template +template +void beneath_beyond_algo_for_ml::compute(const Matrix& rays, const Matrix& lins, Iterator perm){ + + initialize(rays, lins, perm); + + try{ + for (state = compute_state::zero; !perm.at_end(); ++perm) + process_point(*perm); + + if (state == compute_state::low_dim && !facet_normals_valid) + facet_normals_low_dim(); + } + catch (const stop_calculation&){ +#if POLYMAKE_DEBUG + if (debug >= do_dump) cout << "stop: degenerated to full linear space" << endl; +#endif + stop_cleanup(); + } + + finalize(); + +#if POLYMAKE_DEBUG + if (debug >= do_dump) { + cout << "final "; + dump(); + } +#endif + +}; + +template +void beneath_beyond_algo_for_ml::stop_cleanup(){ + state = compute_state::zero; + dual_graph.clear(); + vertices_so_far.clear(); + points = source_points; + interior_points = sequence(0, source_points->rows()); + if (make_triangulation) { + triangulation.clear(); + triang_size = 0; + } +} + +template +void beneath_beyond_algo_for_ml::finalize(){ + switch (state) { + case compute_state::zero: + if (!is_cone) { + // empty polyhedron + AH.resize(0, source_points->cols()); + linealities_so_far.resize(0, source_points->cols()); + } + break; + case compute_state::one: + // There is one empty facet in this case and the point is also a facet normal + facets[dual_graph.add_node()].normal = points->row(vertices_so_far.front()); + if (make_triangulation) { + triang_size=1; + triangulation.push_back(vertices_so_far); + } + break; + case compute_state::low_dim: + case compute_state::full_dim: + dual_graph.squeeze(); + break; + } +} + +} +} + +void polymake_module_add_beneath_beyond(jlcxx::Module& polymake) +{ + polymake + .add_type>>("BeneathBeyondAlgo") + .apply>([](auto wrapped) { + typedef typename decltype(wrapped)::type WrappedT; + typedef typename decltype(wrapped)::type::value_type E; + wrapped.template constructor(); + + wrapped.method("expecting_redundant", &WrappedT::expecting_redundant); + wrapped.method("for_cone", &WrappedT::for_cone); + wrapped.method("making_triangulation", &WrappedT::making_triangulation); + wrapped.method("computing_vertices", &WrappedT::computing_vertices); + + wrapped.method("compute", []( + WrappedT& bb, + const pm::Matrix& rays, + const pm::Matrix& lins + ) { + bb.compute(rays, lins); + return bb; + }); + + wrapped.method("getFacets", &WrappedT::getFacets); + wrapped.method("getVertexFacetIncidence", &WrappedT::getVertexFacetIncidence); + wrapped.method("getAffineHull", &WrappedT::getAffineHull); + wrapped.method("getVertices", &WrappedT::getVertices); + // wrapped.method("getNonRedundantPoints", &WrappedT::getNonRedundantPoints); + wrapped.method("getNonRedundantLinealities", &WrappedT::getNonRedundantLinealities); + wrapped.method("getLinealities", &WrappedT::getLinealities); + // wrapped.method("getDualGraph", &WrappedT::getDualGraph); + wrapped.method("getTriangulation", &WrappedT::getTriangulation); + // wrapped.method("get", &WrappedT::get); + // wrapped.method("get", &WrappedT::get); + // wrapped.method("get", &WrappedT::get); + }); +} diff --git a/deps/src/polymake.cpp b/deps/src/polymake.cpp index 06ad39a9..223c0bea 100644 --- a/deps/src/polymake.cpp +++ b/deps/src/polymake.cpp @@ -43,6 +43,7 @@ JLCXX_MODULE define_module_polymake(jlcxx::Module& polymake) polymake_module_add_polynomial(polymake); polymake_module_add_direct_calls(polymake); + polymake_module_add_beneath_beyond(polymake); polymake_module_add_array_polynomial(polymake, array_type); diff --git a/deps/src/polymake_direct_calls.cpp b/deps/src/polymake_direct_calls.cpp index 9b7319d1..bceeaabe 100644 --- a/deps/src/polymake_direct_calls.cpp +++ b/deps/src/polymake_direct_calls.cpp @@ -1,5 +1,5 @@ #include "polymake_includes.h" - +#include #include "polymake_type_modules.h" template diff --git a/deps/src/polymake_includes.h b/deps/src/polymake_includes.h index 86880ac1..45916021 100644 --- a/deps/src/polymake_includes.h +++ b/deps/src/polymake_includes.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/deps/src/polymake_type_modules.h b/deps/src/polymake_type_modules.h index 4fd88274..684713b2 100644 --- a/deps/src/polymake_type_modules.h +++ b/deps/src/polymake_type_modules.h @@ -9,7 +9,8 @@ tparametric1 polymake_module_add_array(jlcxx::Module& polymake); void polymake_module_add_array_polynomial(jlcxx::Module& polymake, tparametric1 arrayt); void polymake_module_add_bigobject(jlcxx::Module& polymake); -void polymake_module_add_direct_calls(jlcxx::Module&); +void polymake_module_add_direct_calls(jlcxx::Module& polymake); +void polymake_module_add_beneath_beyond(jlcxx::Module& polymake); void polymake_module_add_incidencematrix(jlcxx::Module& polymake); void polymake_module_add_integer(jlcxx::Module& polymake); void polymake_module_add_matrix(jlcxx::Module& polymake); From 97f573499f44359afdce10589c6d1efb96ef0eff Mon Sep 17 00:00:00 2001 From: kalmarek Date: Fri, 31 Jul 2020 00:26:52 +0200 Subject: [PATCH 03/12] =?UTF-8?q?rename=20finalize=20=E2=86=92=20clear?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deps/src/beneath_beyond.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/deps/src/beneath_beyond.cpp b/deps/src/beneath_beyond.cpp index 8b62822c..68b08157 100644 --- a/deps/src/beneath_beyond.cpp +++ b/deps/src/beneath_beyond.cpp @@ -15,28 +15,31 @@ class beneath_beyond_algo_for_ml: public beneath_beyond_algo{ initialized = false; }; - void initialize(const Matrix& rays, const Matrix& lins){ - initialize(rays, lins, entire(sequence(0, rays.rows()))); - }; - template void initialize(const Matrix& rays, const Matrix& lins, Iterator perm); + void initialize(const Matrix& rays, const Matrix& lins) + { + #if POLYMAKE_DEBUG + enable_debug_output(); + #endif + initialize(rays, lins, entire(sequence(0, rays.rows()))); + }; void process_point(Int p); - void finalize(); + void clear(); + + // TODO: bundle all results in a structure, move all numbers into it + template + void compute(const Matrix& rays, const Matrix& lins, Iterator perm); void compute(const Matrix& rays, const Matrix& lins) { #if POLYMAKE_DEBUG enable_debug_output(); #endif compute(rays, lins, entire(sequence(0, rays.rows()))); - } - - // TODO: bundle all results in a structure, move all numbers into it - template - void compute(const Matrix& rays, const Matrix& lins, Iterator perm); + }; protected: void stop_cleanup(); @@ -147,7 +150,7 @@ void beneath_beyond_algo_for_ml::compute(const Matrix& rays, const Matrix< stop_cleanup(); } - finalize(); + clear(); #if POLYMAKE_DEBUG if (debug >= do_dump) { @@ -172,7 +175,8 @@ void beneath_beyond_algo_for_ml::stop_cleanup(){ } template -void beneath_beyond_algo_for_ml::finalize(){ +void beneath_beyond_algo_for_ml::clear(){ + switch (state) { case compute_state::zero: if (!is_cone) { From 26811e13fda5ae2a7360834e6dcf5f7e051d5f44 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Fri, 31 Jul 2020 00:25:29 +0200 Subject: [PATCH 04/12] turn points_added into Bitset that stores the processed indicies --- deps/src/beneath_beyond.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/deps/src/beneath_beyond.cpp b/deps/src/beneath_beyond.cpp index 68b08157..76aafe8a 100644 --- a/deps/src/beneath_beyond.cpp +++ b/deps/src/beneath_beyond.cpp @@ -74,15 +74,14 @@ class beneath_beyond_algo_for_ml: public beneath_beyond_algo{ private: bool initialized; - std::vector points_added; + Bitset points_added; }; + template template void beneath_beyond_algo_for_ml::initialize(const Matrix& rays, const Matrix& lins, Iterator perm) { - assert(initialized == false); - source_points = &rays; source_linealities = &lins; @@ -112,7 +111,7 @@ void beneath_beyond_algo_for_ml::initialize(const Matrix& rays, const Matr interior_points_this_step.resize(points->rows()); } - points_added = std::vector(perm.size(), false); + points_added = Bitset(); initialized = true; } catch (const stop_calculation&) { @@ -125,9 +124,13 @@ void beneath_beyond_algo_for_ml::initialize(const Matrix& rays, const Matr template void beneath_beyond_algo_for_ml::process_point(Int p){ - if ( !points_added[p] ) + if ( !points_added.contains(p) ){ Base::process_point(p); - points_added[p] = true; + points_added += p; +#if POLYMAKE_DEBUG + std::cout << "processed point p = " << p << std::endl; +#endif + }; }; template From ddb4ee93dcccf5269f4335e2a9d284d2c3c8ade5 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Fri, 31 Jul 2020 00:33:32 +0200 Subject: [PATCH 05/12] move checks after main loop to clear() --- deps/src/beneath_beyond.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/deps/src/beneath_beyond.cpp b/deps/src/beneath_beyond.cpp index 76aafe8a..f1249973 100644 --- a/deps/src/beneath_beyond.cpp +++ b/deps/src/beneath_beyond.cpp @@ -125,6 +125,7 @@ void beneath_beyond_algo_for_ml::initialize(const Matrix& rays, const Matr template void beneath_beyond_algo_for_ml::process_point(Int p){ if ( !points_added.contains(p) ){ + state = compute_state::zero; Base::process_point(p); points_added += p; #if POLYMAKE_DEBUG @@ -139,12 +140,10 @@ void beneath_beyond_algo_for_ml::compute(const Matrix& rays, const Matrix< initialize(rays, lins, perm); - try{ - for (state = compute_state::zero; !perm.at_end(); ++perm) + try + { + for (; !perm.at_end(); ++perm) process_point(*perm); - - if (state == compute_state::low_dim && !facet_normals_valid) - facet_normals_low_dim(); } catch (const stop_calculation&){ #if POLYMAKE_DEBUG @@ -197,6 +196,18 @@ void beneath_beyond_algo_for_ml::clear(){ } break; case compute_state::low_dim: + if ( !facet_normals_valid ) + { + try + { + facet_normals_low_dim(); + } + catch(const stop_calculation& ) + { + stop_cleanup(); + } + } + break; case compute_state::full_dim: dual_graph.squeeze(); break; From 3a4ee661b3fa935799f73245e22c49300d152628 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Fri, 31 Jul 2020 00:33:58 +0200 Subject: [PATCH 06/12] initialize doesn't need perm for now --- deps/src/beneath_beyond.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/src/beneath_beyond.cpp b/deps/src/beneath_beyond.cpp index f1249973..e6921e8d 100644 --- a/deps/src/beneath_beyond.cpp +++ b/deps/src/beneath_beyond.cpp @@ -138,7 +138,7 @@ template template void beneath_beyond_algo_for_ml::compute(const Matrix& rays, const Matrix& lins, Iterator perm){ - initialize(rays, lins, perm); + initialize(rays, lins); try { From f712e40268736b3fb1d463f2385a8416b1f5cf05 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Fri, 31 Jul 2020 00:34:47 +0200 Subject: [PATCH 07/12] update cxxwrap interface --- deps/src/beneath_beyond.cpp | 38 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/deps/src/beneath_beyond.cpp b/deps/src/beneath_beyond.cpp index e6921e8d..2483f132 100644 --- a/deps/src/beneath_beyond.cpp +++ b/deps/src/beneath_beyond.cpp @@ -217,8 +217,16 @@ void beneath_beyond_algo_for_ml::clear(){ } } + +template<> struct jlcxx::IsMirroredType< + polymake::polytope::beneath_beyond_algo> : std::false_type { }; + void polymake_module_add_beneath_beyond(jlcxx::Module& polymake) { + polymake + .add_type>>("_BeneathBeyondAlgo") + .apply>([](auto wrapped) {}); + polymake .add_type>>("BeneathBeyondAlgo") .apply>([](auto wrapped) { @@ -226,19 +234,22 @@ void polymake_module_add_beneath_beyond(jlcxx::Module& polymake) typedef typename decltype(wrapped)::type::value_type E; wrapped.template constructor(); - wrapped.method("expecting_redundant", &WrappedT::expecting_redundant); - wrapped.method("for_cone", &WrappedT::for_cone); - wrapped.method("making_triangulation", &WrappedT::making_triangulation); - wrapped.method("computing_vertices", &WrappedT::computing_vertices); + wrapped.method("bb_expecting_redundant", &WrappedT::expecting_redundant); + wrapped.method("bb_for_cone", &WrappedT::for_cone); + wrapped.method("bb_making_triangulation", &WrappedT::making_triangulation); + wrapped.method("bb_computing_vertices", &WrappedT::computing_vertices); + + wrapped.method("bb_compute!", static_cast< + void (polymake::polytope::beneath_beyond_algo_for_ml::*)(const pm::Matrix&, const pm::Matrix&) + >(&WrappedT::compute)); + + wrapped.method("bb_initialize!", static_cast< + void (polymake::polytope::beneath_beyond_algo_for_ml::*)(const pm::Matrix&, const pm::Matrix&) + >(&WrappedT::initialize)); - wrapped.method("compute", []( - WrappedT& bb, - const pm::Matrix& rays, - const pm::Matrix& lins - ) { - bb.compute(rays, lins); - return bb; - }); + // wrapped.method("initialize", &WrappedT::initialize); + wrapped.method("bb_add_point!", &WrappedT::process_point); + wrapped.method("bb_clear!", &WrappedT::clear); wrapped.method("getFacets", &WrappedT::getFacets); wrapped.method("getVertexFacetIncidence", &WrappedT::getVertexFacetIncidence); @@ -249,8 +260,5 @@ void polymake_module_add_beneath_beyond(jlcxx::Module& polymake) wrapped.method("getLinealities", &WrappedT::getLinealities); // wrapped.method("getDualGraph", &WrappedT::getDualGraph); wrapped.method("getTriangulation", &WrappedT::getTriangulation); - // wrapped.method("get", &WrappedT::get); - // wrapped.method("get", &WrappedT::get); - // wrapped.method("get", &WrappedT::get); }); } From 2092c459ef44ef923181e6a2f6b7fda9a440a8e3 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sat, 1 Aug 2020 13:52:55 +0200 Subject: [PATCH 08/12] move compute_state::zero to initialize --- deps/src/beneath_beyond.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deps/src/beneath_beyond.cpp b/deps/src/beneath_beyond.cpp index 2483f132..f8ae8e3e 100644 --- a/deps/src/beneath_beyond.cpp +++ b/deps/src/beneath_beyond.cpp @@ -111,6 +111,8 @@ void beneath_beyond_algo_for_ml::initialize(const Matrix& rays, const Matr interior_points_this_step.resize(points->rows()); } + state = compute_state::zero; // moved from the main compute loop + points_added = Bitset(); initialized = true; } @@ -125,7 +127,6 @@ void beneath_beyond_algo_for_ml::initialize(const Matrix& rays, const Matr template void beneath_beyond_algo_for_ml::process_point(Int p){ if ( !points_added.contains(p) ){ - state = compute_state::zero; Base::process_point(p); points_added += p; #if POLYMAKE_DEBUG From 2eb22dec1e4096ad807b33ffc2ab5b0c4f987678 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sat, 1 Aug 2020 14:11:02 +0200 Subject: [PATCH 09/12] add an initial julia wrapper for BeneathBeyondAlgo --- src/Polymake.jl | 1 + src/beneath_beyond.jl | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/beneath_beyond.jl diff --git a/src/Polymake.jl b/src/Polymake.jl index 1bb7f5f7..ac9c9982 100644 --- a/src/Polymake.jl +++ b/src/Polymake.jl @@ -144,6 +144,7 @@ include("tropicalnumber.jl") include("polynomial.jl") include("polymake_direct_calls.jl") +include("beneath_beyond.jl") using Base.Docs using Markdown diff --git a/src/beneath_beyond.jl b/src/beneath_beyond.jl new file mode 100644 index 00000000..4713681f --- /dev/null +++ b/src/beneath_beyond.jl @@ -0,0 +1,45 @@ +mutable struct BeneathBeyond{T} + algo::Polymake.BeneathBeyondAlgoAllocated{T} + perm::Vector{Int} + + function BeneathBeyond( + rays::AbstractMatrix{T}, + lineality::AbstractMatrix{T}=similar(rays, (0,size(rays,2))); + perm = collect(0:size(rays, 1)-1), + redundant = true, + triangulation = true, + iscone = true, + vertices = false, + ) where {T} + + @assert !isempty(perm) + + algo = Polymake.BeneathBeyondAlgo{T}() + Polymake.bb_expecting_redundant(algo, redundant) + Polymake.bb_making_triangulation(algo, triangulation) + Polymake.bb_for_cone(algo, iscone) + Polymake.bb_computing_vertices(algo, vertices) + + Polymake.bb_initialize!( + algo, + convert(Polymake.Matrix{Polymake.Rational}, rays), + convert(Polymake.Matrix{Polymake.Rational}, lineality), + ) + + bb = new{T}(algo, perm) + + # finalizer(x->bb_clear!(x.algo), bb) + + return bb + end +end + +Base.length(bb::BeneathBeyond) = length(bb.perm) +function Base.iterate(bb::BeneathBeyond, s = 1) + if s > length(bb) + return nothing + end + _, time, _ = @timed bb_add_point!(bb.algo, bb.perm[s]) + @info "Iteration $s; adding point $(bb.perm[s]+1), time = $time (s)" + return nothing, s + 1 +end From 9200d5a94486e18680d4359c3251e1aa300786bd Mon Sep 17 00:00:00 2001 From: kalmarek Date: Tue, 4 Aug 2020 09:37:01 +0200 Subject: [PATCH 10/12] stor rays/lineality in BeneathBeyond to protect from GC --- src/beneath_beyond.jl | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/beneath_beyond.jl b/src/beneath_beyond.jl index 4713681f..f881e1df 100644 --- a/src/beneath_beyond.jl +++ b/src/beneath_beyond.jl @@ -1,5 +1,7 @@ mutable struct BeneathBeyond{T} algo::Polymake.BeneathBeyondAlgoAllocated{T} + rays::Matrix{T} + lineality::Matrix{T} perm::Vector{Int} function BeneathBeyond( @@ -14,19 +16,18 @@ mutable struct BeneathBeyond{T} @assert !isempty(perm) - algo = Polymake.BeneathBeyondAlgo{T}() - Polymake.bb_expecting_redundant(algo, redundant) - Polymake.bb_making_triangulation(algo, triangulation) - Polymake.bb_for_cone(algo, iscone) - Polymake.bb_computing_vertices(algo, vertices) + algo = BeneathBeyondAlgo{T}() + R = convert(Matrix{T}, rays) + L = convert(Matrix{T}, lineality) + p = convert(Vector{T}, perm) + bb = new{T}(algo, R, L, p) - Polymake.bb_initialize!( - algo, - convert(Polymake.Matrix{Polymake.Rational}, rays), - convert(Polymake.Matrix{Polymake.Rational}, lineality), - ) + bb_expecting_redundant(bb.algo, redundant) + bb_making_triangulation(bb.algo, triangulation) + bb_for_cone(bb.algo, iscone) + bb_computing_vertices(bb.algo, vertices) - bb = new{T}(algo, perm) + bb_initialize!(bb.algo, R, L) # finalizer(x->bb_clear!(x.algo), bb) From b916d8d2446d0abd50459fd29db26c180138329f Mon Sep 17 00:00:00 2001 From: kalmarek Date: Tue, 4 Aug 2020 09:37:37 +0200 Subject: [PATCH 11/12] wip add bb_test.jl sctipt --- bb_test.jl | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 bb_test.jl diff --git a/bb_test.jl b/bb_test.jl new file mode 100644 index 00000000..11191a0d --- /dev/null +++ b/bb_test.jl @@ -0,0 +1,69 @@ +using Revise +using Test +using Polymake + +function BB_iterator(c) + N = polytope.dim(c) + @info "running bb using iterator over $N-dimensional polytope" + bb = Polymake.BeneathBeyond(c.POINTS, c.LINEALITY_SPACE, redundant=true, triangulation=true, iscone=true) + tr = GC.@preserve bb begin + for x in bb + @show length(Polymake.getTriangulation(bb.algo)) + end + tr = Polymake.getTriangulation(bb.algo) + @show last(tr) + tr + end + @info "bb is done!" + return tr +end + + +function BB_direct_call(c) + N = polytope.dim(c) + @info "running bb using direct calls over $N-dimensional polytope" + bb = Polymake.BeneathBeyondAlgo{Polymake.Rational}() + P, L = c.POINTS, c.LINEALITY_SPACE + tr = GC.@preserve bb P L begin + Polymake.bb_initialize!(bb, P, L) + + for p in 0:6 + @time Polymake.bb_add_point!(bb, p) + end + + @show Polymake.getTriangulation(bb) + + @time for p in 2:size(c.POINTS, 1)-1 + Polymake.bb_add_point!(bb, p) + end + tr = Polymake.getTriangulation(bb) + @show last(tr) + @info "bb is done!" + tr + end + return tr +end; + + + +const rs = polytope.rand_sphere(4,30); + +@info "running placing_triangulation" +t1 = polytope.placing_triangulation(rs.POINTS) +t2 = let rs = rs + N = polytope.dim(rs) + @info "running bb using bb_compute! over $N-dimensional polytope" + bbalgo = Polymake.BeneathBeyondAlgo{Polymake.Rational}() + P, L = rs.POINTS, rs.LINEALITY_SPACE + GC.@preserve bbalgo P L begin + Polymake.bb_compute!(bbalgo, P, L) + Polymake.getTriangulation(bbalgo) + end +end + +@test t1 == t2 + +t3 = BB_direct_call(rs) +@test t1 == t3 +t4 = BB_iterator(rs) +@test t1 == t4 From 7d8b3bcc6f83a870cc6d219e31c0fff5a459cbd4 Mon Sep 17 00:00:00 2001 From: Benjamin Lorenz Date: Tue, 4 Aug 2020 11:26:52 +0200 Subject: [PATCH 12/12] remove duplicate state variable --- deps/src/beneath_beyond.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/deps/src/beneath_beyond.cpp b/deps/src/beneath_beyond.cpp index f8ae8e3e..d25a638f 100644 --- a/deps/src/beneath_beyond.cpp +++ b/deps/src/beneath_beyond.cpp @@ -66,12 +66,11 @@ class beneath_beyond_algo_for_ml: public beneath_beyond_algo{ using Base::triangulation; using Base::is_cone; using Base::facets; + using compute_state = typename Base::compute_state; + using Base::state; class stop_calculation {}; - enum class compute_state { zero, one, low_dim, full_dim }; - compute_state state; - private: bool initialized; Bitset points_added;