/* solve LP problem coefficients are read from a file matrices are allocated dynamically sample data files feas-t3-0.dat feas-t3-1.dat feas-t3-2.dat Usage: feas-t3.out or feas-t3.out filename */ #include #include "opt.h" main(int argc, char **argv) { FILE *fd; char *filename = "feas-t3-0.dat"; int m, n; double *a, *b, *c, *d, *ox, *ov; double eps = 1e-4; status st; if (argc >= 2) { filename = argv[1]; } if ((fd = fopen(filename,"r")) == NULL) { fprintf(stderr, "cannot open file %s\n", filename); exit(1); } fprintf(stderr, "\n Two Phase Method in file %s\n\n", filename); fscanf(fd, "%d %d", &m, &n); matrixallocfscan(fd, m, n, &a); /* a : m x n matrix */ matrixallocfscan(fd, m, 1, &b); /* b : m x 1 matrix */ matrixallocfscan(fd, 1, n, &c); /* c : 1 x n matrix */ matrixallocfscan(fd, 1, 1, &d); /* d : 1 x 1 matrix */ fclose(fd); matrixfprint(stdout, m, n, a); matrixfprint(stdout, m, 1, b); matrixfprint(stdout, 1, n, c); matrixfprint(stdout, 1, 1, d); ox = allc(dbl,n*1); ov = allc(dbl,1*1); st = TwoPhasemethod(m, n, a, b, c, d, eps, ox, ov); if (st == success) { puts("--- converge ---"); printf("optimal solution\n"); matrixfprint(stdout, n, 1, ox); printf("optimal value = %lf\n", ov[0]); } else if (st == failure) { puts("--- diverge ---"); } else { puts("--- no feasible solution ---"); } }