# source:glpk-cmake/examples/cf12b.mod@1:c445c931472f

Last change on this file since 1:c445c931472f was 1:c445c931472f, checked in by Alpar Juttner <alpar@…>, 10 years ago

Import glpk-4.45

• Generated files and doc/notes are removed
File size: 1.2 KB
Line
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
15set I;
16
17# independent variable
18
19param x {i in I};
20
21# dependent variable
22
23param y {i in I};
24
25# output input values
26
27printf {i in I} "x = %.1f; y = %.1f\n", x[i], y[i];
28
29# define equation variables
30
31var a;
32
33var b;
34
35var u {i in I}, >= 0;
36
37var v {i in I}, >= 0;
38
39var z;
40
41# define objective function
42
43minimize deviation: z;
44
45# define equation constraint
46
47s.t. equation {i in I} : b * x[i] + a + u[i] - v[i] = y[i];
48
49# define deviation constrains
50
51s.t. u_deviation {i in I} : z - u[i] >= 0;
52s.t. v_deviation {i in I} : z - v[i] >= 0;
53
54solve;
55
56printf "y = %.4fx + %.4f Max deviation = %.4f\n", b, a, z;
57
58/*
59 *
60 * DATA section
61 *
62 */
63
64data;
65
66param : 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
88end;
Note: See TracBrowser for help on using the repository browser.