Changeset 08b7c2a in git


Ignore:
Timestamp:
Feb 4, 2015, 11:29:46 PM (9 years ago)
Author:
Yue Ren <ren@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
7cb46755d168b8a6622fc01364fe4ca055f20f4b
Parents:
7723d00a58aba67b90f5f607a5018d386f4f8465
git-author:
Yue Ren <ren@mathematik.uni-kl.de>2015-02-04 23:29:46+01:00
git-committer:
Yue Ren <ren@mathematik.uni-kl.de>2015-02-06 13:47:06+01:00
Message:
chg: removed redundant witness computations
Location:
Singular/dyn_modules/gfanlib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Singular/dyn_modules/gfanlib/groebnerCone.cc

    r7723d00 r08b7c2a  
    408408    if (currentStrategy->restrictToLowerHalfSpace() && R[i][0].sign()==0)
    409409      continue;
    410     poly s = currentStrategy->checkInitialIdealForMonomial(I,r,R[i]);
    411     if (s==NULL)
    412     {
    413       p_Delete(&s,r);
     410    std::pair<poly,int> s = currentStrategy->checkInitialIdealForMonomial(I,r,R[i]);
     411    if (s.first==NULL)
     412    {
     413      if (s.second<0)
     414        // if monomial was initialized, delete it
     415        p_Delete(&s.first,r);
    414416      return R[i];
    415417    }
  • Singular/dyn_modules/gfanlib/tropicalCurves.cc

    r7723d00 r08b7c2a  
    147147
    148148    ideal inIsSTD = gfanlib_kStd_wrapper(inIs,s,isHomog);
     149    id_Delete(&inIs,s);
    149150    ideal ininIs = initial(inIsSTD,s,w,W);
    150151
    151     poly mons = currentStrategy->checkInitialIdealForMonomial(ininIs,s,w);
    152     if (mons!=NULL)
     152    std::pair<poly,int> mons = currentStrategy->checkInitialIdealForMonomial(ininIs,s);
     153
     154    if (mons.first!=NULL)
    153155    {
    154156      poly gs;
    155       if (pNext(mons)==NULL)
    156         gs = witness(mons,inIsSTD,ininIs,s);
     157      if (mons.second>=0)
     158        // cheap way out, ininIsSTD already contains a monomial in its generators
     159        gs = inIsSTD->m[mons.second];
    157160      else
    158         gs = p_Copy(mons,s);
     161        // compute witness
     162        gs = witness(mons.first,inIsSTD,ininIs,s);
     163
    159164      C = intersect(C,tropicalVarietySortedByDimension(gs,s,currentStrategy),d);
    160165      nMapFunc mMap = n_SetMap(s->cf,r->cf);
     
    162167      idInsertPoly(inI,gr);
    163168      k++;
    164       p_Delete(&mons,s);
    165       p_Delete(&gs,s);
    166       zc = C.begin();
    167       // gfan::ZFan* zf = toFanStar(C);
    168       // std::cout << zf->toString(2+4+8+128) << std::endl;
    169       // delete zf;
    170       id_Delete(&inIs,s);
     169
     170      if (mons.second<0)
     171      {
     172        // if necessary, cleanup mons and gs
     173        p_Delete(&mons.first,s);
     174        p_Delete(&gs,s);
     175      }
     176      // cleanup rest, reset zc
    171177      id_Delete(&inIsSTD,s);
    172178      id_Delete(&ininIs,s);
    173179      rDelete(s);
     180      zc = C.begin();
    174181    }
    175182    else
    176183    {
    177       id_Delete(&inIs,s);
     184      // cleanup remaining data of first stage
    178185      id_Delete(&inIsSTD,s);
    179186      id_Delete(&ininIs,s);
     
    190197
    191198        inIsSTD = gfanlib_kStd_wrapper(inIs,s,isHomog);
     199        id_Delete(&inIs,s);
    192200        ininIs = initial(inIsSTD,s,wNeg,W);
    193201
    194         mons = currentStrategy->checkInitialIdealForMonomial(ininIs,s,wNeg);
    195         if (mons!=NULL)
     202        mons = currentStrategy->checkInitialIdealForMonomial(ininIs,s);
     203        if (mons.first!=NULL)
    196204        {
    197205          poly gs;
    198           if (pNext(mons)==NULL)
    199             gs = witness(mons,inIsSTD,ininIs,s);
     206          if (mons.second>=0)
     207            // cheap way out, ininIsSTD already contains a monomial in its generators
     208            gs = inIsSTD->m[mons.second];
    200209          else
    201             gs = p_Copy(mons,s);
     210            // compute witness
     211            gs = witness(mons.first,inIsSTD,ininIs,s);
     212
    202213          C = intersect(C,tropicalVarietySortedByDimension(gs,s,currentStrategy),d);
    203214          nMapFunc mMap = n_SetMap(s->cf,r->cf);
     
    205216          idInsertPoly(inI,gr);
    206217          k++;
    207           p_Delete(&mons,s);
    208           p_Delete(&gs,s);
     218
     219          if (mons.second<0)
     220          {
     221            // if necessary, cleanup mons and gs
     222            p_Delete(&mons.first,s);
     223            p_Delete(&gs,s);
     224          }
     225          // reset zc
    209226          zc = C.begin();
    210           // gfan::ZFan* zf = toFanStar(C);
    211           // std::cout << zf->toString();
    212           // delete zf;
    213227        }
    214228        else
    215229          zc++;
    216         id_Delete(&inIs,s);
     230        // cleanup remaining data of second stage
    217231        id_Delete(&inIsSTD,s);
    218232        id_Delete(&ininIs,s);
  • Singular/dyn_modules/gfanlib/tropicalStrategy.cc

    r7723d00 r08b7c2a  
    456456}
    457457
    458 poly tropicalStrategy::checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector w) const
    459 {
     458std::pair<poly,int> tropicalStrategy::checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector &w) const
     459{
     460  // quick check whether I already contains an ideal
    460461  int k = idSize(I);
    461462  for (int i=0; i<k; i++)
     
    463464    poly g = I->m[i];
    464465    if (pNext(g)==NULL && (isValuationTrivial() || n_IsOne(p_GetCoeff(g,r),r->cf)))
    465     {
    466       poly monomial = p_Copy(g,r);
    467       return monomial;
    468     }
    469   }
    470   // prepend extra weight for homogeneity
    471   // switch to residue field if valuation is non trivial
    472   ring rShortcut = getShortcutRingPrependingWeight(r,w);
    473 
    474   // compute the initial ideal and map it into the constructed ring
    475   // if switched to residue field, remove possibly 0 elements
    476   ideal inI = initial(I,r,w);
    477   ideal inIShortcut = idInit(k);
    478   nMapFunc intoShortcut = n_SetMap(r->cf,rShortcut->cf);
    479   for (int i=0; i<k; i++)
    480     inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,intoShortcut,NULL,0);
    481   if (isValuationNonTrivial())
    482     idSkipZeroes(inIShortcut);
     466      return std::pair<poly,int>(g,i);
     467  }
     468
     469  ring rShortcut;
     470  ideal inIShortcut;
     471  if (w.size()>0)
     472  {
     473    // if needed, prepend extra weight for homogeneity
     474    // switch to residue field if valuation is non trivial
     475    rShortcut = getShortcutRingPrependingWeight(r,w);
     476
     477    // compute the initial ideal and map it into the constructed ring
     478    // if switched to residue field, remove possibly 0 elements
     479    ideal inI = initial(I,r,w);
     480    inIShortcut = idInit(k);
     481    nMapFunc intoShortcut = n_SetMap(r->cf,rShortcut->cf);
     482    for (int i=0; i<k; i++)
     483      inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,intoShortcut,NULL,0);
     484    if (isValuationNonTrivial())
     485      idSkipZeroes(inIShortcut);
     486    id_Delete(&inI,r);
     487  }
     488  else
     489  {
     490    rShortcut = r;
     491    inIShortcut = I;
     492  }
    483493
    484494  // check initial ideal for monomial and
    485495  // if it exsists, return a copy of the monomial in the input ring
    486496  poly p = checkForMonomialViaSuddenSaturation(inIShortcut,rShortcut);
    487   poly monomial = NULL; int n = rVar(r);
     497  poly monomial = NULL;
    488498  if (p!=NULL)
    489499  {
    490500    monomial=p_One(r);
    491     for (int i=1; i<=n; i++)
     501    for (int i=1; i<=rVar(r); i++)
    492502      p_SetExp(monomial,i,p_GetExp(p,i,rShortcut),r);
    493503    p_Delete(&p,rShortcut);
    494504  }
    495   id_Delete(&inI,r);
    496   id_Delete(&inIShortcut,rShortcut);
    497   rDelete(rShortcut);
    498   return monomial;
     505
     506
     507  if (w.size()>0)
     508  {
     509    // if needed, cleanup
     510    id_Delete(&inIShortcut,rShortcut);
     511    rDelete(rShortcut);
     512  }
     513  return std::pair<poly,int>(monomial,-1);
    499514}
    500515
  • Singular/dyn_modules/gfanlib/tropicalStrategy.h

    r7723d00 r08b7c2a  
    306306   * In both cases returns a monomial, if it contains one, returns NULL otherwise.
    307307   **/
    308   poly checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector w=0) const;
     308  std::pair<poly,int> checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector &w=0) const;
    309309
    310310  /**
  • Singular/dyn_modules/gfanlib/tropicalTraversal.cc

    r7723d00 r08b7c2a  
    4848  workingList.insert(startingCone);
    4949  const tropicalStrategy* currentStrategy=startingCone.getTropicalStrategy();
    50   // std::cout << "starting traversal" << std::endl;
    5150  while(!workingList.empty())
    5251  {
     
    5453     * Pick an element the working list and compute interior points on its facets
    5554     */
    56     // std::cout << "picking cone and computing interior facet points..." << std::endl;
    5755    groebnerCone sigma=*(workingList.begin());
    5856    gfan::ZMatrix interiorPoints = interiorPointsOfFacets(sigma.getPolyhedralCone());
     
    6765      {
    6866        ideal inI = initial(sigma.getPolynomialIdeal(),sigma.getPolynomialRing(),interiorPoint);
    69         // std::cout << "picking interiorPoint and computing rays of tropical star..." << std::endl;
    7067        gfan::ZMatrix normalVectors = raysOfTropicalStar(inI,
    7168                                                         sigma.getPolynomialRing(),
     
    7471        id_Delete(&inI,sigma.getPolynomialRing());
    7572
    76         // std::cout << "checking for th neccessity to flip..." << std::endl;
    7773        std::vector<bool> needToFlip = checkNecessaryFlips(tropicalVariety,workingList,interiorPoint,normalVectors);
    7874        for (int j=0; j<normalVectors.getHeight(); j++)
     
    8076          if (needToFlip[j])
    8177          {
    82             // std::cout << "flipping cone..." << std::endl;
    8378            groebnerCone neighbour = sigma.flipCone(interiorPoint,normalVectors[j]);
    8479            workingList.insert(neighbour);
     
    114109    tropicalVariety.insert(sigma);
    115110    workingList.erase(sigma);
    116     // std::cout << "tropicalVariety.size():" << tropicalVariety.size() << std::endl;
    117     // std::cout << "workingList.size():" << workingList.size() << std::endl;
     111    std::cout << "tropicalVariety.size():" << tropicalVariety.size() << std::endl;
     112    std::cout << "workingList.size():" << workingList.size() << std::endl;
    118113  }
    119114  return tropicalVariety;
Note: See TracChangeset for help on using the changeset viewer.