1 /*
2 * Name: isfeas.c
3 * Author: Pietro Belotti
4 * Purpose: check actual feasibility of the feasible subsystem found
5 *
6 * This code is published under the Eclipse Public License (EPL).
7 * See http://www.eclipse.org/legal/epl-v10.html
8 *
9 */
10
11 #include <stdio.h>
12
13 #include "sparse.h"
14
15 /*
16 * feasibility test
17 */
18
isFeas(sparseLP * lp,char * sat,double * x,int * n)19 int isFeas (sparseLP *lp, /* sparse LP data */
20 char *sat, /* alleged fulfilled constraints */
21 double *x, /* current point */
22 int *n /* alleged number of constraints satisfied */
23 ) {
24
25 double sum;
26 int fok = 1;
27 int uok = 1;
28 int nsatd = 0;
29 register int i;
30
31 double *rhs = lp->rhs;
32 double *lb = lp->lb,
33 *ub = lp->ub;
34
35 double **rowC = lp->ic;
36 double *ic;
37
38 int **rowP = lp->ip;
39 int *ip, *il = lp->il;
40
41 for (i=lp->rk; i>0; i--, sat++) {
42
43 sum = - *rhs++;
44
45 ic = *rowC++;
46 ip = *rowP++;
47
48 #ifdef RTR_USE_PRAGMAS
49 calc_lhs (&sum, *il++, ic, x, ip);
50 #else
51 {
52 register int j;
53
54 for (j=*il++; j>0; j--)
55 sum += *ic++ * x [*ip++];
56 }
57 #endif
58
59 if (sum >= 0) {
60 ++nsatd;
61 if (!*sat) uok = 0;
62 }
63 else if (*sat) fok = 0;
64 }
65
66 for (i=lp->c0; i>0; i--, lb++, ub++, x++)
67 if ((*x < *lb) || (*x > *ub)) {
68 /* printf ("%d: x_%d = %.5f out of bounds [%.4f,%.4f]\n",
69 lp->my_id, lp->c0 - i, *x, *lb, *ub);*/
70 return -1;
71 }
72
73 if (nsatd != *n) {
74 printf ("Thread %d: Warning, numbers of satisfied inequalities differ after check (%d != %d)\n", lp->my_id, *n, nsatd);
75 *n = nsatd;
76 }
77
78 /* if (2*fok+uok!=3) printf ("%d: return %d\n", lp->my_id, 2*fok+uok); */
79
80 return 2 * fok + uok;
81 }
82