1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/cf12b.mod Mon Dec 06 13:09:21 2010 +0100
1.3 @@ -0,0 +1,88 @@
1.4 +/*
1.5 +
1.6 + Curve fitting problem 12.11(b) H P Williams "Model Building in Mathematical Programming"
1.7 +
1.8 + Dr. H J Mackenzie
1.9 + HARD software
1.10 + hjm@hardsoftware.com
1.11 +
1.12 + 2006-01-23
1.13 +
1.14 + */
1.15 +
1.16 +# set of points
1.17 +
1.18 +set I;
1.19 +
1.20 +# independent variable
1.21 +
1.22 +param x {i in I};
1.23 +
1.24 +# dependent variable
1.25 +
1.26 +param y {i in I};
1.27 +
1.28 +# output input values
1.29 +
1.30 +printf {i in I} "x = %.1f; y = %.1f\n", x[i], y[i];
1.31 +
1.32 +# define equation variables
1.33 +
1.34 +var a;
1.35 +
1.36 +var b;
1.37 +
1.38 +var u {i in I}, >= 0;
1.39 +
1.40 +var v {i in I}, >= 0;
1.41 +
1.42 +var z;
1.43 +
1.44 +# define objective function
1.45 +
1.46 +minimize deviation: z;
1.47 +
1.48 +# define equation constraint
1.49 +
1.50 +s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i];
1.51 +
1.52 +# define deviation constrains
1.53 +
1.54 +s.t. u_deviation {i in I} : z - u[i] >= 0;
1.55 +s.t. v_deviation {i in I} : z - v[i] >= 0;
1.56 +
1.57 +solve;
1.58 +
1.59 +printf "y = %.4fx + %.4f Max deviation = %.4f\n", b, a, z;
1.60 +
1.61 +/*
1.62 + *
1.63 + * DATA section
1.64 + *
1.65 + */
1.66 +
1.67 +data;
1.68 +
1.69 +param : I : x y :=
1.70 + 1 0 1
1.71 + 2 0.5 0.9
1.72 + 3 1 0.7
1.73 + 4 1.5 1.5
1.74 + 5 1.9 2
1.75 + 6 2.5 2.4
1.76 + 7 3 3.2
1.77 + 8 3.5 2
1.78 + 9 4 2.7
1.79 + 10 4.5 3.5
1.80 + 11 5 1
1.81 + 12 5.5 4
1.82 + 13 6 3.6
1.83 + 14 6.6 2.7
1.84 + 15 7 5.7
1.85 + 16 7.6 4.6
1.86 + 17 8.5 6
1.87 + 18 9 6.8
1.88 + 19 10 7.3
1.89 +;
1.90 +
1.91 +end;