Changeset 62de8de in git


Ignore:
Timestamp:
Oct 25, 2013, 6:24:30 PM (11 years ago)
Author:
Yue Ren <ren@…>
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
Message:
chg: updated callpolymake to newest version
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • dyn_modules/callpolymake/polymake_conversion.cc

    r69b2c1 r62de8de  
    77#include <polymake/Set.h>
    88#include <polymake/common/lattice_tools.h>
    9 // #include <polymake/perl/macros.h>
    10 // #include <polymake/IncidenceMatrix.h>
     9#include <polymake/IncidenceMatrix.h>
    1110
    1211#include <gfanlib/gfanlib.h>
     
    1413
    1514#include <kernel/mod2.h>
    16 // #include <kernel/structs.h>
    17 // #include <kernel/febase.h>
    1815#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?
    2921
    3022/* Functions for converting Integers, Rationals and their Matrices
     
    136128}
    137129
     130number 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
    138143intvec* PmVectorInteger2Intvec (const polymake::Vector<polymake::Integer>* vi, bool &ok)
    139144{
     
    161166}
    162167
    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 // }
     168bigintmat* 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
     185lists 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
     208lists 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}
    173245
    174246intvec* PmSetInteger2Intvec (polymake::Set<polymake::Integer>* si, bool &b)
  • dyn_modules/callpolymake/polymake_conversion.h

    r69b2c1 r62de8de  
    1212#include <polymake/Set.h>
    1313#include <polymake/common/lattice_tools.h>
     14#include <polymake/IncidenceMatrix.h>
    1415
    1516#include <gfanlib/gfanlib.h>
    1617#include <gfanlib/gfanlib_q.h>
    1718
     19#include <libpolys/coeffs/numbers.h>
     20#include <libpolys/coeffs/bigintmat.h>
    1821#include <libpolys/misc/intvec.h>
     22#include <Singular/lists.h>
    1923
    2024/* Functions for converting Integers, Rationals and their Matrices
     
    4145intvec* PmVectorInteger2Intvec (const polymake::Vector<polymake::Integer>* vi, bool &ok);
    4246intvec* PmMatrixInteger2Intvec (polymake::Matrix<polymake::Integer>* mi, bool &ok);
    43 // intvec* PmIncidenceMatrix2Intvec (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat);
     47lists PmIncidenceMatrix2ListOfIntvecs (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat);
     48lists PmAdjacencyMatrix2ListOfEdges (polymake::IncidenceMatrix<polymake::NonSymmetric>* icmat);
    4449intvec* PmSetInteger2Intvec (polymake::Set<polymake::Integer>* si, bool &b);
     50number PmInteger2Number (const polymake::Integer& pi);
     51bigintmat* PmMatrixInteger2Bigintmat (polymake::Matrix<polymake::Integer>* mi);
    4552
    4653/* 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>
    101#include <Singular/ipid.h>
    112
     
    204195    module_help_proc("polymake.so","normalFan", normalFan_help);
    205196
     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
    206207}
  • dyn_modules/callpolymake/polymake_wrapper.cc

    r69b2c1 r62de8de  
    11#include <polymake_conversion.h>
    22#include <polymake_documentation.h>
     3#include <polymake/Graph.h>
    34
    45#include <dyn_modules/callgfanlib/bbcone.h>
     
    16801681}
    16811682
     1683
     1684BOOLEAN 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
     1720BOOLEAN 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
    16821756extern "C" int mod_init(SModulFunctions* p)
    16831757{
     
    16851759    {init_polymake = new polymake::Main();}
    16861760  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);
    16911763  p->iiAddCproc("polymake.so","isLatticePolytope",FALSE,PMisLatticePolytope);
    16921764  p->iiAddCproc("polymake.so","isBounded",FALSE,PMisBounded);
     
    17021774  p->iiAddCproc("polymake.so","latticeCodegree",FALSE,PMlatticeCodegree);
    17031775  p->iiAddCproc("polymake.so","ehrhartPolynomialCoeff",FALSE,PMehrhartPolynomialCoeff);
    1704   //p->iiAddCproc("polymake.so","fVector",FALSE,PMfVector);
     1776  p->iiAddCproc("polymake.so","fVector",FALSE,PMfVector);
    17051777  p->iiAddCproc("polymake.so","hVector",FALSE,PMhVector);
    17061778  p->iiAddCproc("polymake.so","hStarVector",FALSE,PMhStarVector);
     
    17271799  p->iiAddCproc("polymake.so","visual",FALSE,visual);
    17281800  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);
    17381803
    17391804  blackbox* b=getBlackboxStuff(polytopeID);
Note: See TracChangeset for help on using the changeset viewer.