[PPL-devel] [GIT] ppl/ppl(sparse_matrices): Do also read the inhomogeneous term of the objective function.

Enea Zaffanella zaffanella at cs.unipr.it
Sun Aug 29 14:33:05 CEST 2010


Module: ppl/ppl
Branch: sparse_matrices
Commit: c82a27391846139072cadf0754f59f4805f4f99b
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=c82a27391846139072cadf0754f59f4805f4f99b

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Sun Aug 29 11:01:58 2010 +0200

Do also read the inhomogeneous term of the objective function.

This should allow for a (almost) meaningful comparison with the optimizied
value computed by glpk when using command line option -c.

Also corrected a minor bug in the output routine for the objective function
(an open parenthesis was sometimes missing).

---

 demos/ppl_lpsol/ppl_lpsol.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/demos/ppl_lpsol/ppl_lpsol.c b/demos/ppl_lpsol/ppl_lpsol.c
index 3828f6e..fb44b4a 100644
--- a/demos/ppl_lpsol/ppl_lpsol.c
+++ b/demos/ppl_lpsol/ppl_lpsol.c
@@ -1172,7 +1172,12 @@ solve(char* file_name) {
 
   /* Set the ppl_objective_le to be the objective function. */
   ppl_new_Linear_Expression_with_dimension(&ppl_objective_le, dimension);
-  /* The inhomogeneous term is completely useless for our purpose. */
+  /* Set value for objective function's inhomogeneous term. */
+  mpz_mul(tmp_z, den_lcm, mpq_numref(objective[0]));
+  mpz_divexact(tmp_z, tmp_z, mpq_denref(objective[0]));
+  ppl_assign_Coefficient_from_mpz_t(ppl_coeff, tmp_z);
+  ppl_Linear_Expression_add_to_inhomogeneous(ppl_objective_le, ppl_coeff);
+  /* Set values for objective function's variable coefficients. */
   for (i = 1; i <= dimension; ++i) {
     mpz_mul(tmp_z, den_lcm, mpq_numref(objective[i]));
     mpz_divexact(tmp_z, tmp_z, mpq_denref(objective[i]));
@@ -1182,6 +1187,8 @@ solve(char* file_name) {
 
   if (verbosity >= 4) {
     fprintf(output_file, "Objective function:\n");
+    if (mpz_cmp_si(den_lcm, 1) != 0)
+      fprintf(output_file, "(");
     ppl_io_fprint_Linear_Expression(output_file, ppl_objective_le);
   }
 




More information about the PPL-devel mailing list