1 /*
2  *
3  *
4  *  Created on: June 15, 2010
5  *
6  *
7  *  Base class for making polytopes.
8  *
9  *  h-reps: will scale the coeff. to integers
10  *  v-reps: no scaling is performed.
11  *
12  *  h-reps dual: scales the vertices to integers.
13  *  v-reps dual: scales the facets to integers (be finding the lcm of every denominator)
14  */
15 
16 #ifndef BUILD_POLYTOPE_H_
17 #define BUILD_POLYTOPE_H_
18 
19 #include <iomanip>
20 #include <string>
21 #include <fstream>
22 #include <ctime>
23 #include <vector>
24 #include <sstream>
25 #include <cstdlib>
26 #include "gmp.h"
27 #include <gmpxx.h>
28 
29 
30 
31 using namespace std;
32 
33 class BuildPolytope
34 {
35 protected:
36     int ambientDim; 		//dim of space the poly lives in.
37     int dim;				//dim of the polytope found by polymake
38     bool integerPoints;		//if true, makes random integer points; if false, makes random rational points.
39 
40     string fileBaseName; 		//base file name for polymake and latte.
41     							//fileBaseName.polymake
42     							//fileBaseName.vrep.latte
43     							//fileBaseName.hrep.latte
44     bool createdPolymakeFile;	//ture if these files have been created with this object.
45     bool createdPolymakeDualFile;
46     bool createdLatteVRepFile;
47     bool createdLatteHRepFile;
48 
49     bool createdLatteHRepDualFile; //save as above, only for a dual polytope
50     bool createdLatteVRepDualFile;
51 
52 
53     vector< vector<mpq_class> > facets; //facets of the polytope found by polymake
54     vector< vector<mpq_class> > dualVertices;//assumes points DO have a leading "1"..so the length is (dim+1)
55     vector< vector<mpq_class> > dualFacets;//could be different from the vertices if the org. polytope is not centered.
56     int numAffineHull;		//number of affine hull facets found by polymake (saved at the end of the facets vector)
57 
58     string getDualFileBaseName() const;
59 private:
60     vector< vector<mpq_class> > points; //each point lives in ambientDim space. Assumes the points DO have a leading 1.
61 public:
62     BuildPolytope();
63 
64 	//A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
65 
66     void addPoint(vector<mpq_class> onePoint); //adds [1 onePoint] ot the point vector
67     void centerPolytope();
68     void clearPoints();
69 
70     //Delete the generated files.
71 	void deletePolymakeFile();
72 	void deletePolymakeDualFile();
73 	void deleteLatteVRepFile();
74 	void deleteLatteVRepDualFile();
75 	void deleteLatteHRepFile();
76 	void deleteLatteHRepDualFile();
77 
78 
79 	void buildPolymakeFile(); //builds the polymake file.
80 	void buildPolymakeDualFile(); //build the dual polymake file.
81 	void buildLatteHRepFile();//builds the h-rep file in latte style
82 	void buildLatteHRepDualFile(); //builds h-rep of the dual.
83 	void buildLatteVRepFile();//build the v-rep file in latte style.
84 	void buildLatteVRepDualFile(); //build the v-rep for the dual (dilated) polytope
85 
86 
87 	void findDimentions(); //finds the dim of the polytope form polymake.
88 	void findFacets();     //saves the facets in our vector.
89 	void findFacetsDual();//find the dual facets.
90 	void findAffineHull();//find the rests of the facets.
91 	void findVertices();   //saves the vertices in points (overrides the org. points vector).
92 	void findVerticesDual();//finds the facet equations.
93 
94 
95 	int getAmbientDim() const; //returns abmient dim.
96 	int getDim() const; //returns the dim. Assumes polymake has been called.
97 
98 	vector<vector<mpq_class> > getFacets() const;
99 	string getLatteVRepFile() const; //Return file names.
100 	string getLatteVRepDualFile() const;
101 	string getLatteHRepFile() const;
102 	string getLatteHRepDualFile() const;
103 	string getPolymakeFile() const;
104 	string getPolymakeDualFile() const;
105 
106 	vector<vector<mpq_class> > getVertices();
107 	int getVertexCount();
108 	int getVertexDualCount();
109 
110 	void homogenizeDualVertices(); //divides so the first slot is 1.
111 
112 	bool isCentered();
113 	bool isSimplicial();
114 	bool isSimple();
115 	bool isDualSimplicial();
116 	bool isDualSimple();
117 
118 	void makeIntegerRows(vector<vector<mpq_class> > &list);//mult. each equations by a (different) number to clear the denominators for latte.
119 	void makeIntegerList(vector<vector<mpq_class> > &list);//mult. each equations by a number to clear the denominators for latte.
120 	void setBaseFileName(const string & n); //sets the file name root.
121 	void setIntegerPoints(bool t); //should the polytope be interger?
122 	void setBuildPolymakeFile(bool t); //used for registering the existence of files.
123 	void setBuildLatteVRepDualFile(bool t); //used for registering the existence of files.
124 
125 	void forDebugging();
126 	void debugPrintList(const vector<vector<mpq_class> > &list);
127 };//BuildRandomPolytope
128 
129 
130 
131 #endif /* BUILD_POLYTOPE_H_ */
132 
133