Changeset 62de8de in git
- Timestamp:
- Oct 25, 2013, 6:24:30 PM (11 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
- Children:
- 32d8cb4d146c3b9e5d73001109ccb7837d4aae69
- Parents:
- 69b2c1754cbeecd7c1b844e71e2101e1b3794062
- git-author:
- Yue Ren <ren@mathematik.uni-kl.de>2013-10-25 18:24:30+02:00
- git-committer:
- Yue Ren <ren@mathematik.uni-kl.de>2013-10-25 18:25:28+02:00
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
dyn_modules/callpolymake/polymake_conversion.cc
r69b2c1 r62de8de 7 7 #include <polymake/Set.h> 8 8 #include <polymake/common/lattice_tools.h> 9 // #include <polymake/perl/macros.h> 10 // #include <polymake/IncidenceMatrix.h> 9 #include <polymake/IncidenceMatrix.h> 11 10 12 11 #include <gfanlib/gfanlib.h> … … 14 13 15 14 #include <kernel/mod2.h> 16 // #include <kernel/structs.h>17 // #include <kernel/febase.h>18 15 #include <libpolys/misc/intvec.h> 19 20 // #include <callgfanlib/bbcone.h> 21 // #include <callgfanlib/bbfan.h> 22 // #include <callgfanlib/bbpolytope.h> 23 24 // #include <Singular/blackbox.h> 25 // #include <Singular/ipshell.h> 26 // #include <Singular/subexpr.h> 27 // #include <Singular/tok.h> 28 16 #include <libpolys/coeffs/numbers.h> 17 #include <libpolys/coeffs/bigintmat.h> 18 #include <Singular/lists.h> 19 #include <Singular/ipid.h> // for bigints, 20 // is there really nothing better than this? 29 21 30 22 /* Functions for converting Integers, Rationals and their Matrices … … 136 128 } 137 129 130 number PmInteger2Number (const polymake::Integer& pi) 131 { 132 mpz_class cache(pi.get_rep()); 133 long m = 268435456; 134 if(mpz_cmp_si(cache.get_mpz_t(),m)) 135 { 136 int temp = (int) mpz_get_si(cache.get_mpz_t()); 137 return n_Init(temp,coeffs_BIGINT); 138 } 139 else 140 return n_InitMPZ(cache.get_mpz_t(),coeffs_BIGINT); 141 } 142 138 143 intvec* PmVectorInteger2Intvec (const polymake::Vector<polymake::Integer>* vi, bool &ok) 139 144 { … … 161 166 } 162 167 163 // intvec* PmIncidenceMatrix2Intvec (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat) 164 // { 165 // int rows = icmat->rows(); 166 // int cols = icmat->cols(); 167 // intvec* iv = new intvec(rows,cols,0); 168 // for (int r = 1; r <= rows; r++) 169 // for (int c = 1; c <= cols; c++) 170 // IMATELEM(*iv,r,c) = (int) (*icmat).row(r).exists(c); 171 // return iv; 172 // } 168 bigintmat* PmMatrixInteger2Bigintmat (polymake::Matrix<polymake::Integer>* mi) 169 { 170 int rows = mi->rows(); 171 int cols = mi->cols(); 172 bigintmat* bim= new bigintmat(rows,cols,coeffs_BIGINT); 173 const polymake::Integer* pi = concat_rows(*mi).begin(); 174 for (int r = 1; r <= rows; r++) 175 for (int c = 1; c <= cols; c++) 176 { 177 number temp = PmInteger2Number(*pi); 178 bim->set(r,c,temp); 179 n_Delete(&temp,coeffs_BIGINT); 180 pi++; 181 } 182 return bim; 183 } 184 185 lists PmIncidenceMatrix2ListOfIntvecs (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat) 186 { 187 int rows = icmat->rows(); 188 int cols = icmat->cols(); 189 lists L = (lists)omAllocBin(slists_bin); 190 L->Init(rows); 191 192 for (int r = 0; r < rows; r++) 193 { 194 intvec* iv = new intvec(cols); int i=0; 195 for (int c = 0; c < cols; c++) 196 { 197 if ((*icmat).row(r).exists(c)) 198 { (*iv)[i]=c; i++; } 199 } 200 iv->resize(i); 201 L->m[r].rtyp = INTVEC_CMD; 202 L->m[r].data = (void*) iv; 203 } 204 205 return L; 206 } 207 208 lists PmAdjacencyMatrix2ListOfEdges (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat) 209 { 210 int rows = icmat->rows(); 211 int cols = icmat->cols(); 212 213 // counting number of edges 214 int i=0; int r, c; 215 for (r=0; r<rows; r++) 216 { 217 for (c=0; c<cols; c++) 218 { 219 if ((*icmat).row(r).exists(c) && r<c) 220 i++; 221 } 222 } 223 224 lists L = (lists)omAllocBin(slists_bin); 225 L->Init(i); 226 227 i=0; 228 for (r=0; r<rows; r++) 229 { 230 for (c=0; c<cols; c++) 231 { 232 if ((*icmat).row(r).exists(c) && r<c) 233 { 234 intvec* iv = new intvec(2); 235 (*iv)[0]=r; (*iv)[1]=c; 236 L->m[i].rtyp = INTVEC_CMD; 237 L->m[i].data = (void*) iv; 238 i++; 239 } 240 } 241 } 242 243 return L; 244 } 173 245 174 246 intvec* PmSetInteger2Intvec (polymake::Set<polymake::Integer>* si, bool &b) -
dyn_modules/callpolymake/polymake_conversion.h
r69b2c1 r62de8de 12 12 #include <polymake/Set.h> 13 13 #include <polymake/common/lattice_tools.h> 14 #include <polymake/IncidenceMatrix.h> 14 15 15 16 #include <gfanlib/gfanlib.h> 16 17 #include <gfanlib/gfanlib_q.h> 17 18 19 #include <libpolys/coeffs/numbers.h> 20 #include <libpolys/coeffs/bigintmat.h> 18 21 #include <libpolys/misc/intvec.h> 22 #include <Singular/lists.h> 19 23 20 24 /* Functions for converting Integers, Rationals and their Matrices … … 41 45 intvec* PmVectorInteger2Intvec (const polymake::Vector<polymake::Integer>* vi, bool &ok); 42 46 intvec* PmMatrixInteger2Intvec (polymake::Matrix<polymake::Integer>* mi, bool &ok); 43 // intvec* PmIncidenceMatrix2Intvec (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat); 47 lists PmIncidenceMatrix2ListOfIntvecs (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat); 48 lists PmAdjacencyMatrix2ListOfEdges (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat); 44 49 intvec* PmSetInteger2Intvec (polymake::Set<polymake::Integer>* si, bool &b); 50 number PmInteger2Number (const polymake::Integer& pi); 51 bigintmat* PmMatrixInteger2Bigintmat (polymake::Matrix<polymake::Integer>* mi); 45 52 46 53 /* polymake <- singular */ -
dyn_modules/callpolymake/polymake_documentation.cc
r69b2c1 r62de8de 1 #include <polymake_conversion.h>2 3 #include <dyn_modules/callgfanlib/bbcone.h>4 #include <dyn_modules/callgfanlib/bbfan.h>5 #include <dyn_modules/callgfanlib/bbpolytope.h>6 7 #include <Singular/blackbox.h>8 #include <Singular/ipshell.h>9 #include <Singular/subexpr.h>10 1 #include <Singular/ipid.h> 11 2 … … 204 195 module_help_proc("polymake.so","normalFan", normalFan_help); 205 196 197 const char* vertexAdjacencyGraph_help = 198 "USAGE: vertexAdjacencyGraph(polytope p)\nRETURN: list,\nKEYWORDS: polytopes; polymake;\nEXAMPLE: example visual shows an example\n"; 199 200 module_help_proc("polymake.so","vertexAdjacencyGraph", normalFan_help); 201 202 const char* vertexEdgeGraph_help = 203 "USAGE: vertexEdgeGraph(polytope p)\nRETURN: list,\nKEYWORDS: polytopes; polymake;\nEXAMPLE: example visual shows an example\n"; 204 205 module_help_proc("polymake.so","vertexEdgeGraph", normalFan_help); 206 206 207 } -
dyn_modules/callpolymake/polymake_wrapper.cc
r69b2c1 r62de8de 1 1 #include <polymake_conversion.h> 2 2 #include <polymake_documentation.h> 3 #include <polymake/Graph.h> 3 4 4 5 #include <dyn_modules/callgfanlib/bbcone.h> … … 1680 1681 } 1681 1682 1683 1684 BOOLEAN PMvertexAdjacencyGraph(leftv res, leftv args) 1685 { 1686 leftv u = args; 1687 if ((u != NULL) && (u->Typ() == polytopeID)) 1688 { 1689 gfan::ZCone* zp = (gfan::ZCone*) u->Data(); 1690 lists output=(lists)omAllocBin(slists_bin); output->Init(2); 1691 try 1692 { 1693 polymake::perl::Object* p = ZPolytope2PmPolytope(zp); 1694 polymake::Matrix<polymake::Integer> vert0 = p->give("VERTICES"); 1695 bigintmat* vert1 = PmMatrixInteger2Bigintmat(&vert0); 1696 output->m[0].rtyp = BIGINTMAT_CMD; 1697 output->m[0].data = (void*) vert1; 1698 1699 polymake::Graph<> gr=p->give("GRAPH.ADJACENCY"); 1700 polymake::IncidenceMatrix<polymake::NonSymmetric> adj = adjacency_matrix(gr); 1701 lists listOfEdges = PmIncidenceMatrix2ListOfIntvecs(&adj); 1702 output->m[1].rtyp = LIST_CMD; 1703 output->m[1].data = (void*) listOfEdges; 1704 delete p; 1705 } 1706 catch (const std::exception& ex) 1707 { 1708 WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); 1709 return TRUE; 1710 } 1711 res->rtyp = LIST_CMD; 1712 res->data = (void*) output; 1713 return FALSE; 1714 } 1715 WerrorS("vertexEdgeGraph: unexpected parameters"); 1716 return TRUE; 1717 } 1718 1719 1720 BOOLEAN PMvertexEdgeGraph(leftv res, leftv args) 1721 { 1722 leftv u = args; 1723 if ((u != NULL) && (u->Typ() == polytopeID)) 1724 { 1725 gfan::ZCone* zp = (gfan::ZCone*) u->Data(); 1726 lists output=(lists)omAllocBin(slists_bin); output->Init(2); 1727 try 1728 { 1729 polymake::perl::Object* p = ZPolytope2PmPolytope(zp); 1730 polymake::Matrix<polymake::Integer> vert0 = p->give("VERTICES"); 1731 bigintmat* vert1 = PmMatrixInteger2Bigintmat(&vert0); 1732 output->m[0].rtyp = BIGINTMAT_CMD; 1733 output->m[0].data = (void*) vert1; 1734 1735 polymake::Graph<> gr=p->give("GRAPH.ADJACENCY"); 1736 polymake::IncidenceMatrix<polymake::NonSymmetric> adj = adjacency_matrix(gr); 1737 lists listOfEdges = PmAdjacencyMatrix2ListOfEdges(&adj); 1738 output->m[1].rtyp = LIST_CMD; 1739 output->m[1].data = (void*) listOfEdges; 1740 delete p; 1741 } 1742 catch (const std::exception& ex) 1743 { 1744 WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); 1745 return TRUE; 1746 } 1747 res->rtyp = LIST_CMD; 1748 res->data = (void*) output; 1749 return FALSE; 1750 } 1751 WerrorS("vertexEdgeGraph: unexpected parameters"); 1752 return TRUE; 1753 } 1754 1755 1682 1756 extern "C" int mod_init(SModulFunctions* p) 1683 1757 { … … 1685 1759 {init_polymake = new polymake::Main();} 1686 1760 init_polymake->set_application("fan"); 1687 // iiAddCproc("","cube",FALSE,cube); 1688 // iiAddCproc("","cross",FALSE,cross); 1689 //p->iiAddCproc("polymake.so","coneViaPoints",FALSE,PMconeViaRays); 1690 p->iiAddCproc("polymake.so","polytopeViaVertices",FALSE,PMpolytopeViaVertices); 1761 // p->iiAddCproc("polymake.so","coneViaPoints",FALSE,PMconeViaRays); 1762 // p->iiAddCproc("polymake.so","polytopeViaPoints",FALSE,PMpolytopeViaVertices); 1691 1763 p->iiAddCproc("polymake.so","isLatticePolytope",FALSE,PMisLatticePolytope); 1692 1764 p->iiAddCproc("polymake.so","isBounded",FALSE,PMisBounded); … … 1702 1774 p->iiAddCproc("polymake.so","latticeCodegree",FALSE,PMlatticeCodegree); 1703 1775 p->iiAddCproc("polymake.so","ehrhartPolynomialCoeff",FALSE,PMehrhartPolynomialCoeff); 1704 //p->iiAddCproc("polymake.so","fVector",FALSE,PMfVector);1776 p->iiAddCproc("polymake.so","fVector",FALSE,PMfVector); 1705 1777 p->iiAddCproc("polymake.so","hVector",FALSE,PMhVector); 1706 1778 p->iiAddCproc("polymake.so","hStarVector",FALSE,PMhStarVector); … … 1727 1799 p->iiAddCproc("polymake.so","visual",FALSE,visual); 1728 1800 p->iiAddCproc("polymake.so","normalFan",FALSE,normalFan); 1729 // iiAddCproc("","testingtypes",FALSE,testingtypes); 1730 // iiAddCproc("","testingintvec",FALSE,testingintvec); 1731 // iiAddCproc("","testingcones",FALSE,testingcones); 1732 // iiAddCproc("","testingpolytopes",FALSE,testingpolytopes); 1733 // iiAddCproc("","testingfans",FALSE,testingfans); 1734 // iiAddCproc("","testingvisuals",FALSE,testingvisuals); 1735 // iiAddCproc("","testingstrings",FALSE,testingstrings); 1736 // iiAddCproc("","testingmatrices",FALSE,testingmatrices); 1737 // iiAddCproc("","loadPolymakeDocumentation",FALSE,loadPolymakeDocumentation); 1801 p->iiAddCproc("polymake.so","vertexAdjacencyGraph",FALSE,PMvertexAdjacencyGraph); 1802 p->iiAddCproc("polymake.so","vertexEdgeGraph",FALSE,PMvertexEdgeGraph); 1738 1803 1739 1804 blackbox* b=getBlackboxStuff(polytopeID);
Note: See TracChangeset
for help on using the changeset viewer.