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