Skip to content

Commit 88fcc9e

Browse files
committed
implement full dimensional polytope computational examples
1 parent dc02884 commit 88fcc9e

File tree

4 files changed

+576
-1
lines changed

4 files changed

+576
-1
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# VolEsti (volume computation and sampling library)
2+
3+
# Copyright (c) 2012-2025 Vissarion Fisikopoulos
4+
# Copyright (c) 2018-2025 Apostolos Chalkis
5+
6+
# Licensed under GNU LGPL.3, see LICENCE file
7+
8+
project( VolEsti )
9+
10+
CMAKE_MINIMUM_REQUIRED(VERSION 3.11)
11+
12+
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
13+
14+
# Locate Intel MKL root (in case it is enabled)
15+
if (APPLE)
16+
set(MKLROOT /opt/intel/oneapi/mkl/latest)
17+
elseif(UNIX)
18+
set(MKLROOT /opt/intel/oneapi/mkl/latest)
19+
endif()
20+
21+
if(COMMAND cmake_policy)
22+
cmake_policy(SET CMP0003 NEW)
23+
endif(COMMAND cmake_policy)
24+
25+
option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON)
26+
option(BUILTIN_EIGEN "Use eigen from ../../external" OFF)
27+
option(USE_MKL "Use MKL library to build eigen" OFF)
28+
29+
if(DISABLE_NLP_ORACLES)
30+
add_definitions(-DDISABLE_NLP_ORACLES)
31+
else()
32+
find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib)
33+
find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib)
34+
find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu)
35+
find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib)
36+
find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu)
37+
find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu)
38+
39+
if (NOT IFOPT)
40+
message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.")
41+
elseif (NOT GMP)
42+
message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.")
43+
elseif (NOT MPSOLVE)
44+
message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.")
45+
elseif (NOT FFTW3)
46+
message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.")
47+
else()
48+
message(STATUS "Library ifopt found: ${IFOPT}")
49+
message(STATUS "Library gmp found: ${GMP}")
50+
message(STATUS "Library mpsolve found: ${MPSOLVE}")
51+
message(STATUS "Library fftw3 found:" ${FFTW3})
52+
endif(NOT IFOPT)
53+
endif(DISABLE_NLP_ORACLES)
54+
55+
# Include CMake modules for dependencies
56+
include("../../external/cmake-files/Eigen.cmake")
57+
GetEigen()
58+
59+
include("../../external/cmake-files/Boost.cmake")
60+
GetBoost()
61+
62+
include("../../external/cmake-files/LPSolve.cmake")
63+
GetLPSolve()
64+
65+
include("../../external/cmake-files/SuiteSparse.cmake")
66+
GetSuiteSparse()
67+
68+
set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
69+
70+
if (USE_MKL)
71+
find_library(BLAS NAMES libblas.so libblas.dylib PATHS /usr/local/Cellar/lapack/3.9.1_1/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu /usr/local/Cellar/openblas/0.3.15_1/lib /usr/lib)
72+
find_library(GFORTRAN NAME libgfortran.dylib PATHS /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10)
73+
find_library(LAPACK NAME liblapack.dylib PATHS /usr/lib)
74+
find_library(OPENMP NAME libiomp5.dylib PATHS /opt/intel/oneapi/compiler/2021.1.1/mac/compiler/lib)
75+
76+
include_directories (BEFORE ${MKLROOT}/include)
77+
set(PROJECT_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES})
78+
set(MKL_LINK "-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl")
79+
add_definitions(-DEIGEN_USE_MKL_ALL)
80+
else()
81+
set(MKL_LINK "")
82+
endif(USE_MKL)
83+
84+
# Include directories
85+
include_directories (BEFORE ../../external)
86+
include_directories (BEFORE ../../external/minimum_ellipsoid)
87+
include_directories (BEFORE ../../include/)
88+
89+
# for Eigen
90+
if (${CMAKE_VERSION} VERSION_LESS "3.12.0")
91+
add_compile_options(-D "EIGEN_NO_DEBUG")
92+
else ()
93+
add_compile_definitions("EIGEN_NO_DEBUG")
94+
endif ()
95+
96+
# Compiler flags
97+
add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard
98+
add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization
99+
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm")
100+
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl")
101+
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR")
102+
103+
# Build the example executable
104+
add_executable(full_dimensional_example full_dimensional_example.cpp)
105+
106+
# Link libraries (including SuiteSparse for the full_dimensional_polytope function)
107+
target_link_libraries(full_dimensional_example
108+
lp_solve
109+
${SUITESPARSE_LIBRARIES}
110+
${MKL_LINK}
111+
)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Full Dimensional Polytope Examples
2+
3+
This directory contains examples demonstrating the `compute_full_dimensional_polytope` function from `include/preprocess/full_dimensional_polytope.hpp`.
4+
5+
## Overview
6+
7+
The `compute_full_dimensional_polytope` function transforms a potentially lower-dimensional polytope defined by:
8+
- **Equality constraints**: `Aeq * x = beq`
9+
- **Inequality constraints**: `A * x <= b`
10+
11+
Into a full-dimensional polytope: `A_full * y <= b_full`
12+
13+
The transformation provides:
14+
- **shift**: A point satisfying the equality constraints
15+
- **N**: Nullspace basis matrix with orthonormal columns
16+
- **Mapping**: `x = shift + N * y` (from reduced space to original space)
17+
18+
## Building the Example
19+
20+
From this directory:
21+
22+
```bash
23+
mkdir build
24+
cd build
25+
cmake ..
26+
make
27+
```
28+
29+
## Running the Example
30+
31+
```bash
32+
./full_dimensional_example
33+
```
34+
35+
The program will run through 6 examples, pausing between each for you to review the output.
36+
37+
## Output Format
38+
39+
For each example, the program displays:
40+
41+
1. **Description**: What the example demonstrates
42+
2. **Input**: The equality and inequality constraints
43+
3. **Results**:
44+
- Original and reduced dimensions
45+
- Shift vector
46+
- Nullspace basis N
47+
- Output polytope dimensions
48+
- Orthonormality verification
49+
50+
## Key Features Demonstrated
51+
52+
- ✅ Automatic dimension reduction
53+
- ✅ Orthonormal nullspace basis
54+
- ✅ Handling of sparse constraints
55+
- ✅ Multiple equality constraints
56+
- ✅ Extreme reductions (nD → 1D)
57+
- ✅ Real-world polytopes (Birkhoff)
58+
59+
## Mathematical Background
60+
61+
Given a polytope `P = {x : Aeq*x = beq, A*x <= b}` which is lower-dimensional (rank(Aeq) > 0), the function computes:
62+
63+
1. **Shift vector**: Solves `Aeq * shift = beq` using SPQR
64+
2. **Nullspace basis**: Computes `N` such that `Aeq * N = 0` via QR factorization
65+
3. **Transformed polytope**: `P' = {y : A*N*y <= b - A*shift}`
66+
67+
Any point `y` in `P'` maps to a feasible point in `P` via: `x = shift + N*y`
68+
69+
## Dependencies
70+
71+
- Eigen3 (matrix operations)
72+
- SuiteSparse (SPQR for QR factorization, CHOLMOD for linear systems)
73+
- Boost (for polytope generators)
74+
- lp_solve (for polytope operations)
75+
76+
## See Also
77+
78+
- **Header file**: `include/preprocess/full_dimensional_polytope.hpp`
79+
- **Tests**: `test/full_dimensional_polytope_test.cpp`

0 commit comments

Comments
 (0)