Blending: Product Mix Optimization for refineries

Syed Misbah
Data Decoded
Published in
5 min readMay 16, 2020

Introduction

Blending is a product mix optimization problem usually faced in oil refineries — where raw or crude gasoline is mixed or blended in different proportions to achieve various refined products with specified octane value.

An octane value is a standard measure of the performance of a fuel — different applications require fuels of different octane ratings.

A simple process flow of a generic oil refinery is shown below — for the purpose of understanding where the blending process happens.

Process flow for a generic oil refinery unit

Understanding the problem

As mentioned above, the idea is to mix or blend multiple gasolines to create products of different octane ratings.

For instance, let’s assume that we are given crude gasoline R0, R1, … ,Rn, each with a certain octane rating, maximum availabilities in barrels, and a cost in dollars per barrels.

                            Table 1 ┌──────────┬───────────────┬──────────────┬──────────────────┐
│ Gasoline │ Octane Rating │ Availibility │ Cost(per barrel) │
├──────────┼───────────────┼──────────────┼──────────────────┤
│ R0 │ 99 │ 782 │ 55.34 │
│ R1 │ 94 │ 894 │ 54.12 │
│ R2 │ 84 │ 631 │ 53.68 │
│ R3 │ 92 │ 648 │ 57.03 │
│ R4 │ 87 │ 956 │ 54.81 │
│ R5 │ 97 │ 647 │ 56.25 │
│ R6 │ 81 │ 689 │ 57.55 │
│ R7 │ 96 │ 609 │ 58.21 │
└──────────┴───────────────┴──────────────┴──────────────────┘

We are also given demands for multiple types of refined gasoline products with their own octane ratings. The demands are stated in minimum and maximum number of barrels along with their selling prices.

                           Table 2 ┌───────────────┬────────┬─────────────┬────────────┬───────┐
│ Product │ Octane │ Min. Demand │ Max Demand │ Price │
├───────────────┼────────┼─────────────┼────────────┼───────┤
│ Aviation Fuel │ 88 │ 415 │ 11707 │ 61.97 │
│ Petrol │ 90 │ 479 │ 12596 │ 61.99 │
│ Jet A2 │ 94 │ 199 │ 7761 │ 62.04 │
└───────────────┴────────┴─────────────┴────────────┴───────┘

We create these three products by mixing the appropriate raw gasolines together. In most refineries, the octane rating of a product is a linear function of the volumes mixed. If we mix half and half of octane ratings 80 and 90, we get an octane rating of 85 because:

50% of R1 + 50% of R7 = 94/2 + 96/2 = 95

Our task is to construct a model that will tell us exactly how to mix the raw products to satisfy the demands and maximize the profits.

Constructing the problem

As discussed in the last article on optimization(link), every such optimization problem can be constructed mathematically in three steps.

1. Defining the decision variables

In this case, we have to find out how much of raw gas i goes into refined product j. Hence, it will be a two-dimensional decision variable, say Gᵢⱼ where i is the index of the raw gas and j is the index of the refined product.

For example, G52 = 250 — will mean that there are 250 barrels of crude 5 going into the mix of refined product 2.

The key difference between the mixing problems in the first article and this blending problem is that previously we were told the exact composition of the products in terms of the raw material (in each food, the amount of chicken/veggies/spices) while in the problem considered here, the composition of each product is one of the answers we aim to find .

2. Defining the objective function

The objective is to maximize the profit — profit being defined as -

Profit = Total Sales - Cost

We can define the total cost of each crude gasoline as Ri, and the total of each refined product as Fj.

In our case, Σi Ri = Σj Fj. That is, the total volume of crude used is equal to the total volume of refined products. We can think of this as a “continuity” equation in an ideal scenario: it reflects that the refining process does not lose product along the production chain.

Knowing F(product volume) and R(input raw gasoline volume), we can write the objective function as

Objective = Maximise(F*Price - R*Cost)

This can be mathematically written as —

3. Listing the constraints

The basic constraint will be on the availability of the raw material i.e. each gas Rn. (Refer Table 1)

There will be another set of constraints on the demand for each product (Refer Table 2).

The trickier part of constraints would be to model the octane number requirement. As discussed earlier, the octane number of the resulting product will be a linear combination of the raw material inputs. As an example, let’s imagine a simple case: say we mix 800 barrels of crude 1 with octane rating of 98 with 200 barrels of crude 2 with octane rating of 90. What is the resulting octane rating? Since we have a total of 1,000 barrels of refined — then

So, in general, we need the fraction of each crude that goes into a mix times its octane rating. Assuming Oi as the octane rating of crude i and oj the octane rating of refined j, this leads us to

We now have a mathematical model of the problem ready. Let’s code!!

Talk is cheap. Show me the code

Here’s the working code for the solver written in ortools package.

Bottomline

After we solve the optimizer, the results should be similar to below. The total number of barrels of raw gas is equal to the total output of all 3 products. The maximized profit is $37635.

We could also have maximized the sales given a certain budget — or tried other variations of it. In the next blog, we will switch tracks and and discucss project management optimization.

Please do let our team @ Decoding Data know your thoughts, questions or suggestions in the comment section below.

--

--