source: git/Singular/dyn_modules/gfanlib/tropicalVariety.cc @ 4b47563

fieker-DuValspielwiese
Last change on this file since 4b47563 was 4b47563, checked in by Yue Ren <ren@…>, 9 years ago
chg: minor fixes, mainly cleanup
  • Property mode set to 100644
File size: 3.2 KB
Line 
1#include <callgfanlib_conversion.h>
2#include <std_wrapper.h>
3#include <bbfan.h>
4#include <groebnerCone.h>
5#include <tropicalVarietyOfPolynomials.h>
6#include <tropicalVarietyOfIdeals.h>
7#include <libpolys/coeffs/numbers.h>
8#include <libpolys/misc/options.h>
9#include <kernel/structs.h>
10
11#include <iostream>
12#include <gfanlib/gfanlib_zfan.h>
13
14BITSET bitsetSave1, bitsetSave2;
15
16/***
17 * sets option(redSB)
18 **/
19static void setOptionRedSB()
20{
21  SI_SAVE_OPT(bitsetSave1,bitsetSave2);
22  si_opt_1|=Sy_bit(OPT_REDSB);
23}
24
25/***
26 * sets option(noredSB);
27 **/
28static void undoSetOptionRedSB()
29{
30  SI_RESTORE_OPT(bitsetSave1,bitsetSave2);
31}
32
33static gfan::ZFan* toZFan(std::set<gfan::ZCone> maxCones)
34{
35  std::set<gfan::ZCone>::iterator sigma = maxCones.begin();
36  gfan::ZFan* zf = new gfan::ZFan(sigma->ambientDimension());
37  for (; sigma!=maxCones.end(); sigma++)
38    zf->insert(*sigma);
39  return zf;
40}
41
42BOOLEAN tropicalVariety(leftv res, leftv args)
43{
44  omUpdateInfo();
45  Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
46  leftv u = args;
47  if ((u!=NULL) && (u->Typ()==IDEAL_CMD))
48  {
49    ideal I = (ideal) u->Data();
50    leftv v = u->next;
51
52    if (idSize(I)==1)
53    {
54      poly g = I->m[0];
55      if (v==NULL)
56      {
57        tropicalStrategy currentStrategy(I,currRing);
58        std::set<gfan::ZCone> maxCones = tropicalVariety(g,currRing,currentStrategy);
59        // gfan::ZFan* zf = toZFan(maxCones);
60        // delete zf;
61        // res->rtyp = NONE;
62        // res->data = NULL;
63        // while (1)
64        // {
65        //   omUpdateInfo();
66        //   Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
67        //   tropicalStrategy debugTest(I,currRing);
68        //   maxCones = tropicalVariety(g,currRing,debugTest);
69        //   gfan::ZFan* zf = toZFan(maxCones);
70        //   delete zf;
71        // }
72        res->rtyp = fanID;
73        res->data = (char*) toZFan(maxCones);
74        return FALSE;
75      }
76      if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
77      {
78        number p = (number) v->Data();
79        tropicalStrategy currentStrategy(I,p,currRing);
80        std::set<gfan::ZCone> maxCones = tropicalVariety(g,currRing,currentStrategy);
81        res->rtyp = fanID;
82        res->data = (char*) toZFan(maxCones);
83        return FALSE;
84      }
85    }
86
87    if (v==NULL)
88    {
89      setOptionRedSB();
90      ideal stdI;
91      if (!hasFlag(u,FLAG_STD))
92        stdI = gfanlib_kStd_wrapper(I,currRing);
93      else
94        stdI = id_Copy(I,currRing);
95      tropicalStrategy currentStrategy(I,currRing);
96      gfan::ZFan* tropI = tropicalVariety(currentStrategy);
97      res->rtyp = fanID;
98      res->data = (char*) tropI;
99      undoSetOptionRedSB();
100      id_Delete(&stdI,currRing);
101      return FALSE;
102    }
103    if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
104    {
105      number p = (number) v->Data();
106      ideal stdI;
107      if (!hasFlag(u,FLAG_STD))
108        stdI = gfanlib_kStd_wrapper(I,currRing);
109      else
110        stdI = id_Copy(I,currRing);
111      tropicalStrategy currentStrategy(stdI,p,currRing);
112      gfan::ZFan* tropI = tropicalVariety(currentStrategy);
113      res->rtyp = fanID;
114      res->data = (char*) tropI;
115      id_Delete(&stdI,currRing);
116      return FALSE;
117    }
118    return FALSE;
119  }
120  WerrorS("tropicalVariety: unexpected parameters");
121  return TRUE;
122}
Note: See TracBrowser for help on using the repository browser.