24 #ifdef SOPLEX_WITH_GMP 25 static void GMPv_init(mpz_t* vect,
int dim)
27 for(
int i = 0; i < dim; i++ )
31 static void GMPv_clear(mpz_t* vect,
int dim)
33 for(
int i = 0; i < dim; i++ )
39 static std::ostream&
operator<<(std::ostream& os,
const mpz_t* number)
41 os << mpz_get_str(0, 10, *number);
51 static int Reconstruct(
VectorRational& resvec, mpz_t* xnum, mpz_t denom,
int dim,
const Rational& denomBoundSquared,
const DIdxSet* indexSet = 0)
57 assert(mpz_sgn(denom) > 0);
58 assert(denomBoundSquared > 0);
74 mpz_set_q(Dbound, denomBoundSquared.getMpqRef());
76 mpz_set(Dbound, denom);
79 mpz_sqrt(Dbound, Dbound);
81 MSG_DEBUG( std::cout <<
"reconstructing " << dim <<
" dimensional vector with denominator bound " << mpz_get_str(0, 10, Dbound) <<
"\n" );
86 if( mpz_cmp_ui(Dbound,16777216) < 0 )
87 mpz_set_ui(Dbound,16777216);
101 for(
int c = 0; (indexSet == 0 && c < dim) || (indexSet != 0 && c < indexSet->size()); c++ )
103 int j = (indexSet == 0 ? c : indexSet->index(c));
108 MSG_DEBUG( std::cout <<
" --> component " << j <<
" = " << &xnum[j] <<
" / denom\n" );
111 if( mpz_sgn(xnum[j]) != 0 )
119 mpz_divexact(tn,tn,temp);
120 mpz_divexact(td,td,temp);
122 if(mpz_cmp(td,Dbound)<=0)
126 mpq_set_num(resvec[j].getMpqRef_w(),tn);
127 mpq_set_den(resvec[j].getMpqRef_w(),td);
135 mpz_fdiv_q(a0,tn,td);
136 mpz_fdiv_r(temp,tn,td);
139 mpz_fdiv_q(ai,tn,td);
140 mpz_fdiv_r(temp,tn,td);
146 mpz_addmul(p[2],a0,ai);
154 if( mpz_cmp(q[2],Dbound) > 0 )
161 while( !done && mpz_cmp_ui(td,0) )
166 mpz_fdiv_q(ai, tn, td);
167 mpz_fdiv_r(temp, tn, td);
179 mpz_addmul(p[2], p[1], ai);
181 mpz_addmul(q[2], q[1], ai);
183 if( mpz_cmp(q[2], Dbound) > 0 )
187 MSG_DEBUG( std::cout <<
" --> convergent denominator = " << &q[2] <<
"\n" );
191 mpq_set_num(resvec[j].getMpqRef_w(), p[1]);
192 mpq_set_den(resvec[j].getMpqRef_w(), q[1]);
193 mpq_canonicalize(resvec[j].getMpqRef_w());
194 mpz_gcd(temp, gcd, mpq_denref(resvec[j].getMpqRef()));
195 mpz_mul(gcd, gcd, temp);
197 if( mpz_cmp(gcd, Dbound) > 0 )
199 MSG_DEBUG( std::cout <<
"terminating with gcd " << &gcd <<
" exceeding Dbound " << &Dbound <<
"\n" );
227 #ifdef SOPLEX_WITH_GMP 237 GMPv_init(xnum, dim);
238 mpz_init_set_ui(denom, 1);
243 for(
int i = 0; i < dim; i++ )
244 mpz_lcm(denom, denom, mpq_denref(input[i].getMpqRef()));
246 for(
int i = 0; i < dim; i++ )
248 mpz_mul(xnum[i], denom, mpq_numref(input[i].getMpqRef()));
249 mpz_divexact(xnum[i], xnum[i], mpq_denref(input[i].getMpqRef()));
254 for(
int i = 0; i < indexSet->
size(); i++ )
256 assert(indexSet->
index(i) >= 0);
257 assert(indexSet->
index(i) < input.
dim());
258 mpz_lcm(denom, denom, mpq_denref(input[indexSet->
index(i)].getMpqRef()));
261 for(
int i = 0; i < indexSet->
size(); i++ )
263 int k = indexSet->
index(i);
265 assert(k < input.
dim());
266 mpz_mul(xnum[k], denom, mpq_numref(input[k].getMpqRef()));
267 mpz_divexact(xnum[k], xnum[k], mpq_denref(input[k].getMpqRef()));
271 MSG_DEBUG( std::cout <<
"LCM = " << mpz_get_str(0, 10, denom) <<
"\n" );
274 rval = Reconstruct(input, xnum, denom, dim, denomBoundSquared, indexSet);
277 GMPv_clear(xnum, dim);
295 if( solution.hasPrimal() )
308 if( solution.hasPrimalray() )
310 buffer.
reDim((solution._primalray).dim());
311 solution.getPrimalray(buffer);
313 solution._primalray = buffer;
316 if( solution.hasDual() )
321 solution.
_dual = buffer;
323 buffer.
reDim((solution._redcost).dim());
324 solution.getRedcost(buffer);
326 solution._redcost = buffer;
329 if( solution.hasDualfarkas() )
331 buffer.
reDim((solution._dualfarkas).dim());
332 solution.getDualfarkas(buffer);
334 solution._dualfarkas = buffer;
bool getDual(VectorBase< R > &vector) const
gets the dual solution vector; returns true on success
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase's dimension to newdim.
Dense vector.Class VectorBase provides dense linear algebra vectors. It does not provide memory manag...
bool getSlacks(VectorBase< R > &vector) const
gets the vector of slack values; returns true on success
Wrapper for GMP type mpq_class.We wrap mpq_class so that we can replace it by a double type if GMP is...
bool getPrimal(VectorBase< R > &vector) const
gets the primal solution vector; returns true on success
void spx_alloc(T &p, int n=1)
Allocate memory.
Rational reconstruction of solution vector.
bool reconstructVector(VectorRational &input, const Rational &denomBoundSquared, const DIdxSet *indexSet)
bool reconstructSol(SolRational &solution)
std::ostream & operator<<(std::ostream &s, const VectorBase< R > &vec)
Output operator.
int size() const
returns the number of used indices.
Dynamic index set.Class DIdxSet provides dynamic IdxSet in the sense, that no restrictions are posed ...
Debugging, floating point type and parameter definitions.
int dim() const
Dimension of vector.
Everything should be within this namespace.
VectorBase< Rational > VectorRational
int index(int n) const
access n 'th index.
void spx_free(T &p)
Release memory.