Linear Programming for Refinery Flow Allocation: Model Formulation and Constraints (part 2)

       In the first part, we discussed the general tasks and principles of building linear optimization models for simulation models of oil and gas processing facilities. In this part, we move to a practical example demonstrating how linear programming can be used to optimize the allocation of incoming flows between process lines of a unit. Although the problem is referred to as linear programming in the context of this article, the resulting formulation is a Mixed-Integer Linear Programming (MILP) model because binary variables are used to represent process line operating states. This formulation represents a relatively simple and typical flow allocation problem; more complex allocation schemes involving different feedstock compositions, interconnected process units, and dependent operating constraints will be considered in the Advanced Linear Optimization for Refinery Flow Allocation. This approach is part of a broader hybrid simulation and optimization framework used in refinery digital twins.

Problem Formulation

       In a refinery, a process unit (Plant) may consist of one or several parallel process lines that operate according to common rules. We need to determine how the incoming flow should be allocated among the process lines and what portion, if any, will remain unaccepted. The feasible allocation depends on the feedstock type and the operating mode selected for each process line. Each mode defines a minimum and maximum throughput, while the line may also remain idle with zero flow. Therefore, for each line, the optimization must determine whether to keep it idle or operate it within its allowable throughput range. Based on these individual line constraints, the model must determine the optimal allocation of the incoming flow across the available lines and, if the total available capacity is insufficient, the resulting unaccepted flow.
       For more advanced constraints involving multiple process units, penalty functions, target loading, and feed blending, see Advanced Linear Optimization for Refinery Flow Allocation.
Additional Operational Considerations
       The flow allocation problem may also involve additional operational considerations that can be incorporated into an extended optimization model:
       1. Additional throughput limits. The maximum allowable throughput Ui​ of a process line may be lower than its nominal capacity due to user-defined limits, catalyst constraints, reactor operating conditions, or other operational factors. These considerations can be incorporated into the optimization model as additional constraints or objective terms. The formulation below focuses on the core flow allocation problem and explicitly includes line throughput limits, line operating states, flow balance, unaccepted flow, and allocation priorities.
        2. Bypass flow constraints. Some process units allow part of the incoming flow to bypass the unit and be directed to other processing nodes. The bypass flow may itself be subject to constraints, such as a required minimum flow.
        3. Minimizing the number of operating lines. Whenever possible, the required throughput may be handled by the minimum number of process lines, since operating additional lines may increase operating costs.
        4. Avoiding unnecessary switching. Changes in the operating state of process lines can also be considered as an additional optimization criterion based on their previous operating state.

Mathematical Formulation of the Optimization Problem

       Consider a process unit with (N) parallel process lines. The optimization model determines the flow assigned to each line, whether the line is active, and the resulting unaccepted flow.
Let:
        — flow assigned to process line i, ();
        — binary variable indicating whether process line i is active;
        — minimum allowable flow of line i;
        — maximum allowable flow of line i;
        — unaccepted (residual) flow;
        — priority penalty;
        — priority coefficient of process line i;
        — number of active process lines.

Objective Function

       The primary objective is to minimize the unaccepted flow. A large penalty coefficient ensures that this objective has priority over secondary optimization criteria:

where is a sufficiently large positive coefficient. The secondary term is used to introduce preferences between alternative feasible flow allocations.

Process Line Constraints

       For each process line :

.

These constraints define the operating range of each line. If , then . If , the flow must satisfy:

Thus, a process line can either remain idle or operate within its allowable minimum–maximum throughput range.

Flow Balance

       The incoming flow must be distributed between the process lines and the unaccepted flow:

Therefore, .The variable represents the portion of the incoming flow that cannot be accepted by the process unit.

Bypass Flow Constraints

       The unaccepted flow () represents the portion of the incoming flow that is not allocated to the process lines. Depending on the process unit configuration, a bypass route may or may not be available for this flow. If no bypass route is available, the unaccepted flow must be zero . In this case, the optimization model must ensure that the entire incoming flow is accepted by the available process lines. If this is not possible under the current operating constraints, the optimization problem has no feasible solution. In the Anylogic-based Petroleum Refining Library, such a situation can alternatively be handled by limiting the incoming flow to the maximum flow that can be accepted by the process unit.

       If a bypass route is available, the unaccepted flow may be greater than zero and can be subject to additional constraints. For example, a minimum bypass flow can be required when the bypassed stream is needed to maintain the operation of another process unit or piece of equipment: . Similarly, a maximum bypass capacity can be imposed: . Therefore, the bypass flow can be treated not simply as residual flow, but as an additional flow path with its own operational constraints. This allows the optimization model to account for process configurations in which a portion of the incoming flow must either be processed by the unit or routed through a constrained bypass.

Priority Constraint

       To account for preferred allocation between process lines, the model introduces a priority penalty:

The coefficients ​ define the loading priority of the process lines. Since the optimization minimizes the weighted flow, a lower coefficient corresponds to a higher loading priority. In this example, the coefficients are assigned in descending order, ​, for example 110, 101, and 100. This establishes the preferred loading sequence as Line 3 → Line 2 → Line 1, tending to fully load a higher-priority line before allocating flow to the next line.

Active Line Indicator

       The total number of active process lines can be represented by:

where represents the number of currently active lines.

This variable can subsequently be used to introduce additional optimization criteria, for example, to prefer solutions using fewer operating lines.

Variable Bounds

       The model also defines non-negativity constraints:

Finally, the line activation variables are binary:

The resulting model is therefore a mixed-integer linear programming (MILP) problem. Its solution simultaneously determines the operating state of each process line, the flow allocated to every line, and the minimum possible unaccepted flow for the current operating conditions of the process unit.

Optimization in the Petroleum Refining Library

       This approach is implemented directly in the Anylogic-based Petroleum Refining Library. Whenever the incoming flow changes, the operating parameters of the process unit are updated, or the user explicitly triggers recalculation, the unit formulates and solves the defined optimization problem using its built-in wrapper around the ojAlgo optimization solver. The current incoming flow is treated as the maximum available flow, while the optimization determines the optimal flow allocated to each process line and the remaining unaccepted flow. These results are then applied to the simulation model, after which the simulation continues with the updated operating conditions.
Because the solver operates numerically, small deviations may occur near constraint boundaries. A small numerical tolerance, such as , can be used when evaluating solver results near the minimum and maximum throughput limits to prevent insignificant numerical deviations from being treated as constraint violations.

Example: Optimizing Flow Allocation Between Process Lines

      Consider a process unit with three parallel process lines. The available incoming flow is:

For each line, the selected operating mode allows a throughput from . The optimization returns: Second and third lines are active: while the remaining incoming flow is insufficient to meet the minimum throughput required to start Line 1: . The total accepted flow is: The resulting unaccepted flow is:

Conclusions

       This example demonstrates how linear programming can be integrated directly into refinery simulation to dynamically optimize feed flow allocation between parallel process lines. The optimization accounts for line operating limits, active and idle states, unaccepted flow, and operational priorities. The unaccepted flow can subsequently be routed through a bypass or to another destination in the simulation model.
       Although this formulation is relatively simple, it represents a typical flow allocation problem within a process unit. In practice, however, flow allocation can become considerably more complex, involving different feedstock compositions, interconnected process units, dependent operating constraints, and more complex flow-routing schemes. These cases will be addressed in the third part of this series.

FAQ

1. What is the purpose of linear programming in refinery flow allocation?
Linear programming is used to determine how an incoming feed flow should be optimally allocated between parallel process lines while satisfying their operating constraints and minimizing unaccepted flow.

2. Why is mixed-integer linear programming required?
Binary variables are needed to represent the operating state of each process line. A line can either remain idle or operate within its defined minimum and maximum throughput.

3. What constraints can be included in the optimization model?
The model can account for minimum and maximum line throughput, additional capacity limits, bypass flow constraints, line priorities, and operating states. It can also be extended to minimize the number of active lines.

4. What is unaccepted or residual flow?
Unaccepted flow is the portion of the incoming feed that cannot be processed by the available process lines under the current operating constraints and must therefore be diverted elsewhere.

5. When is the optimization problem solved in Petroleum Refining Library?
The optimization can be triggered by a change in incoming flow, a change in the operating parameters of the process unit, or an explicit request from the user.

6. How is the optimization problem solved in Petroleum Refining Library?
Petroleum Refining Library formulates the optimization problem and solves it using a built-in wrapper around the ojAlgo optimization solver.

7. What does the optimization return to the simulation model?
The solver returns the optimal flow assigned to each process line and the resulting unaccepted flow. These values are then applied directly to the simulation.

8. Can the optimization handle an arbitrary number of process lines?
Yes. The mathematical formulation can be generalized to (N) parallel process lines, with each line having its own operating limits, state variables, and priority parameters.

9. How does the optimization differ from a simple flow distribution rule?
Unlike a predefined distribution rule, the optimization evaluates the complete set of constraints and selects the best feasible combination of active lines and flow rates for the current operating conditions.

10. Can this approach be used in a refinery digital twin?
Yes. The combination of dynamic simulation and optimization is well suited to refinery digital twins, where the optimal operating decision may need to be recalculated as process conditions change.