[gnumeric] solver: allow constants on right-hand side of constaints.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] solver: allow constants on right-hand side of constaints.
- Date: Fri, 13 Nov 2009 02:37:19 +0000 (UTC)
commit 29516a7692bb27662cc502fdb1aa5bcaf19cd7fe
Author: Morten Welinder <terra gnome org>
Date: Thu Nov 12 21:36:39 2009 -0500
solver: allow constants on right-hand side of constaints.
NEWS | 1 +
plugins/lpsolve/ChangeLog | 5 +++++
plugins/lpsolve/lpsolve-write.c | 17 ++++++++++++-----
src/dialogs/ChangeLog | 5 +++++
src/dialogs/dialog-solver.c | 8 +++++---
src/widgets/ChangeLog | 6 ++++++
src/widgets/gnumeric-expr-entry.c | 18 ++++++++++++++----
src/widgets/gnumeric-expr-entry.h | 3 ++-
8 files changed, 50 insertions(+), 13 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7781ea8..bf96c3e 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Morten:
* Plug another mps leak.
* Fix problem with remote uris. [#601274]
* Use external solver program.
+ * Allow constants on solver constraints' rhs. [#369728]
--------------------------------------------------------------------------
Gnumeric 1.9.15
diff --git a/plugins/lpsolve/ChangeLog b/plugins/lpsolve/ChangeLog
index 7f7db90..2ebfed1 100644
--- a/plugins/lpsolve/ChangeLog
+++ b/plugins/lpsolve/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-12 Morten Welinder <terra gnome org>
+
+ * lpsolve-write.c (lpsolve_affine_func): Add cst argument and
+ handle the no-cell case. All callers changed.
+
2009-11-11 Morten Welinder <terra gnome org>
* lpsolve-write.c (lpsolve_affine_func): Zero all input cells
diff --git a/plugins/lpsolve/lpsolve-write.c b/plugins/lpsolve/lpsolve-write.c
index 6cbbdd4..29cf6f0 100644
--- a/plugins/lpsolve/lpsolve-write.c
+++ b/plugins/lpsolve/lpsolve-write.c
@@ -83,7 +83,7 @@ lpsolve_var_name (GnmCell const *cell)
}
static gboolean
-lpsolve_affine_func (GString *dst, GnmCell *target,
+lpsolve_affine_func (GString *dst, GnmCell *target, gnm_float cst,
GSList *input_cells, GError **err)
{
GSList *l, *ol;
@@ -92,6 +92,11 @@ lpsolve_affine_func (GString *dst, GnmCell *target,
GSList *old_values = NULL;
gboolean ok = TRUE;
+ if (!target) {
+ gnm_string_add_number (dst, cst);
+ return TRUE;
+ }
+
for (l = input_cells; l; l = l->next) {
GnmCell *cell = l->data;
old_values = g_slist_prepend (old_values,
@@ -102,7 +107,7 @@ lpsolve_affine_func (GString *dst, GnmCell *target,
old_values = g_slist_reverse (old_values);
gnm_cell_eval (target);
- y = value_get_as_float (target->value);
+ y = cst + value_get_as_float (target->value);
for (l = input_cells; l; l = l->next) {
GnmCell *cell = l->data;
@@ -187,7 +192,7 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context, GError **err)
}
go_io_count_progress_update (io_context, 1);
- if (!lpsolve_affine_func (objfunc, target_cell, input_cells, err))
+ if (!lpsolve_affine_func (objfunc, target_cell, 0, input_cells, err))
goto fail;
g_string_append (objfunc, ";\n");
go_io_count_progress_update (io_context, 1);
@@ -261,7 +266,8 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context, GError **err)
gboolean ok;
ok = lpsolve_affine_func
- (constraints, lhs, input_cells, err);
+ (constraints, lhs, cl,
+ input_cells, err);
if (!ok)
goto fail;
@@ -270,7 +276,8 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context, GError **err)
g_string_append_c (constraints, ' ');
ok = lpsolve_affine_func
- (constraints, rhs, input_cells, err);
+ (constraints, rhs, cr,
+ input_cells, err);
if (!ok)
goto fail;
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 66adfa8..a1d2bb7 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-12 Morten Welinder <terra gnome org>
+
+ * dialog-solver.c (dialog_init): Set GNM_EE_CONSTANT_ALLOWED for
+ rhs.
+
2009-11-11 Morten Welinder <terra gnome org>
* dialog-solver.c (cb_notify_result): i18n issues.
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index bae1bbc..366c597 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -938,9 +938,11 @@ dialog_init (SolverState *state)
table = GTK_TABLE (glade_xml_get_widget (state->gui, "edit-table"));
state->rhs.entry = gnm_expr_entry_new (state->wbcg, TRUE);
gnm_expr_entry_set_flags (state->rhs.entry,
- GNM_EE_SINGLE_RANGE |
- GNM_EE_FORCE_ABS_REF |
- GNM_EE_SHEET_OPTIONAL, GNM_EE_MASK);
+ GNM_EE_SINGLE_RANGE |
+ GNM_EE_FORCE_ABS_REF |
+ GNM_EE_SHEET_OPTIONAL |
+ GNM_EE_CONSTANT_ALLOWED,
+ GNM_EE_MASK);
gtk_table_attach (table, GTK_WIDGET (state->rhs.entry),
2, 3, 1, 2,
GTK_EXPAND | GTK_FILL, 0, 0, 0);
diff --git a/src/widgets/ChangeLog b/src/widgets/ChangeLog
index 82c8868..70537f8 100644
--- a/src/widgets/ChangeLog
+++ b/src/widgets/ChangeLog
@@ -1,3 +1,9 @@
+2009-11-12 Morten Welinder <terra gnome org>
+
+ * gnumeric-expr-entry.c (gnm_expr_entry_parse_as_value): If new
+ flag GNM_EE_CONSTANT_ALLOWED is set, also allow a numeric
+ constant.
+
2009-11-01 Morten Welinder <terra gnome org>
* Release 1.9.15
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index de35606..959a143 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -1757,6 +1757,8 @@ gnm_expr_entry_parse_as_value (GnmExprEntry *gee, Sheet *sheet)
{
GnmParsePos pp;
GnmExprParseFlags flags = GNM_EXPR_PARSE_UNKNOWN_NAMES_ARE_STRINGS;
+ GnmValue *v;
+ const char *txt;
g_return_val_if_fail (IS_GNM_EXPR_ENTRY (gee), NULL);
@@ -1767,10 +1769,18 @@ gnm_expr_entry_parse_as_value (GnmExprEntry *gee, Sheet *sheet)
if (!(gee->flags & GNM_EE_SHEET_OPTIONAL))
flags |= GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES;
- return value_new_cellrange_parsepos_str
- (parse_pos_init_sheet (&pp, sheet),
- gtk_entry_get_text (gnm_expr_entry_get_entry (gee)),
- flags);
+ txt = gtk_entry_get_text (gnm_expr_entry_get_entry (gee));
+
+ parse_pos_init_sheet (&pp, sheet);
+ v = value_new_cellrange_parsepos_str (&pp, txt, flags);
+
+ if (!v && (gee->flags & GNM_EE_CONSTANT_ALLOWED)) {
+ GODateConventions const *date_conv =
+ sheet ? workbook_date_conv (sheet->workbook) : NULL;
+ v = format_match_number (txt, NULL, date_conv);
+ }
+
+ return v;
}
/**
diff --git a/src/widgets/gnumeric-expr-entry.h b/src/widgets/gnumeric-expr-entry.h
index 43685a3..1f42dfd 100644
--- a/src/widgets/gnumeric-expr-entry.h
+++ b/src/widgets/gnumeric-expr-entry.h
@@ -20,7 +20,8 @@ typedef enum {
GNM_EE_FULL_ROW = 1 << 5,
GNM_EE_SHEET_OPTIONAL = 1 << 6,
GNM_EE_FORMULA_ONLY = 1 << 7,
- GNM_EE_MASK = 0xFF
+ GNM_EE_CONSTANT_ALLOWED= 1 << 8,
+ GNM_EE_MASK = 0x1FF
} GnmExprEntryFlags;
GType gnm_expr_entry_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]