MODEL:

SETS:

jobs/cant,fond,strutt,muri,tetto,intoi,intoe,pitti,pitte,el0,el1,serr0,serr1,idr0,idr1 
 pavp,pavl,fine/:p,pc,c,s, x, d;

prec(jobs,jobs)/
cant    fond,
fond    strutt
strutt  muri
strutt  tetto
muri    intoi 
tetto   intoi
el0     intoi
serr0   intoi
idr0    intoi
muri    intoe
tetto   intoe
intoi   pitti
pavp    pitti
intoe   pitte
muri    el0
pitti   el1
muri    serr0
pitti   serr1
muri    idr0
pitti   idr1
intoi   pavp 
serr1   pavl
el1     fine
pavl    fine
intoi intoe
pitte pitti/;

ENDSETS

DATA:

p= 2 5 20 8 7    6 5 7 7 4      8 2 5 3 5     9 6 0;
pc= 2 3 20 3 5    2 2 2 2 2    2 1 1 1 1    3 2 0;
d= 0  400 0 250 300  350  
    350  180  200   150   
    240   0  350   170   230
   250   330   0;

ENDDATA

SUBMODEL mincost:
!MIN = c(@INDEX(fine));
Min=costcr;
costcr=@SUM(jobs:x*d);

c(@INDEX(fine))<finaltime;

!costcr<0;

@FOR(jobs(i):
   [durc] c(i) - s(i) = p(i)  - x(i) ;
   [crashc] x(i) < p(i) -pc(i); );

@FOR(prec(i,j):  
   [constrc] c(i) < s (j) );

ENDSUBMODEL

SUBMODEL mintime:
[besttime] MIN = c(@INDEX(fine));
!Min=costcr;
costcr=@SUM(jobs:x*d);
 costcr < budget;

@FOR(jobs(i):
   [durt] c(i) - s(i) = p(i)  - x(i) ;
   [crasht] x(i) < p(i) -pc(i); );

@FOR(prec(i,j):  
   [constrt] c(i) < s (j) );

ENDSUBMODEL

CALC:

@SET( 'DEFAULT');@SET( 'TERSEO', 1);@SET( 'STAWIN', 0);@DIVERT( 'LINGO.LOG');
budget=100000;
@SOLVE(mintime);
starttime=besttime;
budget=0;
@SOLVE(mintime);
endtime=besttime;
currtime=starttime;

@WHILE(currtime #LE# endtime:
finaltime=currtime;
@SOLVE(mincost);
@DIVERT();
@WRITE(costcr,"   ",currtime,@NEWLINE(1););
currtime=currtime+1;
@DIVERT( 'LINGO.LOG');

);
ENDCALC

END