subpack-glpk
Rev | Line | |
---|
[9] | 1 | /* |
---|
| 2 | |
---|
| 3 | Curve fitting problem 12.11(b) H P Williams "Model Building in Mathematical Programming" |
---|
| 4 | |
---|
| 5 | Dr. H J Mackenzie |
---|
| 6 | HARD software |
---|
| 7 | hjm@hardsoftware.com |
---|
| 8 | |
---|
| 9 | 2006-01-23 |
---|
| 10 | |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | # set of points |
---|
| 14 | |
---|
| 15 | set I; |
---|
| 16 | |
---|
| 17 | # independent variable |
---|
| 18 | |
---|
| 19 | param x {i in I}; |
---|
| 20 | |
---|
| 21 | # dependent variable |
---|
| 22 | |
---|
| 23 | param y {i in I}; |
---|
| 24 | |
---|
| 25 | # output input values |
---|
| 26 | |
---|
| 27 | printf {i in I} "x = %.1f; y = %.1f\n", x[i], y[i]; |
---|
| 28 | |
---|
| 29 | # define equation variables |
---|
| 30 | |
---|
| 31 | var a; |
---|
| 32 | |
---|
| 33 | var b; |
---|
| 34 | |
---|
| 35 | var u {i in I}, >= 0; |
---|
| 36 | |
---|
| 37 | var v {i in I}, >= 0; |
---|
| 38 | |
---|
| 39 | var z; |
---|
| 40 | |
---|
| 41 | # define objective function |
---|
| 42 | |
---|
| 43 | minimize deviation: z; |
---|
| 44 | |
---|
| 45 | # define equation constraint |
---|
| 46 | |
---|
| 47 | s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i]; |
---|
| 48 | |
---|
| 49 | # define deviation constrains |
---|
| 50 | |
---|
| 51 | s.t. u_deviation {i in I} : z - u[i] >= 0; |
---|
| 52 | s.t. v_deviation {i in I} : z - v[i] >= 0; |
---|
| 53 | |
---|
| 54 | solve; |
---|
| 55 | |
---|
| 56 | printf "y = %.4fx + %.4f Max deviation = %.4f\n", b, a, z; |
---|
| 57 | |
---|
| 58 | /* |
---|
| 59 | * |
---|
| 60 | * DATA section |
---|
| 61 | * |
---|
| 62 | */ |
---|
| 63 | |
---|
| 64 | data; |
---|
| 65 | |
---|
| 66 | param : I : x y := |
---|
| 67 | 1 0 1 |
---|
| 68 | 2 0.5 0.9 |
---|
| 69 | 3 1 0.7 |
---|
| 70 | 4 1.5 1.5 |
---|
| 71 | 5 1.9 2 |
---|
| 72 | 6 2.5 2.4 |
---|
| 73 | 7 3 3.2 |
---|
| 74 | 8 3.5 2 |
---|
| 75 | 9 4 2.7 |
---|
| 76 | 10 4.5 3.5 |
---|
| 77 | 11 5 1 |
---|
| 78 | 12 5.5 4 |
---|
| 79 | 13 6 3.6 |
---|
| 80 | 14 6.6 2.7 |
---|
| 81 | 15 7 5.7 |
---|
| 82 | 16 7.6 4.6 |
---|
| 83 | 17 8.5 6 |
---|
| 84 | 18 9 6.8 |
---|
| 85 | 19 10 7.3 |
---|
| 86 | ; |
---|
| 87 | |
---|
| 88 | end; |
---|
Note: See
TracBrowser
for help on using the repository browser.