examples/cpp.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
/* CPP, Critical Path Problem */
alpar@1
     2
alpar@1
     3
/* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
alpar@1
     4
alpar@1
     5
/* Note: Reduced costs of auxiliary variables phi[j,k] (see below)
alpar@1
     6
         can be only zero or one. The critical path is defined by the
alpar@1
     7
         constraints, whose reduced cost is one. */
alpar@1
     8
alpar@1
     9
set J;
alpar@1
    10
/* set of jobs (activities) */
alpar@1
    11
alpar@1
    12
set P{j in J}, in J, default {};
alpar@1
    13
/* P[j] is a subset of jobs that immediately precede job j */
alpar@1
    14
alpar@1
    15
param t{j in J}, >= 0;
alpar@1
    16
/* duration required to perform job j */
alpar@1
    17
alpar@1
    18
var x{j in J}, >= 0;
alpar@1
    19
/* starting time of job j */
alpar@1
    20
alpar@1
    21
s.t. phi{j in J, k in P[j]}: x[j] >= x[k] + t[k];
alpar@1
    22
/* job j can start only after all immediately preceding jobs have been
alpar@1
    23
   completely performed */
alpar@1
    24
alpar@1
    25
var z;
alpar@1
    26
/* project makespan */
alpar@1
    27
alpar@1
    28
s.t. fin{j in J}: z >= x[j] + t[j];
alpar@1
    29
/* which is the maximum of the completion times of all the jobs */
alpar@1
    30
alpar@1
    31
minimize obj: z;
alpar@1
    32
/* the objective is make z as small as possible */
alpar@1
    33
alpar@1
    34
data;
alpar@1
    35
alpar@1
    36
/* The optimal solution is 46 */
alpar@1
    37
alpar@1
    38
param : J :  t :=
alpar@1
    39
        A    3    /* Excavate */
alpar@1
    40
        B    4    /* Lay foundation */
alpar@1
    41
        C    3    /* Rough plumbing */
alpar@1
    42
        D   10    /* Frame */
alpar@1
    43
        E    8    /* Finish exterior */
alpar@1
    44
        F    4    /* Install HVAC */
alpar@1
    45
        G    6    /* Rough electric */
alpar@1
    46
        H    8    /* Sheet rock */
alpar@1
    47
        I    5    /* Install cabinets */
alpar@1
    48
        J    5    /* Paint */
alpar@1
    49
        K    4    /* Final plumbing */
alpar@1
    50
        L    2    /* Final electric */
alpar@1
    51
        M    4    /* Install flooring */
alpar@1
    52
;
alpar@1
    53
alpar@1
    54
set P[B] := A;
alpar@1
    55
set P[C] := B;
alpar@1
    56
set P[D] := B;
alpar@1
    57
set P[E] := D;
alpar@1
    58
set P[F] := D;
alpar@1
    59
set P[G] := D;
alpar@1
    60
set P[H] := C E F G;
alpar@1
    61
set P[I] := H;
alpar@1
    62
set P[J] := H;
alpar@1
    63
set P[K] := I;
alpar@1
    64
set P[L] := J;
alpar@1
    65
set P[M] := K L;
alpar@1
    66
alpar@1
    67
end;