gnumeric r16309 - in trunk: . src/tools/solver



Author: mortenw
Date: Wed Jan 30 02:32:39 2008
New Revision: 16309
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16309&view=rev

Log:
2008-01-29  Morten Welinder  <terra gnome org>

	* solver.c (lp_qp_solver_init): Take lhs' value for vars=0 into
	account.  In the typical case, that is vars itself, but in #512500
	it is not.
	(get_lp_coeff): Compute at x=1 first, then at x=0.  Hence we leave
	things at zero.



Modified:
   trunk/NEWS
   trunk/src/tools/solver/ChangeLog
   trunk/src/tools/solver/solver.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Wed Jan 30 02:32:39 2008
@@ -15,6 +15,7 @@
 	* Plug csv leak.
 	* Fix inter-sheet cut problem.  [#511706]
 	* Fix loading of solver constraints.
+	* Fix solver issue.  [#512500]
 
 --------------------------------------------------------------------------
 Gnumeric 1.8.0

Modified: trunk/src/tools/solver/solver.c
==============================================================================
--- trunk/src/tools/solver/solver.c	(original)
+++ trunk/src/tools/solver/solver.c	Wed Jan 30 02:32:39 2008
@@ -350,15 +350,15 @@
 {
         gnm_float x0, x1;
 
-	gnm_cell_set_value (change, value_new_float (0.0));
+	gnm_cell_set_value (change, value_new_float (1));
 	cell_queue_recalc (change);
 	gnm_cell_eval (target);
-	x0 = value_get_as_float (target->value);
+	x1 = value_get_as_float (target->value);
 
-	gnm_cell_set_value (change, value_new_float (1.0));
+	gnm_cell_set_value (change, value_new_float (0));
 	cell_queue_recalc (change);
 	gnm_cell_eval (target);
-	x1 = value_get_as_float (target->value);
+	x0 = value_get_as_float (target->value);
 
 	return x1 - x0;
 }
@@ -481,23 +481,26 @@
 	for (i = ind = 0; i < param->n_total_constraints; i++) {
 	        SolverConstraint const *c = solver_get_constraint (res, i);
 		GTimeVal cur_time;
-		const GnmValue *val;
+		const GnmValue *lval;
+		const GnmValue *rval;
+		gnm_float lx, rx;
 
 		target = sheet_cell_get (sheet, c->lhs.col, c->lhs.row);
 		if (target) {
 			gnm_cell_eval (target);
-			val = target->value;
+			lval = target->value;
 		} else
-			val = NULL;
+			lval = NULL;
 
 		/* Check that LHS is a number type. */
-		if (val == NULL || !VALUE_IS_NUMBER (val)) {
+		if (lval == NULL || !VALUE_IS_NUMBER (lval)) {
 			*errmsg = _("The LHS cells should contain formulas "
 				    "that yield proper numerical values.  "
 				    "Specify valid LHS entries.");
 			solver_results_free (res);
 			return NULL;
 		}
+		lx = value_get_as_float (lval);
 
 		if (c->type == SolverINT) {
 		        n = get_col_nbr (res, &c->lhs);
@@ -529,20 +532,21 @@
 		target = sheet_cell_get (sheet, c->rhs.col, c->rhs.row);
 		if (target) {
 			gnm_cell_eval (target);
-			val = target->value;
+			rval = target->value;
 		} else
-			val = NULL;
+			rval = NULL;
 
 		/* Check that RHS is a number type. */
-		if (val == NULL || !VALUE_IS_NUMBER (val)) {
+		if (rval == NULL || !VALUE_IS_NUMBER (rval)) {
 			*errmsg = _("The RHS cells should contain proper "
 				    "numerical values only.  Specify valid "
 				    "RHS entries.");
 			solver_results_free (res);
 			return NULL;
 		}
+		rx = value_get_as_float (rval);
 
-		x = value_get_as_float (val);
+		x = rx - lx;
 		alg->set_constr_fn (program, ind, c->type, x);
 		res->rhs[i] = x; 
 		ind++;
@@ -604,6 +608,8 @@
 		res->ilp_flag = TRUE;
 	}
 
+	alg->print_fn (program);
+
 	return program;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]