1 | #include <bbcone.h> |
---|
2 | #include <groebnerCone.h> |
---|
3 | #include <tropicalCurves.h> |
---|
4 | |
---|
5 | std::vector<bool> checkNecessaryFlips(const groebnerCones &tropicalVariety, const groebnerCones &workingList, |
---|
6 | const gfan::ZVector &interiorPoint, const gfan::ZMatrix &normalVectors) |
---|
7 | { |
---|
8 | int k = normalVectors.getHeight(); |
---|
9 | std::vector<bool> needToFlip(k,true); |
---|
10 | |
---|
11 | int n = normalVectors.getWidth(); |
---|
12 | gfan::ZMatrix testVectors(k,n); |
---|
13 | gfan::ZVector bigInteriorPoint = 1000*interiorPoint; |
---|
14 | for (int i=0; i<k; i++) |
---|
15 | testVectors[i] = bigInteriorPoint+normalVectors[i]; |
---|
16 | |
---|
17 | for (groebnerCones::iterator sigma = tropicalVariety.begin(); sigma!=tropicalVariety.end(); sigma++) |
---|
18 | { |
---|
19 | if (sigma->contains(interiorPoint)) |
---|
20 | { |
---|
21 | for (int i=0; i<k; i++) |
---|
22 | { |
---|
23 | if (needToFlip[i] && sigma->contains(testVectors[i])) |
---|
24 | needToFlip[i] = false; |
---|
25 | } |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | for (groebnerCones::iterator sigma = workingList.begin(); sigma!=workingList.end(); sigma++) |
---|
30 | { |
---|
31 | if (sigma->contains(interiorPoint)) |
---|
32 | { |
---|
33 | for (int i=0; i<k; i++) |
---|
34 | { |
---|
35 | if (needToFlip[i] && sigma->contains(testVectors[i])) |
---|
36 | needToFlip[i] = false; |
---|
37 | } |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | return needToFlip; |
---|
42 | } |
---|
43 | |
---|
44 | groebnerCones tropicalTraversalMinimizingFlips(const groebnerCone startingCone) |
---|
45 | { |
---|
46 | groebnerCones tropicalVariety; |
---|
47 | groebnerCones workingList; |
---|
48 | workingList.insert(startingCone); |
---|
49 | const tropicalStrategy* currentStrategy=startingCone.getTropicalStrategy(); |
---|
50 | std::cout << "starting traversal" << std::endl; |
---|
51 | while(!workingList.empty()) |
---|
52 | { |
---|
53 | /** |
---|
54 | * Pick an element the working list and compute interior points on its facets |
---|
55 | */ |
---|
56 | std::cout << "picking cone and computing interior facet points..." << std::endl; |
---|
57 | groebnerCone sigma=*(workingList.begin()); |
---|
58 | gfan::ZMatrix interiorPoints = interiorPointsOfFacets(sigma.getPolyhedralCone()); |
---|
59 | |
---|
60 | for (int i=0; i<interiorPoints.getHeight(); i++) |
---|
61 | { |
---|
62 | /** |
---|
63 | * For each interior point, compute the rays of the tropical star in that point |
---|
64 | */ |
---|
65 | gfan::ZVector interiorPoint = interiorPoints[i]; |
---|
66 | if (!(currentStrategy->restrictToLowerHalfSpace() && interiorPoint[0].sign()==0)) |
---|
67 | { |
---|
68 | ideal inI = initial(sigma.getPolynomialIdeal(),sigma.getPolynomialRing(),interiorPoint); |
---|
69 | std::cout << "picking interiorPoint and computing rays of tropical star..." << std::endl; |
---|
70 | gfan::ZMatrix normalVectors = raysOfTropicalStar(inI, |
---|
71 | sigma.getPolynomialRing(), |
---|
72 | interiorPoint, |
---|
73 | sigma.getTropicalStrategy()); |
---|
74 | id_Delete(&inI,sigma.getPolynomialRing()); |
---|
75 | |
---|
76 | std::cout << "checking for th neccessity to flip..." << std::endl; |
---|
77 | std::vector<bool> needToFlip = checkNecessaryFlips(tropicalVariety,workingList,interiorPoint,normalVectors); |
---|
78 | for (int j=0; j<normalVectors.getHeight(); j++) |
---|
79 | { |
---|
80 | if (needToFlip[j]) |
---|
81 | { |
---|
82 | std::cout << "flipping cone..." << std::endl; |
---|
83 | groebnerCone neighbour = sigma.flipCone(interiorPoint,normalVectors[j]); |
---|
84 | workingList.insert(neighbour); |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | sigma.deletePolynomialData(); |
---|
91 | workingList.erase(sigma); |
---|
92 | tropicalVariety.insert(sigma); |
---|
93 | std::cout << "tropicalVariety.size():" << tropicalVariety.size() << std::endl; |
---|
94 | std::cout << "workingList.size():" << workingList.size() << std::endl; |
---|
95 | } |
---|
96 | return tropicalVariety; |
---|
97 | } |
---|
98 | |
---|
99 | groebnerCones tropicalTraversal(const groebnerCone startingCone) |
---|
100 | { |
---|
101 | groebnerCones tropicalVariety; |
---|
102 | groebnerCones workingList; |
---|
103 | workingList.insert(startingCone); |
---|
104 | std::cout << "starting traversal" << std::endl; |
---|
105 | while(!workingList.empty()) |
---|
106 | { |
---|
107 | const groebnerCone sigma=*(workingList.begin()); |
---|
108 | const groebnerCones neighbours = sigma.tropicalNeighbours(); |
---|
109 | for (groebnerCones::iterator tau = neighbours.begin(); tau!=neighbours.end(); tau++) |
---|
110 | { |
---|
111 | if (tropicalVariety.count(*tau)==0) |
---|
112 | workingList.insert(*tau); |
---|
113 | } |
---|
114 | tropicalVariety.insert(sigma); |
---|
115 | workingList.erase(sigma); |
---|
116 | // std::cout << "tropicalVariety.size():" << tropicalVariety.size() << std::endl; |
---|
117 | // std::cout << "workingList.size():" << workingList.size() << std::endl; |
---|
118 | } |
---|
119 | return tropicalVariety; |
---|
120 | } |
---|