politopix  5.0.0
politopy.h
Go to the documentation of this file.
1 // politopix allows to make computations on polytopes such as finding vertices, intersecting, Minkowski sums, ...
2 // Copyright (C) 2021 : Delos Vincent
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
19 // I2M (UMR CNRS 5295 / University of Bordeaux)
20 
21 #include <boost/python.hpp>
22 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
23 
24 using namespace boost::python;
25 
26 
27 // For boost python
28 static polito_EXPORT int computeMinkowskiSumOfPolytopesPy(const boost::python::list& listOfPol, boost::shared_ptr<Polytope_Rn>& C) {
29  std::vector< boost::shared_ptr<Polytope_Rn> > arrayOfPol;
30  for (unsigned int i=0; i<boost::python::len(listOfPol); ++i)
31  arrayOfPol.push_back(boost::python::extract< boost::shared_ptr<Polytope_Rn> >(listOfPol[i]));
33 }
34 
35 int (*computeMinkowskiSumOfPolytopes1)(const boost::shared_ptr<Polytope_Rn>&, const boost::shared_ptr<Polytope_Rn>&, boost::shared_ptr<Polytope_Rn>&) = &politopixAPI::computeMinkowskiSumOfPolytopes;
36 int (*computeMinkowskiSumOfPolytopes2)(const std::vector< boost::shared_ptr<Polytope_Rn> >&, boost::shared_ptr<Polytope_Rn>&) = &politopixAPI::computeMinkowskiSumOfPolytopes;
37 int (*computeMinkowskiSumOfPolytopes3)(const boost::python::list&, boost::shared_ptr<Polytope_Rn>&) = &computeMinkowskiSumOfPolytopesPy;
38 int (*computeIntersection)(const boost::shared_ptr<Polytope_Rn>&, const boost::shared_ptr<Polytope_Rn>&, boost::shared_ptr<Polytope_Rn>&) = &politopixAPI::computeIntersection;
39 int (*computeDoubleDescription2)(boost::shared_ptr<Polytope_Rn>&, double bb_size) = &politopixAPI::computeDoubleDescription;
40 int (*computeDoubleDescription1)(boost::shared_ptr<Polytope_Rn>&) = &politopixAPI::computeDoubleDescription;
41 
42 
43 BOOST_PYTHON_MODULE(libpolito) {
44  Py_Initialize();
45 
46  class_<Generator_Rn, boost::shared_ptr<Generator_Rn> >("generator", init<>())
47  .def("print", &Generator_Rn::print)
48  .def("setCoord", &Generator_Rn::setCoordinate)
49  .def("getCoord", &Generator_Rn::getCoordinate)
50  ;
51 
52  class_<HalfSpace_Rn, boost::shared_ptr<HalfSpace_Rn> >("halfspace", init<>())
53  .def("print", &HalfSpace_Rn::print)
54  .def("setCoef", &HalfSpace_Rn::setCoefficient)
55  .def("getCoef", &HalfSpace_Rn::getCoefficient)
56  .def("setConstant", &HalfSpace_Rn::setConstant)
57  .def("getConstant", &HalfSpace_Rn::getConstant)
58  ;
59 
60  class_<PolyhedralCone_Rn, boost::shared_ptr<PolyhedralCone_Rn> >("polyhedralcone", init<>())
61  .def("getGen", &PolyhedralCone_Rn::getGenerator, return_value_policy<copy_const_reference>())
63  .def("getHS", &PolyhedralCone_Rn::getHalfSpace, return_value_policy<copy_const_reference>())
65  ;
66 
67  class_<Polytope_Rn, boost::shared_ptr<Polytope_Rn>, bases<PolyhedralCone_Rn> >("polytope", init<>())
68  .def("create", &Polytope_Rn::create).staticmethod("create")
69  ;
70 
71  class_<politopixAPI>("politopix")
72  .def("loadPolytope", &politopixAPI::loadPolytope).staticmethod("loadPolytope")
73  .def("savePolytope", &politopixAPI::savePolytope).staticmethod("savePolytope")
74  .def("volume", &politopixAPI::computeVolume).staticmethod("volume")
75  .def("check", &politopixAPI::checkTopologyAndGeometry).staticmethod("check")
76  .def("cube", &politopixAPI::makeCube).staticmethod("cube")
79  .def("sum", computeMinkowskiSumOfPolytopes3).staticmethod("sum")
80  .def("doubledesc", computeDoubleDescription1)
81  .def("doubledesc", computeDoubleDescription2).staticmethod("doubledesc")
82  .def("intersect", computeIntersection).staticmethod("intersect")
83  ;
84 
85  class_<Rn>("Rn")
86  .def("getDim", &Rn::getDimension).staticmethod("getDim")
87  .def("setDim", &Rn::setDimension).staticmethod("setDim")
88  .def("getTol", &Rn::getTolerance).staticmethod("getTol")
89  .def("setTol", &Rn::setTolerance).staticmethod("setTol")
90  ;
91 
92 }
politopixAPI::savePolytope
static polito_EXPORT int savePolytope(const string &pathA, boost::shared_ptr< Polytope_Rn > &A)
Save a polytope in the corresponding file name.
Definition: politopixAPI.cpp:29
HalfSpace_Rn::getCoefficient
double getCoefficient(unsigned int i) const
Definition: HalfSpace_Rn.cpp:33
computeDoubleDescription1
int(* computeDoubleDescription1)(boost::shared_ptr< Polytope_Rn > &)
Definition: politopy.h:40
PolyhedralCone_Rn::getHalfSpace
const boost::shared_ptr< HalfSpace_Rn > & getHalfSpace(unsigned int i) const
Return the i-th half-space.
Definition: PolyhedralCone_Rn.cpp:160
Generator_Rn::setCoordinate
void setCoordinate(unsigned int i, double val)
Definition: Generator_Rn.h:60
Generator_Rn::print
void print() const
Definition: Generator_Rn.h:244
Polytope_Rn::create
static boost::shared_ptr< Polytope_Rn > create()
Return s shared pointer on an empty polytope.
Definition: Polytope_Rn.h:46
PolyhedralCone_Rn::getGenerator
const boost::shared_ptr< Generator_Rn > & getGenerator(unsigned int i) const
Return the i-th generator.
Definition: PolyhedralCone_Rn.cpp:191
politopixAPI::computeMinkowskiSumOfPolytopes
static polito_EXPORT int computeMinkowskiSumOfPolytopes(const boost::shared_ptr< Polytope_Rn > &A, const boost::shared_ptr< Polytope_Rn > &B, boost::shared_ptr< Polytope_Rn > &C)
Compute the Minkowski sum between two HV-polytopes.
Definition: politopixAPI.cpp:350
computeMinkowskiSumOfPolytopes3
int(* computeMinkowskiSumOfPolytopes3)(const boost::python::list &, boost::shared_ptr< Polytope_Rn > &)
Definition: politopy.h:37
polito_EXPORT
#define polito_EXPORT
Definition: polito_Export.h:15
computeMinkowskiSumOfPolytopes1
int(* computeMinkowskiSumOfPolytopes1)(const boost::shared_ptr< Polytope_Rn > &, const boost::shared_ptr< Polytope_Rn > &, boost::shared_ptr< Polytope_Rn > &)
Definition: politopy.h:35
BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(libpolito)
Definition: politopy.h:43
PolyhedralCone_Rn::numberOfHalfSpaces
unsigned int numberOfHalfSpaces() const
Get the total number of half-spaces.
Definition: PolyhedralCone_Rn.h:95
HalfSpace_Rn::setConstant
void setConstant(double c)
Definition: HalfSpace_Rn.h:65
HalfSpace_Rn::setCoefficient
void setCoefficient(unsigned int i, double c)
Definition: HalfSpace_Rn.cpp:44
Rn::getDimension
static polito_EXPORT unsigned int getDimension()
Return the dimension of the cartesian space we work in.
Definition: Rn.cpp:29
politopixAPI::computeIntersection
static polito_EXPORT int computeIntersection(const boost::shared_ptr< Polytope_Rn > &A, const boost::shared_ptr< Polytope_Rn > &B, boost::shared_ptr< Polytope_Rn > &C)
Compute the intersection between two HV-polytopes with the Double Description algorithm.
Definition: politopixAPI.cpp:195
HalfSpace_Rn::print
void print() const
Definition: HalfSpace_Rn.h:118
politopixAPI::computeVolume
static polito_EXPORT double computeVolume(const boost::shared_ptr< Polytope_Rn > P)
Return the volume of the given polytope P with its double description. The implemented algorithm can ...
Definition: politopixAPI.cpp:537
computeMinkowskiSumOfPolytopes2
int(* computeMinkowskiSumOfPolytopes2)(const std::vector< boost::shared_ptr< Polytope_Rn > > &, boost::shared_ptr< Polytope_Rn > &)
Definition: politopy.h:36
politopixAPI::computeDoubleDescription
static polito_EXPORT int computeDoubleDescription(boost::shared_ptr< Polytope_Rn > &A, double bb_size)
Compute the HV-description for a given H-polytope or V-polytope with the Double Description algorithm...
Definition: politopixAPI.cpp:136
politopixAPI::checkTopologyAndGeometry
static polito_EXPORT int checkTopologyAndGeometry(const boost::shared_ptr< PolyhedralCone_Rn > &A, bool check_all=false)
Check whether a HV-polytopes is correct.
Definition: politopixAPI.cpp:564
PolyhedralCone_Rn::numberOfGenerators
unsigned int numberOfGenerators() const
Give the total number of generators.
Definition: PolyhedralCone_Rn.h:143
politopixAPI::makeCube
static polito_EXPORT int makeCube(boost::shared_ptr< Polytope_Rn > &A, double M)
Create a cube whose vertices will be (+-M, ..., +-M)
Definition: politopixAPI.cpp:568
politopixAPI::loadPolytope
static polito_EXPORT int loadPolytope(const string &pathA, boost::shared_ptr< Polytope_Rn > &A)
Load a polytope from the corresponding file name.
Definition: politopixAPI.cpp:40
Generator_Rn::getCoordinate
double getCoordinate(unsigned int i) const
Definition: Generator_Rn.h:62
Rn::setTolerance
static polito_EXPORT void setTolerance(double t)
Give the minimum distance between two points.
Definition: Rn.cpp:33
computeDoubleDescription2
int(* computeDoubleDescription2)(boost::shared_ptr< Polytope_Rn > &, double bb_size)
Definition: politopy.h:39
HalfSpace_Rn::getConstant
double getConstant() const
Definition: HalfSpace_Rn.h:67
Rn::setDimension
static polito_EXPORT void setDimension(unsigned int dim)
Set the dimension for the cartesian space we work in.
Definition: Rn.cpp:27
computeIntersection
int(* computeIntersection)(const boost::shared_ptr< Polytope_Rn > &, const boost::shared_ptr< Polytope_Rn > &, boost::shared_ptr< Polytope_Rn > &)
Definition: politopy.h:38
Rn::getTolerance
static polito_EXPORT double getTolerance()
Give the minimum distance between two points.
Definition: Rn.cpp:31