diff --git a/ppl-glpk-4.52.patch b/ppl-glpk-4.52.patch new file mode 100644 index 0000000..827448d --- /dev/null +++ b/ppl-glpk-4.52.patch @@ -0,0 +1,334 @@ +diff -up ppl-1.0/demos/ppl_lpsol/ppl_lpsol.c.orig ppl-1.0/demos/ppl_lpsol/ppl_lpsol.c +--- ppl-1.0/demos/ppl_lpsol/ppl_lpsol.c.orig 2013-08-06 18:06:15.641556335 -0300 ++++ ppl-1.0/demos/ppl_lpsol/ppl_lpsol.c 2013-08-06 18:21:43.321591859 -0300 +@@ -565,8 +565,7 @@ static mpz_t tmp_z; + static mpq_t tmp1_q; + static mpq_t tmp2_q; + static ppl_Coefficient_t ppl_coeff; +-static LPX* glpk_lp; +-static int glpk_lp_problem_kind; ++static glp_prob* glpk_lp; + static int glpk_lp_num_int; + static ppl_dimension_type* integer_variables; + +@@ -576,40 +575,50 @@ maybe_check_results(const int ppl_status + const char* glpk_status_string; + int glpk_status; + int treat_as_lp = 0; ++ glp_smcp glpk_smcp; ++ + if (!check_results) + return; + +- /* Disable GLPK output. */ +- lpx_set_int_parm(glpk_lp, LPX_K_MSGLEV, 0); +- +- if (no_mip || glpk_lp_problem_kind == LPX_LP) ++ if (no_mip || glpk_lp_num_int == 0) + treat_as_lp = 1; + +- lpx_set_obj_dir(glpk_lp, (maximize ? LPX_MAX : LPX_MIN)); ++ glp_set_obj_dir(glpk_lp, (maximize ? GLP_MAX : GLP_MIN)); ++ ++ glp_init_smcp(&glpk_smcp); ++ /* Disable GLPK output. */ ++ glpk_smcp.msg_lev = GLP_MSG_OFF; + + if (treat_as_lp) { + /* Set the problem class to LP: MIP problems are thus treated as + LP ones. */ +- lpx_set_class(glpk_lp, LPX_LP); +- lpx_exact(glpk_lp); +- glpk_status = lpx_get_status(glpk_lp); ++ glp_exact(glpk_lp, &glpk_smcp); ++ glpk_status = glp_get_status(glpk_lp); + } + else { + /* MIP case. */ +- lpx_intopt(glpk_lp); +- glpk_status = lpx_mip_status(glpk_lp); ++ glp_simplex(glpk_lp, &glpk_smcp); ++ glpk_status = glp_get_status(glpk_lp); ++ if (glpk_status != GLP_NOFEAS && glpk_status != GLP_UNBND) { ++ glp_iocp glpk_iocp; ++ glp_init_iocp(&glpk_iocp); ++ /* Disable GLPK output. */ ++ glpk_iocp.msg_lev = GLP_MSG_OFF; ++ glp_intopt(glpk_lp, &glpk_iocp); ++ glpk_status = glp_mip_status(glpk_lp); ++ } + } + /* If no_optimization is enabled, the second case is not possibile. */ + if (!((ppl_status == PPL_MIP_PROBLEM_STATUS_UNFEASIBLE +- && (glpk_status == LPX_NOFEAS || glpk_status == LPX_I_NOFEAS)) ++ && glpk_status == GLP_NOFEAS) + || (ppl_status == PPL_MIP_PROBLEM_STATUS_UNBOUNDED +- && (glpk_status == LPX_UNBND || glpk_status == LPX_I_UNDEF)) ++ && glpk_status == GLP_UNBND) + || (ppl_status == PPL_MIP_PROBLEM_STATUS_OPTIMIZED +- && ((glpk_status == LPX_OPT || glpk_status == LPX_I_OPT) ++ && (glpk_status == GLP_OPT + /* If no_optimization is enabled, check if the problem is + unbounded for GLPK. */ +- || (no_optimization && (glpk_status == LPX_UNBND +- || glpk_status == LPX_I_UNDEF)))))) { ++ || (no_optimization && (glpk_status == GLP_UNBND ++ || glpk_status == GLP_UNDEF)))))) { + + if (ppl_status == PPL_MIP_PROBLEM_STATUS_UNFEASIBLE) + ppl_status_string = "unfeasible"; +@@ -621,22 +630,16 @@ maybe_check_results(const int ppl_status + ppl_status_string = ""; + + switch (glpk_status) { +- case LPX_NOFEAS: ++ case GLP_NOFEAS: + glpk_status_string = "unfeasible"; + break; +- case LPX_UNBND: ++ case GLP_UNBND: + glpk_status_string = "unbounded"; + break; +- case LPX_OPT: +- glpk_status_string = "optimizable"; +- break; +- case LPX_I_NOFEAS: +- glpk_status_string = "unfeasible"; +- break; +- case LPX_I_OPT: ++ case GLP_OPT: + glpk_status_string = "optimizable"; + break; +- case LPX_I_UNDEF: ++ case GLP_UNDEF: + glpk_status_string = "undefined"; + break; + default: +@@ -652,8 +655,8 @@ maybe_check_results(const int ppl_status + else if (!no_optimization + && ppl_status == PPL_MIP_PROBLEM_STATUS_OPTIMIZED) { + +- double glpk_optimum_value = treat_as_lp ? lpx_get_obj_val(glpk_lp) +- : lpx_mip_obj_val(glpk_lp); ++ double glpk_optimum_value ++ = (treat_as_lp ? glp_get_obj_val(glpk_lp) : glp_mip_obj_val(glpk_lp)); + + if (fabs(ppl_optimum_value - glpk_optimum_value) > check_threshold) { + error("check failed: for GLPK the problem's optimum is %.20g," +@@ -667,7 +670,7 @@ maybe_check_results(const int ppl_status + + static const char* + variable_output_function(ppl_dimension_type var) { +- const char* name = lpx_get_col_name(glpk_lp, var+1); ++ const char* name = glp_get_col_name(glpk_lp, var+1); + if (name != NULL) + return name; + else +@@ -681,10 +684,10 @@ add_constraints(ppl_Linear_Expression_t + ppl_Constraint_t ppl_c; + ppl_Linear_Expression_t ppl_le2; + switch (type) { +- case LPX_FR: ++ case GLP_FR: + break; + +- case LPX_LO: ++ case GLP_LO: + mpz_mul(tmp_z, den_lcm, mpq_numref(rational_lb)); + mpz_divexact(tmp_z, tmp_z, mpq_denref(rational_lb)); + mpz_neg(tmp_z, tmp_z); +@@ -699,7 +702,7 @@ add_constraints(ppl_Linear_Expression_t + ppl_delete_Constraint(ppl_c); + break; + +- case LPX_UP: ++ case GLP_UP: + mpz_mul(tmp_z, den_lcm, mpq_numref(rational_ub)); + mpz_divexact(tmp_z, tmp_z, mpq_denref(rational_ub)); + mpz_neg(tmp_z, tmp_z); +@@ -715,7 +718,7 @@ add_constraints(ppl_Linear_Expression_t + ppl_delete_Constraint(ppl_c); + break; + +- case LPX_DB: ++ case GLP_DB: + ppl_new_Linear_Expression_from_Linear_Expression(&ppl_le2, ppl_le); + + mpz_mul(tmp_z, den_lcm, mpq_numref(rational_lb)); +@@ -746,7 +749,7 @@ add_constraints(ppl_Linear_Expression_t + ppl_delete_Constraint(ppl_c); + break; + +- case LPX_FX: ++ case GLP_FX: + mpz_mul(tmp_z, den_lcm, mpq_numref(rational_lb)); + mpz_divexact(tmp_z, tmp_z, mpq_denref(rational_lb)); + mpz_neg(tmp_z, tmp_z); +@@ -1032,6 +1035,14 @@ solve(char* file_name) { + mpq_t optimum; + mpz_t den_lcm; + int optimum_found; ++ glp_mpscp glpk_mpscp; ++ ++ glpk_lp = glp_create_prob(); ++ glp_init_mpscp(&glpk_mpscp); ++ ++ if (verbosity == 0) { ++ /* FIXME: find a way to suppress output from glp_read_mps. */ ++ } + + #ifdef PPL_LPSOL_SUPPORTS_TIMINGS + +@@ -1040,13 +1051,7 @@ solve(char* file_name) { + + #endif /* defined(PPL_LPSOL_SUPPORTS_TIMINGS) */ + +- if (verbosity == 0) { +- /* FIXME: find a way to suppress output from lpx_read_mps. */ +- } +- +- glpk_lp = lpx_read_mps(file_name); +- +- if (glpk_lp == NULL) ++ if (glp_read_mps(glpk_lp, GLP_MPS_FILE, &glpk_mpscp, file_name) != 0) + fatal("cannot read MPS file `%s'", file_name); + + #ifdef PPL_LPSOL_SUPPORTS_TIMINGS +@@ -1060,29 +1065,31 @@ solve(char* file_name) { + + #endif /* defined(PPL_LPSOL_SUPPORTS_TIMINGS) */ + +- glpk_lp_problem_kind = lpx_get_class(glpk_lp); +- if (glpk_lp_problem_kind == LPX_MIP && !no_mip && !use_simplex) ++ glpk_lp_num_int = glp_get_num_int(glpk_lp); ++ ++ if (glpk_lp_num_int > 0 && !no_mip && !use_simplex) + fatal("the enumeration solving method can not handle MIP problems"); + +- dimension = lpx_get_num_cols(glpk_lp); ++ dimension = glp_get_num_cols(glpk_lp); + + /* Read variables constrained to be integer. */ +- if (glpk_lp_problem_kind == LPX_MIP && !no_mip && use_simplex) { +- if (verbosity >= 4) +- fprintf(output_file, "Integer variables:\n"); +- glpk_lp_num_int = lpx_get_num_int(glpk_lp); +- integer_variables = (ppl_dimension_type*) +- malloc((glpk_lp_num_int + 1)*sizeof(ppl_dimension_type)); +- for (i = 0, j = 0; i < dimension; ++i) +- if (lpx_get_col_kind(glpk_lp, i+1) == LPX_IV) { +- integer_variables[j] = i; +- if (verbosity >= 4) { +- ppl_io_fprint_variable(output_file, i); +- fprintf(output_file, " "); +- } +- ++j; +- } ++ if (glpk_lp_num_int > 0 && !no_mip && use_simplex) { ++ if (verbosity >= 4) ++ fprintf(output_file, "Integer variables:\n"); ++ integer_variables = (ppl_dimension_type*) ++ malloc((glpk_lp_num_int + 1)*sizeof(ppl_dimension_type)); ++ for (i = 0, j = 0; i < dimension; ++i) { ++ int col_kind = glp_get_col_kind(glpk_lp, i+1); ++ if (col_kind == GLP_IV || col_kind == GLP_BV) { ++ integer_variables[j] = i; ++ if (verbosity >= 4) { ++ ppl_io_fprint_variable(output_file, i); ++ fprintf(output_file, " "); ++ } ++ ++j; ++ } + } ++ } + coefficient_index = (int*) malloc((dimension+1)*sizeof(int)); + coefficient_value = (double*) malloc((dimension+1)*sizeof(double)); + rational_coefficient = (mpq_t*) malloc((dimension+1)*sizeof(mpq_t)); +@@ -1101,21 +1108,25 @@ solve(char* file_name) { + fprintf(output_file, "\nConstraints:\n"); + + /* Set up the row (ordinary) constraints. */ +- num_rows = lpx_get_num_rows(glpk_lp); ++ num_rows = glp_get_num_rows(glpk_lp); + for (row = 1; row <= num_rows; ++row) { + /* Initialize the least common multiple computation. */ + mpz_set_si(den_lcm, 1); + /* Set `nz' to the number of non-zero coefficients. */ +- nz = lpx_get_mat_row(glpk_lp, row, coefficient_index, coefficient_value); ++ nz = glp_get_mat_row(glpk_lp, row, coefficient_index, coefficient_value); + for (i = 1; i <= nz; ++i) { + set_mpq_t_from_double(rational_coefficient[i], coefficient_value[i]); + /* Update den_lcm. */ + mpz_lcm(den_lcm, den_lcm, mpq_denref(rational_coefficient[i])); + } +- lpx_get_row_bnds(glpk_lp, row, &type, &lb, &ub); ++ ++ lb = glp_get_row_lb(glpk_lp, row); ++ ub = glp_get_row_ub(glpk_lp, row); ++ + set_mpq_t_from_double(rational_lb, lb); +- mpz_lcm(den_lcm, den_lcm, mpq_denref(rational_lb)); + set_mpq_t_from_double(rational_ub, ub); ++ ++ mpz_lcm(den_lcm, den_lcm, mpq_denref(rational_lb)); + mpz_lcm(den_lcm, den_lcm, mpq_denref(rational_ub)); + + ppl_new_Linear_Expression_with_dimension(&ppl_le, dimension); +@@ -1128,6 +1139,7 @@ solve(char* file_name) { + ppl_coeff); + } + ++ type = glp_get_row_type(glpk_lp, row); + add_constraints(ppl_le, type, rational_lb, rational_ub, den_lcm, ppl_cs); + + ppl_delete_Linear_Expression(ppl_le); +@@ -1150,7 +1162,9 @@ solve(char* file_name) { + + /* Set up the columns constraints, i.e., variable bounds. */ + for (column = 1; column <= dimension; ++column) { +- lpx_get_col_bnds(glpk_lp, column, &type, &lb, &ub); ++ ++ lb = glp_get_col_lb(glpk_lp, column); ++ ub = glp_get_col_ub(glpk_lp, column); + + set_mpq_t_from_double(rational_lb, lb); + set_mpq_t_from_double(rational_ub, ub); +@@ -1164,6 +1178,7 @@ solve(char* file_name) { + ppl_assign_Coefficient_from_mpz_t(ppl_coeff, den_lcm); + ppl_Linear_Expression_add_to_coefficient(ppl_le, column-1, ppl_coeff); + ++ type = glp_get_col_type(glpk_lp, column); + add_constraints(ppl_le, type, rational_lb, rational_ub, den_lcm, ppl_cs); + + ppl_delete_Linear_Expression(ppl_le); +@@ -1179,10 +1194,10 @@ solve(char* file_name) { + mpz_set_si(den_lcm, 1); + + mpq_init(objective[0]); +- set_mpq_t_from_double(objective[0], lpx_get_obj_coef(glpk_lp, 0)); ++ set_mpq_t_from_double(objective[0], glp_get_obj_coef(glpk_lp, 0)); + for (i = 1; i <= dimension; ++i) { + mpq_init(objective[i]); +- set_mpq_t_from_double(objective[i], lpx_get_obj_coef(glpk_lp, i)); ++ set_mpq_t_from_double(objective[i], glp_get_obj_coef(glpk_lp, i)); + /* Update den_lcm. */ + mpz_lcm(den_lcm, den_lcm, mpq_denref(objective[i])); + } +@@ -1240,7 +1255,7 @@ solve(char* file_name) { + + ppl_delete_Linear_Expression(ppl_objective_le); + +- if (glpk_lp_problem_kind == LPX_MIP) ++ if (glpk_lp_num_int > 0) + free(integer_variables); + + if (optimum_found) { +@@ -1287,7 +1302,7 @@ solve(char* file_name) { + ppl_delete_Coefficient(optimum_n); + ppl_delete_Generator(optimum_location); + +- lpx_delete_prob(glpk_lp); ++ glp_delete_prob(glpk_lp); + } + + static void diff --git a/ppl.spec b/ppl.spec index 6d720a2..c9006c1 100644 --- a/ppl.spec +++ b/ppl.spec @@ -20,7 +20,9 @@ Provides: libppl.so.9()(64bit) %else Provides: libppl.so.9 %endif +# Both patches backported from http://www.cs.unipr.it/git/?p=ppl/ppl.git Patch0: %{name}-gmp-5.1.0.patch +Patch1: %{name}-glpk-4.52.patch %description The Parma Polyhedra Library (PPL) is a library for the manipulation of @@ -155,6 +157,7 @@ Install this package if you want to program with the PPL. %prep %setup -q %patch0 -p1 +%patch1 -p1 %build CPPFLAGS="-I%{_includedir}/glpk"