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 class #165

Merged
merged 24 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bfce0c7
Initial commit
vaithak Jun 10, 2021
bb4b290
Add functions for line intersection with rays
vaithak Jun 16, 2021
2011b8c
Add more member functions in order polytope class
vaithak Jun 19, 2021
b1c384a
Add copyright
vaithak Jun 22, 2021
866074d
fix some bugs in order polytope and poset class
vaithak Jun 26, 2021
2cdb765
Add example for order-polytope and poset class methods
vaithak Jun 26, 2021
38cc0dd
Modify gitignore
vaithak Jun 26, 2021
94f8833
fix minor bugs in order polytope and poset class
vaithak Jun 26, 2021
e336f70
Add test for basic methods of order polytope
vaithak Jun 26, 2021
4eab625
Add test for vec_mult and line_intersect methods of order polytope class
vaithak Jun 29, 2021
ce5ce47
minor modification in order-polytope example
vaithak Jun 29, 2021
7b76f51
add test for reflection and fix line_intersect test
vaithak Jun 29, 2021
ee5bfa3
improve README for order polytope example
vaithak Jun 29, 2021
e451ae3
minor fix in compute_reflection with params
vaithak Jun 30, 2021
78e5a40
add boundary oracles for order polytope
vaithak Jul 19, 2021
a4a33a5
minor bug fixes
vaithak Jul 19, 2021
1cf37c0
more bug fixes
vaithak Jul 20, 2021
4a102ba
bug fix in membership oracle of order_polytope
vaithak Jul 20, 2021
2257798
trim trailing whitespaces
vaithak Jul 26, 2021
d35b867
minor changes
vaithak Jul 26, 2021
3cb1756
formatting changes
vaithak Jul 26, 2021
b7d301a
add _ before row_norms member variable
vaithak Jul 26, 2021
ba51eda
remove runtime errors of dividing by 0
vaithak Jul 26, 2021
581ea6b
add todo comments for line_intersect functions which can be removed i…
vaithak Jul 27, 2021
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ test/Testing/Temporary/CTestCostData.txt
*.log
.Rproj.user
*.png
build/
.vscode
.DS_Store
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ else ()
#add_subdirectory(spectrahedra)
add_subdirectory(hpolytope-volume)
add_subdirectory(count-linear-extensions-using-hpolytope)
add_subdirectory(order-polytope-basics)

add_executable (vpolytopevolume vpolytope-volume/vpolytopevolume.cpp)
TARGET_LINK_LIBRARIES(vpolytopevolume ${LP_SOLVE})
Expand Down
4 changes: 4 additions & 0 deletions examples/order-polytope-basics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# VolEsti (volume computation and sampling library)

add_executable (order_polytope order_polytope.cpp)
TARGET_LINK_LIBRARIES(order_polytope ${LP_SOLVE})
18 changes: 18 additions & 0 deletions examples/order-polytope-basics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Compilation
In folder examples, first run cmake, to create the makefile:

```bash
cmake .
```

Then, in folder examples/order-polytope-basics compile and build using the makefile:

```bash
make
```

## Usage:
```bash
./order_polytope poset_data.txt
```
where `poset_data.txt` is the file containing the poset data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you comment on how this file represents a poset?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added instructions regarding the representation of poset data in the file.

101 changes: 101 additions & 0 deletions examples/order-polytope-basics/order_polytope.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include <iostream>
#include <fstream>
#include "misc.h"
#include "poset.h"
#include "cartesian_geom/cartesian_kernel.h"
#include "cartesian_geom/point.h"
#include "orderpolytope.h"

template <typename T>
std::vector<T> linspace(T a, T b, size_t N) {
T h = (b - a) / static_cast<T>(N-1);
std::vector<T> xs(N);
typename std::vector<T>::iterator x;
T val;
for (x = xs.begin(), val = a; x != xs.end(); ++x, val += h)
*x = val;
return xs;
}

typedef typename Poset::RT RT;
typedef typename Poset::RV RV;

Poset read_poset_from_file(std::string filename) {
std::ifstream data_file;
data_file.open(filename);

unsigned int n;
data_file >> n;

RT curr_relation;
RV relations;
while(data_file >> curr_relation.first >> curr_relation.second)
relations.push_back(curr_relation);

return Poset(n, relations);
}


int main(int argc, char const *argv[]) {
std::cout << "\nPoset operations: \n";
// ----------- basic poset operations -----------
Poset poset = read_poset_from_file(std::string(argv[1]));
poset.print();

std::cout << "Checking if a sample Point (linearly spaced coordinates) lies inside the poset: ";
std::vector<double> temp = linspace((double)(0.0), (double)(1.0), poset.num_elem());
std::cout << poset.is_in(temp) << std::endl;
std::cout << "\n";
// ----------------------------------------------


// -------------- order polytope operations --------
std::cout << "\nOrder polytope operations: \n";
typedef Cartesian<double> Kernel;
typedef typename Kernel::Point Point;
OrderPolytope<Point> OP(poset);
OP.print();
std::cout << "\n";


std::cout << "intersection of the order polytope with ray from (0.5, 0.5 .... 0.5) towards the origin" << std::endl;
Point origin(OP.dimension());
Point start_point(OP.dimension(), std::vector<double>(OP.dimension(), 0.5));
Point direction = origin - start_point;
std::pair<double, double> curr_res = OP.line_intersect(start_point, direction, true);
Point intersect_point = start_point + curr_res.first * direction;
intersect_point.print();
std::cout << "\n";


std::cout << "distances of all hyperplanes from origin: " << std::endl;
for (const auto val: OP.get_dists(0.0))
std::cout << val << ' ';
std::cout << "\n\n";


OP.normalize();
std::cout << "normalized order polytope: " << std::endl;
OP.print();
std::cout << "\n";


std::cout << "distances of all hyperplanes from origin (after normalization): " << std::endl;
for (const auto val: OP.get_dists(0.0))
std::cout << val << ' ';
std::cout << "\n\n";


std::cout << "compute reflection (requires normalization) of an incident ray with the facet number 2d (the first relation facet)" << std::endl;
Point ray = Point::all_ones(OP.dimension());
ray.set_coord(0, 1.5);
std::cout << "incident ray: ";
ray.print();

OP.compute_reflection(ray, Point(), 2*OP.dimension());
std::cout << "reflected ray: ";
ray.print();
// ---------------------------------------------

return 0;
}
4 changes: 4 additions & 0 deletions examples/order-polytope-basics/poset_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
4
0 1
0 2
1 3
Loading