1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
#include "reversesearch.h"
#include "buchberger.h"
#include "wallideal.h"
#include "printer.h"
#include "lp.h"
#include "log.h"
bool ReverseSearch::computeSearchEdge(PolynomialSet &groebnerBasis, IntegerVector *edge)
{
// fprintf(Stderr,"Computing search edge..");
IntegerVectorList normals=wallInequalities(groebnerBasis);
normals.sort(LexicographicTermOrder());// Is this needed to make the interior point computation deterministic?
// fprintf(Stderr,"\nBasis with no interior point:\n");
// AsciiPrinter(Stderr).printPolynomialSet(groebnerBasis);
if(normals.empty())
{
log3 fprintf(Stderr,"WARNING: reversesearch.cpp - No normals\n");
}
IntegerVectorList::const_iterator r=shootRay(normals);
// fprintf(Stderr,"..done\n");
if(r!=normals.end())
{
*edge=*r;
return true;
}
return false;
/*
IntegerVectorList normals=wallNormals(groebnerBasis);
normals.sort(LexicographicTermOrder());
for(IntegerVectorList::const_iterator i=normals.begin();i!=normals.end();i++)
if(termOrder(*i,*i-*i))
if(isFacet(normals,i))
if(wallContainsPositiveVector(*i))
{
*edge=*i;
return true;
}
return false;
*/
}
/*void ReverseSearch::setProgressPrinting(bool p)
{
progressPrinting=p;
}
*/
static int depth;
//int ReverseSearch::treeSize(const PolynomialSet &groebnerBasis)
int ReverseSearch::treeSize(PolynomialSet &groebnerBasis)
{
PolynomialRing theRing=groebnerBasis.getRing();
depth++;
// if(progressPrinting)
{
static int n;
n++;
if(!(n%10))
log2 fprintf(Stderr,"%i %i\n",n,depth);
}
int s=1;
if(!targetBasis(groebnerBasis)){broken=true;return s;}
IntegerVectorList flipable;
// fprintf(Stderr,"Number of flipable facets:%i\n",flipable.size());
if(1)
{
// fprintf(Stderr,"isKnownToBeHomogeneous:%i\n",isKnownToBeHomogeneous);
// fprintf(Stderr,"Start finding flipable\n");
flipable=wallFlipableNormals(groebnerBasis,isKnownToBeHomogeneous);
// fprintf(Stderr,"done\n");
}
else
{
// For non-homogeneous ideals the following test does not work since it also findes facets that do not intersect the positive orthant.
assert(isKnownToBeHomogeneous);
//Taken from Breadth-first search. Apparently this is faster..
IntegerVectorList normals=algebraicTest(wallInequalities(groebnerBasis),groebnerBasis);
// fprintf(Stderr,"Number of inequalities:%i\n",normals.size());
// AsciiPrinter(Stderr).printVectorList(normals);
for(IntegerVectorList::iterator i=normals.begin();i!=normals.end();i++)
{
if(!termOrder(*i,*i-*i))
{
// AsciiPrinter(Stderr).printVector(*i);
if(isFacet(normals,i))
{
// fprintf(Stderr,"isFACET!n");
if(wallContainsPositiveVector(*i))
flipable.push_back(*i);
}
else
{
IntegerVectorList::iterator temp=i;
temp++;
normals.erase(i);
temp--;
i=temp;
}
}
}
}
// AsciiPrinter(Stderr).printVectorList(flipable);
// fprintf(Stderr,"Number of flipable facets:%i\n",flipable.size());
for(IntegerVectorList::iterator i=flipable.begin();i!=flipable.end();i++)
{
if(!termOrder(*i,*i-*i))
{
PolynomialSet neighbour=flip(groebnerBasis,*i);
IntegerVector edge;
if(computeSearchEdge(neighbour,&edge))
if(dependent(edge,*i))
{
groebnerBasis=PolynomialSet(theRing);//forget current
s+=treeSize(neighbour);
groebnerBasis=flip(neighbour,edge);//recall
if(broken)return s;
}
}
}
depth--;
return s;
}
PolynomialSet ReverseSearch::findRoot(PolynomialSet groebnerBasis)
{
log2 fprintf(Stderr,"Computing root\n");
log2 buchberger(&groebnerBasis,termOrder);
IntegerVector edge;
while(computeSearchEdge(groebnerBasis,&edge))
{
log2 AsciiPrinter(Stderr).printVector(edge);
groebnerBasis=flip(groebnerBasis,edge);
}
log2 fprintf(Stderr,"Done computing root\n");
return groebnerBasis;
}
ReverseSearch::ReverseSearch(const TermOrder &termOrder_):
numberOfVertices(0),
numberOfEdges(0),
termOrder(termOrder_),
isKnownToBeHomogeneous(false)//,
// progressPrinting(false)
{
}
void ReverseSearch::enumerate(const PolynomialSet &groebnerBasis)
{
broken=false;
PolynomialSet root=findRoot(groebnerBasis);
if(!isKnownToBeHomogeneous)isKnownToBeHomogeneous=isIdealHomogeneous(root);
// fprintf(Stderr,"HOMOGENEOUS:%i\n",isKnownToBeHomogeneous);
targetBeginEnumeration(groebnerBasis);
numberOfVertices=treeSize(root);
targetEndEnumeration();
// fprintf(Stderr,"numberOfVertices:%i\n",numberOfVertices);
}
|