examples/cf12a.mod
changeset 1 c445c931472f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/cf12a.mod	Mon Dec 06 13:09:21 2010 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +/*
     1.5 +
     1.6 +  Curve fitting problem 12.11(a) 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-05
    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 +# define objective function
    1.43 +
    1.44 +minimize error: sum {i in I} u[i] + sum {i in I} v[i];
    1.45 +
    1.46 +# define equation constraint
    1.47 +
    1.48 +s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i];
    1.49 +
    1.50 +solve;
    1.51 +
    1.52 +printf "y = %.4fx + %.4f\n", b, a;
    1.53 +
    1.54 +/*
    1.55 + *
    1.56 + * DATA section
    1.57 + *
    1.58 + */
    1.59 +
    1.60 +data;
    1.61 +
    1.62 +param : I :   x    y :=
    1.63 +        1     0    1
    1.64 +        2   0.5  0.9
    1.65 +        3     1  0.7
    1.66 +        4   1.5  1.5
    1.67 +        5   1.9    2
    1.68 +        6   2.5  2.4
    1.69 +        7     3  3.2
    1.70 +        8   3.5    2
    1.71 +        9     4  2.7
    1.72 +       10   4.5  3.5
    1.73 +       11     5    1
    1.74 +       12   5.5    4
    1.75 +       13     6  3.6
    1.76 +       14   6.6  2.7
    1.77 +       15     7  5.7
    1.78 +       16   7.6  4.6
    1.79 +       17   8.5    6
    1.80 +       18     9  6.8
    1.81 +       19    10  7.3
    1.82 +;
    1.83 +
    1.84 +end;