[gnumeric] glpk: fix cplex exporter problem.



commit 06085f240d6d9ba402f38e09323acf1c721439a9
Author: Morten Welinder <terra gnome org>
Date:   Wed Feb 10 23:11:01 2016 -0500

    glpk: fix cplex exporter problem.
    
    If the bounds section is missing, a lower limit of 0 is assumed for all
    variables.

 NEWS                      |    1 +
 plugins/glpk/ChangeLog    |    2 ++
 plugins/glpk/glpk-write.c |   18 ++++++++++++++----
 3 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index 3fec7e5..fa6671f 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Morten:
        * Plug leak.
        * Fix problems with ssconvert to lp/cplex formats.
        * Add sensitivity report to solver.  (lpsolve only for now.)
+       * Fix bounds problem with cplex exporter.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.27
diff --git a/plugins/glpk/ChangeLog b/plugins/glpk/ChangeLog
index 4e07967..426bd96 100644
--- a/plugins/glpk/ChangeLog
+++ b/plugins/glpk/ChangeLog
@@ -3,6 +3,8 @@
        * glpk-write.c (glpk_file_save):  Handle the situation where
        there is no assigned solver -- i.e., plain ssconvert -- by
        creating a temporary.
+       (glpk_create_program): Create a bounds section explicitly as
+       otherwise a lower limit of 0 is assumed.
 
 2016-02-06  Morten Welinder <terra gnome org>
 
diff --git a/plugins/glpk/glpk-write.c b/plugins/glpk/glpk-write.c
index 9768102..d1cdad9 100644
--- a/plugins/glpk/glpk-write.c
+++ b/plugins/glpk/glpk-write.c
@@ -124,6 +124,7 @@ glpk_create_program (GnmSubSolver *ssol, GOIOContext *io_context, GError **err)
        GnmSolverParameters *sp = sol->params;
        GString *prg = NULL;
        GString *constraints = g_string_new (NULL);
+       GString *bounds = g_string_new (NULL);
        GString *binaries = g_string_new (NULL);
        GString *integers = g_string_new (NULL);
        GString *objfunc = g_string_new (NULL);
@@ -160,7 +161,7 @@ glpk_create_program (GnmSubSolver *ssol, GOIOContext *io_context, GError **err)
        /* ---------------------------------------- */
 
        progress = 3;
-       if (sp->options.assume_non_negative) progress++;
+       /* assume_non_negative */ progress++;
        if (sp->options.assume_discrete) progress++;
        progress += g_slist_length (sp->constraints);
 
@@ -196,12 +197,15 @@ glpk_create_program (GnmSubSolver *ssol, GOIOContext *io_context, GError **err)
 
        /* ---------------------------------------- */
 
-       if (sp->options.assume_non_negative) {
+       {
                unsigned ui;
                for (ui = 0; ui < input_cells->len; ui++) {
                        GnmCell *cell = g_ptr_array_index (input_cells, ui);
-                       g_string_append_printf (constraints, " %s >= 0\n",
-                                               glpk_var_name (ssol, cell));
+                       const char *name = glpk_var_name (ssol, cell);
+                       if (sp->options.assume_non_negative)
+                               g_string_append_printf (bounds, " %s >= 0\n", name);
+                       else
+                               g_string_append_printf (bounds, " %s free\n", name);
                }
                go_io_count_progress_update (io_context, 1);
        }
@@ -298,8 +302,13 @@ glpk_create_program (GnmSubSolver *ssol, GOIOContext *io_context, GError **err)
                                "\\ Created by Gnumeric %s\n\n",
                                GNM_VERSION_FULL);
        go_string_append_gstring (prg, objfunc);
+
        g_string_append (prg, "\nSubject to\n");
        go_string_append_gstring (prg, constraints);
+
+       g_string_append (prg, "\nBounds\n");
+       go_string_append_gstring (prg, bounds);
+
        if (integers->len > 0) {
                g_string_append (prg, "\nGeneral\n");
                go_string_append_gstring (prg, integers);
@@ -313,6 +322,7 @@ glpk_create_program (GnmSubSolver *ssol, GOIOContext *io_context, GError **err)
 fail:
        g_string_free (objfunc, TRUE);
        g_string_free (constraints, TRUE);
+       g_string_free (bounds, TRUE);
        g_string_free (integers, TRUE);
        g_string_free (binaries, TRUE);
        g_free (x1);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]