-
Notifications
You must be signed in to change notification settings - Fork 121
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
Order polytope class #165
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bfce0c7
Initial commit
vaithak bb4b290
Add functions for line intersection with rays
vaithak 2011b8c
Add more member functions in order polytope class
vaithak b1c384a
Add copyright
vaithak 866074d
fix some bugs in order polytope and poset class
vaithak 2cdb765
Add example for order-polytope and poset class methods
vaithak 38cc0dd
Modify gitignore
vaithak 94f8833
fix minor bugs in order polytope and poset class
vaithak e336f70
Add test for basic methods of order polytope
vaithak 4eab625
Add test for vec_mult and line_intersect methods of order polytope class
vaithak ce5ce47
minor modification in order-polytope example
vaithak 7b76f51
add test for reflection and fix line_intersect test
vaithak ee5bfa3
improve README for order polytope example
vaithak e451ae3
minor fix in compute_reflection with params
vaithak 78e5a40
add boundary oracles for order polytope
vaithak a4a33a5
minor bug fixes
vaithak 1cf37c0
more bug fixes
vaithak 4a102ba
bug fix in membership oracle of order_polytope
vaithak 2257798
trim trailing whitespaces
vaithak d35b867
minor changes
vaithak 3cb1756
formatting changes
vaithak b7d301a
add _ before row_norms member variable
vaithak ba51eda
remove runtime errors of dividing by 0
vaithak 581ea6b
add todo comments for line_intersect functions which can be removed i…
vaithak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ test/Testing/Temporary/CTestCostData.txt | |
*.log | ||
.Rproj.user | ||
*.png | ||
build/ | ||
.vscode | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
4 | ||
0 1 | ||
0 2 | ||
1 3 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.