[gnumeric] solver: namespace.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] solver: namespace.
- Date: Thu, 12 Nov 2009 15:10:44 +0000 (UTC)
commit 1a864067f115b1a83e2d02b78ef0aaba323247db
Author: Morten Welinder <terra gnome org>
Date: Thu Nov 12 10:10:32 2009 -0500
solver: namespace.
plugins/lpsolve/lpsolve-write.c | 14 ++--
plugins/mps/mps.c | 8 +-
plugins/mps/parser.c | 2 +-
plugins/openoffice/openoffice-write.c | 1 -
src/dialogs/dialog-solver.c | 13 ++--
src/gnumeric.h | 1 +
src/sheet.c | 2 +-
src/solver.h | 119 +--------------------------------
src/tools/gnm-solver.c | 7 ++-
src/tools/gnm-solver.h | 48 +++++++++++++
src/tools/solver/api.c | 2 +-
src/tools/solver/api.h | 64 ++++++++++++++++++
src/tools/solver/reports-write.c | 25 ++++---
src/tools/solver/reports.c | 22 +++---
src/tools/solver/solver.c | 70 ++++++++++----------
src/xml-sax-read.c | 2 +-
src/xml-sax-write.c | 14 ++--
17 files changed, 207 insertions(+), 207 deletions(-)
---
diff --git a/plugins/lpsolve/lpsolve-write.c b/plugins/lpsolve/lpsolve-write.c
index aae3d53..a8d8f1e 100644
--- a/plugins/lpsolve/lpsolve-write.c
+++ b/plugins/lpsolve/lpsolve-write.c
@@ -25,7 +25,7 @@
#include <value.h>
#include <cell.h>
#include <expr.h>
-#include <solver.h>
+#include <tools/gnm-solver.h>
#include <ranges.h>
#include <parse-util.h>
#include <gutils.h>
@@ -225,7 +225,7 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context, GError **err)
}
for (l = sp->constraints; l; l = l->next) {
- SolverConstraint *c = l->data;
+ GnmSolverConstraint *c = l->data;
const char *op = NULL;
const char *type = NULL;
gboolean right_small = TRUE;
@@ -234,20 +234,20 @@ lpsolve_create_program (Sheet *sheet, GOIOContext *io_context, GError **err)
GnmCell *lhs, *rhs;
switch (c->type) {
- case SolverLE:
+ case GNM_SOLVER_LE:
op = "<=";
right_small = FALSE;
break;
- case SolverGE:
+ case GNM_SOLVER_GE:
op = ">=";
break;
- case SolverEQ:
+ case GNM_SOLVER_EQ:
op = "=";
break;
- case SolverINT:
+ case GNM_SOLVER_INTEGER:
type = "int";
break;
- case SolverBOOL:
+ case GNM_SOLVER_BOOLEAN:
type = "binary";
break;
default:
diff --git a/plugins/mps/mps.c b/plugins/mps/mps.c
index 0c6bab5..016f032 100644
--- a/plugins/mps/mps.c
+++ b/plugins/mps/mps.c
@@ -42,7 +42,7 @@
#include "ranges.h"
#include "style.h"
#include "value.h"
-#include "solver.h"
+#include <tools/gnm-solver.h>
#include "sheet-style.h"
#include "parse-util.h"
#include "func.h"
@@ -321,7 +321,7 @@ mps_write_coefficients (MpsInputContext *ctxt, Sheet *sh,
i = 0;
for (current = ctxt->rows; current != NULL; current = current->next) {
- SolverConstraint *c;
+ GnmSolverConstraint *c;
MpsRow *row = current->data;
int col, r;
const GnmExprTop *texpr;
@@ -330,8 +330,8 @@ mps_write_coefficients (MpsInputContext *ctxt, Sheet *sh,
static const gchar *const type_str[] = {
"=", "<=", ">="
};
- static const SolverConstraintType type_map[] = {
- SolverEQ, SolverLE, SolverGE
+ static const GnmSolverConstraintType type_map[] = {
+ GNM_SOLVER_EQ, GNM_SOLVER_LE, GNM_SOLVER_GE
};
if (row->type == ObjectiveRow)
diff --git a/plugins/mps/parser.c b/plugins/mps/parser.c
index 00ad414..ef59e19 100644
--- a/plugins/mps/parser.c
+++ b/plugins/mps/parser.c
@@ -35,7 +35,7 @@
#include "ranges.h"
#include "style.h"
#include "value.h"
-#include "solver.h"
+#include <tools/gnm-solver.h>
#include "sheet-style.h"
#include "parse-util.h"
#include <glib/gi18n-lib.h>
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 5aa64c7..2e36bc3 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -54,7 +54,6 @@
#include <style-border.h>
#include <validation.h>
#include <hlink.h>
-#include <solver.h>
#include <sheet-filter.h>
#include <print-info.h>
#include <parse-util.h>
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index 0d3f71e..e08162a 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -31,7 +31,6 @@
#include <gui-util.h>
#include <func.h>
-#include <solver.h>
#include <tool-dialogs.h>
#include <value.h>
#include <cell.h>
@@ -75,7 +74,7 @@ typedef struct {
GtkComboBox *type_combo;
GtkComboBox *algorithm_combo;
GtkTreeView *constraint_list;
- SolverConstraint *constr;
+ GnmSolverConstraint *constr;
GtkWidget *warning_dialog;
struct {
@@ -110,7 +109,7 @@ static char const * const model_type_group[] = {
};
static void
-constraint_fill (SolverConstraint *c, SolverState *state)
+constraint_fill (GnmSolverConstraint *c, SolverState *state)
{
Sheet *sheet = state->sheet;
@@ -132,7 +131,7 @@ dialog_set_sec_button_sensitivity (G_GNUC_UNUSED GtkWidget *dummy,
SolverState *state)
{
gboolean select_ready = (state->constr != NULL);
- SolverConstraint *test = gnm_solver_constraint_new (NULL);
+ GnmSolverConstraint *test = gnm_solver_constraint_new (NULL);
gboolean ready, has_rhs;
SolverParameters const *param = state->sheet->solver_parameters;
@@ -157,7 +156,7 @@ constraint_select_click (GtkTreeSelection *Selection,
{
GtkTreeModel *store;
GtkTreeIter iter;
- SolverConstraint const *c;
+ GnmSolverConstraint const *c;
GnmValue const *lhs, *rhs;
if (gtk_tree_selection_get_selected (Selection, &store, &iter))
@@ -232,7 +231,7 @@ static void
constraint_fill_row (SolverState *state, GtkListStore *store, GtkTreeIter *iter)
{
char *text;
- SolverConstraint *c = state->constr;
+ GnmSolverConstraint *c = state->constr;
constraint_fill (c, state);
@@ -1112,7 +1111,7 @@ dialog_init (SolverState *state)
/* Loading the old solver specs... from param */
for (cl = param->constraints; cl; cl = cl->next) {
- SolverConstraint const *c = cl->data;
+ GnmSolverConstraint const *c = cl->data;
GtkTreeIter iter;
char *str;
diff --git a/src/gnumeric.h b/src/gnumeric.h
index b8ac365..559cc7c 100644
--- a/src/gnumeric.h
+++ b/src/gnumeric.h
@@ -184,6 +184,7 @@ typedef struct _GnmSheetSlicer GnmSheetSlicer;
typedef struct _PrintInformation PrintInformation;
typedef struct _SolverParameters SolverParameters;
+typedef struct GnmSolverConstraint_ GnmSolverConstraint;
typedef struct GnmSolverFactory_ GnmSolverFactory;
G_END_DECLS
diff --git a/src/sheet.c b/src/sheet.c
index cda4327..f94b92b 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -55,7 +55,7 @@
#include "gnumeric-gconf.h"
#include "sheet-object-impl.h"
#include "sheet-object-cell-comment.h"
-#include "solver.h"
+#include <tools/gnm-solver.h>
#include "hlink.h"
#include "sheet-filter.h"
#include "sheet-filter-combo.h"
diff --git a/src/solver.h b/src/solver.h
index 2c1afe4..3066a61 100644
--- a/src/solver.h
+++ b/src/solver.h
@@ -83,58 +83,6 @@ gboolean gnm_solver_param_valid (SolverParameters const *sp, GError **err);
/* -------------------------------------------------------------------------- */
-typedef enum {
- SolverLE,
- SolverGE,
- SolverEQ,
- SolverINT,
- SolverBOOL
-} SolverConstraintType;
-
-typedef struct {
- SolverConstraintType type;
-
- /* Must be a range. */
- GnmDependent lhs;
-
- /* Must be a constant or a range. */
- GnmDependent rhs;
-} SolverConstraint;
-
-#ifdef GNM_ENABLE_SOLVER
-
-SolverConstraint *gnm_solver_constraint_new (Sheet *sheet);
-void gnm_solver_constraint_free (SolverConstraint *c);
-
-void gnm_solver_constraint_set_old (SolverConstraint *c,
- SolverConstraintType type,
- int lhs_col, int lhs_row,
- int rhs_col, int rhs_row,
- int cols, int rows);
-
-gboolean gnm_solver_constraint_has_rhs (SolverConstraint const *c);
-gboolean gnm_solver_constraint_valid (SolverConstraint const *c,
- SolverParameters const *sp);
-gboolean gnm_solver_constraint_get_part (SolverConstraint const *c,
- SolverParameters const *sp, int i,
- GnmCell **lhs, gnm_float *cl,
- GnmCell **rhs, gnm_float *cr);
-
-GnmValue const *gnm_solver_constraint_get_lhs (SolverConstraint const *c);
-GnmValue const *gnm_solver_constraint_get_rhs (SolverConstraint const *c);
-
-void gnm_solver_constraint_set_lhs (SolverConstraint *c, GnmValue *v);
-void gnm_solver_constraint_set_rhs (SolverConstraint *c, GnmValue *v);
-
-void gnm_solver_constraint_side_as_str (SolverConstraint const *c,
- Sheet const *sheet,
- GString *buf, gboolean lhs);
-char *gnm_solver_constraint_as_str (SolverConstraint const *c, Sheet *sheet);
-
-#endif
-
-/* -------------------------------------------------------------------------- */
-
#ifdef GNM_ENABLE_SOLVER
typedef enum {
@@ -149,69 +97,6 @@ typedef enum {
typedef gpointer SolverProgram;
-
-/*
- * Solver's API for LP solving algorithms
- */
-typedef SolverProgram
- (solver_init_fn) (SolverParameters const *param);
-typedef void
- (solver_remove_fn) (SolverProgram p);
-typedef void
- (solver_lp_set_obj_fn) (SolverProgram p, int col, gnm_float v);
-typedef void
- (solver_lp_set_constr_mat_fn) (SolverProgram p, int col, int row,
- gnm_float v);
-typedef void
- (solver_lp_set_constr_fn) (SolverProgram p, int row,
- SolverConstraintType t, gnm_float rhs);
-typedef void
- (solver_lp_set_maxim_fn) (SolverProgram p);
-typedef void
- (solver_lp_set_minim_fn) (SolverProgram p);
-typedef void
- (solver_lp_set_int_fn) (SolverProgram p, int col);
-typedef void
- (solver_lp_set_bool_fn) (SolverProgram p, int col);
-typedef SolverStatus
- (solver_lp_solve_fn) (SolverProgram p);
-typedef gnm_float
- (solver_lp_get_obj_fn_value_fn) (SolverProgram p);
-typedef gnm_float
- (solver_lp_get_obj_fn_var_fn) (SolverProgram p, int col);
-typedef gnm_float
- (solver_lp_get_shadow_prize_fn) (SolverProgram p, int row);
-typedef gboolean
- (solver_lp_set_option_fn) (SolverProgram p, SolverOptionType option,
- const gboolean *b_value,
- const gnm_float *f_value,
- const int *i_value);
-typedef void
- (solver_lp_print_fn) (SolverProgram p);
-typedef int
- (solver_lp_get_iterations_fn) (SolverProgram p);
-
-
-typedef struct {
- char const *name;
- solver_init_fn *init_fn;
- solver_remove_fn *remove_fn;
- solver_lp_set_obj_fn *set_obj_fn;
- solver_lp_set_constr_mat_fn *set_constr_mat_fn;
- solver_lp_set_constr_fn *set_constr_fn;
- solver_lp_set_maxim_fn *maxim_fn;
- solver_lp_set_minim_fn *minim_fn;
- solver_lp_set_int_fn *set_int_fn;
- solver_lp_set_bool_fn *set_bool_fn;
- solver_lp_solve_fn *solve_fn;
- solver_lp_get_obj_fn_value_fn *get_obj_fn_value_fn;
- solver_lp_get_obj_fn_var_fn *get_obj_fn_var_fn;
- solver_lp_get_shadow_prize_fn *get_shadow_prize_fn;
- solver_lp_get_iterations_fn *get_iterations_fn;
- solver_lp_set_option_fn *set_option_fn;
- solver_lp_print_fn *print_fn;
-} SolverLPAlgorithm;
-
typedef struct {
gnm_float lower_limit;
gnm_float lower_result;
@@ -246,7 +131,7 @@ typedef struct {
* constraints. Some reports cannot
* be created if there are any. */
GnmCell **input_cells_array;
- SolverConstraint **constraints_array;
+ GnmSolverConstraint **constraints_array;
gnm_float *obj_coeff;
gnm_float **constr_coeff;
SolverLimits *limits;
@@ -273,7 +158,7 @@ void solver_results_free (SolverResults *res);
GnmCell *solver_get_input_var (SolverResults *res, int n);
/* Returns a pointer to a constraint. */
-SolverConstraint* solver_get_constraint (SolverResults *res, int n);
+GnmSolverConstraint* solver_get_constraint (SolverResults *res, int n);
void solver_param_read_sax (GsfXMLIn *xin, xmlChar const **attrs);
diff --git a/src/tools/gnm-solver.c b/src/tools/gnm-solver.c
index b318b2e..187a5c5 100644
--- a/src/tools/gnm-solver.c
+++ b/src/tools/gnm-solver.c
@@ -5,6 +5,7 @@
#include "sheet.h"
#include "workbook.h"
#include "ranges.h"
+#include "gutils.h"
#include "gnm-solver.h"
#include "workbook-view.h"
#include "workbook-control.h"
@@ -649,7 +650,8 @@ gnm_solver_factory_create (GnmSolverFactory *factory,
void
gnm_solver_db_register (GnmSolverFactory *factory)
{
- g_printerr ("Registering %s\n", factory->id);
+ if (gnm_debug_flag ("solver"))
+ g_printerr ("Registering %s\n", factory->id);
g_object_ref (factory);
solvers = g_slist_prepend (solvers, factory);
}
@@ -657,7 +659,8 @@ gnm_solver_db_register (GnmSolverFactory *factory)
void
gnm_solver_db_unregister (GnmSolverFactory *factory)
{
- g_printerr ("Unregistering %s\n", factory->id);
+ if (gnm_debug_flag ("solver"))
+ g_printerr ("Unregistering %s\n", factory->id);
solvers = g_slist_remove (solvers, factory);
g_object_unref (factory);
}
diff --git a/src/tools/gnm-solver.h b/src/tools/gnm-solver.h
index 62fd705..218f1a5 100644
--- a/src/tools/gnm-solver.h
+++ b/src/tools/gnm-solver.h
@@ -31,6 +31,54 @@ typedef enum {
GNM_SOLVER_STATUS_CANCELLED
} GnmSolverStatus;
+typedef enum {
+ GNM_SOLVER_LE,
+ GNM_SOLVER_GE,
+ GNM_SOLVER_EQ,
+ GNM_SOLVER_INTEGER,
+ GNM_SOLVER_BOOLEAN
+} GnmSolverConstraintType;
+
+/* -------------------------------------------------------------------------- */
+
+struct GnmSolverConstraint_ {
+ GnmSolverConstraintType type;
+
+ /* Must be a range. */
+ GnmDependent lhs;
+
+ /* Must be a constant or a range. */
+ GnmDependent rhs;
+};
+
+GnmSolverConstraint *gnm_solver_constraint_new (Sheet *sheet);
+void gnm_solver_constraint_free (GnmSolverConstraint *c);
+
+void gnm_solver_constraint_set_old (GnmSolverConstraint *c,
+ GnmSolverConstraintType type,
+ int lhs_col, int lhs_row,
+ int rhs_col, int rhs_row,
+ int cols, int rows);
+
+gboolean gnm_solver_constraint_has_rhs (GnmSolverConstraint const *c);
+gboolean gnm_solver_constraint_valid (GnmSolverConstraint const *c,
+ SolverParameters const *sp);
+gboolean gnm_solver_constraint_get_part (GnmSolverConstraint const *c,
+ SolverParameters const *sp, int i,
+ GnmCell **lhs, gnm_float *cl,
+ GnmCell **rhs, gnm_float *cr);
+
+GnmValue const *gnm_solver_constraint_get_lhs (GnmSolverConstraint const *c);
+GnmValue const *gnm_solver_constraint_get_rhs (GnmSolverConstraint const *c);
+
+void gnm_solver_constraint_set_lhs (GnmSolverConstraint *c, GnmValue *v);
+void gnm_solver_constraint_set_rhs (GnmSolverConstraint *c, GnmValue *v);
+
+void gnm_solver_constraint_side_as_str (GnmSolverConstraint const *c,
+ Sheet const *sheet,
+ GString *buf, gboolean lhs);
+char *gnm_solver_constraint_as_str (GnmSolverConstraint const *c, Sheet *sheet);
+
/* ------------------------------------------------------------------------- */
#define GNM_SOLVER_RESULT_TYPE (gnm_solver_result_get_type ())
diff --git a/src/tools/solver/api.c b/src/tools/solver/api.c
index 5430091..b906462 100644
--- a/src/tools/solver/api.c
+++ b/src/tools/solver/api.c
@@ -98,7 +98,7 @@ w_qp_dummy_set_constr_mat (SolverProgram program, int col, int row,
static void
w_qp_dummy_set_constr (SolverProgram program, int row,
- SolverConstraintType type,
+ GnmSolverConstraintType type,
gnm_float value)
{
printf ("w_qp_dummy_set_constr %d, %d, %" GNM_FORMAT_g "\n",
diff --git a/src/tools/solver/api.h b/src/tools/solver/api.h
index afab33c..083a83b 100644
--- a/src/tools/solver/api.h
+++ b/src/tools/solver/api.h
@@ -27,6 +27,70 @@
#include "gnumeric.h"
#include "numbers.h"
#include "solver.h"
+#include <tools/gnm-solver.h>
+
+/*
+ * Solver's API for LP solving algorithms
+ */
+typedef SolverProgram
+ (solver_init_fn) (SolverParameters const *param);
+typedef void
+ (solver_remove_fn) (SolverProgram p);
+typedef void
+ (solver_lp_set_obj_fn) (SolverProgram p, int col, gnm_float v);
+typedef void
+ (solver_lp_set_constr_mat_fn) (SolverProgram p, int col, int row,
+ gnm_float v);
+typedef void
+ (solver_lp_set_constr_fn) (SolverProgram p, int row,
+ GnmSolverConstraintType t, gnm_float rhs);
+typedef void
+ (solver_lp_set_maxim_fn) (SolverProgram p);
+typedef void
+ (solver_lp_set_minim_fn) (SolverProgram p);
+typedef void
+ (solver_lp_set_int_fn) (SolverProgram p, int col);
+typedef void
+ (solver_lp_set_bool_fn) (SolverProgram p, int col);
+typedef SolverStatus
+ (solver_lp_solve_fn) (SolverProgram p);
+typedef gnm_float
+ (solver_lp_get_obj_fn_value_fn) (SolverProgram p);
+typedef gnm_float
+ (solver_lp_get_obj_fn_var_fn) (SolverProgram p, int col);
+typedef gnm_float
+ (solver_lp_get_shadow_prize_fn) (SolverProgram p, int row);
+typedef gboolean
+ (solver_lp_set_option_fn) (SolverProgram p, SolverOptionType option,
+ const gboolean *b_value,
+ const gnm_float *f_value,
+ const int *i_value);
+typedef void
+ (solver_lp_print_fn) (SolverProgram p);
+typedef int
+ (solver_lp_get_iterations_fn) (SolverProgram p);
+
+
+typedef struct {
+ char const *name;
+ solver_init_fn *init_fn;
+ solver_remove_fn *remove_fn;
+ solver_lp_set_obj_fn *set_obj_fn;
+ solver_lp_set_constr_mat_fn *set_constr_mat_fn;
+ solver_lp_set_constr_fn *set_constr_fn;
+ solver_lp_set_maxim_fn *maxim_fn;
+ solver_lp_set_minim_fn *minim_fn;
+ solver_lp_set_int_fn *set_int_fn;
+ solver_lp_set_bool_fn *set_bool_fn;
+ solver_lp_solve_fn *solve_fn;
+ solver_lp_get_obj_fn_value_fn *get_obj_fn_value_fn;
+ solver_lp_get_obj_fn_var_fn *get_obj_fn_var_fn;
+ solver_lp_get_shadow_prize_fn *get_shadow_prize_fn;
+ solver_lp_get_iterations_fn *get_iterations_fn;
+ solver_lp_set_option_fn *set_option_fn;
+ solver_lp_print_fn *print_fn;
+} SolverLPAlgorithm;
+
extern const SolverLPAlgorithm lp_algorithm [];
extern const SolverLPAlgorithm qp_algorithm [];
diff --git a/src/tools/solver/reports-write.c b/src/tools/solver/reports-write.c
index 02cd25a..1b71deb 100644
--- a/src/tools/solver/reports-write.c
+++ b/src/tools/solver/reports-write.c
@@ -42,6 +42,7 @@
#include "value.h"
#include "mathfunc.h"
#include "analysis-tools.h"
+#include <tools/gnm-solver.h>
#ifdef HAVE_UNAME
#include <sys/utsname.h>
@@ -134,7 +135,7 @@ solver_answer_report (WorkbookControl *wbc,
dao_set_bold (&dao, 0, 15 + vars, 6, 15 + vars);
for (i = 0; i < res->param->n_total_constraints; i++) {
- SolverConstraint const *c = res->constraints_array[i];
+ GnmSolverConstraint const *c = res->constraints_array[i];
char *str = gnm_solver_constraint_as_str (c, sheet);
GnmCell *lhs, *rhs;
@@ -156,7 +157,7 @@ solver_answer_report (WorkbookControl *wbc,
/* Set `Formula' column */
dao_set_cell (&dao, 4, 16 + vars + i, str);
- if (c->type == SolverINT || c->type == SolverBOOL) {
+ if (c->type == GNM_SOLVER_INTEGER || c->type == GNM_SOLVER_BOOLEAN) {
dao_set_cell (&dao, 5, 16 + vars + i, _("Binding"));
continue;
}
@@ -296,7 +297,7 @@ solver_sensitivity_report (WorkbookControl *wbc,
dao_set_bold (&dao, 0, 10 + vars, 7, 11 + vars);
for (i = 0; i < res->param->n_total_constraints; i++) {
- SolverConstraint *c = res->constraints_array[i];
+ GnmSolverConstraint *c = res->constraints_array[i];
GnmCell *lhs, *rhs;
gnm_solver_constraint_get_part (c, res->param, 0,
@@ -329,19 +330,19 @@ solver_sensitivity_report (WorkbookControl *wbc,
/* FIXME */
} else {
switch (c->type) {
- case SolverLE:
+ case GNM_SOLVER_LE:
dao_set_cell (&dao, 6, 12 + vars + i,
_("Infinity"));
dao_set_cell_float (&dao, 7, 12 + vars + i,
res->slack[i]);
break;
- case SolverGE:
+ case GNM_SOLVER_GE:
dao_set_cell_float (&dao, 6, 12 + vars + i,
res->slack[i]);
dao_set_cell (&dao, 7, 12 + vars + i,
_("Infinity"));
break;
- case SolverEQ:
+ case GNM_SOLVER_EQ:
dao_set_cell_float (&dao, 6, 12 + vars + i, 0);
dao_set_cell_float (&dao, 7, 12 + vars + i, 0);
break;
@@ -824,15 +825,15 @@ solver_program_report (WorkbookControl *wbc,
/* Print the constraints. */
row = 10;
for (i = 0; i < res->param->n_total_constraints; i++, row++) {
- SolverConstraint const *c = res->constraints_array[i];
+ GnmSolverConstraint const *c = res->constraints_array[i];
/* Print the constraint function. */
col = 0;
- if (c->type == SolverINT) {
+ if (c->type == GNM_SOLVER_INTEGER) {
dao_set_cell (&dao, col*3 + 1, row, "integer");
continue;
}
- if (c->type == SolverBOOL) {
+ if (c->type == GNM_SOLVER_BOOLEAN) {
dao_set_cell (&dao, col*3 + 1, row, "bool");
continue;
}
@@ -864,15 +865,15 @@ solver_program_report (WorkbookControl *wbc,
/* Print the type. */
switch (c->type) {
- case SolverLE:
+ case GNM_SOLVER_LE:
/* "<=" character. */
dao_set_cell (&dao, col*3 + 1, row, "\xe2\x89\xa4");
break;
- case SolverGE:
+ case GNM_SOLVER_GE:
/* ">=" character. */
dao_set_cell (&dao, col*3 + 1, row, "\xe2\x89\xa5");
break;
- case SolverEQ:
+ case GNM_SOLVER_EQ:
dao_set_cell (&dao, col*3 + 1, row, "=");
break;
default :
diff --git a/src/tools/solver/reports.c b/src/tools/solver/reports.c
index c04d34b..2f07865 100644
--- a/src/tools/solver/reports.c
+++ b/src/tools/solver/reports.c
@@ -69,7 +69,7 @@ get_constraint_names (SolverResults *res, Sheet *sheet)
int i;
for (i = 0; i < res->param->n_total_constraints; i++) {
- SolverConstraint *c = solver_get_constraint (res, i);
+ GnmSolverConstraint *c = solver_get_constraint (res, i);
GnmCell *lhs;
gnm_solver_constraint_get_part (c, res->param, 0,
@@ -106,7 +106,7 @@ is_still_feasible (Sheet *sheet, SolverResults *res, int col, gnm_float value)
res->optimal_values[col] = value;
for (i = 0; i < res->param->n_total_constraints; i++) {
- SolverConstraint *c = solver_get_constraint (res, i);
+ GnmSolverConstraint *c = solver_get_constraint (res, i);
GnmCell *cell;
gnm_solver_constraint_get_part (c, res->param, 0,
@@ -119,20 +119,20 @@ is_still_feasible (Sheet *sheet, SolverResults *res, int col, gnm_float value)
rhs = value_get_as_float (cell->value);
switch (c->type) {
- case SolverLE:
+ case GNM_SOLVER_LE:
if (c_value - 0.000001 /* FIXME */ > rhs)
goto out;
break;
- case SolverGE:
+ case GNM_SOLVER_GE:
if (c_value + 0.000001 /* FIXME */ < rhs)
goto out;
break;
- case SolverEQ:
+ case GNM_SOLVER_EQ:
if (gnm_abs (c_value - rhs) < 0.000001 /* FIXME */)
goto out;
break;
- case SolverINT:
- case SolverBOOL:
+ case GNM_SOLVER_INTEGER:
+ case GNM_SOLVER_BOOLEAN:
break;
}
}
@@ -153,7 +153,7 @@ calculate_limits (Sheet *sheet, SolverParameters *param, SolverResults *res)
for (i = 0; i < param->n_total_constraints; i++) {
gnm_float slack, lhs, rhs, x, y, old_val;
- SolverConstraint *c = res->constraints_array[i];
+ GnmSolverConstraint *c = res->constraints_array[i];
GnmCell *lcell, *rcell;
gnm_solver_constraint_get_part (c, res->param, 0,
@@ -278,7 +278,7 @@ solver_prepare_reports_success (SolverProgram *program, SolverResults *res,
* Go through the constraints; save LHS, RHS, slack
*/
for (i = 0; i < param->n_constraints; i++) {
- SolverConstraint const *c = solver_get_constraint (res, i);
+ GnmSolverConstraint const *c = solver_get_constraint (res, i);
GnmCell *lhs;
gnm_solver_constraint_get_part (c, param, 0,
@@ -299,9 +299,9 @@ solver_prepare_reports_success (SolverProgram *program, SolverResults *res,
if (param->options.sensitivity_report && ! res->ilp_flag) {
/* gnm_float *store = g_new (gnm_float, param->n_variables);*/
for (i = 0; i < param->n_total_constraints; i++) {
- SolverConstraint *c = res->constraints_array[i];
+ GnmSolverConstraint *c = res->constraints_array[i];
- if (c->type == SolverINT || c->type == SolverBOOL)
+ if (c->type == GNM_SOLVER_INTEGER || c->type == GNM_SOLVER_BOOLEAN)
continue;
if (res->slack[i] < 0.0001 /* FIXME */) {
diff --git a/src/tools/solver/solver.c b/src/tools/solver/solver.c
index cfe4d95..575038d 100644
--- a/src/tools/solver/solver.c
+++ b/src/tools/solver/solver.c
@@ -232,7 +232,7 @@ gnm_solver_param_valid (SolverParameters const *sp, GError **err)
g_slist_free (input_cells);
for (i = 1, l = sp->constraints; l; i++, l = l->next) {
- SolverConstraint *c = l->data;
+ GnmSolverConstraint *c = l->data;
if (!gnm_solver_constraint_valid (c, sp)) {
g_set_error (err,
go_error_invalid (),
@@ -252,7 +252,7 @@ static void
solver_constr_start (GsfXMLIn *xin, xmlChar const **attrs)
{
int type = 0;
- SolverConstraint *c;
+ GnmSolverConstraint *c;
Sheet *sheet = gnm_xml_in_cur_sheet (xin);
SolverParameters *sp = sheet->solver_parameters;
int lhs_col = 0, lhs_row = 0, rhs_col = 0, rhs_row = 0;
@@ -287,12 +287,12 @@ solver_constr_start (GsfXMLIn *xin, xmlChar const **attrs)
}
switch (type) {
- case 1: c->type = SolverLE; break;
- case 2: c->type = SolverGE; break;
- case 4: c->type = SolverEQ; break;
- case 8: c->type = SolverINT; break;
- case 16: c->type = SolverBOOL; break;
- default: c->type = SolverLE; break;
+ case 1: c->type = GNM_SOLVER_LE; break;
+ case 2: c->type = GNM_SOLVER_GE; break;
+ case 4: c->type = GNM_SOLVER_EQ; break;
+ case 8: c->type = GNM_SOLVER_INTEGER; break;
+ case 16: c->type = GNM_SOLVER_BOOLEAN; break;
+ default: c->type = GNM_SOLVER_LE; break;
}
if (old)
@@ -424,33 +424,33 @@ solver_get_input_var (SolverResults *res, int n)
return res->input_cells_array[n];
}
-SolverConstraint*
+GnmSolverConstraint*
solver_get_constraint (SolverResults *res, int n)
{
return res->constraints_array[n];
}
-SolverConstraint *
+GnmSolverConstraint *
gnm_solver_constraint_new (Sheet *sheet)
{
- SolverConstraint *res = g_new0 (SolverConstraint, 1);
+ GnmSolverConstraint *res = g_new0 (GnmSolverConstraint, 1);
dependent_managed_init (&res->lhs, sheet);
dependent_managed_init (&res->rhs, sheet);
return res;
}
void
-gnm_solver_constraint_free (SolverConstraint *c)
+gnm_solver_constraint_free (GnmSolverConstraint *c)
{
gnm_solver_constraint_set_lhs (c, NULL);
gnm_solver_constraint_set_rhs (c, NULL);
g_free (c);
}
-static SolverConstraint *
-gnm_solver_constraint_dup (SolverConstraint *c, Sheet *sheet)
+static GnmSolverConstraint *
+gnm_solver_constraint_dup (GnmSolverConstraint *c, Sheet *sheet)
{
- SolverConstraint *res = gnm_solver_constraint_new (sheet);
+ GnmSolverConstraint *res = gnm_solver_constraint_new (sheet);
res->type = c->type;
dependent_managed_set_expr (&res->lhs, res->lhs.texpr);
dependent_managed_set_expr (&res->rhs, res->lhs.texpr);
@@ -458,24 +458,24 @@ gnm_solver_constraint_dup (SolverConstraint *c, Sheet *sheet)
}
gboolean
-gnm_solver_constraint_has_rhs (SolverConstraint const *c)
+gnm_solver_constraint_has_rhs (GnmSolverConstraint const *c)
{
g_return_val_if_fail (c != NULL, FALSE);
switch (c->type) {
- case SolverLE:
- case SolverGE:
- case SolverEQ:
+ case GNM_SOLVER_LE:
+ case GNM_SOLVER_GE:
+ case GNM_SOLVER_EQ:
return TRUE;
- case SolverINT:
- case SolverBOOL:
+ case GNM_SOLVER_INTEGER:
+ case GNM_SOLVER_BOOLEAN:
default:
return FALSE;
}
}
gboolean
-gnm_solver_constraint_valid (SolverConstraint const *c,
+gnm_solver_constraint_valid (GnmSolverConstraint const *c,
SolverParameters const *sp)
{
GnmValue const *lhs;
@@ -506,8 +506,8 @@ gnm_solver_constraint_valid (SolverConstraint const *c,
}
switch (c->type) {
- case SolverINT:
- case SolverBOOL: {
+ case GNM_SOLVER_INTEGER:
+ case GNM_SOLVER_BOOLEAN: {
GnmValue const *vinput = gnm_solver_param_get_input (sp);
GnmSheetRange sr_input, sr_c;
@@ -532,14 +532,14 @@ gnm_solver_constraint_valid (SolverConstraint const *c,
}
GnmValue const *
-gnm_solver_constraint_get_lhs (SolverConstraint const *c)
+gnm_solver_constraint_get_lhs (GnmSolverConstraint const *c)
{
GnmExprTop const *texpr = c->lhs.texpr;
return texpr ? gnm_expr_top_get_constant (texpr) : NULL;
}
void
-gnm_solver_constraint_set_lhs (SolverConstraint *c, GnmValue *v)
+gnm_solver_constraint_set_lhs (GnmSolverConstraint *c, GnmValue *v)
{
/* Takes ownership. */
GnmExprTop const *texpr = v ? gnm_expr_top_new_constant (v) : NULL;
@@ -548,14 +548,14 @@ gnm_solver_constraint_set_lhs (SolverConstraint *c, GnmValue *v)
}
GnmValue const *
-gnm_solver_constraint_get_rhs (SolverConstraint const *c)
+gnm_solver_constraint_get_rhs (GnmSolverConstraint const *c)
{
GnmExprTop const *texpr = c->rhs.texpr;
return texpr ? gnm_expr_top_get_constant (texpr) : NULL;
}
void
-gnm_solver_constraint_set_rhs (SolverConstraint *c, GnmValue *v)
+gnm_solver_constraint_set_rhs (GnmSolverConstraint *c, GnmValue *v)
{
/* Takes ownership. */
GnmExprTop const *texpr = v ? gnm_expr_top_new_constant (v) : NULL;
@@ -565,7 +565,7 @@ gnm_solver_constraint_set_rhs (SolverConstraint *c, GnmValue *v)
gboolean
-gnm_solver_constraint_get_part (SolverConstraint const *c,
+gnm_solver_constraint_get_part (GnmSolverConstraint const *c,
SolverParameters const *sp, int i,
GnmCell **lhs, gnm_float *cl,
GnmCell **rhs, gnm_float *cr)
@@ -615,8 +615,8 @@ gnm_solver_constraint_get_part (SolverConstraint const *c,
}
void
-gnm_solver_constraint_set_old (SolverConstraint *c,
- SolverConstraintType type,
+gnm_solver_constraint_set_old (GnmSolverConstraint *c,
+ GnmSolverConstraintType type,
int lhs_col, int lhs_row,
int rhs_col, int rhs_row,
int cols, int rows)
@@ -644,7 +644,7 @@ gnm_solver_constraint_set_old (SolverConstraint *c,
/* ------------------------------------------------------------------------- */
void
-gnm_solver_constraint_side_as_str (SolverConstraint const *c,
+gnm_solver_constraint_side_as_str (GnmSolverConstraint const *c,
Sheet const *sheet,
GString *buf, gboolean lhs)
{
@@ -666,7 +666,7 @@ gnm_solver_constraint_side_as_str (SolverConstraint const *c,
}
char *
-gnm_solver_constraint_as_str (SolverConstraint const *c, Sheet *sheet)
+gnm_solver_constraint_as_str (GnmSolverConstraint const *c, Sheet *sheet)
{
const char * const type_str[] = {
"\xe2\x89\xa4" /* "<=" */,
@@ -708,8 +708,8 @@ gnm_solver_param_dup (const SolverParameters *src_param, Sheet *new_sheet)
/* Copy the constraints */
for (constraints = src_param->constraints; constraints;
constraints = constraints->next) {
- SolverConstraint *old = constraints->data;
- SolverConstraint *new = gnm_solver_constraint_dup (old, new_sheet);
+ GnmSolverConstraint *old = constraints->data;
+ GnmSolverConstraint *new = gnm_solver_constraint_dup (old, new_sheet);
dst_param->constraints =
g_slist_prepend (dst_param->constraints, new);
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index 95fb42d..cc0c276 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -32,7 +32,7 @@
#include "sheet-filter.h"
#include "sheet.h"
#include "ranges.h"
-#include "solver.h"
+#include <tools/gnm-solver.h>
#include "style.h"
#include "style-border.h"
#include "style-color.h"
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index 71ea13e..7a5a6d9 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -47,7 +47,7 @@
#include <validation.h>
#include <hlink.h>
#include <input-msg.h>
-#include <solver.h>
+#include <tools/gnm-solver.h>
#include <sheet-filter.h>
#include <sheet-object-impl.h>
#include <print-info.h>
@@ -1017,18 +1017,18 @@ xml_write_solver (GnmOutputXML *state)
param->options.program_report);
for (ptr = param->constraints; ptr != NULL ; ptr = ptr->next) {
- SolverConstraint const *c = ptr->data;
+ GnmSolverConstraint const *c = ptr->data;
int type;
GString *str = g_string_new (NULL);
/* Historical values. Not a bit field. */
switch (c->type) {
default: type = 0; break;
- case SolverLE: type = 1; break;
- case SolverGE: type = 2; break;
- case SolverEQ: type = 4; break;
- case SolverINT: type = 8; break;
- case SolverBOOL: type = 16; break;
+ case GNM_SOLVER_LE: type = 1; break;
+ case GNM_SOLVER_GE: type = 2; break;
+ case GNM_SOLVER_EQ: type = 4; break;
+ case GNM_SOLVER_INTEGER: type = 8; break;
+ case GNM_SOLVER_BOOLEAN: type = 16; break;
}
gsf_xml_out_start_element (state->output, GNM "Constr");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]