[gnumeric] glpk: partial support for sensitivity analysis.



commit 79e8f6b3250f50f181b1a84c647e49f017c2b702
Author: Morten Welinder <terra gnome org>
Date:   Wed Feb 10 23:01:12 2016 -0500

    glpk: partial support for sensitivity analysis.

 plugins/glpk/glpk-write.c |   10 +++++++++-
 plugins/glpk/gnm-glpk.c   |    7 +++++++
 2 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/plugins/glpk/glpk-write.c b/plugins/glpk/glpk-write.c
index aa9b981..9768102 100644
--- a/plugins/glpk/glpk-write.c
+++ b/plugins/glpk/glpk-write.c
@@ -220,6 +220,7 @@ glpk_create_program (GnmSubSolver *ssol, GOIOContext *io_context, GError **err)
                GnmSolverConstraint *c = l->data;
                const char *op = NULL;
                int i;
+               int cidx = 0;
                gnm_float cl, cr;
                GnmCell *lhs, *rhs;
                GString *type = NULL;
@@ -248,16 +249,23 @@ glpk_create_program (GnmSubSolver *ssol, GOIOContext *io_context, GError **err)
                     gnm_solver_constraint_get_part (c, sp, i,
                                                     &lhs, &cl,
                                                     &rhs, &cr);
-                    i++) {
+                    i++, cidx++) {
                        if (type) {
                                g_string_append_printf
                                        (type, " %s\n",
                                         glpk_var_name (ssol, lhs));
                        } else {
                                gboolean ok;
+                               char *name;
 
                                g_string_append_c (constraints, ' ');
 
+                               name = g_strdup_printf ("C_%d", cidx);
+                               gnm_sub_solver_name_constraint (ssol, cidx, name);
+                               g_string_append (constraints, name);
+                               g_string_append (constraints, ": ");
+                               g_free (name);
+
                                ok = glpk_affine_func
                                        (constraints, lhs, ssol,
                                         x1, x2,
diff --git a/plugins/glpk/gnm-glpk.c b/plugins/glpk/gnm-glpk.c
index c342604..53d9195 100644
--- a/plugins/glpk/gnm-glpk.c
+++ b/plugins/glpk/gnm-glpk.c
@@ -73,6 +73,7 @@ gnm_glpk_read_solution (GnmGlpk *lp)
        int pstat, dstat;
        gnm_float val;
        GnmSolverResult *result;
+       GnmSolverSensitivity *sensitivity;
        gboolean has_integer;
        GSList *l;
 
@@ -97,6 +98,8 @@ gnm_glpk_read_solution (GnmGlpk *lp)
        result = g_object_new (GNM_SOLVER_RESULT_TYPE, NULL);
        result->solution = g_new0 (gnm_float, sol->input_cells->len);
 
+       sensitivity = gnm_solver_sensitivity_new (sol);
+
        if ((line = gsf_input_textline_utf8_gets (tl)) == NULL)
                goto fail;
        if (sscanf (line, "%u %u", &rows, &cols) != 2 ||
@@ -150,11 +153,15 @@ gnm_glpk_read_solution (GnmGlpk *lp)
                        goto fail;
 
                result->solution[idx] = pval;
+               if (!has_integer)
+                       sensitivity->vars[idx].reduced_cost = dval;
        }
 
        gnm_solver_set_status (sol, GNM_SOLVER_STATUS_DONE);
        g_object_set (subsol, "result", result, NULL);
        g_object_unref (result);
+       g_object_set (subsol, "sensitivity", sensitivity, NULL);
+       g_object_unref (sensitivity);
 
        g_object_unref (tl);
        return;


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