Linear Programming for Refinery Flow Allocation: Practical Modeling Techniques

       Linear programming for refinery flow allocation is used to determine how incoming feedstock should be distributed between process units and production lines in an oil refinery simulation. This refinery optimization approach helps model feedstock allocation, production capacity, material balances, and operating constraints in petroleum refining. Even in an oil refinery simulation, many operating decisions still require analytical refinery optimization. One of the most common problems is refinery flow allocation — determining how incoming feedstock should be distributed between process units, production lines, and downstream processing units.
       This refinery flow allocation problem exists at virtually every oil refinery. Large feedstock streams enter the plant and must be routed through upstream process units that may process different feedstocks, operate in different operating modes, and have different capacity constraints. These units are also connected to downstream processing units, each with its own throughput limits, capacity constraints, and requirements for intermediate products and downstream production. As a result, changing the flow to one unit can affect the loading and feasibility of many others.
       An oil refinery simulation model must therefore consider material balances, process unit and production line capacities, operating modes, equipment availability, downstream requirements, blending constraints, and refinery operating priorities simultaneously.In complex refinery models, the logic responsible for flow allocation can represent a substantial part of the overall model.
       Linear programming (LP) and mixed-integer linear programming (MILP) provide an effective way to formulate refinery flow allocation and refinery optimization problems as mathematical equations and constraints and determine the best feasible feedstock allocation according to the objective function and refinery operating constraints. The relationship between refinery simulation, optimization, operational data, and decision-making is described in more detail in our article on digital twin architecture for refinery operations.
       This article presents practical techniques for using LP/MILP to distribute refinery flows between process units and production lines, including material balances, prioritized allocation, overload and underload penalties, binary operating modes, equipment availability, and mode-dependent blending constraints. PRL supports both linear programming (LP) and mixed-integer linear programming (MILP) through its Java-based optimization layer. The ojAlgo solver integration in PRL provides the underlying optimization engine for these models.

Why Refinery Flow Allocation Matters in an Oil Refinery

       This is especially important for process units at the beginning of an oil refinery process scheme, where large feedstock streams must be allocated across multiple processing destinations. Large feedstock streams must be distributed among units with different capacities, operating modes, feedstock requirements, and downstream constraints. As a result, the allocation decision must consider not only the receiving unit but also the production network that follows it. This macro-level refinery flow allocation problem is common to virtually every oil refinery and requires a consistent mathematical formulation to reproduce realistic refinery operating decisions in simulation. This guide presents practical examples of how refinery operating rules can be translated into linear and mixed-integer linear programming equations. The examples cover material balances, prioritized flow allocation, equipment overload and underload, operating modes, line activation, equipment availability, and mode-dependent blending constraints.

How Linear Programming and Refinery Simulation Work Together

        The simulation and optimisation continuously reproduces the refinery operation, while the optimization model determines how flows should be allocated under the current operating conditions.
       The optimization model is recalculated when an event occurs that can change the optimal allocation, for example:
        - a change in refinery feedstock flow rates;
        - a seasonal or production-period change;
        - a process unit being started, stopped, or sent for maintenance;
        - a change in process unit or production line capacity or operating mode;
        - a change in downstream production requirements or refinery operating constraints.
       When such an event occurs, the simulation passes the current refinery state to a dedicated optimization class. The refinery optimization model is defined by a predefined LP/MILP mathematical model containing flow variables, material balances, capacity constraints, operating constraints, binary variables, and an objective function. For practical implementation of LP and MILP optimization in AnyLogic, see our guide to the ojAlgo optimization solver for AnyLogic and PRL. The current numerical parameters are inserted into this template, and the solver calculates a new solution. To understand how refinery simulation and optimization fit into the overall digital twin framework, see Digital Twin Architecture for Refinery Operations.
The result is typically a flow allocation between process units and their production lines. The simulation applies this allocation and continues the process until another event triggers a new optimization run. This approach allows the mathematical optimization model to remain relatively stable while its numerical parameters dynamically change with the state of the refinery.

Why Refinery Flow Allocation Is Difficult in Real Oil Refineries

       At first glance, refinery flow allocation may seem simple: an incoming feedstock stream can be divided between several process units using a few conditional rules. In a real refinery, however, these decisions are strongly interconnected, making a rule-based approach increasingly difficult to maintain. A single refinery feedstock stream may have several possible processing destinations, each with its own minimum and maximum capacity. Process units may also consist of several production lines with different capacities, throughput limits, and operating ranges. As a result, the model must determine not only how much flow each unit receives, but also how that flow is distributed between individual lines. The situation becomes more complex when operating priorities are introduced. Two units may both be able to accept the same feed, but overloading one may be much more undesirable than overloading the other. Similarly, a small overload may be operationally acceptable while a larger overload should be strongly penalized. Most importantly, refinery process units cannot be optimized independently, because upstream feedstock allocation affects downstream processing, intermediate products, storage and tank farm capacity, and overall production feasibility. Increasing the feed to an upstream unit also changes the production of intermediate products and therefore affects downstream process units, storage facilities, and their capacity requirements. A decision that is feasible for one unit can therefore make the overall production system infeasible. In addition, refinery optimization decisions combine continuous and discrete variables. Refinery flow rates are continuous, while decisions such as starting a production line, selecting an operating mode, or taking equipment out of service are discrete. A single process unit may have several mutually exclusive operating modes, each with different throughput and blending constraints. Equipment availability must also be considered. The nominal capacity of a unit or line may become unavailable because of maintenance, shutdowns, or other operating conditions.
These characteristics create a highly interconnected decision problem:

feed allocation → unit selection → line selection → operating mode → throughput → downstream feasibility

       A sequence of if statements can represent individual rules, but it becomes increasingly difficult to manage when all these conditions must be satisfied simultaneously. Linear programming (LP) and mixed-integer linear programming (MILP) provide a more systematic approach to refinery flow allocation: refinery operating logic is expressed through material balances, capacity constraints, binary variables, equipment availability constraints, and an objective function, allowing the optimization solver to determine the best feasible allocation.

Refinery Simulation and Optimization Performance

       Repeated refinery optimization calls can significantly slow down an oil refinery simulation, especially when the LP/MILP mathematical model is large. Several techniques can reduce this overhead. First, avoid unnecessary optimization calls. Recalculate only when the refinery state has changed sufficiently to affect the optimal allocation. Otherwise, reuse the previous solution. Second,improve refinery optimization model and optimization solver performance by:
  • reducing unnecessary LP/MILP variables and constraints;
  • using presolve and exploiting model sparsity;
  • selecting an appropriate optimization solver;
  • using warm starts for similar consecutive refinery optimization problems;
  • precalculating parameters and relationships that do not change during simulation;
  • tuning solver-specific settings when necessary.
       Optimization frequency should also be separated from simulation accuracy. More frequent optimization does not necessarily produce a more accurate simulation if the relevant refinery state has not changed. Combining event-based recalculation with model reduction and solver optimization can substantially improve the performance of complex refinery simulation and flow-allocation models. The largest performance improvement often comes from reducing the number of optimization calls rather than only reducing solver execution time.
Simulation describes what happens. Optimization determines how flows should be allocated.

Building a Refinery Optimization Model from the Refinery Structure

       An oil refinery simulation already contains most of the information needed to build a refinery flow allocation optimization model. The main task is to translate the physical refinery structure and operating rules into mathematical variables, material balances, capacity constraints, operating constraints, binary variables, and an objective function.
       These elements are translated into an LP/MILP model:
Refinery structure → units, lines, flows, capacities, modes, availability, downstream requirements
Optimization model → flow variables, material balances, technological constraints, binary variables, objective function
       A material balance constraint ensures that refinery flow allocation remains consistent with the available incoming feedstock. For example, a material balance can define how an incoming stream is distributed:

TotalFlow = FlowOnPlant1+ FlowOnPlant2+ FlowOnPlant3 + Residual

Residual feedstock represents feed that cannot be allocated to the available process units or production lines under the current refinery operating constraints.
       Capacity and other technological constraints define the feasible range of the solution, while binary variables represent discrete decisions such as line activation or operating-mode selection. When such variables are required, the problem becomes a mixed-integer linear programming (MILP) problem. The objective function then determines which feasible allocation is preferred. In refinery flow allocation, this is often implemented through penalty functions that represent operational priorities, such as minimizing unallocated feed, equipment overload, or inefficient line utilization.The mathematical structure can remain fixed while its numerical parameters are updated from the current simulation state. This allows the same optimization model to be repeatedly solved as refinery conditions change. The following sections focus on practical formulations for the most common refinery flow-allocation constraints.

Continuous and Discrete Decisions in Refinery Flow Allocation Optimization

       Refinery flow-allocation problems often combine continuous and discrete decisions.
Continuous variables determine quantities such as:
  • how much feedstock is sent to a process unit;
  • how much is sent to an individual production line;
  • how much of a component is used in a blend.
       Discrete decisions determine the operating configuration, for example:
  • whether a production line is operating;
  • which operating mode is selected;
  • whether a process unit is available;
  • which of several alternative process configurations is used.
       Continuous decisions can be represented with standard linear programming. Once binary variables are introduced to represent these discrete choices, the problem becomes mixed-integer linear programming (MILP). This distinction is important for refinery simulation because flow rates and equipment configuration often have to be optimized simultaneously.

Conclusions

       Refinery flow allocation is a recurring refinery optimization problem that becomes particularly complex when multiple process units, production lines, operating modes, and downstream constraints interact. When integrated with oil refinery simulation, LP/MILP provides a mathematical refinery optimization layer that recalculates feedstock allocation as refinery operating conditions change. The simulation represents the dynamic behavior of the refinery, while the optimization model determines the most appropriate allocation under the current constraints.
       The key principles are:
  • Material balances describe how flows are distributed through the refinery.
  • Constraints represent technological and operational limits.
  • Binary variables represent discrete decisions such as line activation and operating-mode selection.
  • Objective functions and penalties express operational priorities.
  • Simulation events trigger optimization when the refinery state changes.
  • Solver performance and recalculation strategy determine how efficiently the combined model can run.
       The quality of the optimization result depends primarily on how accurately refinery operating rules are translated into mathematical constraints and objective functions.

FAQ

1. Why is linear programming useful for refinery flow allocation?
Linear programming for refinery flow allocation allows incoming feedstock to be distributed between process units and production lines while simultaneously considering material balances, capacities, downstream requirements, and refinery operating constraints.

2. When is MILP required for refinery flow allocation instead of LP?
MILP is required when the optimization includes discrete decisions, such as selecting an operating mode, activating a production line, or determining equipment availability.

3. Should the optimization model be recalculated continuously during simulation?
Not necessarily. It is usually more efficient to recalculate when a relevant refinery state changes. If the state has not changed sufficiently, the previous solution can be reused.

4. How can equipment overload be represented in an optimization model?
Overload can be represented using penalty variables. Different penalty levels can distinguish between a small, acceptable overload and a more significant overload that should be strongly avoided.

5. How can operational priorities be represented?
Operational priorities can be incorporated into the objective function using penalty coefficients. Different orders of magnitude can be used to establish a hierarchy between competing decisions.

6. Can the same optimization model be used throughout a simulation?
Yes. The mathematical structure can remain fixed while current flow rates, capacities, equipment states, and other parameters are updated from the simulation.

7. How can optimization performance be improved?
Performance can be improved by reducing unnecessary optimization calls, using presolve and warm starts, reducing unnecessary variables and constraints, selecting an appropriate solver, and tuning solver-specific settings.

8. Does refinery optimization replace refinery simulation?
No. Refinery optimization determines the best flow allocation according to the mathematical model, while refinery simulation represents how the refinery actually evolves over time and validates whether the resulting operating decisions remain feasible.