Skip to content

Commit c12e624

Browse files
committed
Revert "Order polytope improvements (#319)"
This reverts commit 0b97f7e.
1 parent 0b97f7e commit c12e624

File tree

5 files changed

+32
-136
lines changed

5 files changed

+32
-136
lines changed

examples/crhmc_sampling/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ CRHMC_SIMD_*
55
sampling_functions
66
simple_crhmc
77
libQD_LIB.a
8-
liblp_solve.a

include/convex_bodies/orderpolytope.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ class OrderPolytope {
9494
return _A.sparseView();
9595
}
9696

97-
// return the matrix A
98-
MT get_full_mat() const
99-
{
100-
return _A;
101-
}
102-
10397

10498
VT get_vec() const
10599
{

include/generators/order_polytope_generator.h

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,11 @@
99
#ifndef ORDER_POLYTOPES_GEN_H
1010
#define ORDER_POLYTOPES_GEN_H
1111

12-
#include <chrono>
1312
#include <sstream>
14-
#include <type_traits>
1513
#include <unordered_map>
16-
#include <vector>
17-
#include <algorithm>
18-
19-
#include "misc/misc.h"
14+
#include "misc.h"
2015
#include "misc/poset.h"
2116

22-
#include <boost/random.hpp>
23-
#include <boost/random/uniform_int.hpp>
24-
#include <boost/random/normal_distribution.hpp>
25-
#include <boost/random/uniform_real_distribution.hpp>
26-
27-
#include "generators/boost_random_number_generator.hpp"
28-
29-
#include "convex_bodies/orderpolytope.h"
30-
#include "convex_bodies/hpolytope.h"
31-
3217

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

5439
};
5540

56-
// generates a Polytope from a poset
57-
/// @tparam Polytope Type of returned polytope
58-
template <class Polytope>
59-
Polytope get_orderpoly(Poset const &poset) {
60-
typedef typename Polytope::PointType Point;
61-
62-
OrderPolytope<Point> OP(poset);
63-
if constexpr (std::is_same< Polytope, OrderPolytope<Point> >::value ) {
64-
return OP;
65-
} else if constexpr (std::is_same<Polytope, HPolytope<Point> >::value ){
66-
Polytope HP(OP.dimension(), OP.get_full_mat(), OP.get_vec());
67-
return HP;
68-
} else {
69-
throw "Unable to generate an Order Polytope of requested type";
70-
}
71-
}
72-
7341
// generates an Order Polytope from an instance name
7442
// Instances taken from: https://github.com/ttalvitie/le-counting-practice
7543
/// @tparam Polytope Type of returned polytope
7644
template <class Polytope>
7745
Polytope generate_orderpoly(std::string& instance_name) {
7846
std::stringstream in_ss(instances.at(instance_name));
7947
Poset poset = read_poset_from_file_adj_matrix(in_ss).second;
80-
return get_orderpoly<Polytope>(poset);
48+
return Polytope(poset);
8149
}
8250

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

8957
RV order_relations;
9058
Poset poset(dim, order_relations);
91-
return get_orderpoly<Polytope>(poset);
92-
}
93-
94-
// Generates a random Order Polytope with given dimension and number of facets
95-
/// @tparam Polytope Type of returned polytope
96-
/// @tparam RNGType RNGType Type
97-
template <class Polytope, typename NT>
98-
Polytope random_orderpoly(unsigned int dim, unsigned int m, int seed = std::numeric_limits<int>::signaling_NaN()) {
99-
100-
typedef typename Poset::RV RV;
101-
102-
int rng_seed = std::chrono::system_clock::now().time_since_epoch().count();
103-
if (!isnan(seed)) {
104-
rng_seed = seed;
105-
}
106-
107-
typedef BoostRandomNumberGenerator<boost::mt19937, NT> RNG;
108-
RNG rng(dim);
109-
rng.set_seed(rng_seed);
110-
111-
112-
std::vector<unsigned int> order(dim);
113-
for(int i = 0; i < dim; ++i) {
114-
order[i] = i;
115-
}
116-
boost::mt19937 shuffle_rng(rng_seed);
117-
std::shuffle(order.begin(), order.end(), shuffle_rng);
118-
119-
120-
RV order_relations;
121-
for(int i = 0; i < m - 2 * dim; ++i) {
122-
unsigned int x = rng.sample_uidist();
123-
unsigned int y = rng.sample_uidist();
124-
while(x == y) {
125-
y = rng.sample_uidist();
126-
}
127-
if(x > y)
128-
std::swap(x, y);
129-
order_relations.push_back(std::make_pair(order[x], order[y]));
130-
}
131-
132-
133-
Poset poset(dim, order_relations);
134-
return get_orderpoly<Polytope>(poset);
59+
Polytope OP(poset);
60+
return OP;
13561
}
13662

13763
#endif

include/misc/poset.h

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,6 @@ class Poset {
2525
unsigned int n; // elements will be from 0 to n-1
2626
RV order_relations; // pairs of form a <= b
2727

28-
static void sorted_list(const unsigned int &n, const RV &relations, std::vector<unsigned int> &res)
29-
{
30-
std::vector<std::vector<unsigned int> > adjList(n);
31-
std::vector<unsigned int> indegree(n, 0);
32-
33-
for(auto x: relations) {
34-
adjList[x.first].push_back(x.second);
35-
indegree[x.second] += 1;
36-
}
37-
38-
std::queue<unsigned int> q;
39-
for(unsigned int i=0; i<n; ++i) {
40-
if(indegree[i] == 0)
41-
q.push(i);
42-
}
43-
44-
while(!q.empty()) {
45-
unsigned int curr = q.front();
46-
res.push_back(curr);
47-
q.pop();
48-
49-
for(unsigned int i=0; i<adjList[curr].size(); ++i) {
50-
unsigned int adj_idx = adjList[curr][i];
51-
indegree[adj_idx] -= 1;
52-
if(indegree[adj_idx] == 0)
53-
q.push(adj_idx);
54-
}
55-
}
56-
}
57-
5828
public:
5929
Poset() {}
6030

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

77-
std::vector<unsigned int> order;
78-
sorted_list(n, relations, order);
79-
80-
if(order.size() < n) { // TODO: accept cycles in the poset
81-
throw "corresponding DAG is not acyclic";
82-
}
47+
// TODO: Check if corresponding DAG is actually acyclic
8348

8449
return relations;
8550
}
@@ -131,8 +96,34 @@ class Poset {
13196

13297
std::vector<unsigned int> topologically_sorted_list() const
13398
{
99+
std::vector<std::vector<unsigned int> > adjList(n);
100+
std::vector<unsigned int> indegree(n, 0);
101+
102+
for(auto x: order_relations) {
103+
adjList[x.first].push_back(x.second);
104+
indegree[x.second] += 1;
105+
}
106+
107+
std::queue<unsigned int> q;
108+
for(unsigned int i=0; i<n; ++i) {
109+
if(indegree[i] == 0)
110+
q.push(i);
111+
}
112+
134113
std::vector<unsigned int> res;
135-
sorted_list(n, order_relations, res);
114+
while(!q.empty()) {
115+
unsigned int curr = q.front();
116+
res.push_back(curr);
117+
q.pop();
118+
119+
for(unsigned int i=0; i<adjList[curr].size(); ++i) {
120+
unsigned int adj_idx = adjList[curr][i];
121+
indegree[adj_idx] -= 1;
122+
if(indegree[adj_idx] == 0)
123+
q.push(adj_idx);
124+
}
125+
}
126+
136127
return res;
137128
}
138129
};

test/order_polytope.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
#include "cartesian_geom/cartesian_kernel.h"
2222
#include "cartesian_geom/point.h"
2323
#include "convex_bodies/orderpolytope.h"
24-
#include "convex_bodies/hpolytope.h"
25-
26-
#include "generators/order_polytope_generator.h"
27-
2824
#include "misc/poset.h"
2925
#include "misc/misc.h"
3026

@@ -154,16 +150,6 @@ void call_test_basics() {
154150
CHECK(OP.is_in(Point(4, {0.5, 0.5, 0.0, 1.0})) == 0); // a0 <= a2 violated
155151
CHECK(OP.is_in(Point(4, {-0.1, 0.5, 1.0, 1.0})) == 0); // a0 >= 0 violated
156152
CHECK(OP.is_in(Point(4, {1.0, 0.5, 1.0, 1.1})) == 0); // a3 <= 1 violated
157-
158-
// Create a random Order Polytope of dimension 10 with 30 facets as an Hpolytope class
159-
HPolytope<Point> HP = random_orderpoly<HPolytope<Point>, NT>(10, 30);
160-
161-
d = HP.dimension();
162-
m = HP.num_of_hyperplanes();
163-
164-
CHECK(d == 10);
165-
CHECK(m == 30);
166-
167153
}
168154

169155

0 commit comments

Comments
 (0)