[gnumeric] nlsolve: simplify code.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] nlsolve: simplify code.
- Date: Sat, 9 May 2015 01:33:53 +0000 (UTC)
commit 1f0fb574464ae86e983fee32ce9bcb32972e49f7
Author: Morten Welinder <terra gnome org>
Date: Fri May 8 21:29:04 2015 -0400
nlsolve: simplify code.
Use the precomputed discrete flags and variable limits.
plugins/nlsolve/ChangeLog | 4 ++++
plugins/nlsolve/gnm-nlsolve.c | 28 ++++++++++++++++++++--------
2 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/plugins/nlsolve/ChangeLog b/plugins/nlsolve/ChangeLog
index 60ee4fa..5143113 100644
--- a/plugins/nlsolve/ChangeLog
+++ b/plugins/nlsolve/ChangeLog
@@ -1,3 +1,7 @@
+2015-05-08 Morten Welinder <terra gnome org>
+
+ * gnm-nlsolve.c (check_program): Simplify.
+
2015-05-06 Morten Welinder <terra gnome org>
* gnm-nlsolve.c (check_program): We really don't handle equality
diff --git a/plugins/nlsolve/gnm-nlsolve.c b/plugins/nlsolve/gnm-nlsolve.c
index 7c31ba8..cbcbf40 100644
--- a/plugins/nlsolve/gnm-nlsolve.c
+++ b/plugins/nlsolve/gnm-nlsolve.c
@@ -59,26 +59,38 @@ typedef struct {
} GnmNlsolve;
static gboolean
-check_program (const GnmSolverParameters *params, GError **err)
+check_program (GnmSolver *sol, GError **err)
{
+ unsigned ui;
+ const GnmSolverParameters *params = sol->params;
GSList *l;
- if (params->options.assume_discrete)
- goto no_discrete;
-
for (l = params->constraints; l; l = l->next) {
GnmSolverConstraint *c = l->data;
switch (c->type) {
- case GNM_SOLVER_INTEGER:
- case GNM_SOLVER_BOOLEAN:
- goto no_discrete;
case GNM_SOLVER_EQ:
+ /*
+ * This catches also equalities where the sides are not
+ * input variables.
+ */
goto no_equal;
default:
break;
}
}
+ for (ui = 0; ui < sol->input_cells->len; ui++) {
+ if (sol->discrete[ui])
+ goto no_discrete;
+
+ /*
+ * This also catches using two inequality constraints used
+ * to emulate equality.
+ */
+ if (sol->min[ui] == sol->max[ui])
+ goto no_equal;
+ }
+
return TRUE;
no_discrete:
@@ -154,7 +166,7 @@ gnm_nlsolve_prepare (GnmSolver *sol, WorkbookControl *wbc, GError **err,
gnm_solver_set_status (sol, GNM_SOLVER_STATUS_PREPARING);
- ok = check_program (sol->params, err);
+ ok = check_program (sol, err);
if (ok)
ok = gnm_iter_solver_get_initial_solution (nl->isol, err);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]