示例#1
0
static gint
gnm_nlsolve_idle (gpointer data)
{
	GnmNlsolve *nl = data;
	GnmSolver *sol = nl->parent;
	const int n = nl->vars->len;
	gboolean ok;
	gboolean call_again = TRUE;

	if (nl->k == 0)
		rosenbrock_init (nl);

	if (nl->debug) {
		g_printerr ("Iteration %d at %.15" GNM_FORMAT_g "\n",
			    nl->k, nl->yk);
		print_vector ("Current point", nl->xk, n);
	}

	nl->k++;
	ok = rosenbrock_iter (nl);

	if (!ok && !nl->tentative) {
		ok = polish_iter (nl);
	}

	if (!ok) {
		gnm_solver_set_status (sol, GNM_SOLVER_STATUS_DONE);
		call_again = FALSE;
	}

	if (call_again && nl->k >= nl->max_iter) {
		gnm_solver_set_status (sol, GNM_SOLVER_STATUS_DONE);
		call_again = FALSE;
	}

	if (!call_again) {
		set_vector (nl, nl->x0);
		gnm_app_recalc ();

		rosenbrock_shutdown (nl);
	}

	if (!call_again)
		nl->idle_tag = 0;

	return call_again;
}
示例#2
0
static gboolean
gnm_nlsolve_iterate (GnmSolverIterator *iter, GnmNlsolve *nl)
{
    GnmIterSolver *isol = nl->isol;
    const int n = nl->n;

    if (isol->iterations == 0)
        rosenbrock_init (nl);

    if (nl->debug) {
        g_printerr ("Iteration %ld at %.15" GNM_FORMAT_g "\n",
                    (long)(isol->iterations), isol->yk);
        print_vector ("Current point", isol->xk, n);
    }

    return rosenbrock_iter (nl);
}