subpack-glpk
Line | |
---|
1 | /* |
---|
2 | |
---|
3 | Curve fitting problem 12.11(a) 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-05 |
---|
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 | # define objective function |
---|
40 | |
---|
41 | minimize error: sum {i in I} u[i] + sum {i in I} v[i]; |
---|
42 | |
---|
43 | # define equation constraint |
---|
44 | |
---|
45 | s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i]; |
---|
46 | |
---|
47 | solve; |
---|
48 | |
---|
49 | printf "y = %.4fx + %.4f\n", b, a; |
---|
50 | |
---|
51 | /* |
---|
52 | * |
---|
53 | * DATA section |
---|
54 | * |
---|
55 | */ |
---|
56 | |
---|
57 | data; |
---|
58 | |
---|
59 | param : I : x y := |
---|
60 | 1 0 1 |
---|
61 | 2 0.5 0.9 |
---|
62 | 3 1 0.7 |
---|
63 | 4 1.5 1.5 |
---|
64 | 5 1.9 2 |
---|
65 | 6 2.5 2.4 |
---|
66 | 7 3 3.2 |
---|
67 | 8 3.5 2 |
---|
68 | 9 4 2.7 |
---|
69 | 10 4.5 3.5 |
---|
70 | 11 5 1 |
---|
71 | 12 5.5 4 |
---|
72 | 13 6 3.6 |
---|
73 | 14 6.6 2.7 |
---|
74 | 15 7 5.7 |
---|
75 | 16 7.6 4.6 |
---|
76 | 17 8.5 6 |
---|
77 | 18 9 6.8 |
---|
78 | 19 10 7.3 |
---|
79 | ; |
---|
80 | |
---|
81 | end; |
---|
Note: See
TracBrowser
for help on using the repository browser.