Commit f1caff3e authored by Morten Welinder's avatar Morten Welinder

Solver: take more constaints into account.

parent ea45ab9d
......@@ -20,6 +20,7 @@ Morten:
* Resurrect support for non-ascii filenames on win32. [#557815]
* Fix timeout related critical in ItemGrid.
* Fix win32 print crash. [#719997]
* Fix solver problem with constraints.
--------------------------------------------------------------------------
Gnumeric 1.12.9
......
2013-12-29 Morten Welinder <terra@gnome.org>
* gnm-nlsolve.c (rosenbrock_iter): Make sure to set the right
solution we found!
2013-11-28 Morten Welinder <terra@gnome.org>
* Release 1.12.9
......
......@@ -97,6 +97,18 @@ no_discrete:
return FALSE;
}
static void
print_vector (const char *name, const gnm_float *v, int n)
{
int i;
if (name)
g_printerr ("%s:\n", name);
for (i = 0; i < n; i++)
g_printerr ("%15.8" GNM_FORMAT_f " ", v[i]);
g_printerr ("\n");
}
static void
set_value (GnmNlsolve *nl, int i, gnm_float x)
{
......@@ -166,6 +178,10 @@ gnm_nlsolve_set_solution (GnmNlsolve *nl)
g_object_set (sol, "result", result, NULL);
g_object_unref (result);
if (!gnm_solver_check_constraints (sol)) {
g_printerr ("Infeasible solution set\n");
}
}
static gboolean
......@@ -221,18 +237,6 @@ gnm_nlsolve_prepare (GnmSolver *sol, WorkbookControl *wbc, GError **err,
return ok;
}
static void
print_vector (const char *name, const gnm_float *v, int n)
{
int i;
if (name)
g_printerr ("%s:\n", name);
for (i = 0; i < n; i++)
g_printerr ("%15.8" GNM_FORMAT_f " ", v[i]);
g_printerr ("\n");
}
static gnm_float *
compute_gradient (GnmNlsolve *nl, const gnm_float *xs)
{
......@@ -551,8 +555,10 @@ rosenbrock_iter (GnmNlsolve *nl)
/* ---------------------------------------- */
if (!nl->tentative)
if (!nl->tentative) {
set_vector (nl, nl->xk);
gnm_nlsolve_set_solution (nl);
}
if (nl->tentative) {
if (nl->yk < nl->tentative_yk) {
......
2013-12-29 Morten Welinder <terra@gnome.org>
* gnm-solver.c (gnm_solver_check_constraints): Evalutate
constraint cells as needed.
2013-12-10 Morten Welinder <terra@gnome.org>
* tabulate.c (do_tabulation): Fix cut-off when we go off sheet.
......
......@@ -593,6 +593,7 @@ gnm_solver_param_valid (GnmSolverParameters const *sp, GError **err)
_("Invalid solver target"));
return FALSE;
}
gnm_cell_eval (target_cell);
if (!gnm_cell_has_expr (target_cell) ||
target_cell->value == NULL ||
......@@ -1109,7 +1110,10 @@ gnm_solver_check_constraints (GnmSolver *solver)
for (l = input_cells; l; l = l->next) {
GnmCell *cell = l->data;
gnm_float val = value_get_as_float (cell->value);
gnm_float val;
gnm_cell_eval (cell);
val = value_get_as_float (cell->value);
if (sp->options.assume_non_negative && val < 0)
break;
if (sp->options.assume_discrete &&
......@@ -1133,10 +1137,14 @@ gnm_solver_check_constraints (GnmSolver *solver)
&lhs, &cl,
&rhs, &cr);
i++) {
if (lhs)
if (lhs) {
gnm_cell_eval (lhs);
cl = value_get_as_float (lhs->value);
if (rhs)
}
if (rhs) {
gnm_cell_eval (rhs);
cr = value_get_as_float (rhs->value);
}
switch (c->type) {
case GNM_SOLVER_INTEGER:
......@@ -1293,7 +1301,7 @@ cell_in_cr (GnmCell const *cell, GnmSheetRange *sr, gboolean follow,
}
static gboolean
cell_is_constant (GnmCell const *cell, gnm_float *pc)
cell_is_constant (GnmCell *cell, gnm_float *pc)
{
if (!cell)
return TRUE;
......@@ -1301,6 +1309,7 @@ cell_is_constant (GnmCell const *cell, gnm_float *pc)
if (cell->base.texpr)
return FALSE;
gnm_cell_eval (cell);
*pc = value_get_as_float (cell->value);
return TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment