## July 2021

## Bonus Report: The Digital Plan

# Optimize product blending using Excel spreadsheets and Lingo software—Part 2

Linear programming (LP) for blending. LP is an optimization model that can be used to good advantage despite the highly nonlinear characteristics of the fluid flow-cash flow model.

This article is a continuation of Part 1, which appeared in the June issue.

## Linear programming (LP) for blending

LP is an optimization model that can be used to good advantage despite the highly nonlinear characteristics of the fluid flow-cash flow model. These nonlinearities can be resolved within the framework of a linear program model by adding constraints to make the model piece-wise linear. This requires a powerful computer to solve such linear program models.

The structure of the linear program model closely follows the schematic in **FIG. 5**. For instance, each refinery is represented by a sublinear program model of 100 or more constraints. Furthermore, sublinear models are used to represent the movement of crude oil from the fields to refineries, and the transportation of finished products from refineries to market.

Areas where this technique is employed include:^{3}

- Blending gasolines
- Refinery models
- Allocation of transportation facilities for shipping products from refineries to terminals
- Integrated operations, simultaneously considering complete refinery models (2) and transportation models (3)
- Allocation of transportation facilities for shipping products from the crude oil field to refineries
- Integrated operations encompassing 1–5.

The general linear programming problem is to find a vector (*x*_{1}, *x*_{2}, …*x _{n}*), where

*n*is the independent variable, which minimizes or maximizes the linear form or the objective function, P as (Eq. 39):

P = c_{1}x_{1} + c_{2}x_{2} + c_{3}x_{3} + ............... c_{j}x_{j} + ............... + c_{n}x_{n} (39)

subject to the linear constraints (Eq. 40):

x_{j} ≥ 0,j = 1,2, ..............., n (40)

and (Eqs. 41–43):

a_{11}x_{1} + a_{12}x_{2} + ............... a_{ij}x_{j} + ............... + a_{ln}x_{n} ≤ b_{i} (41)

a_{il}x_{1} + a_{i2}x_{2} + ............... a_{ij}x_{j} + ............... + a_{in}x_{n} ≤ b_{i} (42)

a_{ml}x_{1} + a_{m2}x_{2} + ............... a_{mj}x_{j} + ............... + a_{mn}x_{n} ≤ b_{m} (43)

where *a _{ij}*,

*b*and

_{i}*c*are given constants and m < n.

_{i}One way of looking at the model is that the structure of the fluid-flow portion is represented by the following constraints (Eqs. 44 and 45):

* A* × *X* = *b* (44)

subject to

X ≥ 0 (45)

Conversely, the cash flow aspect of the model is represented by minimizing or maximizing *C* × *X*, where *C* = (*c _{1}*,

*c*, ...

_{2}*c*) is a row vector,

_{m}*X*= (

*x*,

_{1}*x*, ...

_{2}*x*) is a column vector,

_{m}*A*= (

*a*) is a matrix and

_{ij}*B*= (

*b*,

_{1}*b*, ...

_{2}*b*) is a column vector.

_{m}The objective function (*P*) is usually the octane number of the blend that must be maximized. In some instances, the objective function can be the minimized cost or setting the Reid vapor pressure (RVP) to a certain value. The primary constraints variables (*x _{1}* to

*x*) are the volume of each cut of a blend, which must be greater than zero. Other constraints include the capacity of the tank in which the sum of

_{n}*x*will not exceed, as well as any blend properties. Therefore,

_{1,}s*a*to

_{i1}*a*are the properties or their indices for components 1 to

_{mn}*n*, and

*b*to

_{i}*b*are the targeted blending properties of their indices.

_{m}In most blending cases, two or more properties are required to be adjusted by the addition of modifiers to the blend. For example, oxygenates are added to enhance gasoline octane number and n-butane is added to adjust the RVP. Determining the quantities of the additives becomes more difficult in non-linear properties cases. Determining the amounts of these blends is based on solving two or more equations with two or more unknowns, depending on the property equations.

A typical refinery optimization problem can be split into sub-problems using a spatial decomposition scheme proposed by Jia and Ierapetritou.^{4} These sub-problems are solved as independent optimization problems, and the combined results are considered an approximate solution to the overall refinery optimization problem.

Several commercial tools are available for solving stand-alone refinery optimization problems, including software products for online and offline blending optimization problems^{a,b}; products for online and offline blending optimization^{c,d,e}; and online optimization solutions for primary and secondary process units^{f,g}.

**FIG. 6** shows a schematic decomposition of the refinery optimization problem, and **FIG. 7** shows an overview of petroleum refining and blending processes.

## Mathematical formulation

The problem formulation includes multiple blenders and storage tanks, as shown in **FIG. 6**. Properties of the final products are modelled using blend laws that relate the final product property to the quantities and properties of feed components. Blend product properties are either linearly or non-linearly blended based on the volume or mass of the feed components. For example, the RON of the blend is modelled by linear blend laws, while the RVP of the blend is modelled by non-linear blend laws. The blend laws used to estimate product property based on volume/mass fraction or volume/mass flow and property of feed components are:

- Linearly blended by component fractions in tanks: the property of product blend is a linear function of component volume/mass fractions and properties (Eq. 46):

(46)

where*X*is the volume/mass fraction of component_{i}*i*in the product tank.

- Linearly blended by component flows in blend headers: the instantaneous property of the product blend is a linear function of component volume/mass flowrates and properties (Eq. 47):

(47)

where*F*is the volume/mass flowrate of component_{i}*i*to the blend header.

Blend optimization is subjected to different constraints types, including operational (equipment limits on component flow), inventory (volume limits on feed components) and quality (analyzer limits and tank property specification).

## Solving the problem

Solving the proposed problem in real time is one of the main requirements; however, if this is impossible, then the intermediate iteration result after a fixed time interval should be feasible and better than the previous iteration results. This requirement ensures that a feasible solution is provided for cases where the solver cannot converge in the available time for a real-time optimization. The proposed problem is solved using a developed solver^{h} due to its feasible region search robust nonlinear programming (NLP) solver and meets all solution requirements.^{4}

NLP is an optimization problem that minimizes (or maximizes) a nonlinear objective function subject to linear or nonlinear constraints. Problems formulated as NLP are more accurate compared to their LP counterparts since most chemical processes are nonlinear in nature. Refinery models that account for the nonlinear relationship of process variables are more reliable and more closely represent refinery systems. The general representations of NLP problems are shown in Eqs. 48, 49 and 50:

Minimize/maximize f(x) ............... x = [x_{1},x_{2}, ............ x_{n}]^{T} (48)

Subject to: h_{i} (x) = b_{i} .......... i = 1,2, .............. m (49)

gj (x) ≤ cj .......... j = 1,2, .............. r (50)

In these formulation, bilinear and trilinear terms, and basic mathematical functions can be found. In Eqs. 48–50, the objective function *f(x)*, the equality constraint *h _{i}(x)* or the inequality constraint

*g*must be nonlinear.

_{j}(x)The challenge in modelling using the NLP formulation is achieving a reasonable convergence. This is largely because many real-valued functions are non-convex. Convexity of a feasible region can only be guaranteed if constraints are all linear. Furthermore, it is difficult to determine whether objective functions or inequality constraints are convex or not. However, a convexity test can be carried out to satisfy conditions of optimality referred to as Kuhn-Tucker (KKT) conditions. Most algorithms embedded in commercial solvers terminate when these conditions are satisfied within some tolerance. For problems with several variables, KKT solutions can sometimes be found analytically, and the one with the best objective function value is chosen.

Unlike LP, NLP is reported in a significant number of publications in refinery problems involving blending relation and pooling. Moro, *et al.*^{5} developed a non-linear optimization model for the entire refinery topology that considers all process units and includes non-linearity due to blending. Pinto, *et al.*^{6} extended this work, as did Neiro and Pinto^{7} for multi-period and multi-scenario cases involving nonlinear models. They considered nonlinearity in the development of the scheduling model for refinery production with product blending. Furthermore, Hamisu^{8} considered nonlinearity in the development of a scheduling model for refinery production with product blending.

## Example 2

A blend is performed for LSR gasoline, hydrocracker gasoline, fluid catalytic cracking (FCC) gasoline and n-butane. Calculate the amount of each component that must be added to produce gasoline blend of maximum octane number and 12 psi RVP. The properties of each cut are shown in **TABLE 3**. The olefin contents in each cut are assumed to be zero. The maximum blend storage capacity is 15,000 bbl. Recalculate if the available amount of FCC gasoline is 6,000 barrels.

The objective function is maximizing the octane number. Since the olefin contents are zero, Eqs. 51–56 are used:

(51), (52)

where:

(53), (54), (55)

X_{1} ≥ 0, X_{2} ≥ 0, X_{3} ≥ 0 and X_{4} ≥ 0 (56)

An additional constraint is shown in Eq. 57:

X_{1} + X_{2} + X_{3} + X_{4} < 15,000 barrels (57)

The constraint equation for the blend RVP can be obtained by calculating the RVP index from Eq. 58:

(58)

where:

*BI _{RVPi}* is the RVP blending index for component

*i*and

*RVPi*is the

*RVP*of component

*i*in psi. Using the index, the RVP of a blend is (Eqs. 59–61):

(59), (60)

or

(61)

Using the solver in an Excel spreadsheet to maximize RON, the objective function of Eq. 52 with the above constraints (Eqs. 56, 57 and 60), the results are:

RON = 96.54 and X_{1} = 0, X_{2} = 0, X_{3} = 13,259 and

X_{4} = 1,741 bbl.

If a constraint for FCC gasoline (6,000 barrels) is added, the results for the maximum blend storage would be:

RON= 93.23 and X_{1} = 0, X_{2} = 8,855, X_{3} = 6,000 and

X_{4} = 145 bbl.

## Case study.^{9,10}

An oil refinery produces a stream of hydrocarbon-based fuel from each of four different processing units. The processing units have capacities of C_{1}, C_{2}, C_{3} and C_{4} bpd, respectively. A portion of each base fuel is fed to a central blending station where the base fuels are mixed into three grades of gasoline. The remainder of each base fuel is sold “as is” at the refinery. Storage facilities are available at the blending station for temporary storage of the blended gasolines, if required.

Let *N _{1}*,

*N*,

_{2}*N*and

_{3}*N*be the octane ratings of the respective base fuels, and let

_{4}*S*,

_{1}*S*,

_{2}*S*and

_{3}*S*be the profit derived from their direct sale. Let

_{4}*O*,

_{1}*O*and

_{2}*O*be the octane numbers of the three grades of gasoline that must be blended on any given day to satisfy customer demands

_{3}*D*,

_{1}*D*and

_{2}*D*. Let

_{3}*R*,

_{1}*R*and

_{2}*R*be the minimum octane requirements of the three grades of blended gasoline, and let

_{3}*P*,

_{1}*P*and

_{2}*P*be the profit per gallon that is realized from the sale of each grade of blended gasoline. Finally, let

_{3}*x*be the quantity of the

_{ij}*ith*base fuel used to blend the

*jth*gasoline.

The octane number of each gasoline can be expressed as the weighted average of the octane numbers of the constituent base fuels. The weighting factors are the fractions of the base fuels in each gasoline. Therefore (Eqs. 62–64):

(62)

(63)

(64)

Develop a linear programming model to determine how much of each base fuel should be blended into gasoline and how much should be sold “as is” to maximize profit. Solve the model using numerical data in **TABLE 4** and below:

Maximize y = P_{1} (x_{11} + x_{21} + x_{31} + x_{41}) + P_{2} (x_{12} + x_{22} + x_{32} + x_{42})

+ P_{3} (x_{13} + x_{23} + x_{33} + x_{43}) + (S_{1}/42) (42C_{1} – x_{11} – x_{12} – x_{13})

+ (S_{2}/42) (42C_{2} – x_{21} – x_{22} – x_{23}) + (S_{3}/42)

(42C_{3} – x_{31} – x_{32} – x_{33})

+ (S_{4}/42) (42C_{4} – x_{41} – x_{42} – x_{43})

Subject to ∑ x_{ij} ≥ 42D_{j}

∑ x_{ij} N_{i} x_{11}N_{1} + x_{21}N_{2} + x_{31}N_{3} + x_{41}N_{4} ≥ R_{1} (x_{11} + x_{21} + x_{31} + x_{41})

x_{12}N_{1} + x_{22}N_{2} + x_{32}N_{3} + x_{42}N_{4} ≥ R_{2} (x_{12 }+ x_{22} + x_{32} + x_{42})

x_{13}N_{1} + x_{23}N_{2} + x_{33}N_{3} + x_{43}N_{4} ≥ R_{3} (x_{13} + x_{23} + x_{33} + x_{43})

where *x _{ij}* = gallons of base fuel

*i*used in gasoline

*j*.

The model assumes full capacity production. The optimal value for the target cell is determined using a what-if analysis tool in the solver, which works by changing the values for parameters that are used to calculate the value of the target cell. The results of the optimization are:

y_{max} = 111,836,36 at x_{11} = 436,800, x_{41}= 109,200, x_{12} = 756,000, x_{42} = 294,000

x_{13} = 423,360, x_{43}= 332,640, all other x_{ij} = 0.

All *x _{ij}* expressed in terms of gal/d.

The same approach can be used to determine the optimum value of the target parameter when there are changes in other parameters, such as an increase or decrease in selling prices of one and/or all gasoline blends. The same calculation approach can solve for any changes in capacity (*C*), demand (*D*) or any other relevant parameter(s).

Alsuhaibani^{11} employed a linear optimization programming method (LINGO) for the case study. **TABLE 5** shows the code and results and are in good agreement with the results obtained from the Excel spreadsheet.^{12 }

## Takeaway

Linear programming includes two kinds of programs: a solver program and a mixed inter linear program (MILP). Microsoft Excel incorporates an NLP solver that operates on the values and formulas of a spreadsheet model. The solver uses the spreadsheet interpreter to evaluate the constraint and objective functions, and approximates derivatives using finite differences. The NLP solution engine for the Excel Solver is the generalized reduced gradient (GRG2) algorithm, and this has successfully been implemented in the examples and case study presented in this article and supported by the LINGO program. **HP**

**NOTES**

^{ a} AspenTech’s Aspen Blend^{ b} AspenTech’s Aspen PIMS-MBO™^{ c} Honeywell’s EBC™^{ d} Honeywell’s OpenBPC™^{ e} Honeywell’s Blend™^{ f} Honeywell’s Profit Controller™^{ g} Invensys’ ROMeo™^{ h} MINOS, developed by Stanford Systems Optimization Laboratory

^{}

**LITERATURE CITED**

- Maples, R. E.,
*Petroleum refinery process economics,*2nd Ed., PennWell Corp., January 2000. - Healy Jr., W. C., C. W. Maasen and R. T. Peterson, “Predicting octane numbers of multi-component blends,” Report number RT-70, Ethyl Corp., Detroit, Michigan, April 1959.
- Gary, J. H., G. E. Handwerk and M. J. Kaiser,
*Petroleum refining: Technology and economics,*5th Ed., CRC Press, Taylor & Francis Group, 2007. - Jia, Z. and M. Ieraptetritou, “Mixed-integer linear programming model for gasoline blending and distribution scheduling,”
*Industrial & Engineering Chemistry Research,*February 2003. - Moro, L., A. Zanin and J. Pinto, “A planning model for refinery diesel production,”
*Computers & Chemical Engineering,*March 1998. - Pinto, J. M., M. Joly and L. F. L., “Planning and scheduling models for refinery operations,”
*Computers & Chemical Engineering,*October 2000. - Neiro, S. and J. Pinto, “Multiperiod optimization for production planning of petroleum refineries,”
*Chemical Engineering Communications,*Vol. 192, Iss. 1, 2005. - Hamisu, A. A., “Petroleum refinery scheduling with consideration for uncertainty,” PhD Thesis, Cranfield University, Cranfield, England, 2015.
- Aronofsky, J. S., “Linear programming—A problem-solving tool for petroleum industry management,”
*Journal of Petroleum Technology,*July 1962. - Gottfried, B. S.,
*Spreadsheet tools for engineers: Excel 5.0 version,*McGraw-Hill College, March 1996. - Alsuhaibani, A. S., Texas A & M University, private communications.
- Jiang, S., “Optimization of diesel and gasoline blending operations,” PhD thesis, Centre for Process Integration, School of Chemical Engineering and Analytical Science, The University of Manchester, 2016.

## Comments