Commit e692b098 authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka
Browse files

Implemented the `>=' and `=' constraints. Solver should be quite usable

2000-01-26  Jukka-Pekka Iivonen  <iivonen@iki.fi>

	* src/solver-lp.c: Implemented the `>=' and `=' constraints.
  	Solver should be quite usable now for LP problems assumed to be
 	non-negative.

	* src/dialogs/dialog-solver.c: Related changes.

	* src/dialogs/advanced-filter.glade,
 	src/dialogs/dialog-advanced-filter.c: New files added.  Not done
 	yet.
parent ddfafec8
2000-01-26 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/solver-lp.c: Implemented the `>=' and `=' constraints.
Solver should be quite usable now for LP problems assumed to be
non-negative.
* src/dialogs/dialog-solver.c: Related changes.
* src/dialogs/advanced-filter.glade,
src/dialogs/dialog-advanced-filter.c: New files added. Not done
yet.
2000-01-25 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/dialogs/dialog-autocorrect.c (dialog_autocorrect): Made the
unimplemented replace option unsensitive.
2000-01-25 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/workbook.[ch]: Made workbook_is_dirty() public.
......
Gnumeric 0.49
Jukka:
* More minor improvements for the Solver tool.
* `>=' and `=' constraint support for the Solver tool. Solver
should be quite usable now for LP problems that are assumed to
be non-negative.
* Minor improvements for the AutoSave tool.
* GUI improvements for the Data Analysis tool.
......
2000-01-26 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/solver-lp.c: Implemented the `>=' and `=' constraints.
Solver should be quite usable now for LP problems assumed to be
non-negative.
* src/dialogs/dialog-solver.c: Related changes.
* src/dialogs/advanced-filter.glade,
src/dialogs/dialog-advanced-filter.c: New files added. Not done
yet.
2000-01-25 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/dialogs/dialog-autocorrect.c (dialog_autocorrect): Made the
unimplemented replace option unsensitive.
2000-01-25 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/workbook.[ch]: Made workbook_is_dirty() public.
......
......@@ -1639,7 +1639,7 @@ int random_tool (Workbook *wb, Sheet *sheet, int vars, int count,
{
char buf[256];
int i, n, j;
float_t range, p;
float_t range, p, tmp;
float_t *prob, *cumul_p;
Value **values, *v;
Cell *cell;
......@@ -1750,6 +1750,17 @@ int random_tool (Workbook *wb, Sheet *sheet, int vars, int count,
}
}
break;
case PoissonDistribution:
for (i=0; i<vars; i++) {
for (n=0; n<count; n++) {
tmp = random_01();
sprintf (buf, "%f",
floor (exp (param->poisson.lambda *
exp(tmp-1)) + 0.5));
set_cell (dao, i, n, buf);
}
}
break;
default:
printf ("Not implemented yet.\n");
break;
......
......@@ -16,6 +16,7 @@ INCLUDES = \
noinst_LIBRARIES = libdialogs.a
libdialogs_a_SOURCES = \
dialog-advanced-filter.c \
dialog-analysis-tools.c \
dialog-autocorrect.c \
dialog-autosave.c \
......@@ -45,6 +46,7 @@ libdialogs_a_SOURCES = \
gladedir = $(datadir)/gnumeric/glade
glade_DATA = \
advanced-filter.glade \
analysis-tools.glade \
autocorrect.glade \
autocorrect-exceptions.glade \
......
<?xml version="1.0"?>
<GTK-Interface>
<project>
<name>AdvancedFilter.glade</name>
<program_name>advanced-filter.glade</program_name>
<directory></directory>
<source_directory>src</source_directory>
<pixmaps_directory>pixmaps</pixmaps_directory>
<language>C</language>
<gnome_support>True</gnome_support>
<gettext_support>True</gettext_support>
<use_widget_names>False</use_widget_names>
<output_main_file>True</output_main_file>
<output_support_files>True</output_support_files>
<output_build_files>True</output_build_files>
<backup_source_files>True</backup_source_files>
<main_source_file>interface.c</main_source_file>
<main_header_file>interface.h</main_header_file>
<handler_source_file>callbacks.c</handler_source_file>
<handler_header_file>callbacks.h</handler_header_file>
<support_source_file>support.c</support_source_file>
<support_header_file>support.h</support_header_file>
<translatable_strings_file></translatable_strings_file>
</project>
<widget>
<class>GnomeDialog</class>
<name>AdvancedFilter</name>
<visible>False</visible>
<title>Advanced Filter</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>False</allow_grow>
<auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
<widget>
<class>GtkVBox</class>
<child_name>GnomeDialog:vbox</child_name>
<name>dialog-vbox1</name>
<homogeneous>False</homogeneous>
<spacing>8</spacing>
<child>
<padding>4</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkVBox</class>
<name>vbox1</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkFrame</class>
<name>frame1</name>
<label>Action</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkVBox</class>
<name>vbox2</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkRadioButton</class>
<name>radiobutton1</name>
<can_focus>True</can_focus>
<label>Filter the list (in-place)</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkRadioButton</class>
<name>radiobutton2</name>
<can_focus>True</can_focus>
<label>Copy to another location</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkTable</class>
<name>table1</name>
<rows>3</rows>
<columns>2</columns>
<homogeneous>False</homogeneous>
<row_spacing>0</row_spacing>
<column_spacing>0</column_spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label1</name>
<label>List range: </label>
<justify>GTK_JUSTIFY_LEFT</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>False</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label2</name>
<label>Criteria range:</label>
<justify>GTK_JUSTIFY_LEFT</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>False</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label3</name>
<label>Copy to: </label>
<justify>GTK_JUSTIFY_LEFT</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>False</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>entry1</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>entry2</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>entry3</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
</widget>
<widget>
<class>GtkCheckButton</class>
<name>checkbutton1</name>
<can_focus>True</can_focus>
<label>Unique records only</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
<widget>
<class>GtkHButtonBox</class>
<child_name>GnomeDialog:action_area</child_name>
<name>dialog-action_area1</name>
<layout_style>GTK_BUTTONBOX_END</layout_style>
<spacing>8</spacing>
<child_min_width>85</child_min_width>
<child_min_height>27</child_min_height>
<child_ipad_x>7</child_ipad_x>
<child_ipad_y>0</child_ipad_y>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>True</fill>
<pack>GTK_PACK_END</pack>
</child>
<widget>
<class>GtkButton</class>
<name>button3</name>
<can_default>True</can_default>
<has_default>True</has_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_OK</stock_button>
</widget>
<widget>
<class>GtkButton</class>
<name>button5</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>
</widget>
</widget>
</widget>
</widget>
</GTK-Interface>
/*
* dialog-advanced-filter.c:
*
* Author:
* Jukka-Pekka Iivonen <iivonen@iki.fi>
*
* (C) Copyright 2000 by Jukka-Pekka Iivonen <iivonen@iki.fi>
**/
#include <config.h>
#include <gnome.h>
#include <glade/glade.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "gnumeric-sheet.h"
#include "dialogs.h"
static gboolean unique_only_flag;
static void
unique_only_toggled(GtkWidget *widget, Workbook *wb)
{
unique_only_flag = GTK_TOGGLE_BUTTON (widget)->active;
}
/* Returns TRUE on error, FALSE otherwise.
*/
static gboolean
advanced_filter (Workbook *wb,
gint input_col_b, gint input_row_b,
gint input_col_e, gint input_row_e,
gint criteria_col_b, gint criteria_row_b,
gint criteria_col_e, gint criteria_row_e,
gboolean unique_only_flag)
{
return FALSE;
}
void
dialog_advanced_filter (Workbook *wb)
{
GladeXML *gui;
GtkWidget *dia;
GtkWidget *list_range;
GtkWidget *criteria_range;
GtkWidget *copy_to;
GtkWidget *unique_only;
gint v, ok_flag;
gint list_col_b, list_col_e, list_row_b, list_row_e;
gint crit_col_b, crit_col_e, crit_row_b, crit_row_e;
gchar *text;
gui = glade_xml_new (GNUMERIC_GLADEDIR "/advanced-filter.glade", NULL);
if (!gui) {
printf ("Could not find advanced-filter.glade\n");
return;
}
dia = glade_xml_get_widget (gui, "AdvancedFilter");
if (!dia) {
printf ("Corrupt file advanced-filter.glade\n");
return;
}
gnome_dialog_set_parent (GNOME_DIALOG (dia),
GTK_WINDOW (wb->toplevel));
list_range = glade_xml_get_widget (gui, "entry1");
criteria_range = glade_xml_get_widget (gui, "entry2");
copy_to = glade_xml_get_widget (gui, "entry3");
unique_only = glade_xml_get_widget (gui, "checkbutton1");
if (unique_only_flag)
gtk_toggle_button_set_active ((GtkToggleButton *)
unique_only, unique_only_flag);
gtk_signal_connect (GTK_OBJECT (unique_only), "toggled",
GTK_SIGNAL_FUNC (unique_only_toggled), wb);
gnome_dialog_editable_enters (GNOME_DIALOG (dia),
GTK_EDITABLE (list_range));
gnome_dialog_editable_enters (GNOME_DIALOG (dia),
GTK_EDITABLE (criteria_range));
gnome_dialog_editable_enters (GNOME_DIALOG (dia),
GTK_EDITABLE (copy_to));
gtk_widget_grab_focus (list_range);
loop:
v = gnumeric_dialog_run (wb, GNOME_DIALOG (dia));
if (v == 1) {
/* Canceled */
gtk_object_destroy (GTK_OBJECT (dia));
gtk_object_unref (GTK_OBJECT (gui));
return;
}
text = gtk_entry_get_text (GTK_ENTRY (list_range));
ok_flag = parse_range (text, &list_col_b, &list_row_b,
&list_col_e, &list_row_e);
if (! ok_flag) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("You should introduce a valid cell names "
"in 'List Range:'"));
gtk_widget_grab_focus (list_range);
gtk_entry_set_position(GTK_ENTRY (list_range), 0);
gtk_entry_select_region(GTK_ENTRY (list_range), 0,
GTK_ENTRY(list_range)->text_length);
goto loop;
}
text = gtk_entry_get_text (GTK_ENTRY (criteria_range));
ok_flag = parse_range (text, &crit_col_b, &crit_row_b,
&crit_col_e, &crit_row_e);
if (! ok_flag) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("You should introduce a valid cell names "
"in 'Criteria Range:'"));
gtk_widget_grab_focus (criteria_range);
gtk_entry_set_position(GTK_ENTRY (criteria_range), 0);
gtk_entry_select_region(GTK_ENTRY (criteria_range), 0,
GTK_ENTRY(criteria_range)->text_length);
goto loop;
}
if (v != -1)
gtk_object_destroy (GTK_OBJECT (dia));
gtk_object_unref (GTK_OBJECT (gui));
if (advanced_filter (wb, list_col_b, list_row_b, list_col_e,
list_row_e, crit_col_b, crit_row_b, crit_col_e,
crit_row_e, unique_only_flag)) {
printf("not done yet.\n");
}
}
......@@ -109,6 +109,7 @@ static tool_list_t tools[] = {
static const char *distribution_strs[] = {
N_("Discrete"),
N_("Normal"),
/* N_("Poisson"), */
N_("Bernoulli"),
N_("Uniform"),
NULL
......@@ -194,7 +195,7 @@ static check_button_t standard_errors_button[] = {
static int selected_row;
static int
int
parse_range (char *text, int *start_col, int *start_row,
int *end_col, int *end_row)
{
......@@ -1357,6 +1358,9 @@ distribution_callback (GtkWidget *widget, random_tool_callback_t *p)
case DiscreteDistribution:
gtk_widget_hide (p->discrete_box);
break;
case PoissonDistribution:
gtk_widget_hide (p->poisson_box);
break;
default:
break;
}
......@@ -1375,6 +1379,9 @@ distribution_callback (GtkWidget *widget, random_tool_callback_t *p)
} else if (strcmp(text, _("Discrete")) == 0) {
distribution = DiscreteDistribution;
gtk_widget_show (p->discrete_box);
} else if (strcmp(text, _("Poisson")) == 0) {
distribution = PoissonDistribution;
gtk_widget_show (p->poisson_box);
}
}
......@@ -1478,12 +1485,16 @@ dialog_random_tool (Workbook *wb, Sheet *sheet)
gtk_container_add(GTK_CONTAINER(param_box),
callback_data.bernoulli_box);
gtk_container_add(GTK_CONTAINER(param_box),
callback_data.poisson_box);
gtk_container_add(GTK_CONTAINER(param_box),
callback_data.uniform_box);
gtk_container_add(GTK_CONTAINER(param_box),
callback_data.normal_box);
gtk_widget_show_all (dialog);
gtk_widget_hide (callback_data.poisson_box);
gtk_widget_hide (callback_data.uniform_box);
gtk_widget_hide (callback_data.normal_box);
gtk_widget_hide (callback_data.bernoulli_box);
......@@ -1494,21 +1505,31 @@ dialog_random_tool (Workbook *wb, Sheet *sheet)
gtk_widget_hide (callback_data.uniform_box);
gtk_widget_hide (callback_data.normal_box);
gtk_widget_hide (callback_data.bernoulli_box);
gtk_widget_hide (callback_data.poisson_box);
break;
case NormalDistribution: