#########################################
# Sets
set I; # suppliers
set J; # reactors
set K; # end products
set L; # drying methods
set R; # chemical compounds
#########################################
# Parameters (to be specified in .dat-file) (units as defined in the PM)
param RCapcell{J} >= 0; # reactor capacity cellulose in
param RCapcl{J} >= 0; # reactor capacity chlorides in
param RMC{I,R} >= 0; # raw material cost
param TC{I,J} >= 0; # transport costs supplier -> reactor
param TCD{J} >= 0; # transport costs reactor -> dryer
param PC{J,K} >= 0; # producing cost
param DC{L} >= 0; # drying cost
param BP{K} >= 0; # buying price of raw products
param SPnd{K} >= 0; # selling price of raw products
param SPd{K,L} >= 0; # selling price of end products
param D{K} >= 0; # total market demand
param q{K,L} >= 0, <= 1; # proportion of demand on different quality products
check {k in K}:
sum {l in L} q[k,l] = 1; # check that sums of proportions equal one
param M{R} >= 0; # molar weight of chemical compounds
param Madded{K} >= 0; # molar weight of the added group in production of end products
param Mremoved >= 0; # molar weight of the removed group (H)
param maxbuy >= 0; # max total amount of raw products allowed to be bought (set to inf if allowed)
param maxsell >= 0; # max total amount of raw products allowed to be sold (set to inf if allowed)
param proddays >= 0; # number of days per year when production runs
########################################
# Decision variables
var x{I,J} >= 0; # kgs of Cellulose bought from supplier i to be used in reactor j
var y{I,J} >= 0; # NaOH
var u{I,J} >= 0; # MetCl
var v{I,J} >= 0; # EtCl
var m{J,K} >= 0; # kgs of raw product k produced in reactor j
var z{K,L} >= 0; # units of product k dried using technique l
var s{K} >= 0; # units of raw product k bought
var t{K} >= 0; # units of raw product k sold
#######################################
# Objective function: Minimize total negative income + costs
minimize total_cost: -sum{k in K, l in L}SPd[k,l]*z[k,l] + sum{i in I, j in J}(RMC[i,'CellOH']*x[i,j] + RMC[i,'NaOH']*y[i,j] + RMC[i,'MetCl']*u[i,j] + RMC[i,'EtCl']*v[i,j]) + sum{i in I, j in J}TC[i,j]*(x[i,j] + y[i,j] + u[i,j] + v[i,j]) + sum{j in J, k in K}PC[j,k]*m[j,k] + sum{j in J, k in K}TCD[j]*m[j,k] + sum{k in K, l in L}DC[l]*z[k,l] + sum{k in K}(BP[k]*s[k] - SPnd[k]*t[k]);
#######################################
# Constraints
# Capacity of cellulose that can be handled in the reactors
subject to Reac_Cap_Cell {j in J}:
sum{i in I}x[i,j] <= proddays*RCapcell[j];
# Capacity of chlorides that can be handled in the reactors
subject to Reac_Cap_Cl {j in J}:
sum{i in I}(u[i,j] + v[i,j]) <= proddays*RCapcl[j];
# All suppliers cannot supply all raw materials (not really needed if costs are pushed to inf)
subject to No_Delivery:
sum{j in J} (x['B',j] + x['C',j] + y['C',j] + u['A',j] + u['B',j] + v['A',j] + v['B',j]) == 0;
# Mass Balance in reactors CellOH
subject to MolesReacCellOH {j in J}:
sum{k in K}(m[j,k]/(M['CellOH'] + Madded[k] - Mremoved)) - sum{i in I}x[i,j]/M['CellOH'] <= 0;
# Mass Balance in reactors NaOH
subject to MolesReacNaOH {j in J}:
sum{k in K}(m[j,k]/(M['CellOH'] + Madded[k] - Mremoved)) - sum{i in I}y[i,j]/M['NaOH'] <= 0;
# Mass Balance in reactors MetCl
subject to MolesReacMetCl {j in J}:
m[j,'MC']/(M['CellOH'] + Madded['MC'] - Mremoved) - sum{i in I}u[i,j]/M['MetCl'] <= 0;
# Mass Balance in reactors EtCl
subject to MolesReacEtCl {j in J}:
m[j,'EC']/(M['CellOH'] + Madded['EC'] - Mremoved) - sum{i in I}v[i,j]/M['EtCl'] <= 0;
# Mass balance raw/end products
subject to MassRawEnd {k in K}:
sum{j in J}m[j,k] + s[k] - t[k] - sum{l in L}z[k,l] >= 0;
# Do not sell more than the market demand
subject to Demand {k in K, l in L}:
z[k,l] <= D[k]*q[k,l];
# Limitation (if any) on the total amount of raw products that can be bought
subject to Maxbuy:
sum {k in K} s[k] <= maxbuy;
# Limitation (if any) on the total amount of raw products that can be sold
subject to Maxsell:
sum {k in K} t[k] <= maxsell;
####################################