Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order polytope improvements #319

Merged
merged 52 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
157955c
Fix the warning message in R Mac's cran test (#285)
TolisChal Oct 16, 2023
074a562
No-U-Turn Sampler in HMC (#216)
TolisChal Oct 17, 2023
c31e98b
Use of SIMD computation in CRHMC walk [fixed] (#286)
iakoviid Nov 2, 2023
e767f46
Update CODE_OF_CONDUCT.md
vissarion Nov 15, 2023
c9fb177
Add define lp_solve guards to orderpolytope
vissarion Feb 9, 2024
f91d4a9
Rename LinearProgramFunctor to ExponentialFunctor and add inverse var…
vissarion Feb 9, 2024
b15c9d8
Rename LinearProgramFunctor to ExponentialFunctor, add inverse varian…
vfisikop Feb 14, 2024
1ae6a45
Remove C11 flags from cran
vfisikop Feb 14, 2024
ad049d5
Merge pull request #289 from vfisikop/remove_volesti4dingo
vfisikop Feb 14, 2024
432b967
Build only with lp-solve source code, no need for liblpsolve55.so files
vfisikop Feb 15, 2024
7da53c4
Update tests and some examples to buid with lp solve from sources
vfisikop Feb 15, 2024
f8db05c
Upgrade boost from 1.76 to 1.84
vfisikop Feb 16, 2024
1703e69
Fix ambiguous call to pow for clang, and disable LoadableBlasLib
vfisikop Feb 16, 2024
93bbc50
Merge pull request #290 from vfisikop/fix/lpsolve_build_from_source
vfisikop Feb 16, 2024
5bf9188
Update requirements.txt
vfisikop Feb 20, 2024
b2b5c06
Autopoint (#256)
zhanggiene Mar 6, 2024
bf1ebd0
Enable c++17 support in tests and fix saxpy calls (#292)
vfisikop Mar 6, 2024
acad38a
Refactor/eliminate include directives (#244)
elias-tsigaridas Mar 6, 2024
8f7a9f2
Remove R interface and update CI to test Rvolesti repository with cur…
vfisikop Mar 6, 2024
8724a73
Fix includes of header files
vfisikop Mar 6, 2024
4c6bcc3
Fix windows CI tests
vfisikop Mar 6, 2024
4ee5374
Remove unused header files
vfisikop Mar 7, 2024
795e948
Merge pull request #293 from vfisikop/remove_R_interface
vfisikop Mar 7, 2024
9114f37
Update and simplify documentation
vfisikop Mar 15, 2024
742eb01
Refactor trigonometric_positive_intersect function for hpolytopes
vfisikop Mar 28, 2024
6a5a17e
Merge pull request #299 from vfisikop/trigonometric_intersect
vfisikop Apr 9, 2024
9c32d0b
update_position complexity improvement
vgnecula Jun 11, 2024
3129f7b
Merge pull request #307 from vgnecula/refinements
vfisikop Jun 14, 2024
e484865
Feature/spectra correlations (#306)
atrayees Jun 17, 2024
ddcf97b
Improve max volume ellipsoid computation (#309)
TolisChal Jun 20, 2024
723869e
Improve max ball computation and develop analytic center computation …
TolisChal Jun 21, 2024
d076bf0
Position Nudging after Position Update (#308)
vgnecula Jun 25, 2024
5bc28d6
Generalize the rounding loop and support sparse computations in prepr…
TolisChal Jun 27, 2024
f1abc36
Function/is correlation (#315)
atrayees Jul 5, 2024
e6dd7fd
Implement rounding method using the volumetric barrier (#313)
TolisChal Jul 8, 2024
348aab4
Order Polytopes generation
lucaperju Jun 28, 2024
65056ed
minor changes for PR
lucaperju Jul 11, 2024
c44355b
Merge branch 'GeomScale:develop' into order_polytope_improvements
lucaperju Jul 12, 2024
f533e95
remove space and comment
lucaperju Jul 12, 2024
3ca6ab1
Merge branch 'order_polytope_improvements' of github.com:lucaperju/vo…
lucaperju Jul 12, 2024
3087d98
remove bug
lucaperju Jul 12, 2024
5fb206a
Unit test for Random Order Polytope, and minor changes
lucaperju Jul 12, 2024
159ec1d
remove comment
lucaperju Jul 12, 2024
12c1f8a
Order Polytopes generation
lucaperju Jun 28, 2024
cff93cb
minor changes for PR
lucaperju Jul 11, 2024
634d3cc
remove space and comment
lucaperju Jul 12, 2024
e388d43
remove bug
lucaperju Jul 12, 2024
d67be4b
Unit test for Random Order Polytope, and minor changes
lucaperju Jul 12, 2024
81aeb51
remove comment
lucaperju Jul 12, 2024
1dba5e5
Merge branch 'order_polytope_improvements' of github.com:lucaperju/vo…
lucaperju Jul 17, 2024
fee9579
fix rebase bugs
lucaperju Jul 17, 2024
e764a69
remove accidental line
lucaperju Jul 17, 2024
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
1 change: 1 addition & 0 deletions examples/crhmc_sampling/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CRHMC_SIMD_*
sampling_functions
simple_crhmc
libQD_LIB.a
liblp_solve.a
6 changes: 6 additions & 0 deletions include/convex_bodies/orderpolytope.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class OrderPolytope {
return _A.sparseView();
}

// return the matrix A
MT get_full_mat() const
{
return _A;
}


VT get_vec() const
{
Expand Down
82 changes: 78 additions & 4 deletions include/generators/order_polytope_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@
#ifndef ORDER_POLYTOPES_GEN_H
#define ORDER_POLYTOPES_GEN_H

#include <chrono>
#include <sstream>
#include <type_traits>
#include <unordered_map>
#include "misc.h"
#include <vector>
#include <algorithm>

#include "misc/misc.h"
#include "misc/poset.h"

#include <boost/random.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/uniform_real_distribution.hpp>

#include "generators/boost_random_number_generator.hpp"

#include "convex_bodies/orderpolytope.h"
#include "convex_bodies/hpolytope.h"


// Instances taken from: https://github.com/ttalvitie/le-counting-practice
static const std::unordered_map<std::string, std::string> instances =
Expand All @@ -38,14 +53,31 @@ static const std::unordered_map<std::string, std::string> instances =

};

// generates a Polytope from a poset
/// @tparam Polytope Type of returned polytope
template <class Polytope>
Polytope get_orderpoly(Poset const &poset) {
typedef typename Polytope::PointType Point;

OrderPolytope<Point> OP(poset);
if constexpr (std::is_same< Polytope, OrderPolytope<Point> >::value ) {
return OP;
} else if constexpr (std::is_same<Polytope, HPolytope<Point> >::value ){
Polytope HP(OP.dimension(), OP.get_full_mat(), OP.get_vec());
return HP;
} else {
throw "Unable to generate an Order Polytope of requested type";
}
}

// generates an Order Polytope from an instance name
// Instances taken from: https://github.com/ttalvitie/le-counting-practice
/// @tparam Polytope Type of returned polytope
template <class Polytope>
Polytope generate_orderpoly(std::string& instance_name) {
std::stringstream in_ss(instances.at(instance_name));
Poset poset = read_poset_from_file_adj_matrix(in_ss).second;
return Polytope(poset);
return get_orderpoly<Polytope>(poset);
}

// Generates a cube as an Order Polytope
Expand All @@ -56,8 +88,50 @@ Polytope generate_cube_orderpoly(unsigned int dim) {

RV order_relations;
Poset poset(dim, order_relations);
Polytope OP(poset);
return OP;
return get_orderpoly<Polytope>(poset);
}

// Generates a random Order Polytope with given dimension and number of facets
/// @tparam Polytope Type of returned polytope
/// @tparam RNGType RNGType Type
template <class Polytope, typename NT>
Polytope random_orderpoly(unsigned int dim, unsigned int m, int seed = std::numeric_limits<int>::signaling_NaN()) {

typedef typename Poset::RV RV;

int rng_seed = std::chrono::system_clock::now().time_since_epoch().count();
if (!isnan(seed)) {
rng_seed = seed;
}

typedef BoostRandomNumberGenerator<boost::mt19937, NT> RNG;
RNG rng(dim);
rng.set_seed(rng_seed);


std::vector<unsigned int> order(dim);
for(int i = 0; i < dim; ++i) {
order[i] = i;
}
boost::mt19937 shuffle_rng(rng_seed);
std::shuffle(order.begin(), order.end(), shuffle_rng);


RV order_relations;
for(int i = 0; i < m - 2 * dim; ++i) {
unsigned int x = rng.sample_uidist();
unsigned int y = rng.sample_uidist();
while(x == y) {
y = rng.sample_uidist();
}
if(x > y)
std::swap(x, y);
order_relations.push_back(std::make_pair(order[x], order[y]));
}


Poset poset(dim, order_relations);
return get_orderpoly<Polytope>(poset);
}

#endif
65 changes: 37 additions & 28 deletions include/misc/poset.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@ class Poset {
unsigned int n; // elements will be from 0 to n-1
RV order_relations; // pairs of form a <= b

static void sorted_list(const unsigned int &n, const RV &relations, std::vector<unsigned int> &res)
{
std::vector<std::vector<unsigned int> > adjList(n);
std::vector<unsigned int> indegree(n, 0);

for(auto x: relations) {
adjList[x.first].push_back(x.second);
indegree[x.second] += 1;
}

std::queue<unsigned int> q;
for(unsigned int i=0; i<n; ++i) {
if(indegree[i] == 0)
q.push(i);
}

while(!q.empty()) {
unsigned int curr = q.front();
res.push_back(curr);
q.pop();

for(unsigned int i=0; i<adjList[curr].size(); ++i) {
unsigned int adj_idx = adjList[curr][i];
indegree[adj_idx] -= 1;
if(indegree[adj_idx] == 0)
q.push(adj_idx);
}
}
}

public:
Poset() {}

Expand All @@ -44,7 +74,12 @@ class Poset {
throw "invalid elements in order relations";
}

// TODO: Check if corresponding DAG is actually acyclic
std::vector<unsigned int> order;
sorted_list(n, relations, order);

if(order.size() < n) { // TODO: accept cycles in the poset
throw "corresponding DAG is not acyclic";
}

return relations;
}
Expand Down Expand Up @@ -96,34 +131,8 @@ class Poset {

std::vector<unsigned int> topologically_sorted_list() const
{
std::vector<std::vector<unsigned int> > adjList(n);
std::vector<unsigned int> indegree(n, 0);

for(auto x: order_relations) {
adjList[x.first].push_back(x.second);
indegree[x.second] += 1;
}

std::queue<unsigned int> q;
for(unsigned int i=0; i<n; ++i) {
if(indegree[i] == 0)
q.push(i);
}

std::vector<unsigned int> res;
while(!q.empty()) {
unsigned int curr = q.front();
res.push_back(curr);
q.pop();

for(unsigned int i=0; i<adjList[curr].size(); ++i) {
unsigned int adj_idx = adjList[curr][i];
indegree[adj_idx] -= 1;
if(indegree[adj_idx] == 0)
q.push(adj_idx);
}
}

sorted_list(n, order_relations, res);
return res;
}
};
Expand Down
14 changes: 14 additions & 0 deletions test/order_polytope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "cartesian_geom/cartesian_kernel.h"
#include "cartesian_geom/point.h"
#include "convex_bodies/orderpolytope.h"
#include "convex_bodies/hpolytope.h"

#include "generators/order_polytope_generator.h"

#include "misc/poset.h"
#include "misc/misc.h"

Expand Down Expand Up @@ -150,6 +154,16 @@ void call_test_basics() {
CHECK(OP.is_in(Point(4, {0.5, 0.5, 0.0, 1.0})) == 0); // a0 <= a2 violated
CHECK(OP.is_in(Point(4, {-0.1, 0.5, 1.0, 1.0})) == 0); // a0 >= 0 violated
CHECK(OP.is_in(Point(4, {1.0, 0.5, 1.0, 1.1})) == 0); // a3 <= 1 violated

// Create a random Order Polytope of dimension 10 with 30 facets as an Hpolytope class
HPolytope<Point> HP = random_orderpoly<HPolytope<Point>, NT>(10, 30);

d = HP.dimension();
m = HP.num_of_hyperplanes();

CHECK(d == 10);
CHECK(m == 30);

}


Expand Down
Loading