Lindo Systems

!  Oil refinery model based on:
  Aronofsky, J., J. Dutton, and M. Tayyabkhan(1978),
  Managerial Planning with Linear Programming: in
  Process Industry Applications, John Wiley & Sons;
 !   There are two main entities: materials and processes.
   Each process takes one or more materials and converts
   them to one or more other materials in fixed proportions.
     In a final step, materials are blended into finished
   products in proportions to be determined so as to satisfy
   certain quality requirements.
     Each process may use resources of limited time availability.

 ! Keywords: Process industry, refinery, petroleum refining, blending;
SETS:
  matl: buy, octanem, vaporpm, densitym, sulfurm;
  canbuy(matl): pricep, ur;
  fprod: pricef, octanefl, vaporpfu, densityfu, sulfurfu, x;
  process: costp, z;
  resource: cap;
  rxp(resource, process): uses;
 ! cxm(crude,matl): ur, octanem, vaporpm, densitym, sulfurm, ;
  mxp(matl,process): rate;
  mxf(matl,fprod): w;
ENDSETS

! Variables:
    buy(m) = barrels(bbl) purchased of material type m, 
    z(p) = units of process p run,
    w(m, cf) = bbl of material m blended into finished product cf,
    x(cf) = bbl blended and sold of finished product cf,
 Parameters:
   rate(m,p) = bbl of material m produced per unit of process p. 
               Negative means input or used;

DATA:
! These data model a refinery that can process two crude oil
 types: Mid-continent and West-Texas. 
  Crude is first processed through an atmospheric distiller, where
 the crude is split into(light to heavy): fuel gas, naptha, gasoline, 
 light distillate, heavy distillate(gas-oil), and residual bottoms. 
  Naptha can be further processed through a reformer to produce:
 fuel gas and reformed gasoline. 
  Distillate can be processed through the cracker to produce:
 fuel gas and cracked gasoline.
  Gas-oil can be processed through the cracker to produce:
 fuel gas and cracked gasoline.
  Residual can be processed through the hydro treater to produce
 hydro treated residual that has lower sulfur content.
  In the final step, the various materials can be blended into
 premium gasoline, regular gasoline, distillate,  and fuel oil
 so as to satisfy quality requirements on octane, vapor pressure,
 density, and sulfur content.   Fuel gas is sold directly without
 blending. 
  Butane may be bought to blend into gasoline to increase octane;

! Here are all the material types, excluding finished products;
 matl = mccrude  mcsrgas mcsrnap mcsrdist mcsrgasoil mcsresid  
                 mcgasrf mcfuelgas mccgas mccgasoil
        wtcrude  wtsrgas wtsrnap wtsrdist wtsrgasoil wtsresid  
                 wtgasrf wtfuelgas wtcgas wtcgasoil, wthyres
        butane; 

!The quality features of the above materials;
 octanem = 0       78.5    65       0           0        0
                   104      0        93.7       0          
           0       78.5    65       0           0        0
                   104      0        93.7       0        0 
          91.8;
 vaporpm = 0       18.4    6.54       0         0        0
                   2.57      0        6.9       0          
           0       18.4    6.54       0         0        0
                   2.57      0        6.9       0        0 
          199.2;

 densitym=  0      0       272     292       295        343
                   0         0       0      294.4 
            0      0       272     297.6     303.3      365
                   0         0       0      299.1       365
            0;  
 sulfurm =  0      0       .283    .526      .980       4.7
                   0         0       0       .353 
            0      0       1.48    2.83     5.05         11
                   0         0       0      1.31         6
            0;  

! (Subset of) Materials we can buy from outside:
     Mid-continent and West-texas crude + butane;
 canbuy = mccrude wtcrude butane;
! Availabilities of materials we can buy;
  ur =     200     200     9999;
  pricep= 7.50    6.50     6.75;

! The finished products to be blended, prices, and
 quality requirements;
 fprod    = gasprm gasreg distlt fueloil fuelgas;
 pricef   =  10.50   9.10   7.70    6.65   1.50;
 octanefl =  90     86       0      0        0;
 vaporpfu =  12.7   12.7   999     999     999;
 densityfu=  999   999     306     352     999;
 sulfurfu=   999   999      0.5     3.5    999;

! The processes that convert materials;
 process = mcadist mcnreform mccrackd mccrackg 
           wtadist wtnreform wtcrackd wtcrackg  wthydro;
  costp =   .10     .15       .08      .08    
            .10     .15       .08      .08       .10;

! Here we describe the various processing of materials,
  what the process uses(-) and what it produces(+);
          mxp,        rate=
! Mid continent crude thru the distiller;
 mccrude    mcadist,  -1.0
 mcsrgas    mcadist,  .236
 mcsrnap    mcadist,  .223
 mcsrdist   mcadist,  .087
 mcsrgasoil mcadist,  .111
 mcsresid   mcadist,  .315
 mcfuelgas  mcadist,  .029

! West Texas crude thru the distiller;
 wtcrude    wtadist,  -1.0
 wtsrgas    wtadist,  .180
 wtsrnap    wtadist,  .196
 wtsrdist   wtadist,  .073
 wtsrgasoil wtadist,  .091
 wtsresid   wtadist,  .443
 wtfuelgas  wtadist,  .017

! Mid continent based material thru naptha reformer;
 mcsrnap   mcnreform, -1.0
 mcgasrf   mcnreform, .807
 mcfuelgas mcnreform, .129

! West Texas based material thru naptha reformer;
 wtsrnap   wtnreform, -1.0
 wtgasrf   wtnreform, .836
 wtfuelgas wtnreform, .099

! Mid continent based distillate thru catalytic cracker;
 mcsrdist  mccrackd,  -1.0
 mcfuelgas mccrackd,  .300
 mccgas    mccrackd,  .590
 mccgasoil mccrackd,  .210

! West Texas based distillate thru catalytic cracker;
 wtsrdist  wtcrackd,  -1.0
 wtfuelgas wtcrackd,  .360
 wtcgas    wtcrackd,  .580
 wtcgasoil wtcrackd,  .150

! Mid continent based gas-oil thru catalytic cracker;
 mcsrgasoil mccrackg, -1.0
 mcfuelgas  mccrackg, .310
 mccgas     mccrackg, .590
 mccgasoil  mccrackg, .220

! West Texas based gas-oil thru catalytic cracker;
 wtsrgasoil wtcrackg, -1.0
 wtfuelgas  wtcrackg, .380
 wtcgas     wtcrackg, .600
 wtcgasoil  wtcrackg, .150

! West Texas based material thru hydro treater;
 wtsresid wthydro, -1.0
 wthyres  wthydro, .970;

 resource = atmstill reformer cracker;
    cap =     100      20        30;    
! Which process uses which resource;
       rxp,    uses =
   atmstill, mcadist   1
   reformer, mcnreform 1
   cracker,  mccrackd  1
   cracker,  mccrackg  1
   atmstill, wtadist   1
   reformer, wtnreform 1
   cracker,  wtcrackd  1
   cracker,  wtcrackg  1;

!  Which materials can be used in which finished products;
    mxf = butane, gasprm
          mcsrgas,gasprm 
          mccgas, gasprm
          mcsrnap,gasprm
          mcgasrf,gasprm
          wtsrgas,gasprm 
          wtcgas, gasprm
          wtsrnap,gasprm
          wtgasrf,gasprm 
          butane, gasreg
          mcsrgas,gasreg 
          mccgas, gasreg
          mcsrnap,gasreg
          mcgasrf,gasreg
          wtsrgas,gasreg 
          wtcgas, gasreg
          wtsrnap,gasreg
          wtgasrf,gasreg
          mcsrdist,  distlt
          mcsrnap,   distlt
          mcsrgasoil,distlt
          mccgasoil, distlt
          wtsrdist,  distlt
          wtsrnap,   distlt
          wtsrgasoil,distlt
          wtcgasoil, distlt
          mcsrgasoil,fueloil
          mcsresid,  fueloil
          mccgasoil, fueloil
          wtsrgasoil,fueloil
          wtsresid,  fueloil
          wtcgasoil, fueloil
          wthyres,   fueloil
          mcfuelgas, fuelgas
          wtfuelgas, fuelgas;
ENDDATA

! Maximize profit;
   max = revenue - pcost - ocost;

! Compute cost of raw materials purchased;
    pcost = @sum(canbuy(m): pricep(m)*buy(m));

! Operating cost of the processes;
    ocost = @sum(process(p): costp(p)*z(p));

! Revenues;
   revenue = @sum(fprod(f): pricef(f)*x(f));

!  Cannot buy more of each material than is available;
  @for(canbuy(m):
   [buylim] buy(m) <= ur(m)
      );
  @for(matl(m) | #NOT# @in(canbuy, m):
   [buylm0] buy(m) = 0
      );

! For each material type m
     sources >= uses, i.e. amount bought
      + net from processes >= amount to finished products;
  @for( matl(m):
     [mtlbal] buy(m) + @sum(mxp(m,p): rate(m,p)*z(p)) >=
       @sum(mxf(m,cf): w(m,cf));
      );

! For each resource, cannot use it more than it 
    has time available;
  @for(resource(r):
    [rcap] @sum(rxp(r,p): uses(r,p)*z(p)) <= cap(r);
      );

! Blending step;
! For each finished good, sources = uses;
 @for(fprod(cf):
  [fpbal] @sum(mxf(m,cf): w(m, cf)) = x(cf)
     );

! For each finished good, must meet quality requirements;
  @for(fprod(cf):
   [octlim] @sum(mxf(m,cf): octanem(m) *w(m, cf)) >= octanefl(cf) *x(cf);
   [vaplim] @sum(mxf(m,cf): vaporpm(m) *w(m, cf)) <= vaporpfu(cf) *x(cf);
   [denlim] @sum(mxf(m,cf): densitym(m)*w(m, cf)) <= densityfu(cf)*x(cf);
   [slflim] @sum(mxf(m,cf): sulfurm(m) *w(m, cf)) <= sulfurfu(cf) *x(cf);
       );