malt-wr
dsimplx.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int simplx (double **a, int m, int n, int *izrov, int *iposv)
 

Function Documentation

int simplx ( double **  a,
int  m,
int  n,
int *  izrov,
int *  iposv 
)

Definition at line 11 of file dsimplx.c.

12 {
13  int i,ip,ir,is,k,kh,kp,m12,nl1,nl2;
14  int *l1,*l2;
15  double q1,bmax;
16  void simp1(),simp2(),simp3();
17 
18  l1=ivector(1,n+1);
19  l2=ivector(1,m);
20  nl1=n;
21  for (k=1;k<=n;k++) l1[k]=izrov[k]=k;
22  nl2=m;
23  for (i=1;i<=m;i++) {
24  if (a[i+1][1] < 0.0) nrerror("Bad input tableau in SIMPLX");
25  l2[i]=i;
26  iposv[i]=n+i;
27  }
28 /* stage one */
29  ir=1;
30  for (k=1;k<=(n+1);k++) {
31  q1=0.0;
32  for (i=1;i<=m;i++) q1 += a[i+1][k];
33  a[m+2][k] = -q1;
34  }
35  do {
36  simp1(a,m+1,l1,nl1,0,&kp,&bmax);
37  if (bmax <= EPS1 && a[m+2][1] < -EPS1) {
38  FREEALL
39  return -1;
40  } else if (bmax <= EPS1 && a[m+2][1] <= EPS1) {
41  for (ip=1;ip<=m;ip++) {
42  if (iposv[ip] == (ip+n)) {
43  simp1(a,ip,l1,nl1,1,&kp,&bmax);
44  if (bmax > 0.0) goto one;
45  }
46  }
47  ir=0;
48  break;
49  }
50  simp2(a,n,l2,nl2,&ip,kp,&q1);
51  if (ip == 0) {
52  FREEALL
53  return -1;
54  }
55 one: simp3(a,m+1,n,ip,kp);
56  if (iposv[ip] >= (n+1)) {
57  for (k=1;k<=nl1;k++)
58  if (l1[k] == kp) break;
59  --nl1;
60  for (is=k;is<=nl1;is++) l1[is]=l1[is+1];
61  a[m+2][kp+1] += 1.0;
62  for (i=1;i<=m+2;i++) a[i][kp+1] = -a[i][kp+1];
63  }
64  is=izrov[kp];
65  izrov[kp]=iposv[ip];
66  iposv[ip]=is;
67  } while (ir);
68 /* phase two */
69  for (;;) {
70  simp1(a,0,l1,nl1,0,&kp,&bmax);
71  if (bmax <= 0.0) {
72  FREEALL
73  return 0;
74  }
75  simp2(a,n,l2,nl2,&ip,kp,&q1);
76  if (ip == 0) {
77  FREEALL
78  return 1;
79  }
80  simp3(a,m,n,ip,kp);
81  is=izrov[kp];
82  izrov[kp]=iposv[ip];
83  iposv[ip]=is;
84  }
85 }
int * ivector(int nl, int nh)
Definition: qnrutil.c:8
void nrerror(char *error_text)
Definition: lineread.c:7
void simp2(double **a, int n, int *l2, int nl2, int *ip, int kp, double *q1)
Definition: dsimplx.c:106
void simp1(double **a, int mm, int *ll, int nll, int iabf, int *kp, double *bmax)
Definition: dsimplx.c:87
#define EPS1
Definition: dsimplx.c:7
#define FREEALL
Definition: dsimplx.c:9
void simp3(double **a, int i1, int k1, int ip, int kp)
Definition: dsimplx.c:137