diff: improved floundering handling in CLP(R) interface

Fergus Henderson fjh at kryten.cs.mu.OZ.AU
Sun Sep 14 22:07:40 AEST 1997


Improve the handling of floundering in cfloat.m. 

Also fix a bug in CLP(R): print_nl_eqn() did not work, because `dumpF'
was not being initialized.

clpr/cfloat.m:
	Improve the precision of the floundering check:
	instead of just checking `nlin_count' (which can give
	rise to spurious warnings and can also miss warnings)
	walk the list of non-linear constraints looking
	for any that are still delayed.
	Also improve the error message when floundering is detected:
	print out the delayed non-linear constraints.

clpr/clpr/clpr_misc.h:
	Declare `print_nl_eqn()' and `nl_eqn_top', for use by cfloat.m.

clpr/clpr/dump.c:
	Make `dumpF' external.

clpr/clpr/clpr_misc.h:
	Declare `dumpF'.

clpr/clpr/clpr_misc.c:
	Initialize dumpF in CLPR_init(),

cvs diff clpr/cfloat.m clpr/clpr/clpr_misc.c clpr/clpr/clpr_misc.h clpr/clpr/dump.c
Index: clpr/cfloat.m
===================================================================
RCS file: /home/mercury1/repository/clpr/cfloat.m,v
retrieving revision 1.11
diff -u -r1.11 cfloat.m
--- 1.11	1997/09/08 16:46:52
+++ cfloat.m	1997/09/14 11:07:23
@@ -392,6 +392,7 @@
 	int slack_id;
 	int solver_id;
 	int trtop;
+	NL_EQN_ptr nl_eqn_top;
 	struct ML_cfloat_choicepoint *next;
 } ML_cfloat_choicepoint;
 
@@ -422,6 +423,7 @@
 	choicepoint->slack_id = slack_id;
 	choicepoint->solver_id = solver_id;
 	choicepoint->trtop = trtop;
+	choicepoint->nl_eqn_top = nl_eqn_top;
 	MR_trail_function(ML_cfloat_untrail_func, (Word) choicepoint);
 
 	if (choicepoint->next == NULL) {
@@ -435,6 +437,41 @@
 	stamp = MR_current_choicepoint_id();
 }
 
+static void
+ML_cfloat_check_floundering(NL_EQN_ptr old_top)
+{
+	NL_EQN_ptr ptr;
+	bool floundered;
+
+	/*
+	** Check if we have added any non-linear equations
+	** since `old_top' and not yet woken them up.
+	*/
+
+	floundered = FALSE;
+	for (ptr = nl_eqn_top; ptr != old_top; ptr = ptr->next) {
+		if (ptr->type != WOKEN && ptr->partner == NULL) {
+			floundered = TRUE;
+		}
+	}
+
+	if (floundered) {
+		fflush(stdout);
+		fprintf(stderr,
+			""\\ncfloat.m: warning: goal floundered.\\n""
+			""\\tThis solver can only solve linear constraints.\\n""
+			""\\tThe following delayed goals\\n""
+		);
+		for (ptr = nl_eqn_top; ptr != old_top; ptr = ptr->next) {
+			if (ptr->type != WOKEN && ptr->partner == NULL) {
+				fprintf(stderr, ""\\t\\t"");
+				print_nl_eqn(ptr);
+			}
+		}
+		fprintf(stderr, ""\\twere assumed to be solvable.\\n"");
+	}
+}
+
 void
 ML_cfloat_untrail_func(Word datum, MR_untrail_reason reason)
 {
@@ -457,11 +494,7 @@
 		}
 		case MR_commit:
 			stamp = choicepoint->stamp;
-			if (nlin_count != 0) {
-				fprintf(stderr, ""cfloat.m: warning: ""
-					""non-linear goals delayed, ""
-					""but committing anyway\n"");
-			}
+			ML_cfloat_check_floundering(choicepoint->nl_eqn_top);
 			break;
 		default:
 			fatal_error(""cfloat.m: unknown MR_untrail_reason"");
Index: clpr/clpr/clpr_misc.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/clpr_misc.c,v
retrieving revision 1.5
diff -u -r1.5 clpr_misc.c
--- 1.5	1997/09/08 18:45:50
+++ clpr_misc.c	1997/09/14 10:52:42
@@ -17,7 +17,7 @@
 	/* get some memory for the CLP(R) trail */
 	trail = (CLPR_int **) malloc(DEF_TRAIL_SZ * sizeof(CLPR_int *));
 	if (!trail) {
-		fatal("init_CLPR: cannot allocate trail: malloc failed");
+		fatal("CLPR_init: cannot allocate trail: malloc failed");
 	}
 	trtop = 0;
 	stamp = -1;
@@ -25,4 +25,5 @@
 	/* initialise the CLP(R) streams */
 	error_stream = stderr;
 	outfile = stderr;
+	dumpF = stderr;
 }
Index: clpr/clpr/clpr_misc.h
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/clpr_misc.h,v
retrieving revision 1.5
diff -u -r1.5 clpr_misc.h
--- 1.5	1997/09/08 19:04:30
+++ clpr_misc.h	1997/09/14 11:12:13
@@ -20,6 +20,7 @@
 	*/
 extern FILE *error_stream;
 extern FILE *outfile;
+extern FILE *dumpF;
 
 	/* some CLP(R) functions */
 void init_solver(void);
@@ -54,6 +55,11 @@
 CLPR_int s_cos(CLPR_svar, CLPR_svar);
 CLPR_int s_arcsin(CLPR_svar, CLPR_svar);
 CLPR_int s_arccos(CLPR_svar, CLPR_svar);
+
+	/* pointer to list of currently delayed non-linear equations */
+extern NL_EQN_ptr nl_eqn_top;
+
+void print_nl_eqn(NL_EQN_ptr);
 
 	/* check if a variable is ground, and if so, find its value */
 CLPR_int is_ground(CLPR_svar, double *);
Index: clpr/clpr/dump.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/dump.c,v
retrieving revision 1.7
diff -u -r1.7 dump.c
--- 1.7	1997/09/08 19:04:42
+++ dump.c	1997/09/14 10:31:06
@@ -188,7 +188,7 @@
 /*---------------------------------------------------------------------------*/
 
 
-static FILE *dumpF;
+FILE *dumpF;
 
 
 void init_dump (void);

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list