Commit 6b1a937a authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka

Gladefied the Solver tool. Implemented `Change' (constraint) button.

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

	* src/dialogs/dialog-solver.c, src/dialogs/solver.glade,
 	src/dialogs/Makefile.am: Gladefied the Solver tool.  Implemented
 	`Change' (constraint) button.

	* src/functions/fn-math.c: Added RandExp(), RandPoisson(),
 	RandBinom(), RandNegBinom(), and RandBernoulli() functions.

	* src/functions/fn-math.c, src/mathfunc.[ch]: Moved gcd to
 	mathfunc.c.
parent a038ab94
2000-01-31 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/dialogs/dialog-solver.c, src/dialogs/solver.glade,
src/dialogs/Makefile.am: Gladefied the Solver tool. Implemented
`Change' (constraint) button.
* src/functions/fn-math.c: Added RandExp(), RandPoisson(),
RandBinom(), RandNegBinom(), and RandBernoulli() functions.
* src/functions/fn-math.c, src/mathfunc.[ch]: Moved gcd to
mathfunc.c.
2000-01-31 Jody Goldberg <jgoldberg@home.com>
* src/worksheet.h : Move more of the pure view elements into
......
......@@ -13,6 +13,8 @@ Jukka:
- Exponential
* Minor improvements for the AutoSave tool.
* GUI improvements for the Data Analysis tool.
* Added RandExp(), RandPoisson(), RandBinom(), RandNegBinom(),
and RandBernoulli() functions.
Jody:
* Row/Col header redraw improvements.
......
2000-01-31 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/dialogs/dialog-solver.c, src/dialogs/solver.glade,
src/dialogs/Makefile.am: Gladefied the Solver tool. Implemented
`Change' (constraint) button.
* src/functions/fn-math.c: Added RandExp(), RandPoisson(),
RandBinom(), RandNegBinom(), and RandBernoulli() functions.
* src/functions/fn-math.c, src/mathfunc.[ch]: Moved gcd to
mathfunc.c.
2000-01-31 Jody Goldberg <jgoldberg@home.com>
* src/worksheet.h : Move more of the pure view elements into
......
......@@ -14,22 +14,6 @@
#include "collect.h"
#include "auto-format.h"
static int
gcd (int a, int b)
{
/* Euclid's Algorithm. Assumes non-negative numbers. */
while (b != 0) {
int r;
r = a - (a / b) * b; /* r = remainder from
* dividing a by b */
a = b;
b = r;
}
return a;
}
typedef struct {
GSList *list;
......@@ -1278,6 +1262,144 @@ gnumeric_rand (FunctionEvalInfo *ei, Value **argv)
/***************************************************************************/
static char *help_randexp = {
N_("@FUNCTION=RandExp\n"
"@SYNTAX=RandExp(b)\n"
"@DESCRIPTION="
"RandExp returns a exponentially distributed random number. "
"\n"
"@EXAMPLES=\n"
"RandExp(0.5).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randexp (FunctionEvalInfo *ei, Value **argv)
{
float_t x = value_get_as_float (argv[0]);
return value_new_float (random_exponential (x));
}
/***************************************************************************/
static char *help_randpoisson = {
N_("@FUNCTION=RandPoisson\n"
"@SYNTAX=RandPoisson(lambda)\n"
"@DESCRIPTION="
"RandPoisson returns a poisson distributed random number. "
"\n"
"@EXAMPLES=\n"
"RandPoisson(3).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randpoisson (FunctionEvalInfo *ei, Value **argv)
{
float_t x = value_get_as_float (argv[0]);
if (x < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (random_poisson (x));
}
/***************************************************************************/
static char *help_randbinom = {
N_("@FUNCTION=RandBinom\n"
"@SYNTAX=RandBinom(p,trials)\n"
"@DESCRIPTION="
"RandBinom returns a binomialy distributed random number. "
"\n"
"If @p < 0 or @p > 1 RandBinom returns #NUM! error. "
"If @trials < 0 RandBinom returns #NUM! error. "
"\n"
"@EXAMPLES=\n"
"RandBinom(0.5,2).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randbinom (FunctionEvalInfo *ei, Value **argv)
{
float_t p = value_get_as_float (argv[0]);
int trials = value_get_as_int (argv[1]);
if (p < 0 || p > 1 || trials < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (random_binomial (p, trials));
}
/***************************************************************************/
static char *help_randnegbinom = {
N_("@FUNCTION=RandNegBinom\n"
"@SYNTAX=RandNegBinom(p,failures)\n"
"@DESCRIPTION="
"RandNegBinom returns a negitive binomialy distributed random "
"number. "
"\n"
"If @p < 0 or @p > 1 RandNegBinom returns #NUM! error. "
"If @failures RandNegBinom returns #NUM! error. "
"\n"
"@EXAMPLES=\n"
"RandNegBinom(0.5,2).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randnegbinom (FunctionEvalInfo *ei, Value **argv)
{
float_t p = value_get_as_float (argv[0]);
int failures = value_get_as_int (argv[1]);
if (p < 0 || p > 1 || failures < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (random_negbinom (p, failures));
}
/***************************************************************************/
static char *help_randbernoulli = {
N_("@FUNCTION=RandBernoulli\n"
"@SYNTAX=RandBernoulli(p)\n"
"@DESCRIPTION="
"RandBernoulli returns a Bernoulli distributed random number. "
"\n"
"If @p < 0 or @p > 1 RandBernoulli returns #NUM! error. "
"\n"
"@EXAMPLES=\n"
"RandBernoulli(0.5).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randbernoulli (FunctionEvalInfo *ei, Value **argv)
{
float_t p = value_get_as_float (argv[0]);
if (p < 0 || p > 1)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (random_bernoulli (p));
}
/***************************************************************************/
static char *help_sin = {
N_("@FUNCTION=SIN\n"
"@SYNTAX=SIN(x)\n"
......@@ -3465,9 +3587,24 @@ math_functions_init (void)
gnumeric_radians);
function_add_args (cat, "rand", "",
"", &help_rand, gnumeric_rand);
function_add_args (cat, "randbetween", "ff",
"bottom,top",
&help_randbetween, gnumeric_randbetween);
function_add_args (cat, "randbernoulli", "f",
"p",
&help_randbernoulli, gnumeric_randbernoulli);
function_add_args (cat, "randbetween", "ff",
"bottom,top",
&help_randbetween, gnumeric_randbetween);
function_add_args (cat, "randbinom", "ff",
"p,trials",
&help_randbinom, gnumeric_randbinom);
function_add_args (cat, "randexp", "f",
"b",
&help_randexp, gnumeric_randexp);
function_add_args (cat, "randnegbinom", "ff",
"p,failures",
&help_randnegbinom, gnumeric_randnegbinom);
function_add_args (cat, "randpoisson", "f",
"lambda",
&help_randpoisson, gnumeric_randpoisson);
function_add_args (cat, "roman", "f|f",
"number[,type]",
&help_roman, gnumeric_roman);
......
......@@ -61,17 +61,18 @@ INSTOBJEXT = @INSTOBJEXT@
.c.o:
$(COMPILE) $<
%.pox: %.po $(srcdir)/$(PACKAGE).pot
.po.pox:
$(MAKE) $(PACKAGE).pot
$(MSGMERGE) $< $(srcdir)/$(PACKAGE).pot -o $*.pox
%.mo: %.po
.po.mo:
$(MSGFMT) -o $@ $<
%.gmo: %.po
.po.gmo:
file=$(srcdir)/`echo $* | sed 's,.*/,,'`.gmo \
&& rm -f $$file && $(GMSGFMT) -o $$file $<
%.cat: %.po
.po.cat:
sed -f ../intl/po2msg.sed < $< > $*.msg \
&& rm -f $@ && $(GENCAT) $@ $*.msg
......@@ -90,7 +91,7 @@ $(srcdir)/$(PACKAGE).pot: $(POTFILES)
&& mv $(PACKAGE).po $(srcdir)/$(PACKAGE).pot )
$(srcdir)/cat-id-tbl.c: stamp-cat-id; @:
$(srcdir)/stamp-cat-id: $(srcdir)/$(PACKAGE).pot
$(srcdir)/stamp-cat-id: $(PACKAGE).pot
rm -f cat-id-tbl.tmp
sed -f ../intl/po2tbl.sed $(srcdir)/$(PACKAGE).pot \
| sed -e "s/@PACKAGE NAME@/$(PACKAGE)/" > cat-id-tbl.tmp
......@@ -205,7 +206,8 @@ dist distdir: update-po $(DISTFILES)
|| cp -p $(srcdir)/$$file $(distdir); \
done
update-po: Makefile $(srcdir)/$(PACKAGE).pot
update-po: Makefile
$(MAKE) $(PACKAGE).pot
PATH=`pwd`/../src:$$PATH; \
cd $(srcdir); \
catalogs='$(CATALOGS)'; \
......
......@@ -60,6 +60,7 @@ glade_DATA = \
print.glade \
row-height.glade \
sheet-rename.glade \
solver.glade \
solver-options.glade \
summary.glade \
dialog-zoom.glade \
......
This diff is collapsed.
......@@ -27,6 +27,7 @@
<widget>
<class>GnomeDialog</class>
<name>SolverOptions</name>
<visible>False</visible>
<title>Solver Options</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
......
This diff is collapsed.
......@@ -14,22 +14,6 @@
#include "collect.h"
#include "auto-format.h"
static int
gcd (int a, int b)
{
/* Euclid's Algorithm. Assumes non-negative numbers. */
while (b != 0) {
int r;
r = a - (a / b) * b; /* r = remainder from
* dividing a by b */
a = b;
b = r;
}
return a;
}
typedef struct {
GSList *list;
......@@ -1278,6 +1262,144 @@ gnumeric_rand (FunctionEvalInfo *ei, Value **argv)
/***************************************************************************/
static char *help_randexp = {
N_("@FUNCTION=RandExp\n"
"@SYNTAX=RandExp(b)\n"
"@DESCRIPTION="
"RandExp returns a exponentially distributed random number. "
"\n"
"@EXAMPLES=\n"
"RandExp(0.5).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randexp (FunctionEvalInfo *ei, Value **argv)
{
float_t x = value_get_as_float (argv[0]);
return value_new_float (random_exponential (x));
}
/***************************************************************************/
static char *help_randpoisson = {
N_("@FUNCTION=RandPoisson\n"
"@SYNTAX=RandPoisson(lambda)\n"
"@DESCRIPTION="
"RandPoisson returns a poisson distributed random number. "
"\n"
"@EXAMPLES=\n"
"RandPoisson(3).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randpoisson (FunctionEvalInfo *ei, Value **argv)
{
float_t x = value_get_as_float (argv[0]);
if (x < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (random_poisson (x));
}
/***************************************************************************/
static char *help_randbinom = {
N_("@FUNCTION=RandBinom\n"
"@SYNTAX=RandBinom(p,trials)\n"
"@DESCRIPTION="
"RandBinom returns a binomialy distributed random number. "
"\n"
"If @p < 0 or @p > 1 RandBinom returns #NUM! error. "
"If @trials < 0 RandBinom returns #NUM! error. "
"\n"
"@EXAMPLES=\n"
"RandBinom(0.5,2).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randbinom (FunctionEvalInfo *ei, Value **argv)
{
float_t p = value_get_as_float (argv[0]);
int trials = value_get_as_int (argv[1]);
if (p < 0 || p > 1 || trials < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (random_binomial (p, trials));
}
/***************************************************************************/
static char *help_randnegbinom = {
N_("@FUNCTION=RandNegBinom\n"
"@SYNTAX=RandNegBinom(p,failures)\n"
"@DESCRIPTION="
"RandNegBinom returns a negitive binomialy distributed random "
"number. "
"\n"
"If @p < 0 or @p > 1 RandNegBinom returns #NUM! error. "
"If @failures RandNegBinom returns #NUM! error. "
"\n"
"@EXAMPLES=\n"
"RandNegBinom(0.5,2).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randnegbinom (FunctionEvalInfo *ei, Value **argv)
{
float_t p = value_get_as_float (argv[0]);
int failures = value_get_as_int (argv[1]);
if (p < 0 || p > 1 || failures < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (random_negbinom (p, failures));
}
/***************************************************************************/
static char *help_randbernoulli = {
N_("@FUNCTION=RandBernoulli\n"
"@SYNTAX=RandBernoulli(p)\n"
"@DESCRIPTION="
"RandBernoulli returns a Bernoulli distributed random number. "
"\n"
"If @p < 0 or @p > 1 RandBernoulli returns #NUM! error. "
"\n"
"@EXAMPLES=\n"
"RandBernoulli(0.5).\n"
"\n"
"@SEEALSO=RAND,RANDBETWEEN")
};
static Value *
gnumeric_randbernoulli (FunctionEvalInfo *ei, Value **argv)
{
float_t p = value_get_as_float (argv[0]);
if (p < 0 || p > 1)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (random_bernoulli (p));
}
/***************************************************************************/
static char *help_sin = {
N_("@FUNCTION=SIN\n"
"@SYNTAX=SIN(x)\n"
......@@ -3465,9 +3587,24 @@ math_functions_init (void)
gnumeric_radians);
function_add_args (cat, "rand", "",
"", &help_rand, gnumeric_rand);
function_add_args (cat, "randbetween", "ff",
"bottom,top",
&help_randbetween, gnumeric_randbetween);
function_add_args (cat, "randbernoulli", "f",
"p",
&help_randbernoulli, gnumeric_randbernoulli);
function_add_args (cat, "randbetween", "ff",
"bottom,top",
&help_randbetween, gnumeric_randbetween);
function_add_args (cat, "randbinom", "ff",
"p,trials",
&help_randbinom, gnumeric_randbinom);
function_add_args (cat, "randexp", "f",
"b",
&help_randexp, gnumeric_randexp);
function_add_args (cat, "randnegbinom", "ff",
"p,failures",
&help_randnegbinom, gnumeric_randnegbinom);
function_add_args (cat, "randpoisson", "f",
"lambda",
&help_randpoisson, gnumeric_randpoisson);
function_add_args (cat, "roman", "f|f",
"number[,type]",
&help_roman, gnumeric_roman);
......
......@@ -4010,3 +4010,22 @@ gpow10 (int n)
}
return res;
}
/*
* Euclid's Algorithm. Assumes non-negative numbers.
*/
int
gcd (int a, int b)
{
while (b != 0) {
int r;
r = a - (a / b) * b; /* r = remainder from
* dividing a by b */
a = b;
b = r;
}
return a;
}
......@@ -117,6 +117,8 @@ double random_normal (void);
/* ------------------------------------------------------------------------- */
/* Misc. */
float_t gpow10 (int n);
int gcd (int a, int b);
#endif
......@@ -77,8 +77,7 @@ simplex_step_one(Sheet *sheet, int target_col, int target_row,
n = 1;
while (current != NULL) {
c = (SolverConstraint *) current->data;
lhs = sheet_cell_fetch(sheet, c->lhs->col->pos,
c->lhs->row->pos);
lhs = sheet_cell_fetch(sheet, c->lhs_col, c->lhs_row);
cell_eval_content(lhs);
table[i + n**table_cols] =
-value_get_as_float(lhs->value);
......@@ -93,8 +92,7 @@ simplex_step_one(Sheet *sheet, int target_col, int target_row,
n = 1;
while (current != NULL) {
c = (SolverConstraint *) current->data;
lhs = sheet_cell_fetch(sheet, c->lhs->col->pos,
c->lhs->row->pos);
lhs = sheet_cell_fetch(sheet, c->lhs_col, c->lhs_row);
cell_eval_content(lhs);
table[i + n * *table_cols] +=
value_get_as_float(lhs->value);
......@@ -116,8 +114,7 @@ simplex_step_one(Sheet *sheet, int target_col, int target_row,
while (constraints != NULL) {
c = (SolverConstraint *) constraints->data;
table[i * *table_cols] = i-1 + n_vars;
rhs = sheet_cell_fetch(sheet, c->rhs->col->pos,
c->rhs->row->pos);
rhs = sheet_cell_fetch(sheet, c->rhs_col, c->rhs_row);
table[1 + i * *table_cols] = value_get_as_float(rhs->value);
if (strcmp(c->type, "<=") == 0) {
table[1 + n_vars + n + i* *table_cols] = 1;
......@@ -127,8 +124,8 @@ simplex_step_one(Sheet *sheet, int target_col, int target_row,
++n;
}
printf ("%-30s (col=%d, row=%d %s col=%d, row=%d\n",
c->str, c->lhs->col->pos, c->lhs->row->pos,
c->type, c->rhs->col->pos, c->rhs->row->pos);
c->str, c->lhs_col, c->lhs_row,
c->type, c->rhs_col, c->rhs_row);
constraints = constraints->next;
i++;
}
......@@ -288,8 +285,7 @@ int solver_simplex (Workbook *wb, Sheet *sheet)
while (constraints != NULL) {
SolverConstraint *c = (SolverConstraint *) constraints->data;
cell = sheet_cell_fetch(sheet, c->lhs->col->pos,
c->lhs->row->pos);
cell = sheet_cell_fetch(sheet, c->lhs_col, c->lhs_row);
cell_eval_content(cell);
constraints = constraints->next;
}
......
......@@ -32,10 +32,10 @@ struct _SolverOptions {
};
struct _SolverConstraint {
Cell *lhs; /* left hand side */
Cell *rhs; /* right hand side */
gchar *type; /* <=, =, >=, int, bool */
char *str; /* the same in string form */
gint lhs_col, lhs_row; /* left hand side */
gint rhs_col, rhs_row; /* right hand side */
gchar *type; /* <=, =, >=, int, bool */
char *str; /* the same in string form */
};
struct _SolverParameters {
......
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