Commit c5110c7b authored by Morten Welinder's avatar Morten Welinder

solver: minor cleanups.

parent 8fd065c8
2015-04-24 Morten Welinder <terra@gnome.org>
* gnm-solver.c (gnm_solver_get_current_values): Delete unused
function.
(gnm_solver_check_constraints): Avoid undefined C behaviour.
(gnm_solver_param_get_input_cells): Avoid O(n^2) list handling.
2015-04-16 Morten Welinder <terra@gnome.org>
* Release 1.12.22
......
......@@ -513,7 +513,7 @@ cb_grab_cells (GnmCellIter const *iter, gpointer user)
if (NULL == (cell = iter->cell))
cell = sheet_cell_create (iter->pp.sheet,
iter->pp.eval.col, iter->pp.eval.row);
*the_list = g_slist_append (*the_list, cell);
*the_list = g_slist_prepend (*the_list, cell);
return NULL;
}
......@@ -531,7 +531,7 @@ gnm_solver_param_get_input_cells (GnmSolverParameters const *sp)
workbook_foreach_cell_in_range (&ep, vr, CELL_ITER_ALL,
cb_grab_cells,
&input_cells);
return input_cells;
return g_slist_reverse (input_cells);
}
void
......@@ -1108,6 +1108,7 @@ gnm_solver_check_constraints (GnmSolver *solver)
sp->options.assume_discrete) {
GSList *input_cells = gnm_solver_param_get_input_cells (sp);
GSList *l;
gboolean bad;
for (l = input_cells; l; l = l->next) {
GnmCell *cell = l->data;
......@@ -1121,9 +1122,10 @@ gnm_solver_check_constraints (GnmSolver *solver)
val != gnm_floor (val))
break;
}
bad = (l != NULL);
g_slist_free (input_cells);
if (l)
if (bad)
return FALSE;
}
......@@ -1183,39 +1185,6 @@ gnm_solver_check_constraints (GnmSolver *solver)
return TRUE;
}
static GnmValue *
cb_get_value (GnmValueIter const *iter, gpointer user_data)
{
GnmValue *res = user_data;
value_array_set (res, iter->x, iter->y,
iter->v
? value_dup (iter->v)
: value_new_int (0));
return NULL;
}
GnmValue *
gnm_solver_get_current_values (GnmSolver *solver)
{
int w, h;
GnmValue *res;
GnmSolverParameters const *sp = solver->params;
GnmValue const *vinput = gnm_solver_param_get_input (sp);
GnmEvalPos ep;
eval_pos_init_sheet (&ep, sp->sheet);
w = value_area_get_width (vinput, &ep);
h = value_area_get_height (vinput, &ep);
res = value_new_array_empty (w, h);
value_area_foreach (vinput, &ep, CELL_ITER_ALL, cb_get_value, res);
return res;
}
gboolean
gnm_solver_saveas (GnmSolver *solver, WorkbookControl *wbc,
GOFileSaver *fs,
......
......@@ -239,8 +239,6 @@ gboolean gnm_solver_has_solution (GnmSolver *solver);
gboolean gnm_solver_check_constraints (GnmSolver *solver);
GnmValue *gnm_solver_get_current_values (GnmSolver *solver);
gboolean gnm_solver_saveas (GnmSolver *solver, WorkbookControl *wbc,
GOFileSaver *fs,
const char *templ, char **filename,
......
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