- removed special handling of Gmpq from QP_models, since the read-from-float

capability is now available in Gmpq.h
This commit is contained in:
Bernd Gärtner
2006-09-19 14:30:56 +00:00
parent fc6a79c9b7
commit 49cac0da8b
7 changed files with 26 additions and 218 deletions
+3 -22
View File
@@ -796,38 +796,19 @@ private: // parsing routines:
put_back_token = token;
}
// here is a general template for halving a number; we must
// have a specialization for Gmpz that performs exact division
// (and therefore fails if the result is incorrect)
// here is a general template for halving a number; ToDo: we must
// somehow trigger an error if this division is not exact
template<typename NumberType>
void halve(NumberType& entry) {
entry /= 2;
}
void halve(CGAL::Gmpz& entry) {
entry = CGAL::exact_division(entry,2);
}
// here is the general template, and the C-file contains
// implementations of a specialization for Gmpq
template<typename NumberType>
bool number(NumberType& entry) {
whitespace();
// whitespace(); the following >> should care for this
from >> entry;
return from.good();
}
bool number(CGAL::Gmpq& entry) {
// accept rational or floating-point format
std::string s = token() + " "; // routines below can't deal with EOF
std::istringstream from1(s), from2(s);
return
number_from_quotient (entry, from1) ||
number_from_float (entry, from2);
}
bool number_from_quotient(CGAL::Gmpq& entry, std::istringstream& from);
bool number_from_float(CGAL::Gmpq& entry, std::istringstream& from);
bool name_section();
bool rows_section();
@@ -28,135 +28,6 @@
CGAL_BEGIN_NAMESPACE
// for parsing rational numbers
template<typename IT_, typename Is_linear_,
typename Sparse_D_,
typename Sparse_A_>
bool QP_from_mps<IT_, Is_linear_,
Sparse_D_,
Sparse_A_>::number_from_quotient(CGAL::Gmpq& entry, std::istringstream& from) {
// reads rational in the form p/q
CGAL::Gmpz p,q;
char ch;
from >> p;
if (!from.good()) {
return false;
}
from >> ch;
if (ch != '/') {
return false;
}
from >> q;
if (!from.good()) {
return false;
}
entry = CGAL::Gmpq(p,q);
return true;
}
template<typename IT_, typename Is_linear_,
typename Sparse_D_,
typename Sparse_A_>
bool QP_from_mps<IT_, Is_linear_,
Sparse_D_,
Sparse_A_>::number_from_float(CGAL::Gmpq& entry, std::istringstream& from) {
// reads rationals from a decimal floating-point string;
// e.g. "0.1" will be parsed as 1/10
char c;
// sign -> plus_sign
bool plus_sign = true;
from.get(c);
if ((c == '+') || (c == '-'))
plus_sign = (c == '+');
else
from.putback(c);
if (!from.good()) return false;
// digit-sequence before decimal point -> n
CGAL::Gmpz n;
bool digits = false; // are there digits before OR after decimal point?
from.get(c);
if (c != '.') {
if (!isdigit(c)) return false;
from.putback(c);
from >> n;
digits = true;
} else {
from.putback(c);
n = 0;
}
if (!from.good()) return false;
// decimal point
bool decimal_point;
from.get(c);
if (c == '.') {
decimal_point = true;
} else {
from.putback(c);
decimal_point = false;
}
if (!from.good()) return false; // possible decimal point is eaten
// digit-sequence after decimal point; update n with every digit
// found and remember according power-of-ten shift in denominator
CGAL::Gmpz d = (plus_sign? 1 : -1);
if (decimal_point) {
from.get(c);
if (!isdigit(c)) {
from.putback(c);
} else {
digits = true;
do {
d *= 10;
n = n*10 + (c-'0');
from.get(c);
} while (isdigit(c));
from.putback(c);
}
}
if (!from.good()) return false;
// exponent part -> e
int e = 0;
from.get(c);
if (isspace(c)) {
from.putback(c); // number parsed, no exponent
} else {
if (c == 'e' || c == 'E') {
from >> e; // read exponent
if (!from.good()) return false;
}
from.get(c);
if (isspace(c)) {
from.putback(c); // number parsed, no literal identifier
} else {
if ( c != 'f' && c != 'F' && c != 'l' && c != 'L') {
return false; // invalid literal symbol
}
}
}
if (!from.good()) return false;
// now build the rational number
if (!digits) return false;
// handle e
if (e > 0) {
while (e > 0) {
e -= 1;
n *= 10;
}
} else {
while (e < 0) {
e += 1;
d *= 10;
}
}
entry = CGAL::Gmpq(n,d);
return true;
}
template<typename IT_, typename Is_linear_,
typename Sparse_D_,
typename Sparse_A_>
@@ -105,8 +105,8 @@ for file in $MASTERS
exit 1
fi
# for each master, find all its derivatives:
DERS=$(find test_solver_data/derivatives -name "${name}*.mps")
# for each master, find one derivative:
DERS=$(find test_solver_data/derivatives -name "${name}_shifted.mps")
# check if one of the derivatives is older:
older=0
File diff suppressed because one or more lines are too long
+20 -20
View File
@@ -1360,26 +1360,6 @@ Processing: test_solver_data/derivatives/b_float_free.mps
Strategy: pf
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: fe
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: pe
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: eb
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: ff
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: pf
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_shifted.mps
Strategy: fe
Verbosity: 0
@@ -1400,6 +1380,26 @@ Processing: test_solver_data/derivatives/b_shifted.mps
Strategy: pf
Verbosity: 0
Solution: -10001(2) -10001(2) -10001(2) -10001(2)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: fe
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: pe
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: eb
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: ff
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/derivatives/b_free.mps
Strategy: pf
Verbosity: 0
Solution: -10000(3) -10000(3) -10000(3) -10000(3)
Processing: test_solver_data/masters/cgal/b.mps
Strategy: fe
Verbosity: 0
@@ -15,49 +15,17 @@ ROWS
COLUMNS
x0 obj 5
x0 c0 -1
x0 c1 0
x0 c2 0
x0 c3 0
x0 c4 1
x0 c5 0
x0 c6 0
x0 c7 0
x1 obj 5
x1 c0 0
x1 c1 -1
x1 c2 0
x1 c3 0
x1 c4 0
x1 c5 1
x1 c6 0
x1 c7 0
x2 obj 5
x2 c0 0
x2 c1 0
x2 c2 -1
x2 c3 0
x2 c4 0
x2 c5 0
x2 c6 1
x2 c7 0
x3 obj 5
x3 c0 0
x3 c1 0
x3 c2 0
x3 c3 -1
x3 c4 0
x3 c5 0
x3 c6 0
x3 c7 1
RHS
rhs c0 0
rhs c1 0
rhs c2 0
rhs c3 0
rhs c4 0
rhs c5 0
rhs c6 0
rhs c7 0
BOUNDS
MI BND x0
MI BND x1
@@ -11,23 +11,11 @@ ROWS
COLUMNS
x0 obj 5
x0 c0 -1
x0 c1 0
x0 c2 0
x0 c3 0
x1 obj 5
x1 c0 0
x1 c1 -1
x1 c2 0
x1 c3 0
x2 obj 5
x2 c0 0
x2 c1 0
x2 c2 -1
x2 c3 0
x3 obj 5
x3 c0 0
x3 c1 0
x3 c2 0
x3 c3 -1
RHS
rhs c0 -1