alpar@1: /* alpar@1: alpar@1: Curve fitting problem 12.11(b) H P Williams "Model Building in Mathematical Programming" alpar@1: alpar@1: Dr. H J Mackenzie alpar@1: HARD software alpar@1: hjm@hardsoftware.com alpar@1: alpar@1: 2006-01-23 alpar@1: alpar@1: */ alpar@1: alpar@1: # set of points alpar@1: alpar@1: set I; alpar@1: alpar@1: # independent variable alpar@1: alpar@1: param x {i in I}; alpar@1: alpar@1: # dependent variable alpar@1: alpar@1: param y {i in I}; alpar@1: alpar@1: # output input values alpar@1: alpar@1: printf {i in I} "x = %.1f; y = %.1f\n", x[i], y[i]; alpar@1: alpar@1: # define equation variables alpar@1: alpar@1: var a; alpar@1: alpar@1: var b; alpar@1: alpar@1: var u {i in I}, >= 0; alpar@1: alpar@1: var v {i in I}, >= 0; alpar@1: alpar@1: var z; alpar@1: alpar@1: # define objective function alpar@1: alpar@1: minimize deviation: z; alpar@1: alpar@1: # define equation constraint alpar@1: alpar@1: s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i]; alpar@1: alpar@1: # define deviation constrains alpar@1: alpar@1: s.t. u_deviation {i in I} : z - u[i] >= 0; alpar@1: s.t. v_deviation {i in I} : z - v[i] >= 0; alpar@1: alpar@1: solve; alpar@1: alpar@1: printf "y = %.4fx + %.4f Max deviation = %.4f\n", b, a, z; alpar@1: alpar@1: /* alpar@1: * alpar@1: * DATA section alpar@1: * alpar@1: */ alpar@1: alpar@1: data; alpar@1: alpar@1: param : I : x y := alpar@1: 1 0 1 alpar@1: 2 0.5 0.9 alpar@1: 3 1 0.7 alpar@1: 4 1.5 1.5 alpar@1: 5 1.9 2 alpar@1: 6 2.5 2.4 alpar@1: 7 3 3.2 alpar@1: 8 3.5 2 alpar@1: 9 4 2.7 alpar@1: 10 4.5 3.5 alpar@1: 11 5 1 alpar@1: 12 5.5 4 alpar@1: 13 6 3.6 alpar@1: 14 6.6 2.7 alpar@1: 15 7 5.7 alpar@1: 16 7.6 4.6 alpar@1: 17 8.5 6 alpar@1: 18 9 6.8 alpar@1: 19 10 7.3 alpar@1: ; alpar@1: alpar@1: end;