source: git/Singular/dyn_modules/gfanlib/tropicalVariety.cc @ e5618c

spielwiese
Last change on this file since e5618c was e5618c, checked in by Yue Ren <ren@…>, 9 years ago
chg: final version for Singular release
  • Property mode set to 100644
File size: 3.4 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        ideal startingIdeal = currentStrategy.getStartingIdeal();
81        ring startingRing = currentStrategy.getStartingRing();
82        poly gStart = startingIdeal->m[0];
83        std::set<gfan::ZCone> maxCones = tropicalVariety(gStart,startingRing,currentStrategy);
84        res->rtyp = fanID;
85        res->data = (char*) toZFan(maxCones);
86        return FALSE;
87      }
88    }
89
90    if (v==NULL)
91    {
92      setOptionRedSB();
93      ideal stdI;
94      if (!hasFlag(u,FLAG_STD))
95        stdI = gfanlib_kStd_wrapper(I,currRing);
96      else
97        stdI = id_Copy(I,currRing);
98      tropicalStrategy currentStrategy(I,currRing);
99      gfan::ZFan* tropI = tropicalVariety(currentStrategy);
100      res->rtyp = fanID;
101      res->data = (char*) tropI;
102      undoSetOptionRedSB();
103      id_Delete(&stdI,currRing);
104      return FALSE;
105    }
106    if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
107    {
108      number p = (number) v->Data();
109      ideal stdI;
110      if (!hasFlag(u,FLAG_STD))
111        stdI = gfanlib_kStd_wrapper(I,currRing);
112      else
113        stdI = id_Copy(I,currRing);
114      tropicalStrategy currentStrategy(stdI,p,currRing);
115      gfan::ZFan* tropI = tropicalVariety(currentStrategy);
116      res->rtyp = fanID;
117      res->data = (char*) tropI;
118      id_Delete(&stdI,currRing);
119      return FALSE;
120    }
121    return FALSE;
122  }
123  WerrorS("tropicalVariety: unexpected parameters");
124  return TRUE;
125}
Note: See TracBrowser for help on using the repository browser.