Mathematical Formulation of Automatic Product Blend Optimization

Problem Statement

       This article presents the mathematical formulation of an automatic product blending optimization algorithm for petroleum refineries. Refinery product blending is a fundamental optimization problem in petroleum refining. Multiple blending components with different flow rates and quality properties must be combined to produce a final product that satisfies all specification limits while achieving a defined optimization objective.
       The ProductMixer component from the Petroleum Refining Library formulates this task as a linear programming (LP) problem. Instead of relying on predefined blend recipes, it automatically generates a linear programming model (LP model) from the current process conditions, available component flows, and fuel quality specifications.

Mathematical Model Structure

       For each blending component, the algorithm automatically creates a set of decision variables representing possible material allocation within the blend blending model. The variable names used in the mathematical formulation below correspond to the constant names defined in the ProductMixer.Constants nested class.

       Component Flow Variables
       For every available product flow i, the following variables are introduced:
        - available mass flow of the product.
        - mass flow directed to the final product.
        - mass flow directed to a residual stream.
        - volumetric contribution to the final product.
The optimization determines the values of ​ and ​, while the available flow ​ is provided by the simulation model.

       Aggregated Variables
       To simplify the mathematical formulation, ProductMixer also introduces aggregated variables:
        - total product mass flow;
       ​ - total residual mass flow;
       ​ - total product volume;
These variables are calculated automatically from the individual product flows and are used to formulate global material balance equations and product blending constraints.

Material Balance Equations

       The first group of constraints ensures mass conservation for every blending product. Each incoming stream can only be divided into two destinations: the final product or a residual stream.
       For every product i, the following material balance equation is generated:

,

       The total mass, total product and residual flows are calculated as the sum of all product contributions:

,

,

.

        To evaluate volumetric product specifications, the algorithm also converts mass flows into volumetric contributions using component densities:

where is the density of product i.

       The total product volume is then computed as

.

       These equations form the structural foundation of the blending model. Every feasible solution produced by the LP solver automatically satisfies the conservation of mass before product blending constraints are evaluated.

Objective Functions

       The objective function defines the optimization strategy. Depending on the selected operating mode, the ProductMixer blend optimization algorithm automatically generates one of several objective functions.

       Maximum Product Recovery. When the objective is to maximize production, the optimization maximizes the total amount of blended product:

.

       This objective is typically used when sufficient blending components are available and the primary goal is to maximize product yield while satisfying all quality specifications.

Product Quality Constraints

       Product quality constraints ensure that the blended product satisfies all required specification limits. Unlike material balance equations, which describe physical conservation, these constraints define the acceptable operating region of the optimization problem. For each quality property j the ProductMixer blend optimization algorithm automatically generates a linear constraint based on the properties of the available blending components (blend components). The value of the blended property is calculated as a weighted average of the blend component properties:

where:
       - calculated value of the i-th product quality property;
        - value of property k for product i;
       The following expression represents the limiting blend value for the specified quality constraint k, accounting for the possible addition of a balancing additive in the second stage of the algorithm.

where
        - minimum required value of quality property k,
        - quality property k of the balancing additive,
        - required limit for quality property k.
        - required flow rate of the balancing additive to satisfy quality constraint k.
       Additionally, a system of equations is introduced to constrain the total product flow rate and to distribute it between the source streams and the balancing additive:

,

,

       Maximum Balancing Additive Utilization Constraint

,

       The following equation introduces a penalty for product underproduction, allowing the optimization to remain feasible when the required production rate cannot be achieved:

,

Automatic LP Model Generation

       Unlike traditional blending systems that rely on manually prepared blending models, ProductMixer constructs the linear programming problem automatically during simulation. The generated LP problem is recreated whenever the simulation state changes.
       For every optimization cycle, the algorithm performs the following steps:
  1. Reads the available blending component flows from the simulation model.
  2. Retrieves the quality properties of every component.
  3. Loads the product quality specifications.
  4. Creates the required decision variables.
  5. Generates material balance equations.
  6. Generates product quality constraints.
  7. Selects the appropriate objective function.
  8. Solves the LP problem.
  9. Applies the calculated flow distribution to the simulation model.

       As a result, the blending model is regenerated every time the process conditions change. No manual reformulation of the mathematical model is required. The overall workflow can be represented as

       The generated LP model contains only linear equations and inequalities, allowing standard linear programming solvers to obtain an optimal solution efficiently even for large blending problems. Because the mathematical formulation is generated directly from the current simulation state, the optimization automatically adapts to:

        - changing feedstock availability;
        - varying component properties;
        - updated product specifications;
        - different optimization objectives;

        - changing process topology.

       This automatic model generation enables ProductMixer to operate as an optimization engine within a refinery digital twin, continuously recalculating optimal blending decisions as process conditions evolve.

Benefits of the Mathematical Formulation

       The proposed mathematical formulation provides a flexible and scalable framework for solving refinery blending problems. Because the blending model is generated automatically from the current simulation state, the same algorithm can be applied to different products, blending schemes, and operating conditions without modifying the mathematical structure.
       The approach offers several practical advantages:
       Automatic model generation eliminates the need to manually formulate linear programming problems for each blending scenario.
       Reusable mathematical formulation allows different optimization strategies to be implemented by changing only the objective function while preserving the same system of constraints.
       Guaranteed material balance ensures that every feasible solution satisfies conservation of mass.
       Automatic quality verification enforces all product specification limits during optimization.
       Scalability allows the model to handle arbitrary numbers of blending components, quality properties, and residual streams.
       Computational efficiency enables large optimization problems to be solved within seconds using standard LP solvers.
       Digital twin integration allows optimization to be executed continuously as operating conditions change, providing real-time support for refinery decision making.
       These characteristics make the proposed algorithm suitable not only for standalone blend optimization but also as a core component of refinery-wide simulation and digital twin platforms.

Practical examples

Example 1 (Max product)
The following system of linear equations and constraints represents the LP model exported by the Product Mixer for a single product (productId = 37). The product is blended from a feed stream with an octane number of 85 and a balancing additive with an octane number of 101. The balancing additive flow rate is limited to the range from 0 to 0.2. The finished product must satisfy an octane number specification of at least 90. The optimization objective is to maximize the production rate while satisfying all quality, material balance, and capacity constraints.
Model result:
FlowMassProduct37 = 68.75
FlowMassResidual37 = 31.25
//LpSolve equations
min: -1.0*FLOW_MASS_PRODUCT;

1*FLOW_MASS37 = 360000.0;
1*FLOW_MASS37 + -1*FLOW_MASS_PRODUCT37 + -1*FLOW_MASS_RESIDUAL37 = 0.0;
1*FLOW_VOLUME_PRODUCT37 + -1.287995878413189*FLOW_MASS_PRODUCT37 = 0.0;
1*FLOW_MASS_RESIDUAL_FIRST + -1*FLOW_MASS_RESIDUAL37 = 0;
1*FLOW_MASS_RESIDUAL_SECOND = 0;
1*FLOW_MASS + -1*FLOW_MASS37 = 0;
1*FLOW_MASS_PRODUCT + -1*FLOW_MASS_PRODUCT37 = 0;
1*FLOW_MASS_RESIDUAL + -1*FLOW_MASS_RESIDUAL37 = 0;
1*FLOW_VOLUME_PRODUCT + -1*FLOW_VOLUME_PRODUCT37 = 0;
1*FLOW_MASS_PRODUCT + 1*FLOW_PENALTY_MIN <= 100.0;
1*FLOW_PENALTY_MIN + -0.0*FLOW_MASS_PRODUCT >= 0;
1*FLOW_LIMIT1 + -85.0*FLOW_MASS_PRODUCT37 = 0;
90.0*FLOW_MASS_PRODUCT + -11.0*FLOW_PENALTY1 + -1.0*FLOW_LIMIT1 <= 0;
1.0*FLOW_PENALTY1 + -0.2*FLOW_MASS_PRODUCT <= 0;
1.0*FLOW_PENALTY1 + -1*FLOW_PENALTY_MIN <= 0;
1*FLOW_PENALTY + -1*FLOW_PENALTY1 = 0;

Conclusion

       Product blend optimization can be formulated as a linear programming problem that combines material balance equations, blending constraints, and configurable objective functions within a single mathematical framework. The algorithm can therefore be used as a general-purpose refinery optimization component.
       The ProductMixer component automatically generates this blending model from the current simulation state, allowing the blending strategy to adapt continuously to changing feedstock availability, product specifications, and process conditions. Because the mathematical formulation remains unchanged while only the objective function is modified, the same optimization engine supports multiple refinery operating strategies without requiring manual model redesign. The presented formulation provides a practical foundation for implementing scalable, real-time refinery product blend optimization in refinery simulation and digital twin applications.

FAQ

1. What is product blend optimization?
Product blend optimization is the process of determining the optimal proportions of multiple blending components to produce a final product that satisfies all quality specifications while achieving a selected operational objective, such as maximizing production or minimizing additive consumption.

2. Why is linear programming used for product blending?
Most refinery blending problems can be formulated using linear material balance equations and linear quality constraints. This allows efficient optimization with standard linear programming (LP) solvers, even for large-scale blending systems.

3. What is optimized by the ProductMixer algorithm?
Depending on the selected operating mode, ProductMixer can maximize product recovery, minimize residual streams, minimize additive consumption, reduce quality deviations, or optimize several objectives simultaneously using weighted priorities.

4. How are product quality specifications enforced?
The algorithm automatically generates quality constraints from the current product specification and component properties. Every feasible LP solution must satisfy these constraints or, when allowed, minimize the corresponding penalty variables.

5. Does the mathematical model change for different optimization tasks?
No. The system of decision variables, material balance equations, and blending constraints remains the same. Only the objective function changes, allowing the same mathematical formulation to support multiple optimization strategies.

6. Can the algorithm handle changing feedstock properties?
Yes. The LP model is generated automatically from the current simulation state. Changes in available components, flow rates, densities, or quality properties are incorporated into the blending model without manual reconfiguration.

7. Can multiple residual streams be optimized?
Yes. ProductMixer supports multiple residual destinations with different optimization priorities, allowing valuable intermediate streams to be recovered before lower-priority residuals.

8. How does ProductMixer integrate with a refinery digital twin?
ProductMixer operates as an embedded optimization engine within the simulation model. It continuously regenerates and solves the LP problem as operating conditions change, enabling real-time blend optimization and decision support.

9. Why does ProductMixer generate the LP model automatically instead of using predefined equations?
Traditional blending systems often require engineers to manually create or modify blending models. ProductMixer automatically generates the LP model from the current simulation state, allowing the optimization to adapt to changing feedstock availability, product specifications, and process topology without manual reformulation.

10. Can the same algorithm optimize gasoline, diesel, and other refinery products?
Yes. The mathematical formulation is independent of the specific product being blended. Any refinery product can be optimized provided that the required component properties and product specifications are available.