Commit 86ad3cc8 authored by Jukka Pekka's avatar Jukka Pekka Committed by jpekka

Algorithm selection works now for QP too.

2002-08-17  Jukka Pekka  <jiivonen@hutcs.cs.hut.fi>

	* dialog-solver.c: Algorithm selection works now for QP too.
parent 67836fc7
......@@ -20,7 +20,7 @@ Jukka:
much better than lp-solve if the model is large, see
a benchmark in ftp://plato.la.asu.edu/pub/lpsimp.txt.
- Added the algorithm selection into the dialog.
- Solver dialog improvements.
- Other dialog improvements.
Morten:
* Add poor man's utf8 regexp routines.
......
2002-08-17 Jukka Pekka <jiivonen@hutcs.cs.hut.fi>
* dialog-solver.c: Algorithm selection works now for QP too.
2002-08-17 Jukka Pekka <jiivonen@hutcs.cs.hut.fi>
* dialog-solver.c (dialog_init): Implemented the algorithm
......
......@@ -59,6 +59,7 @@ typedef struct {
GtkWidget *add_button;
GtkWidget *change_button;
GtkWidget *delete_button;
GtkWidget *model_button;
GnumericExprEntry *lhs_entry;
GnumericExprEntry *rhs_entry;
GtkOptionMenu *type_combo;
......@@ -91,15 +92,19 @@ static char const * constraint_strs_untranslated[] = {
};
#endif
typedef struct {
char const *name;
SolverLPAlgorithmType type;
char const *name;
SolverAlgorithmType alg;
SolverModelType type;
} algorithm_def_t;
static algorithm_def_t algorithm_defs [] = {
{ N_("Revised Simplex (GLPK 3.2)"), GLPKSimplex },
{ N_("Simplex (LP Solve 3.2)"), LPSolve },
{ NULL, 0 }
{ N_("Revised Simplex (GLPK 3.2)"), GLPKSimplex, SolverLPModel },
{ N_("Simplex (LP Solve 3.2)"), LPSolve, SolverLPModel },
{ N_("< Not available >"), QPDummy, SolverQPModel },
{ NULL, 0, 0 }
};
typedef struct {
......@@ -129,6 +134,9 @@ static const char *model_type_group[] = {
0
};
static GList *lp_alg_name_list = NULL;
static GList *qp_alg_name_list = NULL;
/**
* is_hom_row_or_col_ref:
* @Widget:
......@@ -389,6 +397,44 @@ cb_dialog_set_rhs_sensitivity (GtkWidget *dummy, SolverState *state)
}
}
/**
* cb_dialog_lp_clicked:
* @button:
* @state:
*
*
**/
static void
cb_dialog_model_type_clicked (GtkWidget *button, SolverState *state)
{
SolverModelType type;
type = gnumeric_glade_group_value (state->gui, model_type_group);
switch (type) {
case SolverLPModel:
gtk_combo_set_popdown_strings
(GTK_COMBO (state->algorithm_combo), lp_alg_name_list);
gtk_widget_set_sensitive (GTK_WIDGET (state->solve_button),
TRUE);
break;
case SolverQPModel:
gtk_combo_set_popdown_strings
(GTK_COMBO (state->algorithm_combo), qp_alg_name_list);
gtk_widget_set_sensitive (GTK_WIDGET (state->solve_button),
FALSE);
gnumeric_notice_nonmodal ((GtkWindow *) state->dialog,
&(state->warning_dialog),
GTK_MESSAGE_INFO,
_("Looking for a subject for your "
"thesis? Maybe you would like to "
"write a QP solver for "
"Gnumeric?"));
break;
default:
break;
}
}
/**
* free_original_values:
* @ov:
......@@ -864,10 +910,12 @@ cb_dialog_solve_clicked (GtkWidget *button, SolverState *state)
(GTK_COMBO (state->algorithm_combo)->entry);
G_CONST_RETURN gchar *name = gtk_entry_get_text (entry);
if (strcmp (algorithm_defs [i].name, name) == 0) {
param->options.algorithm = algorithm_defs [i].type;
break;
}
if (param->options.model_type == algorithm_defs [i].type)
if (strcmp (algorithm_defs [i].name, name) == 0) {
param->options.algorithm =
algorithm_defs [i].alg;
break;
}
}
param->options.assume_non_negative = gtk_toggle_button_get_active
......@@ -976,19 +1024,28 @@ dialog_init (SolverState *state)
GtkTable *table;
constraint_conversion_t conv;
SolverParameters *param;
static GList *alg_name_list = NULL;
int i;
if (alg_name_list == NULL) {
int i;
param = state->sheet->solver_parameters;
if (lp_alg_name_list == NULL) {
for (i = 0; algorithm_defs [i].name; i++)
alg_name_list = g_list_append
(alg_name_list,
(gpointer) algorithm_defs [i].name);
switch (algorithm_defs [i].type) {
case SolverLPModel:
lp_alg_name_list = g_list_append
(lp_alg_name_list,
(gpointer) algorithm_defs [i].name);
break;
case SolverQPModel:
qp_alg_name_list = g_list_append
(qp_alg_name_list,
(gpointer) algorithm_defs [i].name);
break;
default:
break;
}
}
param = state->sheet->solver_parameters;
state->gui = gnumeric_glade_xml_new (state->wbcg, "solver.glade");
if (state->gui == NULL)
return TRUE;
......@@ -1070,8 +1127,22 @@ dialog_init (SolverState *state)
/* Algorithm */
state->algorithm_combo = GTK_OPTION_MENU
(glade_xml_get_widget (state->gui, "algorithm_combo"));
gtk_combo_set_popdown_strings (GTK_COMBO (state->algorithm_combo),
alg_name_list);
switch (param->options.model_type) {
case SolverLPModel:
gtk_combo_set_popdown_strings
(GTK_COMBO (state->algorithm_combo), lp_alg_name_list);
break;
case SolverQPModel:
gtk_combo_set_popdown_strings
(GTK_COMBO (state->algorithm_combo), qp_alg_name_list);
break;
default:
break;
}
state->model_button =
glade_xml_get_widget(state->gui, "lp_model_button");
g_signal_connect (G_OBJECT (state->model_button), "clicked",
G_CALLBACK (cb_dialog_model_type_clicked), state);
/* Options */
state->max_iter_entry = glade_xml_get_widget (state->gui,
......@@ -1188,12 +1259,10 @@ dialog_init (SolverState *state)
param->problem_type == SolverMinimize);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
glade_xml_get_widget(state->gui, "lp_model_button")),
param->options.model_type
== SolverLPModel);
param->options.model_type == SolverLPModel);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
glade_xml_get_widget(state->gui, "qp_model_button")),
param->options.model_type
== SolverQPModel);
param->options.model_type == SolverQPModel);
conv.c_listing = state->constraint_list;
conv.c_list = param->constraints;
......
......@@ -480,15 +480,15 @@
</child>
<child>
<widget class="GtkLabel" id="label19">
<widget class="GtkLabel" id="label20">
<property name="visible">True</property>
<property name="label" translatable="yes">Max Iterations:</property>
<property name="label" translatable="yes">Max Time (sec.):</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="xalign">0.67</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
......@@ -496,23 +496,24 @@
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label20">
<widget class="GtkLabel" id="label19">
<property name="width_request">154</property>
<property name="visible">True</property>
<property name="label" translatable="yes">Max Time (sec.):</property>
<property name="label" translatable="yes">Max Iterations:</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="xalign">0.72</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
......@@ -520,8 +521,8 @@
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
......@@ -820,39 +821,54 @@
<widget class="GtkOptionMenu" id="type_menu">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="history">-1</property>
<property name="history">0</property>
<child internal-child="menu">
<widget class="GtkMenu" id="convertwidget3">
<property name="visible">True</property>
<child>
<widget class="GtkMenuItem" id="convertwidget4">
<widget class="GtkMenuItem" id="&lt;=">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;=</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_le_activate" last_modification_time="Sat, 17 Aug 2002 06:19:10 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="convertwidget5">
<widget class="GtkMenuItem" id="&gt;=">
<property name="visible">True</property>
<property name="label" translatable="yes">&gt;=</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_ge_activate" last_modification_time="Sat, 17 Aug 2002 06:19:10 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="convertwidget6">
<widget class="GtkMenuItem" id="=">
<property name="visible">True</property>
<property name="label" translatable="yes">=</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_eq_activate" last_modification_time="Sat, 17 Aug 2002 06:19:10 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="convertwidget7">
<widget class="GtkMenuItem" id="int1">
<property name="visible">True</property>
<property name="label" translatable="yes">Int</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_int1_activate" last_modification_time="Sat, 17 Aug 2002 06:19:10 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="convertwidget7">
<widget class="GtkMenuItem" id="bool1">
<property name="visible">True</property>
<property name="label" translatable="yes">Bool</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_bool1_activate" last_modification_time="Sat, 17 Aug 2002 06:19:10 GMT"/>
</widget>
</child>
</widget>
......
......@@ -46,8 +46,8 @@ typedef enum {
} SolverConstraintType;
typedef enum {
LPSolve = 0, GLPKSimplex
} SolverLPAlgorithmType;
LPSolve = 0, GLPKSimplex, QPDummy
} SolverAlgorithmType;
typedef enum {
SolverOptAssumeNonNegative, SolverOptAutomaticScaling, SolverOptMaxIter,
......@@ -124,20 +124,20 @@ typedef enum {
} SolverModelType;
struct _SolverOptions {
int max_time_sec;
int max_iter;
SolverModelType model_type;
gboolean assume_non_negative;
gboolean assume_discrete;
gboolean automatic_scaling;
gboolean show_iter_results;
gboolean answer_report;
gboolean sensitivity_report;
gboolean limits_report;
gboolean performance_report;
gboolean program_report;
gboolean dual_program_report;
SolverLPAlgorithmType algorithm;
int max_time_sec;
int max_iter;
SolverModelType model_type;
gboolean assume_non_negative;
gboolean assume_discrete;
gboolean automatic_scaling;
gboolean show_iter_results;
gboolean answer_report;
gboolean sensitivity_report;
gboolean limits_report;
gboolean performance_report;
gboolean program_report;
gboolean dual_program_report;
SolverAlgorithmType algorithm;
};
struct _SolverConstraint {
......
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