[C++] Fix GLPK bound type.
@@ -13,20 +13,26 @@ void intersection (const Bound& a, const Bound& b, Bound& c)
c[1] = std::min(a[1], b[1]);
}
+int bnd_type(const value_type& l, const value_type& u)
+{
+ if (l == -infty) {
+ if (u == infty) return GLP_FR;
+ else return GLP_UP;
+ } else {
+ if (l == u) return GLP_FX;
+ else if (u == infty) return GLP_LO;
+ else return GLP_DB;
+ }
+}
+
void set_col_bnds(glp_prob* lp, int i, const Bound& ub)
{
- glp_set_col_bnds(lp, i, (ub[0] == -infty
- ? (ub[1] == infty ? GLP_FR : GLP_UP)
- : (ub[1] == infty ? GLP_LO : GLP_DB)
- ), ub[0], ub[1]);
+ glp_set_col_bnds(lp, i, bnd_type(ub[0], ub[1]), ub[0], ub[1]);
}
void set_row_bnds(glp_prob* lp, int i, const value_type& l, const value_type& u)
{
- glp_set_row_bnds(lp, i, (l == -infty
- ? (u == infty ? GLP_FR : GLP_UP)
- : (u == infty ? GLP_LO : GLP_DB)
- ), l, u);
+ glp_set_row_bnds(lp, i, bnd_type(l,u), l, u);
}
void set_row_bnds(glp_prob* lp, int i, const Bound& b) { set_row_bnds(lp, i, b[0], b[1]); }
