Skip to content

Commit

Permalink
infinite value mixed up fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
cheshmi committed Jun 15, 2020
1 parent 7c9dbd8 commit 4ddf9f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
11 changes: 6 additions & 5 deletions def.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
#else
#define PRINT_CSV(x)
#endif

double max_dbl = 1e20;
double min_dbl = -max_dbl;
#define MAX_DBL 1e20
#define MIN_DBL -MAX_DBL
//double max_dbl = 1e20;
// double min_dbl = -max_dbl;

template <class T> bool is_equal(T a, T b, double threshold = 1e-6){
if(std::isnan(a) || std::isnan(b))
Expand Down Expand Up @@ -361,7 +362,7 @@
bool is_finite(){
bool all_infinite = true;
for (int i = 0; i < row * col; ++i) {
if(a[i] != max_dbl){
if(a[i] != MAX_DBL){
all_infinite = false;
break;
}
Expand All @@ -370,7 +371,7 @@
return false;
all_infinite = true;
for (int i = 0; i < row * col; ++i) {
if(a[i] != min_dbl){
if(a[i] != MIN_DBL){
all_infinite = false;
break;
}
Expand Down
32 changes: 16 additions & 16 deletions mp_format_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ namespace format {
double *l = ld ? ld->a : new double[n_const];
double *u = ud ? ud->a : new double[n_const];
if(!ld)
std::fill_n(l, n_const, min_dbl);
std::fill_n(l, n_const, MIN_DBL);
if(!ud)
std::fill_n(l, n_const, max_dbl);
std::fill_n(l, n_const, MAX_DBL);
//ie_out->b = new Dense(2*n_const,1,1);; a_eq = ie_out->b->a;
ie_out->d = new Dense(2*n_const,1,1);; a_ineq = ie_out->d->a;
ie_out->AT = AT_eq;
Expand All @@ -299,9 +299,9 @@ namespace format {
u[i] = std::abs(u[i]) < 1e-14 ? 0 : u[i];

// Invalid constraint
if ((is_equal(l[i], min_dbl) && is_equal(u[i], max_dbl)) ||
(is_equal(l[i], max_dbl) && is_equal(u[i], max_dbl)) ||
(is_equal(l[i], min_dbl) && is_equal(u[i], min_dbl))) {
if ((is_equal(l[i], MIN_DBL) && is_equal(u[i], MAX_DBL)) ||
(is_equal(l[i], MAX_DBL) && is_equal(u[i], MAX_DBL)) ||
(is_equal(l[i], MIN_DBL) && is_equal(u[i], MIN_DBL))) {
continue;
}
if (is_equal(l[i], u[i])) {//eq
Expand All @@ -315,7 +315,7 @@ namespace format {
} else { // ineq
constraint *c_csnt = new constraint;
c_csnt->idx_no = i;
if (is_equal(l[i], min_dbl)) {//one constraint Ax<=b
if (is_equal(l[i], MIN_DBL)) {//one constraint Ax<=b
a_ineq[num_ineq] = u[i];
num_ineq++;
nnz_ineq += (AT->p[i + 1] - AT->p[i]);
Expand All @@ -324,7 +324,7 @@ namespace format {
for (int j = AT->p[i]; j < AT->p[i + 1]; ++j) {
col_cnt_A_ineq[AT->i[j]]++;
}
} else if (is_equal(u[i], max_dbl)) {//one constraint Ax>=b ==> Ax <= -b
} else if (is_equal(u[i], MAX_DBL)) {//one constraint Ax>=b ==> Ax <= -b
a_ineq[num_ineq] = -l[i];
num_ineq++;
nnz_ineq += (AT->p[i + 1] - AT->p[i]);
Expand Down Expand Up @@ -461,17 +461,17 @@ namespace format {
double *l = ld ? ld->a : new double[n_const];
double *u = ud ? ud->a : new double[n_const];
if(!ld)
std::fill_n(l, n_const, min_dbl);
std::fill_n(l, n_const, MIN_DBL);
if(!ud)
std::fill_n(l, n_const, max_dbl);
std::fill_n(l, n_const, MAX_DBL);
smp_out->b_ = new Dense(n_const,1,1); a_eq = smp_out->b_->a;
smp_out->l_ = new Dense(n_const,1,1); l_ineq = smp_out->l_->a;
smp_out->u_ = new Dense(n_const,1,1); u_ineq = smp_out->u_->a;
smp_out->CT_ = AT_ineq;
for (int i = 0; i < A->m; ++i) {
if ((is_equal(l[i], min_dbl) && is_equal(u[i], max_dbl)) ||
(is_equal(l[i], max_dbl) && is_equal(u[i], max_dbl)) ||
(is_equal(l[i], min_dbl) && is_equal(u[i], min_dbl))) {
if ((is_equal(l[i], MIN_DBL) && is_equal(u[i], MAX_DBL)) ||
(is_equal(l[i], MAX_DBL) && is_equal(u[i], MAX_DBL)) ||
(is_equal(l[i], MIN_DBL) && is_equal(u[i], MIN_DBL))) {
continue;
}
if (is_equal(l[i], u[i])) {//eq
Expand Down Expand Up @@ -625,8 +625,8 @@ namespace format {
a_eq(NULLPNTR), a_ineq(NULLPNTR), H(NULLPNTR), AB_d(NULLPNTR), ab_eqineq(NULLPNTR),
H_d(NULLPNTR), A_d(NULLPNTR), B_d(NULLPNTR), q(NULLPNTR){
mode = 0;
max_dbl = max_dbl;//std::numeric_limits<double >::max();
min_dbl = -max_dbl;//std::numeric_limits<double >::min();
max_dbl = MAX_DBL;//std::numeric_limits<double >::max();
min_dbl = -MAX_DBL;//std::numeric_limits<double >::min();
num_eq = 0;
num_ineq = 0;
nnz_eq = 0;
Expand All @@ -640,8 +640,8 @@ namespace format {
QPFormatConverter(CSC *H_full_in, double *q_in, CSC *A_in, double *l_in, double *u_in) :
H_full(H_full_in), q(q_in), A(A_in), l(l_in), u(u_in) {
mode = 1;
max_dbl = max_dbl;//std::numeric_limits<double >::max();
min_dbl = -max_dbl;//std::numeric_limits<double >::min();
max_dbl = MAX_DBL;//std::numeric_limits<double >::max();
min_dbl = -MAX_DBL;//std::numeric_limits<double >::min();
num_eq = 0;
num_ineq = 0;
nnz_eq = 0;
Expand Down

0 comments on commit 4ddf9f2

Please sign in to comment.