[gnumeric] solver: cleanups.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] solver: cleanups.
- Date: Sun, 15 Nov 2009 00:15:21 +0000 (UTC)
commit 2632eabf26c369fb5af7e46415e52929622af216
Author: Morten Welinder <terra gnome org>
Date: Sat Nov 14 19:15:04 2009 -0500
solver: cleanups.
plugins/glpk/glpk-write.c | 4 ----
plugins/glpk/gnm-glpk.c | 9 +++++----
plugins/lpsolve/gnm-lpsolve.c | 25 ++++++++++++++++---------
plugins/lpsolve/lpsolve-write.c | 35 +++++++++++++++++++----------------
src/dialogs/dialog-solver.c | 8 ++++----
src/numbers.h | 4 ++++
6 files changed, 48 insertions(+), 37 deletions(-)
---
diff --git a/plugins/glpk/glpk-write.c b/plugins/glpk/glpk-write.c
index d4d81a3..5335835 100644
--- a/plugins/glpk/glpk-write.c
+++ b/plugins/glpk/glpk-write.c
@@ -72,10 +72,6 @@ out:
return res;
}
-/*
- * FIXME: we need to handle the situation where cells from more than one
- * sheet are involved.
- */
static const char *
glpk_var_name (GnmSubSolver *ssol, GnmCell const *cell)
{
diff --git a/plugins/glpk/gnm-glpk.c b/plugins/glpk/gnm-glpk.c
index 1bd16f6..8e2ef30 100644
--- a/plugins/glpk/gnm-glpk.c
+++ b/plugins/glpk/gnm-glpk.c
@@ -70,7 +70,7 @@ gnm_glpk_read_solution (GnmGlpk *lp)
const char *line;
unsigned rows, cols, c, r;
int pstat, dstat;
- double val;
+ gnm_float val;
GnmSolverResult *result;
int width, height;
@@ -94,7 +94,7 @@ gnm_glpk_read_solution (GnmGlpk *lp)
line = gsf_input_textline_utf8_gets (tl);
if (line == NULL ||
- sscanf (line, "%d %d %lg", &pstat, &dstat, &val) != 3)
+ sscanf (line, "%d %d %" GNM_SCANF_g, &pstat, &dstat, &val) != 3)
goto fail;
result->value = val;
switch (pstat) {
@@ -120,13 +120,14 @@ gnm_glpk_read_solution (GnmGlpk *lp)
}
for (c = 1; c <= cols; c++) {
- double pval, dval;
+ gnm_float pval, dval;
unsigned cstat;
int x, y;
line = gsf_input_textline_utf8_gets (tl);
if (line == NULL ||
- sscanf (line, "%u %lg %lg", &cstat, &pval, &dval) != 3)
+ sscanf (line, "%u %" GNM_SCANF_g " %" GNM_SCANF_g,
+ &cstat, &pval, &dval) != 3)
goto fail;
x = (c - 1) % width;
diff --git a/plugins/lpsolve/gnm-lpsolve.c b/plugins/lpsolve/gnm-lpsolve.c
index 27605a4..e444737 100644
--- a/plugins/lpsolve/gnm-lpsolve.c
+++ b/plugins/lpsolve/gnm-lpsolve.c
@@ -83,7 +83,6 @@ gnm_lpsolve_flush_solution (GnmLPSolve *lp)
static gboolean
cb_read_stdout (GIOChannel *channel, GIOCondition cond, GnmLPSolve *lp)
{
- GnmSolver *sol = GNM_SOLVER (lp->parent);
const char obj_line_prefix[] = "Value of objective function:";
size_t obj_line_len = sizeof (obj_line_prefix) - 1;
const char val_header_line[] = "Actual values of the variables:";
@@ -116,19 +115,27 @@ cb_read_stdout (GIOChannel *channel, GIOCondition cond, GnmLPSolve *lp)
lp->section = SEC_VALUES;
} else if (lp->section == SEC_VALUES && lp->result) {
GnmSolverResult *r = lp->result;
- Sheet *sheet = sol->params->sheet;
- GnmCellPos pos;
int x, y;
double v;
- const char *after =
- cellpos_parse (line, &sheet->size, &pos, FALSE);
- if (!after || *after != ' ') {
+ char *space = strchr (line, ' ');
+ GnmCell *cell;
+
+ if (!space) {
lp->section = SEC_UNKNOWN;
continue;
}
- v = g_ascii_strtod (after, NULL);
- x = pos.col - lp->srinput.range.start.col;
- y = pos.row - lp->srinput.range.start.row;
+ *space = 0;
+ cell = gnm_sub_solver_find_cell (lp->parent, line);
+ if (!cell) {
+ g_printerr ("Strange cell %s in output\n",
+ line);
+ lp->section = SEC_UNKNOWN;
+ continue;
+ }
+
+ v = g_ascii_strtod (space + 1, NULL);
+ x = cell->pos.col - lp->srinput.range.start.col;
+ y = cell->pos.row - lp->srinput.range.start.row;
if (x >= 0 &&
x < value_area_get_width (r->solution, NULL) &&
y >= 0 &&
diff --git a/plugins/lpsolve/lpsolve-write.c b/plugins/lpsolve/lpsolve-write.c
index 8f19e1f..1766017 100644
--- a/plugins/lpsolve/lpsolve-write.c
+++ b/plugins/lpsolve/lpsolve-write.c
@@ -72,19 +72,21 @@ out:
return res;
}
-/*
- * FIXME: we need to handle the situation where cells from more than one
- * sheet are involved.
- */
static const char *
-lpsolve_var_name (GnmCell const *cell)
+lpsolve_var_name (GnmSubSolver *ssol, GnmCell const *cell)
{
+ if (ssol) {
+ const char *old = gnm_sub_solver_get_cell_name (ssol, cell);
+ if (old)
+ return old;
+ return gnm_sub_solver_name_cell (ssol, cell, cell_name (cell));
+ }
return cell_name (cell);
}
static gboolean
-lpsolve_affine_func (GString *dst, GnmCell *target, gnm_float cst,
- GSList *input_cells, GError **err)
+lpsolve_affine_func (GString *dst, GnmCell *target, GnmSubSolver *ssol,
+ gnm_float cst, GSList *input_cells, GError **err)
{
GSList *l, *ol;
gboolean any = FALSE;
@@ -134,7 +136,7 @@ lpsolve_affine_func (GString *dst, GnmCell *target, gnm_float cst,
g_string_append_c (dst, ' ');
}
- g_string_append (dst, lpsolve_var_name (cell));
+ g_string_append (dst, lpsolve_var_name (ssol, cell));
any = TRUE;
}
@@ -193,7 +195,8 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context,
}
go_io_count_progress_update (io_context, 1);
- if (!lpsolve_affine_func (objfunc, target_cell, 0, input_cells, err))
+ if (!lpsolve_affine_func (objfunc, target_cell, ssol,
+ 0, input_cells, err))
goto fail;
g_string_append (objfunc, ";\n");
go_io_count_progress_update (io_context, 1);
@@ -205,7 +208,7 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context,
for (l = input_cells; l; l = l->next) {
GnmCell *cell = l->data;
g_string_append (constraints,
- lpsolve_var_name (cell));
+ lpsolve_var_name (ssol, cell));
g_string_append (constraints, " >= 0;\n");
}
go_io_count_progress_update (io_context, 1);
@@ -217,7 +220,7 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context,
GnmCell *cell = l->data;
g_string_append (declarations, "int ");
g_string_append (declarations,
- lpsolve_var_name (cell));
+ lpsolve_var_name (ssol, cell));
g_string_append (declarations, ";\n");
}
go_io_count_progress_update (io_context, 1);
@@ -261,14 +264,14 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context,
if (type) {
g_string_append (declarations, type);
g_string_append_c (declarations, ' ');
- g_string_append (declarations, lpsolve_var_name (lhs));
+ g_string_append (declarations, lpsolve_var_name (ssol, lhs));
g_string_append (declarations, ";\n");
} else {
gboolean ok;
ok = lpsolve_affine_func
- (constraints, lhs, cl,
- input_cells, err);
+ (constraints, lhs, ssol,
+ cl, input_cells, err);
if (!ok)
goto fail;
@@ -277,8 +280,8 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context,
g_string_append_c (constraints, ' ');
ok = lpsolve_affine_func
- (constraints, rhs, cr,
- input_cells, err);
+ (constraints, rhs, ssol,
+ cr, input_cells, err);
if (!ok)
goto fail;
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index 42c7990..b28e9ba 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -447,16 +447,16 @@ cb_notify_result (SolverState *state)
break;
case GNM_SOLVER_RESULT_FEASIBLE: {
- char *valtxt = go_format_value (go_format_general (),
- r->value);
+ char *valtxt = gnm_format_value (go_format_general (),
+ r->value);
txt = g_strdup_printf (_("Feasible: %s"), valtxt);
g_free (valtxt);
break;
}
case GNM_SOLVER_RESULT_OPTIMAL: {
- char *valtxt = go_format_value (go_format_general (),
- r->value);
+ char *valtxt = gnm_format_value (go_format_general (),
+ r->value);
txt = g_strdup_printf (_("Optimal: %s"), valtxt);
g_free (valtxt);
break;
diff --git a/src/numbers.h b/src/numbers.h
index 9c86aaf..2c8ee4e 100644
--- a/src/numbers.h
+++ b/src/numbers.h
@@ -78,6 +78,7 @@ gnm_float gnm_yn (int n, gnm_float x);
#define gnm_finite finitel
#define gnm_floor floorl
#define gnm_fmod fmodl
+#define gnm_format_value go_format_valuel
#define gnm_format_value_gstring go_format_value_gstringl
#define gnm_frexp frexpl
#define gnm_hypot hypotl
@@ -109,6 +110,7 @@ gnm_float gnm_yn (int n, gnm_float x);
#define GNM_FORMAT_f "Lf"
#define GNM_FORMAT_g "Lg"
#define GNM_FORMAT_G "LG"
+#define GNM_SCANF_g "Lg"
#define GNM_DIG LDBL_DIG
#define GNM_MANT_DIG LDBL_MANT_DIG
#define GNM_MIN_EXP LDBL_MIN_EXP
@@ -145,6 +147,7 @@ typedef double gnm_float;
#define gnm_finite go_finite
#define gnm_floor floor
#define gnm_fmod fmod
+#define gnm_format_value go_format_value
#define gnm_format_value_gstring go_format_value_gstring
#define gnm_frexp frexp
#define gnm_hypot hypot
@@ -177,6 +180,7 @@ typedef double gnm_float;
#define GNM_FORMAT_f "f"
#define GNM_FORMAT_g "g"
#define GNM_FORMAT_G "G"
+#define GNM_SCANF_g "lg"
#define GNM_DIG DBL_DIG
#define GNM_MANT_DIG DBL_MANT_DIG
#define GNM_MIN_EXP DBL_MIN_EXP
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]