/* solve LP problem coefficients are given in this program */ #include #include "opt.h" /* max 2*x0 + 4*x1 + 100 s.t. 2*x0 + 3*x1 <= 1 1*x0 + 3*x1 <= 1 2*x0 + 7*x1 <= 2 x0, x1 >= 0 solution : max = 101.25 at x0=1/8 and x1=1/4 */ #define NumEqs 3 #define NumVars 5 main() { int m = NumEqs; int n = NumVars; double a[NumEqs][NumVars] = {{2.00, 3.00, 1.00, 0.00, 0.00}, {1.00, 3.00, 0.00, 1.00, 0.00}, {2.00, 7.00, 0.00, 0.00, 1.00}}; double b[NumEqs] = {1.00, 1.00, 2.00}; double c[NumVars] = {2.00, 4.00, 0.00, 0.00, 0.00}; double d = 100.00; double eps = 1e-4; double ox[NumVars], opt; status st; matrixfprint(stdout, m, n, a); matrixfprint(stdout, m, 1, b); matrixfprint(stdout, 1, n, c); fprintf(stdout, "%lf\n", d); st = LPsimplex(m, n, a, b, c, &d, eps, ox, &opt); if (st == success) { puts("--- converge ---"); printf("optimal solution\n"); matrixfprint(stdout, n, 1, ox); printf("optimal value = %lf\n", opt); } else if (st == failure) { puts("--- diverge ---"); } else { puts("--- error ---"); } }