[gnumeric] Solver: fix problems with constraints and affine parts.



commit 7c2cdb4a0ef43eeabc1618df1d351395fbcd3970
Author: Morten Welinder <terra gnome org>
Date:   Sat Feb 26 08:55:19 2011 -0500

    Solver: fix problems with constraints and affine parts.

 NEWS                            |    2 ++
 plugins/glpk/ChangeLog          |    4 ++++
 plugins/glpk/glpk-write.c       |    8 +++++++-
 plugins/lpsolve/ChangeLog       |    5 +++++
 plugins/lpsolve/lpsolve-write.c |    8 +++++++-
 src/xml-sax-read.c              |   25 ++++++++++++++++++++-----
 6 files changed, 45 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index 26f6a81..4eb4340 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,8 @@ Morten:
 	* Fix stf import problem diagnosed by Andreas.  [#642477]
 	* Restore toolbar positioning code.
 	* Fix solver crash.  [Redhat #680572]
+	* Fix xml reading of constraints.  [Redhat #680572]
+	* Fix lpsolve/glpk writing of affine part.
 
 --------------------------------------------------------------------------
 Gnumeric 1.10.13
diff --git a/plugins/glpk/ChangeLog b/plugins/glpk/ChangeLog
index 624ba81..aecf006 100644
--- a/plugins/glpk/ChangeLog
+++ b/plugins/glpk/ChangeLog
@@ -1,3 +1,7 @@
+2011-02-26  Morten Welinder  <terra gnome org>
+
+	* glpk-write.c (glpk_affine_func): Fix writing of affine part.
+
 2011-02-02  Morten Welinder <terra gnome org>
 
 	* Release 1.10.13
diff --git a/plugins/glpk/glpk-write.c b/plugins/glpk/glpk-write.c
index 5335835..4582373 100644
--- a/plugins/glpk/glpk-write.c
+++ b/plugins/glpk/glpk-write.c
@@ -138,8 +138,14 @@ glpk_affine_func (GString *dst, GnmCell *target, GnmSubSolver *ssol,
 		any = TRUE;
 	}
 
-	if (!any || y)
+	if (!any || y) {
+		if (any) {
+			g_string_append_c (dst, ' ');
+			if (y > 0)
+				g_string_append_c (dst, '+');
+		}
 		gnm_string_add_number (dst, y);
+	}
 
 fail:
  	for (l = input_cells, ol = old_values;
diff --git a/plugins/lpsolve/ChangeLog b/plugins/lpsolve/ChangeLog
index 11d7374..8992288 100644
--- a/plugins/lpsolve/ChangeLog
+++ b/plugins/lpsolve/ChangeLog
@@ -1,3 +1,8 @@
+2011-02-26  Morten Welinder  <terra gnome org>
+
+	* lpsolve-write.c (lpsolve_affine_func): Fix writing of affine
+	part.
+
 2011-02-02  Morten Welinder <terra gnome org>
 
 	* Release 1.10.13
diff --git a/plugins/lpsolve/lpsolve-write.c b/plugins/lpsolve/lpsolve-write.c
index 1766017..ef1c5b5 100644
--- a/plugins/lpsolve/lpsolve-write.c
+++ b/plugins/lpsolve/lpsolve-write.c
@@ -141,8 +141,14 @@ lpsolve_affine_func (GString *dst, GnmCell *target, GnmSubSolver *ssol,
 		any = TRUE;
 	}
 
-	if (!any || y)
+	if (!any || y) {
+		if (any) {
+			g_string_append_c (dst, ' ');
+			if (y > 0)
+				g_string_append_c (dst, '+');
+		}
 		gnm_string_add_number (dst, y);
+	}
 
 fail:
  	for (l = input_cells, ol = old_values;
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index ba56fd5..55de28d 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -61,6 +61,7 @@
 #include "application.h"
 #include "gutils.h"
 #include "clipboard.h"
+#include "number-match.h"
 
 #include <goffice/goffice.h>
 
@@ -2382,6 +2383,21 @@ xml_sax_object_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 	 */
 }
 
+static GnmValue *
+parse_contraint_side (const char *s, const GnmParsePos *pp)
+{
+	GODateConventions const *date_conv =
+		workbook_date_conv (pp->sheet->workbook);
+	GnmValue *v = format_match_number (s, NULL, date_conv);
+
+	if (!v) {
+		GnmExprParseFlags flags = GNM_EXPR_PARSE_DEFAULT;
+		v = value_new_cellrange_parsepos_str (pp, s, flags);
+	}
+
+	return v;
+}
+
 static void
 xml_sax_solver_constr_start (GsfXMLIn *xin, xmlChar const **attrs)
 {
@@ -2393,7 +2409,6 @@ xml_sax_solver_constr_start (GsfXMLIn *xin, xmlChar const **attrs)
 	int cols = 1, rows = 1;
 	gboolean old = FALSE;
 	GnmParsePos pp;
-	GnmExprParseFlags flags = GNM_EXPR_PARSE_DEFAULT;
 
 	c = gnm_solver_constraint_new (sheet);
 
@@ -2410,12 +2425,12 @@ xml_sax_solver_constr_start (GsfXMLIn *xin, xmlChar const **attrs)
 		else if (gnm_xml_attr_int (attrs, "Type", &type))
 			; /* Nothing */
 		else if (attr_eq (attrs[0], "lhs")) {
-			GnmValue *v = value_new_cellrange_parsepos_str
-				(&pp, CXML2C (attrs[1]), flags);
+			GnmValue *v = parse_contraint_side (CXML2C (attrs[1]),
+							    &pp);
 			gnm_solver_constraint_set_lhs (c, v);
 		} else if (attr_eq (attrs[0], "rhs")) {
-			GnmValue *v = value_new_cellrange_parsepos_str
-				(&pp, CXML2C (attrs[1]), flags);
+			GnmValue *v = parse_contraint_side (CXML2C (attrs[1]),
+							    &pp);
 			gnm_solver_constraint_set_rhs (c, v);
 		}
 	}



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