[gnumeric] solver: remove linked-in solvers.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] solver: remove linked-in solvers.
- Date: Thu, 12 Nov 2009 14:35:32 +0000 (UTC)
commit 89c70e14ac4f9309deee35253b8f1591dc3902c4
Author: Morten Welinder <terra gnome org>
Date: Thu Nov 12 09:34:44 2009 -0500
solver: remove linked-in solvers.
configure.in | 4 -
src/dialogs/dialog-solver.c | 4 -
src/solver.h | 6 -
src/tools/solver/Makefile.am | 3 +-
src/tools/solver/api.c | 640 +-
src/tools/solver/glpk/.gitignore | 7 -
src/tools/solver/glpk/AUTHORS | 33 -
src/tools/solver/glpk/ChangeLog | 1323 -
src/tools/solver/glpk/Makefile.am | 14 -
src/tools/solver/glpk/NEWS | 622 -
src/tools/solver/glpk/README | 34 -
src/tools/solver/glpk/doc/bench.txt | 105 -
src/tools/solver/glpk/doc/lang.latex | 3299 ---
src/tools/solver/glpk/doc/refman.latex | 5505 ----
src/tools/solver/glpk/include/.gitignore | 7 -
src/tools/solver/glpk/include/Makefile.am | 15 -
src/tools/solver/glpk/include/glpavl.h | 138 -
src/tools/solver/glpk/include/glpdmp.h | 85 -
src/tools/solver/glpk/include/glpiet.h | 656 -
src/tools/solver/glpk/include/glpinv.h | 184 -
src/tools/solver/glpk/include/glpios.h | 658 -
src/tools/solver/glpk/include/glpipp.h | 342 -
src/tools/solver/glpk/include/glpk.h | 39 -
src/tools/solver/glpk/include/glplib.h | 212 -
src/tools/solver/glpk/include/glplpp.h | 340 -
src/tools/solver/glpk/include/glplpx.h | 1280 -
src/tools/solver/glpk/include/glpluf.h | 358 -
src/tools/solver/glpk/include/glpmip.h | 332 -
src/tools/solver/glpk/include/glpspx.h | 421 -
src/tools/solver/glpk/include/glpstr.h | 92 -
src/tools/solver/glpk/source/.gitignore | 7 -
src/tools/solver/glpk/source/Makefile.am | 43 -
src/tools/solver/glpk/source/glpavl.c | 750 -
src/tools/solver/glpk/source/glpdmp.c | 284 -
src/tools/solver/glpk/source/glpinv.c | 777 -
src/tools/solver/glpk/source/glpipp1.c | 807 -
src/tools/solver/glpk/source/glpipp2.c | 1365 -
src/tools/solver/glpk/source/glplib1a.c | 70 -
src/tools/solver/glpk/source/glplib1b.c | 75 -
src/tools/solver/glpk/source/glplib2.c | 591 -
src/tools/solver/glpk/source/glplib3.c | 357 -
src/tools/solver/glpk/source/glplib4.c | 166 -
src/tools/solver/glpk/source/glplpp1.c | 844 -
src/tools/solver/glpk/source/glplpp2.c | 1715 --
src/tools/solver/glpk/source/glplpx1.c | 1701 --
src/tools/solver/glpk/source/glplpx2.c | 1283 -
src/tools/solver/glpk/source/glplpx3.c | 419 -
src/tools/solver/glpk/source/glplpx4.c | 429 -
src/tools/solver/glpk/source/glplpx5.c | 584 -
src/tools/solver/glpk/source/glplpx6a.c | 1007 -
src/tools/solver/glpk/source/glplpx6c.c | 376 -
src/tools/solver/glpk/source/glplpx6d.c | 593 -
src/tools/solver/glpk/source/glplpx7.c | 1473 -
src/tools/solver/glpk/source/glplpx7a.c | 566 -
src/tools/solver/glpk/source/glpluf.c | 1882 --
src/tools/solver/glpk/source/glpmip1.c | 755 -
src/tools/solver/glpk/source/glpmip2.c | 1115 -
src/tools/solver/glpk/source/glpspx1.c | 2090 --
src/tools/solver/glpk/source/glpspx2.c | 1372 -
src/tools/solver/glpk/source/glpstr.c | 252 -
src/tools/solver/lp_solve/.gitignore | 2 -
src/tools/solver/lp_solve/ChangeLog | 606 -
src/tools/solver/lp_solve/LICENSE | 504 -
src/tools/solver/lp_solve/Makefile.am | 12 -
src/tools/solver/lp_solve/README | 205 -
src/tools/solver/lp_solve/lp_solve.c |44185 -----------------------------
src/tools/solver/lp_solve/lp_solve.h | 46 -
src/tools/solver/lp_solve/lp_solve.man | 330 -
src/tools/solver/solver.c | 583 -
69 files changed, 17 insertions(+), 86962 deletions(-)
---
diff --git a/configure.in b/configure.in
index 084fe81..66ff91e 100644
--- a/configure.in
+++ b/configure.in
@@ -1029,10 +1029,6 @@ src/pixmaps/Makefile
src/widgets/Makefile
src/tools/Makefile
src/tools/solver/Makefile
-src/tools/solver/glpk/Makefile
-src/tools/solver/glpk/source/Makefile
-src/tools/solver/glpk/include/Makefile
-src/tools/solver/lp_solve/Makefile
src/cut-n-paste-code/Makefile
doc/Makefile
doc/C/Makefile
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index 676d365..0d3f71e 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -871,11 +871,7 @@ cb_dialog_solve_clicked (G_GNUC_UNUSED GtkWidget *button,
goto out;
}
-#if 0
- res = solver (WORKBOOK_CONTROL (state->wbcg), state->sheet, &err);
-#else
res = run_solver (state, param);
-#endif
workbook_recalc (state->sheet->workbook);
diff --git a/src/solver.h b/src/solver.h
index d8e2d0b..2c1afe4 100644
--- a/src/solver.h
+++ b/src/solver.h
@@ -259,12 +259,6 @@ typedef struct {
* The API functions to the Solver tool.
*/
-/* Runs the solver. Returs a pointer to a data structure containing
- * the results of the run. Note that it should be freed when no longer
- * needed (by calling solver_results_free). */
-SolverResults *solver (WorkbookControl *wbc, Sheet *sheet,
- GError **err);
-
/* Creates the Solver's reports. */
gchar * solver_reports (WorkbookControl *wbc, Sheet *sheet,
SolverResults *res,
diff --git a/src/tools/solver/Makefile.am b/src/tools/solver/Makefile.am
index fd62840..98c1b59 100644
--- a/src/tools/solver/Makefile.am
+++ b/src/tools/solver/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = glpk lp_solve
+SUBDIRS =
AM_CPPFLAGS = \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
@@ -7,7 +7,6 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/dialogs \
-I$(top_srcdir)/src/tools \
-I$(top_srcdir)/src/tools/solver \
- -I$(top_srcdir)/src/tools/solver/glpk/include \
-DGNUMERIC_INTERNAL \
$(GNUMERIC_CFLAGS)
diff --git a/src/tools/solver/api.c b/src/tools/solver/api.c
index 31dbdcf..5430091 100644
--- a/src/tools/solver/api.c
+++ b/src/tools/solver/api.c
@@ -42,594 +42,9 @@
#include <math.h>
#include <stdlib.h>
-#include "lp_solve/lp_solve.h"
#include "api.h"
-#include "glpk.h"
/* ------------------------------------------------------------------------- */
-
-/*
- * Solver's API wrappings for the LP Solve 5.5.
- *
- * Package: LP Solve
- * Version: 5.5
- * License: LGPL
- * Homepage:
- */
-
-typedef struct {
- lprec *p;
- gboolean assume_non_negative;
-} lp_solve_t;
-
-static SolverProgram
-w_lp_solve_init (const SolverParameters *param)
-{
- lp_solve_t *lp;
-
- lp = g_new (lp_solve_t, 1);
- lp->assume_non_negative = param->options.assume_non_negative;
- if (lp->assume_non_negative)
- lp->p = lp_solve_make_lp (param->n_constraints,
- param->n_variables);
- else
- lp->p = lp_solve_make_lp (param->n_constraints,
- 2 * param->n_variables);
-
- return lp;
-}
-
-static void
-w_lp_solve_delete_lp (SolverProgram program)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- lp_solve_delete_lp (lp->p);
- g_free (lp);
-}
-
-static void
-w_lp_solve_set_maxim (SolverProgram program)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- lp_solve_set_maxim (lp->p);
-}
-
-static void
-w_lp_solve_set_minim (SolverProgram program)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- lp_solve_set_minim (lp->p);
-}
-
-static void
-w_lp_solve_set_obj_fn (SolverProgram program, int col, gnm_float value)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- if (lp->assume_non_negative)
- lp_solve_set_mat (lp->p, 0, col + 1, value);
- else {
- lp_solve_set_mat (lp->p, 0, 2 * col + 1, value);
- lp_solve_set_mat (lp->p, 0, 2 * col + 2, -value);
- }
-}
-
-static void
-w_lp_solve_set_constr_mat (SolverProgram program, int col, int row,
- gnm_float value)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- if (lp->assume_non_negative)
- lp_solve_set_mat (lp->p, row + 1, col + 1, value);
- else {
- lp_solve_set_mat (lp->p, row + 1, 2 * col + 1, value);
- lp_solve_set_mat (lp->p, row + 1, 2 * col + 2, -value);
- }
-}
-
-static void
-w_lp_solve_set_constr (SolverProgram program, int row,
- SolverConstraintType type, gnm_float rhs)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
- int lp_constraint_type;
- switch (type) {
- case SolverLE: lp_constraint_type = ROWTYPE_LE; break;
- case SolverGE: lp_constraint_type = ROWTYPE_GE; break;
- case SolverEQ: lp_constraint_type = ROWTYPE_EQ; break;
- default:
- g_warning ("unexpected constraint type %d", type);
- lp_constraint_type = 0; /* silence the compiler */
- }
- lp_solve_set_constr_type (lp->p, row + 1, lp_constraint_type);
- lp_solve_set_rh (lp->p, row + 1, rhs);
-}
-
-static void
-w_lp_solve_set_int (SolverProgram program, int col)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- if (lp->assume_non_negative)
- lp_solve_set_int (lp->p, col + 1, TRUE);
- else {
- lp_solve_set_int (lp->p, 2 * col + 1, TRUE);
- lp_solve_set_int (lp->p, 2 * col + 2, TRUE);
- }
-}
-
-static void
-w_lp_solve_set_bool (SolverProgram program, int col)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- if (lp->assume_non_negative) {
- lp_solve_set_int (lp->p, col + 1, TRUE);
- lp_solve_set_upbo (lp->p, col + 1, 1);
- lp_solve_set_lowbo (lp->p, col + 1, 0);
- } else {
- lp_solve_set_int (lp->p, 2 * col + 1, TRUE);
- lp_solve_set_upbo (lp->p, 2 * col + 1, 1);
- lp_solve_set_lowbo (lp->p, 2 * col + 1, 0);
-
- lp_solve_set_int (lp->p, 2 * col + 2, TRUE);
- lp_solve_set_upbo (lp->p, 2 * col + 2, 0);
- lp_solve_set_lowbo (lp->p, 2 * col + 2, 0);
- }
-}
-
-static void
-w_lp_solve_print_lp (SolverProgram program)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- lp_solve_print_lp (lp->p);
-}
-
-static SolverStatus
-w_lp_solve_solve (SolverProgram program)
-{
- int res;
- lp_solve_t *lp = (lp_solve_t *) program;
-
-#if SOLVER_DEBUG
- w_lp_solve_print_lp (program);
-#endif
- switch ((res = lp_solve_solve (lp->p))) {
- default:
- g_warning ("unknown result from lp_solve_solve '%d'" , res);
-
- case UNKNOWNERROR:
- case DATAIGNORED:
- case NOBFP:
- case NOMEMORY:
- case NOTRUN:
- case DEGENERATE:
- case NUMFAILURE:
- case USERABORT:
- case TIMEOUT:
- return SolverFailure;
-
- case OPTIMAL: return SolverOptimal;
- case SUBOPTIMAL: return SolverMaxIterExc; /* or SolverMaxTimeExc */
- case INFEASIBLE:return SolverInfeasible;
- case UNBOUNDED: return SolverUnbounded;
- case RUNNING: return SolverRunning;
- }
-}
-
-static gnm_float
-w_lp_solve_get_solution (SolverProgram program, int column)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
- int nrows = lp_solve_get_nrows (lp->p);
-
- if (lp->assume_non_negative)
- return lp_solve_get_primal (lp->p, nrows + column + 1);
- else {
- int i = nrows + 2 * column + 1;
- gnm_float x = lp_solve_get_primal (lp->p, i);
- gnm_float neg_x = lp_solve_get_primal (lp->p, i + 1);
-
- if (x > neg_x)
- return x;
- else
- return -neg_x;
- }
-}
-
-static gnm_float
-w_lp_solve_get_value_of_obj_fn (SolverProgram program)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
- g_return_val_if_fail (lp != NULL, 0.);
- g_return_val_if_fail (lp->p != NULL, 0.);
-
- return lp_solve_get_primal (lp->p, 0);
-}
-
-static gnm_float
-w_lp_solve_get_dual (SolverProgram program, int row)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
- g_return_val_if_fail (lp != NULL, 0.);
- g_return_val_if_fail (lp->p != NULL, 0.);
-
- return lp_solve_get_dual (lp->p, row + 1);
-}
-
-static int
-w_lp_solve_get_iterations (SolverProgram program)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
- g_return_val_if_fail (lp != NULL, 0);
- g_return_val_if_fail (lp->p != NULL, 0);
-
- /* FIXME: gint64 */
- return lp_solve_get_total_iter (lp->p);
-}
-
-static gboolean
-w_lp_solve_set_option (SolverProgram program, SolverOptionType option,
- const gboolean *b_value,
- const gnm_float *f_value, const int *i_value)
-{
- lp_solve_t *lp = (lp_solve_t *) program;
-
- switch (option) {
- case SolverOptAutomaticScaling:
-#if 0
- No longer needed with 5.x
-#endif
- return FALSE;
- case SolverOptMaxIter:
- lp_solve_set_scalelimit (lp->p, *i_value);
- return FALSE;
- case SolverOptMaxTimeSec:
- lp_solve_set_timeout (lp->p, *i_value);
- return FALSE;
- default:
- return TRUE;
- }
-}
-
-
-/* ------------------------------------------------------------------------- */
-
-/*
- * Solver's API wrappings for the GLPK 3.2.
- *
- * Package: GLPK
- * Version: 3.2 (Jul 15, 2002)
- * License: GPL
- * Homepage: http://www.gnu.org/software/glpk/glpk.html
- * Algorithm: revised simplex method
- *
- */
-
-
-typedef struct {
- LPX *p;
- int *rn;
- int *cn;
- gnm_float *a;
- int n;
- gboolean assume_non_negative;
- gboolean scaling;
-} glpk_simplex_t;
-
-static SolverProgram
-w_glpk_init (const SolverParameters *param)
-{
- glpk_simplex_t *lp;
- int i, cols;
-
- lp = g_new (glpk_simplex_t, 1);
- lp->p = lpx_create_prob ();
- lp->assume_non_negative = param->options.assume_non_negative;
- lp->scaling = param->options.automatic_scaling;
-
- cols = param->n_variables;
-
- lpx_add_cols (lp->p, cols);
- lpx_add_rows (lp->p, param->n_constraints);
- lp->a = g_new (gnm_float, cols * param->n_constraints + 1);
- lp->cn = g_new (int, cols * param->n_constraints + 1);
- lp->rn = g_new (int, cols * param->n_constraints + 1);
- lp->n = 1;
-
- if (lp->assume_non_negative)
- for (i = 0; i < cols; i++)
- lpx_set_col_bnds (lp->p, i + 1, LPX_LO, 0, 0);
- else
- for (i = 0; i < cols; i++)
- lpx_set_col_bnds (lp->p, i + 1, LPX_FR, 0, 0);
-
- return lp;
-}
-
-static void
-w_glpk_delete_lp (SolverProgram program)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- lpx_delete_prob (lp->p);
- g_free (lp->cn);
- g_free (lp->rn);
- g_free (lp->a);
- g_free (lp);
-}
-
-static void
-w_glpk_set_maxim (SolverProgram program)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- lpx_set_obj_dir (lp->p, LPX_MAX);
-}
-
-static void
-w_glpk_set_minim (SolverProgram program)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- lpx_set_obj_dir (lp->p, LPX_MIN);
-}
-
-static void
-w_glpk_set_obj_fn (SolverProgram program, int col, gnm_float value)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- lpx_set_obj_coef (lp->p, col + 1, value);
-}
-
-static void
-w_glpk_set_constr_mat (SolverProgram program, int col, int row,
- gnm_float value)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- lp->cn [lp->n] = col + 1;
- lp->rn [lp->n] = row + 1;
- lp->a [lp->n] = value;
- (lp->n)++;
-}
-
-static void
-w_glpk_set_constr (SolverProgram program, int row, SolverConstraintType type,
- gnm_float value)
-{
- int typemap [] = { LPX_UP, LPX_LO, LPX_FX, -1, -1, -1 };
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- if (typemap [type] != -1)
- lpx_set_row_bnds (lp->p, row + 1, typemap [type], value,
- value);
- else
- printf ("Error\n");
-}
-
-static void
-w_glpk_set_int (SolverProgram program, int col)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- lpx_set_class (lp->p, LPX_MIP);
- lpx_set_col_kind (lp->p, col + 1, LPX_IV);
-}
-
-static void
-w_glpk_set_bool (SolverProgram program, int col)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- lpx_set_class (lp->p, LPX_MIP);
- lpx_set_col_kind (lp->p, col + 1, LPX_IV);
- lpx_set_col_bnds (lp->p, col + 1, LPX_DB, 0, 1);
-}
-
-static void
-w_glpk_print_lp (SolverProgram program)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
- int i, n, cols, rows;
- int typex;
- gnm_float lb, ub;
-
- cols = lpx_get_num_cols (lp->p);
- rows = lpx_get_num_rows (lp->p);
-
- printf ("\t\t");
- for (i = 0; i < cols; i++)
- printf ("Var[%3d] ", i + 1);
- printf ("\n");
-
- if (lpx_get_obj_dir (lp->p) == LPX_MAX)
- printf ("Maximize\t");
- else
- printf ("Minimize\t");
- for (i = 0; i < cols; i++)
- printf ("%8g ", lpx_get_obj_coef (lp->p, i + 1));
- printf ("\n");
-
- for (i = 0; i < rows; i++) {
- gnm_float *a;
- int *ndx, t;
-
- printf ("Row[%3d]\t", i + 1);
-
- a = g_new (gnm_float, cols + 1);
- ndx = g_new (int, cols + 1);
- lpx_get_mat_row (lp->p, i + 1, ndx, a);
- for (n = 0, t = 1; n < cols; n++) {
- if (ndx [t] == n + 1)
- printf ("%8g ", a[t++]);
- else
- printf ("%8g ", 0.0);
- }
- g_free (ndx);
- g_free (a);
-
- lpx_get_row_bnds (lp->p, i + 1, &typex, &lb, &ub);
- if (typex == LPX_LO)
- printf (">= %8g\n", lb);
- else if (typex == LPX_UP)
- printf ("<= %8g\n", ub);
- else
- printf ("= %8g\n", lb);
- }
-
- printf ("Type\t\t");
- for (i = 0; i < cols; i++)
- if (lpx_get_class (lp->p) == LPX_LP
- || lpx_get_col_kind (lp->p, i + 1) == LPX_CV)
- printf (" Real\t");
- else
- printf (" Int\t");
-
- printf ("\nupbo\t\t");
- for (i = 0; i < cols; i++) {
- lpx_get_col_bnds (lp->p, i + 1, &typex, &lb, &ub);
- if (typex == LPX_LO || typex == LPX_FR)
- printf ("Infinite ");
- else
- printf ("%8g ", ub);
- }
-
- printf ("\nlowbo\t\t");
- for (i = 0; i < cols; i++) {
- lpx_get_col_bnds (lp->p, i + 1, &typex, &lb, &ub);
- if (typex == LPX_UP || typex == LPX_FR)
- printf ("-Infinite ");
- else
- printf ("%8g ", ub);
- }
- printf ("\n");
-}
-
-static SolverStatus
-w_glpk_simplex_solve (SolverProgram program)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- if (lp->scaling)
- lpx_scale_prob (lp->p);
-
- lpx_load_matrix (lp->p, lp->n - 1, lp->rn, lp->cn, lp->a);
-
-#if SOLVER_DEBUG
- w_glpk_print_lp (program);
-#endif
-
- lpx_simplex (lp->p);
- if (lpx_get_class (lp->p) == LPX_MIP) {
- switch (lpx_get_status (lp->p)) {
- case LPX_OPT:
- break;
- case LPX_INFEAS:
- return SolverInfeasible;
- case LPX_UNBND:
- return SolverUnbounded;
- default:
- printf ("Error: w_glpk_simplex_solve\n");
- return SolverInfeasible;
- }
-
- lpx_intopt (lp->p);
- switch (lpx_mip_status (lp->p)) {
- case LPX_I_OPT:
- return SolverOptimal;
- case LPX_I_NOFEAS:
- return SolverInfeasible;
- default:
- printf ("Error: w_glpk_simplex_solve\n");
- return SolverInfeasible;
- }
- } else {
- if (lp->scaling)
- lpx_unscale_prob (lp->p);
-
- switch (lpx_get_status (lp->p)) {
- case LPX_OPT:
- return SolverOptimal;
- case LPX_INFEAS:
- return SolverInfeasible;
- case LPX_UNBND:
- return SolverUnbounded;
- default:
- printf ("Error: w_glpk_simplex_solve\n");
- return SolverInfeasible;
- }
- }
-}
-
-static gnm_float
-w_glpk_get_solution (SolverProgram program, int col)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
- gnm_float x;
-
- if (lpx_get_class (lp->p) == LPX_LP)
- lpx_get_col_info (lp->p, col + 1, NULL, &x, NULL);
- else
- x = lpx_mip_col_val (lp->p, col + 1);
-
- return x;
-}
-
-static gnm_float
-w_glpk_get_value_of_obj_fn (SolverProgram program)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
-
- if (lpx_get_class (lp->p) == LPX_LP)
- return lpx_get_obj_val (lp->p);
- else
- return lpx_mip_obj_val (lp->p);
-}
-
-static gnm_float
-w_glpk_get_dual (SolverProgram program, int row)
-{
- glpk_simplex_t *lp = (glpk_simplex_t *) program;
- gnm_float x;
-
- lpx_get_row_info (lp->p, row + 1, NULL, NULL, &x);
- return x;
-}
-
-static int
-w_glpk_get_iterations (SolverProgram program)
-{
- return -1;
-}
-
-static gboolean
-w_glpk_set_option (SolverProgram program, SolverOptionType option,
- const gboolean *b_value,
- const gnm_float *f_value, const int *i_value)
-{
- switch (option) {
- case SolverOptAutomaticScaling:
- return FALSE;
- case SolverOptMaxIter:
-printf ("FIXME: Max iter=%d\n", *i_value);
- return FALSE;
- case SolverOptMaxTimeSec:
-printf ("FIXME: Max time (sec.)=%d\n", *i_value);
- return FALSE;
- default:
- return TRUE;
- }
-}
-
-
-/* ------------------------------------------------------------------------- */
/*
* Solver's API wrappings for QP (currently dummy only).
@@ -762,46 +177,23 @@ w_qp_dummy_print (SolverProgram program)
const SolverLPAlgorithm lp_algorithm [] = {
{
NULL,
- (solver_init_fn*) w_lp_solve_init,
- (solver_remove_fn*) w_lp_solve_delete_lp,
- (solver_lp_set_obj_fn*) w_lp_solve_set_obj_fn,
- (solver_lp_set_constr_mat_fn*) w_lp_solve_set_constr_mat,
- (solver_lp_set_constr_fn*) w_lp_solve_set_constr,
- (solver_lp_set_maxim_fn*) w_lp_solve_set_maxim,
- (solver_lp_set_minim_fn*) w_lp_solve_set_minim,
- (solver_lp_set_int_fn*) w_lp_solve_set_int,
- (solver_lp_set_bool_fn*) w_lp_solve_set_bool,
- (solver_lp_solve_fn*) w_lp_solve_solve,
- (solver_lp_get_obj_fn_value_fn*) w_lp_solve_get_value_of_obj_fn,
- (solver_lp_get_obj_fn_var_fn*) w_lp_solve_get_solution,
- (solver_lp_get_shadow_prize_fn*) w_lp_solve_get_dual,
- (solver_lp_get_iterations_fn*) w_lp_solve_get_iterations,
- (solver_lp_set_option_fn*) w_lp_solve_set_option,
- (solver_lp_print_fn*) w_lp_solve_print_lp
- },
-
-#if __HAVE_GLPK__
- {
- NULL,
- (solver_init_fn*) w_glpk_init,
- (solver_remove_fn*) w_glpk_delete_lp,
- (solver_lp_set_obj_fn*) w_glpk_set_obj_fn,
- (solver_lp_set_constr_mat_fn*) w_glpk_set_constr_mat,
- (solver_lp_set_constr_fn*) w_glpk_set_constr,
- (solver_lp_set_maxim_fn*) w_glpk_set_maxim,
- (solver_lp_set_minim_fn*) w_glpk_set_minim,
- (solver_lp_set_int_fn*) w_glpk_set_int,
- (solver_lp_set_bool_fn*) w_glpk_set_bool,
- (solver_lp_solve_fn*) w_glpk_simplex_solve,
- (solver_lp_get_obj_fn_value_fn*) w_glpk_get_value_of_obj_fn,
- (solver_lp_get_obj_fn_var_fn*) w_glpk_get_solution,
- (solver_lp_get_shadow_prize_fn*) w_glpk_get_dual,
- (solver_lp_get_iterations_fn*) w_glpk_get_iterations,
- (solver_lp_set_option_fn*) w_glpk_set_option,
- (solver_lp_print_fn*) w_glpk_print_lp
+ (solver_init_fn*) w_qp_dummy_init,
+ (solver_remove_fn*) w_qp_dummy_delete,
+ (solver_lp_set_obj_fn*) w_qp_dummy_set_obj_fn,
+ (solver_lp_set_constr_mat_fn*) w_qp_dummy_set_constr_mat,
+ (solver_lp_set_constr_fn*) w_qp_dummy_set_constr,
+ (solver_lp_set_maxim_fn*) w_qp_dummy_set_maxim,
+ (solver_lp_set_minim_fn*) w_qp_dummy_set_minim,
+ (solver_lp_set_int_fn*) w_qp_dummy_set_int,
+ (solver_lp_set_bool_fn*) w_qp_dummy_set_bool,
+ (solver_lp_solve_fn*) w_qp_dummy_solve,
+ (solver_lp_get_obj_fn_value_fn*) w_qp_dummy_get_value_of_obj_fn,
+ (solver_lp_get_obj_fn_var_fn*) w_qp_dummy_get_solution,
+ (solver_lp_get_shadow_prize_fn*) w_qp_dummy_get_dual,
+ (solver_lp_get_iterations_fn *) w_qp_dummy_solver_lp_get_iterations,
+ (solver_lp_set_option_fn*) w_qp_dummy_set_option,
+ (solver_lp_print_fn*) w_qp_dummy_print
},
-#endif
-
{ NULL }
};
diff --git a/src/tools/solver/solver.c b/src/tools/solver/solver.c
index ef1a80f..cfe4d95 100644
--- a/src/tools/solver/solver.c
+++ b/src/tools/solver/solver.c
@@ -379,42 +379,6 @@ solver_param_read_sax (GsfXMLIn *xin, xmlChar const **attrs)
-static SolverResults *
-solver_results_init (const SolverParameters *sp)
-{
- SolverResults *res = g_new (SolverResults, 1);
-
- res->optimal_values = g_new (gnm_float, sp->n_variables);
- res->original_values = g_new (gnm_float, sp->n_variables);
- res->variable_names = g_new0 (gchar *, sp->n_variables);
- res->constraint_names = g_new0 (gchar *, sp->n_total_constraints);
- res->shadow_prizes = g_new0 (gnm_float, sp->n_total_constraints);
- res->slack = g_new0 (gnm_float, sp->n_total_constraints);
- res->lhs = g_new0 (gnm_float, sp->n_total_constraints);
- res->rhs = g_new0 (gnm_float, sp->n_total_constraints);
- res->n_variables = sp->n_variables;
- res->n_constraints = sp->n_constraints;
- res->n_nonzeros_in_obj = 0;
- res->n_nonzeros_in_mat = 0;
- res->n_iterations = 0;
- res->time_user = 0;
- res->time_system = 0;
- res->time_real = 0;
- res->ilp_flag = FALSE;
- res->target_name = NULL;
- res->input_cells_array = NULL;
- res->constraints_array = NULL;
- res->obj_coeff = NULL;
- res->constr_coeff = NULL;
- res->limits = NULL;
- res->constr_allowable_increase =
- g_new0 (gnm_float, sp->n_total_constraints);
- res->constr_allowable_decrease =
- g_new0 (gnm_float, sp->n_total_constraints);
-
- return res;
-}
-
void
solver_results_free (SolverResults *res)
{
@@ -567,27 +531,6 @@ gnm_solver_constraint_valid (SolverConstraint const *c,
return TRUE;
}
-static int
-gnm_solver_constraint_get_size (SolverConstraint const *c)
-{
- GnmRange r;
- GnmValue const *lhs;
-
- g_return_val_if_fail (c != NULL, 0);
-
- lhs = gnm_solver_constraint_get_lhs (c);
- if (lhs) {
- if (VALUE_IS_FLOAT (lhs))
- return 1;
- if (lhs->type == VALUE_CELLRANGE) {
- range_init_value (&r, lhs);
- return range_width (&r) * range_height (&r);
- }
- }
-
- return 0;
-}
-
GnmValue const *
gnm_solver_constraint_get_lhs (SolverConstraint const *c)
{
@@ -671,53 +614,6 @@ gnm_solver_constraint_get_part (SolverConstraint const *c,
return TRUE;
}
-static gboolean
-gnm_solver_constraint_get_part_val (SolverConstraint const *c,
- SolverParameters const *sp, int i,
- GnmValue **lhs, GnmValue **rhs)
-{
- GnmRange r;
- int h, w, dx, dy;
- GnmValue const *vl, *vr;
-
- if (lhs) *lhs = NULL;
- if (rhs) *rhs = NULL;
-
- if (!gnm_solver_constraint_valid (c, sp))
- return FALSE;
-
- vl = gnm_solver_constraint_get_lhs (c);
- vr = gnm_solver_constraint_get_rhs (c);
-
- range_init_value (&r, vl);
- w = range_width (&r);
- h = range_height (&r);
-
- dy = i / w;
- dx = i % w;
- if (dy >= h)
- return FALSE;
-
- r.start.col += dx;
- r.start.row += dy;
- r.end = r.start;
- if (lhs) *lhs = value_new_cellrange_r (sp->sheet, &r);
-
- if (rhs && gnm_solver_constraint_has_rhs (c)) {
- if (VALUE_IS_FLOAT (vr)) {
- *rhs = value_dup (vr);
- } else {
- range_init_value (&r, vr);
- r.start.col += dx;
- r.start.row += dy;
- r.end = r.start;
- *rhs = value_new_cellrange_r (sp->sheet, &r);
- }
- }
-
- return TRUE;
-}
-
void
gnm_solver_constraint_set_old (SolverConstraint *c,
SolverConstraintType type,
@@ -792,485 +688,6 @@ gnm_solver_constraint_as_str (SolverConstraint const *c, Sheet *sheet)
/* ------------------------------------------------------------------------- */
-/*
- * This function implements a simple way to determine linear
- * coefficents. For example, if we have the minization target cell in
- * `target' and the first input variable in `change', this function
- * returns the coefficent of the first variable of the objective
- * function.
- */
-static gnm_float
-get_lp_coeff (GnmCell *target, GnmCell *change)
-{
- gnm_float x0, x1;
-
- gnm_cell_set_value (change, value_new_float (1));
- cell_queue_recalc (change);
- gnm_cell_eval (target);
- x1 = value_get_as_float (target->value);
-
- gnm_cell_set_value (change, value_new_float (0));
- cell_queue_recalc (change);
- gnm_cell_eval (target);
- x0 = value_get_as_float (target->value);
-
- return x1 - x0;
-}
-
-/*
- * Saves the original values of the input variables into a
- * SolverResults entry.
- */
-static void
-save_original_values (SolverResults *res,
- const SolverParameters *param,
- Sheet *sheet)
-{
- GSList *input_cells = gnm_solver_param_get_input_cells (param);
- GSList *l;
- GnmCell *cell;
- int i;
-
- for (i = 0, l = input_cells; l; i++, l = l->next) {
- GnmCell *cell = l->data;
-
- if (cell == NULL || cell->value == NULL)
- res->original_values[i] = 0;
- else
- res->original_values[i] =
- value_get_as_float (cell->value);
- }
-
- g_slist_free (input_cells);
-
- cell = gnm_solver_param_get_target_cell (param);
- res->original_value_of_obj_fn = value_get_as_float (cell->value);
-}
-
-/************************************************************************
- */
-
-static int
-get_col_nbr (SolverResults *res, GnmValue const *v)
-{
- int i;
- GnmRange r;
-
- range_init_value (&r, v);
-
- for (i = 0; i < res->param->n_variables; i++) {
- GnmCell *cell = solver_get_input_var (res, i);
- if (gnm_cellpos_equal (&r.start, &cell->pos))
- return i;
- }
- return -1;
-}
-
-/* ------------------------------------------------------------------------- */
-
-static void
-clear_input_vars (int n_variables, SolverResults *res)
-{
- int i;
-
- for (i = 0; i < n_variables; i++)
- sheet_cell_set_value (solver_get_input_var (res, i),
- value_new_float (0.0));
-}
-
-/*
- * Initializes the program according to the information given in the
- * solver dialog and the related sheet. After the call, the LP
- * program is ready to run.
- */
-static SolverProgram
-lp_qp_solver_init (Sheet *sheet, const SolverParameters *param,
- SolverResults *res, const SolverLPAlgorithm *alg,
- gnm_float start_time, GTimeVal start, GError **err)
-{
- SolverProgram program;
- GnmCell *target;
- gnm_float x;
- int i, n, ind;
-
- /* Initialize the SolverProgram structure. */
- program = alg->init_fn (param);
-
- /* Set up the objective function coefficients. */
- target = gnm_solver_param_get_target_cell (param);
- clear_input_vars (param->n_variables, res);
-
- gnm_cell_eval (target);
-
- if (param->options.model_type == SolverLPModel) {
- for (i = 0; i < param->n_variables; i++) {
- x = get_lp_coeff (target,
- solver_get_input_var (res, i));
- if (x != 0) {
- alg->set_obj_fn (program, i, x);
- res->n_nonzeros_in_obj += 1;
- res->obj_coeff[i] = x;
- }
- }
- } else {
- /* FIXME: Init qp */
- }
-
- /* Add constraints. */
- for (i = ind = 0; i < param->n_total_constraints; i++) {
- SolverConstraint const *c = solver_get_constraint (res, i);
- GTimeVal cur_time;
- const GnmValue *lval;
- const GnmValue *rval;
- gnm_float lx, rx;
-
- gnm_solver_constraint_get_part (c, param, 0,
- &target, NULL,
- NULL, NULL);
- if (target) {
- gnm_cell_eval (target);
- lval = target->value;
- } else
- lval = NULL;
-
- /* Check that LHS is a number type. */
- if (lval == NULL || !VALUE_IS_NUMBER (lval)) {
- g_set_error (err, go_error_invalid (), 0,
- _("The LHS cells should contain formulas "
- "that yield proper numerical values. "
- "Specify valid LHS entries."));
- return NULL;
- }
- lx = value_get_as_float (lval);
-
- if (c->type == SolverINT) {
- n = get_col_nbr (res, gnm_solver_constraint_get_lhs (c));
- if (n == -1)
- return NULL;
- alg->set_int_fn (program, n);
- res->ilp_flag = TRUE;
- continue;
- }
- if (c->type == SolverBOOL) {
- n = get_col_nbr (res, gnm_solver_constraint_get_lhs (c));
- if (n == -1)
- return NULL;
- alg->set_bool_fn (program, n);
- res->ilp_flag = TRUE;
- continue;
- }
- clear_input_vars (param->n_variables, res);
- for (n = 0; n < param->n_variables; n++) {
- x = get_lp_coeff (target,
- solver_get_input_var (res, n));
- if (x != 0) {
- res->n_nonzeros_in_mat += 1;
- alg->set_constr_mat_fn (program, n, ind, x);
- res->constr_coeff[i][n] = x;
- }
- }
-
- gnm_solver_constraint_get_part (c, param, 0,
- NULL, NULL, &target, NULL);
- if (target) {
- gnm_cell_eval (target);
- rval = target->value;
- } else
- rval = NULL;
-
- /* Check that RHS is a number type. */
- if (rval == NULL || !VALUE_IS_NUMBER (rval)) {
- g_set_error (err, go_error_invalid (), 0,
- _("The RHS cells should contain proper "
- "numerical values only. Specify valid "
- "RHS entries."));
- return NULL;
- }
- rx = value_get_as_float (rval);
-
- x = rx - lx;
- alg->set_constr_fn (program, ind, c->type, x);
- res->rhs[i] = x;
- ind++;
-
- /* Check that max time has not elapsed. */
- g_get_current_time (&cur_time);
- if (cur_time.tv_sec - start.tv_sec >
- param->options.max_time_sec) {
- g_set_error (err, go_error_invalid (), 0,
- SOLVER_MAX_TIME_ERR);
- return NULL;
- }
-
- }
-
- /* Set up the problem type. */
- switch (param->problem_type) {
- case SolverMinimize:
- alg->minim_fn (program);
- break;
- case SolverMaximize:
- alg->maxim_fn (program);
- break;
- case SolverEqualTo:
- g_set_error (err, go_error_invalid (), 0,
- _("EqualTo models are not supported yet. "
- "Please use Min or Max"));
- return NULL; /* FIXME: Equal to feature not yet implemented. */
- default:
- g_warning ("unknown problem type %d", param->problem_type);
- return NULL;
- }
-
- /* Set options. */
- if (alg->set_option_fn (program, SolverOptAutomaticScaling,
- &(param->options.automatic_scaling),
- NULL, NULL)) {
- g_set_error (err, go_error_invalid (), 0,
- _("Failure setting automatic scaling with this solver, try a different algorithm."));
- return NULL;
- }
- if (alg->set_option_fn (program, SolverOptMaxIter, NULL, NULL,
- &(param->options.max_iter))) {
- g_set_error (err, go_error_invalid (), 0,
- _("Failure setting the maximum number of iterations with this solver, try a different algorithm."));
- return NULL;
- }
- if (alg->set_option_fn (program, SolverOptMaxTimeSec, NULL, &start_time,
- &(param->options.max_time_sec))) {
- g_set_error (err, go_error_invalid (), 0,
- _("Failure setting the maximum solving time with this solver, try a different algorithm."));
- return NULL;
- }
-
- /* Assume Integer (Discrete) button. */
- if (param->options.assume_discrete) {
- for (i = 0; i < param->n_variables; i++)
- alg->set_int_fn (program, i);
- res->ilp_flag = TRUE;
- }
-
- alg->print_fn (program);
-
- return program;
-}
-
-/*
- * Returns TRUE if an error is found in the program definition.
- * Otherwise, return FALSE (Ok).
- */
-static gboolean
-check_program_definition_failures (Sheet *sheet,
- SolverParameters *param,
- SolverResults **res,
- GError **err)
-{
- GSList *inputs;
- GSList *c;
- int i;
- GnmCell **input_cells_array;
- SolverConstraint **constraints_array;
- GSList *input_cells = gnm_solver_param_get_input_cells (param);
-
- param->n_variables = 0;
-
- /*
- * Checks for the Input cells.
- */
-
- /* Count the nbr of the input cells and check that each cell
- * is in the list only once. */
- for (inputs = input_cells; inputs ; inputs = inputs->next) {
- GnmCell *cell = inputs->data;
-
- /* Check that the cell contains a number or is empty. */
- if (! (cell->value == NULL || VALUE_IS_EMPTY (cell->value)
- || VALUE_IS_NUMBER (cell->value))) {
- g_set_error (err, go_error_invalid (), 0,
- _("Some of the input cells contain "
- "non-numeric values. Specify a valid "
- "input range."));
- g_slist_free (input_cells);
- return TRUE;
- }
-
- param->n_variables += 1;
- }
- input_cells_array = g_new (GnmCell *, param->n_variables);
- i = 0;
- for (inputs = input_cells; inputs ; inputs = inputs->next)
- input_cells_array[i++] = (GnmCell *) inputs->data;
- g_slist_free (input_cells);
-
- param->n_constraints = 0;
- param->n_int_constraints = 0;
- param->n_bool_constraints = 0;
- i = 0;
- for (c = param->constraints; c ; c = c->next) {
- SolverConstraint *sc = c->data;
- int N = gnm_solver_constraint_get_size (sc);
-
- if (sc->type == SolverINT)
- param->n_int_constraints += N;
- else if (sc->type == SolverBOOL)
- param->n_bool_constraints += N;
- else
- param->n_constraints += N;
- }
- param->n_total_constraints = param->n_constraints +
- param->n_int_constraints + param->n_bool_constraints;
- constraints_array = g_new (SolverConstraint *,
- param->n_total_constraints);
- i = 0;
- for (c = param->constraints; c ; c = c->next) {
- SolverConstraint *sc = c->data;
- int j;
- GnmValue *lhs, *rhs;
-
- for (j = 0;
- gnm_solver_constraint_get_part_val (sc, param, j,
- &lhs, &rhs);
- j++) {
- SolverConstraint *nc =
- gnm_solver_constraint_new (sheet);
- nc->type = sc->type;
- gnm_solver_constraint_set_lhs (nc, lhs);
- gnm_solver_constraint_set_rhs (nc, rhs);
- constraints_array[i++] = nc;
- }
- }
-
- *res = solver_results_init (param);
-
- (*res)->param = param;
- (*res)->input_cells_array = input_cells_array;
- (*res)->constraints_array = constraints_array;
- (*res)->obj_coeff = g_new0 (gnm_float, param->n_variables);
-
- (*res)->constr_coeff = g_new0 (gnm_float *, param->n_total_constraints);
- for (i = 0; i < param->n_total_constraints; i++)
- (*res)->constr_coeff[i] = g_new0 (gnm_float,
- param->n_variables);
- (*res)->limits = g_new (SolverLimits, param->n_variables);
-
- return FALSE; /* Everything Ok. */
-}
-
-static SolverResults *
-solver_run (WorkbookControl *wbc, Sheet *sheet,
- const SolverLPAlgorithm *alg, GError **err)
-{
- SolverParameters *param = sheet->solver_parameters;
- SolverProgram program;
- SolverResults *res;
- GnmValue const * vinput = gnm_solver_param_get_input (param);
- GnmSheetRange sr;
- GOUndo *undo;
- GTimeVal start, end;
-#if defined(HAVE_TIMES) && defined(HAVE_SYSCONF)
- struct tms buf;
-
- times (&buf);
-#warning what is the equivalent of times for win32
-#endif
-
- g_get_current_time (&start);
-
- if (!gnm_solver_param_valid (param, err))
- return NULL;
-
- if (check_program_definition_failures (sheet, param, &res, err))
- return NULL;
-
-#if defined(HAVE_TIMES) && defined(HAVE_SYSCONF)
- res->time_user = - buf.tms_utime / (gnm_float) sysconf (_SC_CLK_TCK);
- res->time_system = - buf.tms_stime / (gnm_float) sysconf (_SC_CLK_TCK);
-#else
- res->time_user = 0;
- res->time_system = 0;
-#warning TODO
-#endif
- res->time_real = - (start.tv_sec +
- start.tv_usec / (gnm_float) G_USEC_PER_SEC);
-
- gnm_sheet_range_from_value (&sr, vinput);
- if (!sr.sheet) sr.sheet = sheet;
- undo = clipboard_copy_range_undo (sr.sheet, &sr.range);
-
- save_original_values (res, param, sheet);
-
- program = lp_qp_solver_init (sheet, param, res, alg,
- -res->time_real, start,
- err);
- if (program == NULL)
- goto fail;
-
- res->status = alg->solve_fn (program);
- g_get_current_time (&end);
-#if defined(HAVE_TIMES) && defined(HAVE_SYSCONF)
- times (&buf);
- res->time_user += buf.tms_utime / (gnm_float) sysconf (_SC_CLK_TCK);
- res->time_system += buf.tms_stime / (gnm_float) sysconf (_SC_CLK_TCK);
-#else
-#warning TODO
- res->time_user = 0;
- res->time_system = 0;
-#endif
- res->time_real += end.tv_sec + end.tv_usec /
- (gnm_float) G_USEC_PER_SEC;
- res->n_iterations = alg->get_iterations_fn (program);
-
- solver_prepare_reports (program, res, sheet);
- if (res->status == SolverOptimal) {
- GOUndo *redo;
- if (solver_prepare_reports_success (program, res, sheet)) {
- alg->remove_fn (program);
- goto fail;
- }
- redo = clipboard_copy_range_undo (sr.sheet, &sr.range);
- cmd_solver (wbc, undo, redo);
- } else {
- go_undo_undo (undo);
- g_object_unref (undo);
- undo = NULL;
- }
-
- alg->remove_fn (program);
-
- return res;
-
- fail:
- if (res)
- solver_results_free (res);
- if (undo)
- g_object_unref (undo);
- return NULL;
-}
-
-SolverResults *
-solver (WorkbookControl *wbc, Sheet *sheet, GError **err)
-{
- const SolverLPAlgorithm *alg = NULL;
- SolverParameters *param = sheet->solver_parameters;
-
- switch (sheet->solver_parameters->options.model_type) {
- case SolverLPModel:
- alg = &lp_algorithm [0 /* param->options.algorithm */];
- break;
- case SolverQPModel:
- alg = &qp_algorithm [0 /* param->options.algorithm */];
- break;
- case SolverNLPModel:
- return NULL;
-
- default :
- g_assert_not_reached ();
- }
-
- return solver_run (wbc, sheet, alg, err);
-}
-
-
SolverParameters *
gnm_solver_param_dup (const SolverParameters *src_param, Sheet *new_sheet)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]