Advanced Linear Optimization for Refinery Flow Allocation (part 3)
→ min
The penalty weight defines the priority of the corresponding preference. A higher weight makes the model more strongly avoid that deviation, while a lower weight allows it to be sacrificed when higher-priority objectives must be satisfied. By adjusting these weights, complex refinery operations can be managed through a clear hierarchy of priorities without changing the underlying optimization model. This makes penalty functions particularly useful for representing changing operational priorities in refinery digital twins.
Example
For the configuration described in Example 1, the penalty function can be formulated as a weighted sum of the main undesirable outcomes:
where
- significant overload of the NGL processing unit, causing part of the valuable NGL flow to be routed to another refinery;
- significant overload of the stabilized-condensate processing unit, causing part of the valuable stabilized-condensate flow to be routed to another refinery;
- unused capacity of the stabilized-condensate processing unit; this penalty encourages the optimizer to load the unit up to its maximum capacity;
- CSU underloading, representing the incoming flow not allocated to the CSU lines;
- small overload of the NGL processing unit. This is an acceptable trade-off because, in Normal operation, NGL and stabilized condensate are produced together, so a small amount of additional NGL can be sacrificed to increase stabilized-condensate processing;
- line-specific priority coefficient;
- flow assigned to CSU line i;
- dynamic penalty weight for residual flow R, which can be adjusted according to the current tank-farm level (see the detailed explanation below.).
As shown in the formulas above, the NGL downstream processing unit uses two levels of overload penalties.. This approach has proven effective in practice. A small NGL overload () allows more CSU lines to operate in Normal mode and further load the stabilized-condensate processing unit, while accepting a small amount of NGL being routed to another refinery, it provides greater flexibility in managing the overall flow. If the small-penalty threshold is insufficient to satisfy the operating requirements, the model enters the large-penalty range (), making the corresponding operating mode effectively infeasible.
Penalty weights should be chosen so that, under realistic operating conditions, the maximum possible contribution of a lower-priority penalty remains below the minimum contribution of a higher-priority penalty. This preserves the intended hierarchy of operational priorities. However, excessively large penalties or large gaps between penalty weights can make the optimization numerically unstable. Therefore, penalty coefficients should be calibrated through numerical experiments, taking into account the required priority separation, solver stability, and the capabilities of the selected solver. In Anylogic-based Petroleum Refining Library, linear optimization is performed using the ojAlgo solver.
In this example, the coefficients are assigned sequentially: . These coefficients do not represent physical process constraints. Their purpose is to introduce a weak preference for the loading sequence of the CSU lines. This prevents the optimizer from treating different line-loading combinations as mathematically equivalent and helps avoid alternative optimal solutions during subsequent optimization runs.
Material balance is a fundamental requirement in every feedstock allocation model. All flow-splitting equations must conserve mass at each stage of the process.
For example, in the configuration above, the incoming flow is distributed between the four CSU units:,
where is the incoming flow and R is the residual flow.
Each CSU flow is then distributed between its individual lines. For Example for :
.
The residual flow requires particular attention. In some configurations, must always equal zero. For example, if a CSU is directly connected to the tank farm and there is no bypass or alternative flow path, a non-zero residual indicates an infeasible solution or an error in the optimization model. In other configurations, a residual flow is physically possible but undesirable. In this case, it can be minimized by adding to the penalty function with an appropriate weight. This reflects the operational principle of accepting as much incoming feed as possible. The weight () assigned to can also be made dynamic. When the tank farm is highly loaded, its penalty can be increased significantly, encouraging the model to increase the withdrawal rate even if this requires sacrificing lower-priority objectives..
For a plant line with a nominal capacity of :
,
where
- actual flow to the process unit (t/h).
- unit underloading relative to its target capacity (and may be penalized when underloading is undesirable);
- total unit overload;
- small, acceptable overload subject to a relatively low penalty (for example );
- overload beyond the acceptable range, subject to a substantially higher penalty.
The important principle is that underloading and overloading are modeled explicitly as deviations from the desired unit loading, allowing the optimization to balance them according to their assigned penalties. This provides much greater flexibility than treating the nominal unit capacity as a simple hard constraint.
,
where is a binary variable indicating whether the corresponding mode is selected.
Additionally, the maximum flow on a line can be limited by a user-defined value. This allows the optimization model to impose an operational limit below the technical maximum of the selected mode. The effective upper bound on the line flow is therefore the lower of the mode-specific maximum and the user-defined maximum. The optimizer determines the actual flow within this allowable range according to the objective function. Thus, the line flow must satisfy both constraints simultaneously: it cannot exceed either the maximum allowed by the operating mode or the user-defined maximum. This provides an additional level of operational control without changing the underlying mode-specific limits.
A process line can be assigned at most one operating mode at a time. This can be enforced by requiring the sum of the binary variables for all available modes to be no greater than one.For example: . The binary variable can take the value 1 when the mode is available and selected, or 0 when it is not selected. This also allows a line to be made unavailable - for example, when the line is under maintenance - by setting the corresponding availability variable to zero. Thus, the same formulation can simultaneously control mode selection, minimum and maximum loading, and equipment availability.
The binary mode-selection variables can also be used to determine the active operating mode ID of each process line. By multiplying each binary variable by the corresponding mode ID stored in the database and summing the results, the optimization model returns the ID of the selected mode. For example:
,
where 29, 30, and 33 are mode IDs from the database, and , , and are binary mode-selection variables. The resulting is the ID of the active mode for CSU1 line 1.
The binary variable ensures that only the capacity of the selected operating mode contributes to the underloading calculation.
The total underloading can then be expressed as:
This approach allows the model to evaluate how much available capacity remains unused at each unit and across the entire processing scheme.