Trade Model Setup - High-Level Overview¶
Purpose¶
The trade model optimizes global steel and iron trade flows by solving a linear programming (LP) problem. It determines the most cost-effective way to route materials from suppliers through production facilities to demand centers, subject to capacity constraints, trade policies, and physical limitations.
Core Concept¶
The model represents the global steel value chain as a network:
Nodes: Suppliers (mines), production facilities (furnaces), and demand centers (regions)
Edges: Valid material flows between compatible technologies
Objective: Minimize total cost (production + transport + tariffs + carbon)
Constraints: Capacity limits, trade policies, distance restrictions, feedstock ratios
Main Functions¶
1. set_up_steel_trade_lp() - Build the Optimization Model¶
What it does: Constructs the complete LP model structure from simulation data.
Process:
Initializes an empty LP model with solver tolerance settings
Adds all commodities being modeled (steel, iron, etc.)
Creates process centers for suppliers, production facilities, and demand
Defines valid connections between process types
Applies optional constraints (tariffs, distance limits, feedstock ratios)
Adds location-specific transportation costs if available
Key decisions:
Only includes active furnace groups (configurable status filter)
Scales production capacity by safety factor (typically 95%)
Reuses process definitions across multiple furnaces with same technology
Outputs: A fully configured TradeLPModel ready for optimization
2. Helper Functions - Building Model Components¶
create_process_from_furnace_group()¶
Purpose: Converts a furnace group’s technology specifications into an LP process definition.
What it captures:
Input-output relationships (bill of materials)
Minimum/maximum feedstock ratios
Secondary feedstock requirements
Energy costs per input type
Handles edge cases:
Skips feedstocks with missing or invalid data
Warns about technologies with no primary outputs
Reuses existing BOM elements when possible
add_furnace_groups_as_process_centers()¶
Purpose: Represents each steel production facility as an LP node.
What it models:
Production capacity (scaled by availability factor)
Geographic location for distance calculations
Production cost (carbon cost)
Soft minimum utilization target
Filters: Only includes furnaces with active operating status
add_demand_centers_as_process_centers()¶
Purpose: Represents regional steel demand as LP nodes.
What it models:
Regional demand quantity for the simulation year
Geographic center of demand region
Single shared demand process (all regions demand “steel”)
add_suppliers_as_process_centers()¶
Purpose: Represents raw material sources (mines, scrap yards) as LP nodes.
What it models:
Supply capacity for the simulation year
Geographic location
Production/extraction cost
One process type per commodity (e.g., all scrap sources “scrap_supply”)
Per-year supplier fields. Supplier exposes time-varying capacity, production cost, mine cost and mine price as dicts keyed by Year:
Field |
Lookup |
|---|---|
|
Volumes (tonnes) available that year |
|
Production / extraction cost ($/t) |
|
Mine-level cost ($/t), iron-ore mines only |
|
Mine-level price ($/t), iron-ore mines only |
Trade-LP setup, the average-commodity-price calculation in Environment.calculate_average_commodity_price_per_region(), and downstream callers all read the value for the current simulation year. The same per-year structure applies to non-mine suppliers (scrap, etc.) — they simply populate a flat constant across years if their underlying input has no annual variation. Suppliers whose production_cost_by_year does not contain the current year are silently skipped from the average-price calculation.
Scrap production costs. Scrap suppliers start the run at SimulationConfig.initial_scrap_production_cost (default INITIAL_SCRAP_PRODUCTION_COST, 333 USD/t): data preparation writes the constant into every scrap scenario’s suppliers.json for every horizon year, and bootstrap_simulation re-applies the configured value at run time, so a cached preparation cannot pin a stale placeholder. From the second simulation year onward, finalise_iteration (step 4 in handlers.py) reprices the current year from BOF hot-metal costs — 0.95 × the average-BOM unit cost when available, else 0.90 × the country’s fallback material cost, else the same configured default — meaning only the first year trades scrap at the placeholder.
3. Constraint Functions¶
enforce_trade_tariffs_on_allocations()¶
Purpose: Applies trade policy restrictions to cross-border flows.
Supports three tariff types:
Volume quotas: Maximum tons per year on a route
Absolute taxes: Fixed cost per ton ($/ton)
Percentage taxes: Cost based on commodity price (% of market price)
See Tariffs, Quotas and Carbon Border Adjustments for the Tariffs sheet, the country and bloc syntax, and how overlapping rows combine.
fix_to_zero_allocations_where_distance_doesnt_match_commodity()¶
Purpose: Enforces physical locality constraints on commodity transport at the LP stage.
Four modes, selected by config (the default is mode 4, clustering by plant):
Clustering disabled (
enable_furnace_group_clustering=False, CLI--no-clustering): Distance-based fixing againsthot_metal_radius— hot commodities zeroed beyond the radius, cold commodities zeroed inside it.Clustering enabled, iso3 keying (
geographical_clustering_scope="iso3"): Hot commodities are fixed to zero across iso3 boundaries and where either side has no country; cold commodities remain free. Per-FG radius enforcement is deferred to disaggregation.Clustering enabled, plant-group keying (
geographical_clustering_scope="plant_group"): Hot commodities are zeroed between meta-furnace-groups with different cluster location keys (the plant group for hot-metal-affected technologies, the iso3 for others), and on edges where either side has no key, such as suppliers and demand centres. No country check; per-FG radius enforcement is deferred to disaggregation.Clustering enabled, plant-level keying (
geographical_clustering_scope="plant", the default): Hot commodities are zeroed on edges longer thanhot_metal_radius(haversine distance) and where either side has no location. No owner or country check, so a BOF can draw hot metal from a BF at a neighbouring plant.
Applied before solving and reduces model size. Emits one summary per year that counts the blocked flows by reason, for example [LP HOT-METAL] Fixed to zero (clustering_scope=plant, radius=5 km): {'beyond-radius': 1234}. The reasons are beyond-radius / missing-location (plant), cross-plant-group / missing-cluster-key (plant_group) and cross-country / missing-iso3 (iso3); the line reads none when nothing was blocked.
Secondary Feedstock & Aggregated Constraints¶
Purpose: Limits constrained secondary feedstocks and enforces technology-specific feedstock ratios.
Secondary feedstock constraints:
Annual limits on
bio_pciper TIAM-UCL region and onco2_stored(CO2 storage) per country, from theBiomass availabilityandCO2 storagesheets respectivelyExample: “furnace groups in Western Europe can use at most X t of bio-PCI in 2030”
Each constrained commodity comes from a synthetic zero-cost supplier connected to every production process; the limit caps its flows into the region. Scrap is not limited this way: its availability comes from scrap suppliers.
Aggregated constraints:
Technology-level min/max ratios
Example: “EAF must use 50-90% scrap, 10-50% DRI”
4. solve_steel_trade_lp_and_return_commodity_allocations() - Solve & Extract Results¶
What it does:
Solves the LP optimization problem using Pyomo, via HiGHS (default) or Gurobi
Extracts optimal allocation values from solver variables
Maps LP results back to domain objects (plants, suppliers, demand centers)
Filters out negligible allocations (< 0.0001 tons)
Error handling:
Returns empty allocations if solver fails to find optimal solution
Logs detailed error messages with termination condition
Continues simulation rather than crashing
Debug output:
Writes
trade_lp_variables.csvwith all allocation detailsLogs statistics on non-zero allocations per commodity
Outputs: Dictionary mapping each commodity to its optimal allocation flows
5. Post-Processing Functions¶
identify_bottlenecks()¶
Purpose: Analyzes results to find capacity-constrained facilities.
What it detects:
Furnace groups operating at or near maximum capacity
Potential supply chain chokepoints
Useful for understanding why demand might not be fully met
Note: Currently logs warnings but doesn’t return structured data.
adapt_allocation_costs_for_carbon_border_mechanisms()¶
Purpose: Charges imports into carbon-border regions on the embedded direct emissions of the product, at the destination’s carbon price, net of carbon already paid upstream.
What it models: For every legal arc from a production centre into a country covered by an active mechanism, the allocation cost rises by max(0, E × P_d − C): the product’s embedded direct emissions at the destination’s carbon price, net of carbon already paid. Non-zero adjustments are recorded on Allocations.carbon_border_charges.
See Tariffs, Quotas and Carbon Border Adjustments for the inputs, the rules and export rebates.
Configuration¶
Key SimulationConfig Parameters¶
Model behavior:
lp_epsilon: Solver tolerance (1e-3) - how close to constraints is acceptableoptimization_solver: LP solver backend,"highs"(default, no license needed) or"gurobi"(requiresgurobipyimportable and able to obtain a license at solve time - install withuv sync --extra gurobi). Also settable viarun_simulation --optimization-solver gurobi. Gurobi is commercial software that this project does not license. You need your own Gurobi license and must use it as its license agreement allows (for example, an academic license is not valid for commercial use). HiGHS and Gurobi don’t share a tuning-option vocabulary, soTradeLPModel.solver_optionsdefaults differ per backend (see_default_solver_options()intrade_lp_modelling.py); overridingsolver_optionsmust use the selected backend’s own option names. The Gurobi defaults are barrier (Method=2), one thread (Threads=1), and the HiGHS default tolerances (FeasibilityTol=1e-7,OptimalityTol=1e-7,BarConvTol=1e-8). Warm-starting between simulation years only works with simplex-family methods on either backend - HiGHS’s defaulthipoand Gurobi’s default barrier method both start fresh each year. The HiGHS retry chain (fallback_solvers) does not apply to Gurobi: a non-optimal Gurobi solve is not retried.capacity_limit: Production safety factor (0.95) - models realistic availabilityactive_statuses: Which furnace states to include (e.g., [“operating”, “mothballed”])carbon_border_export_rebates: Also rebate exports leaving a carbon-border region (default False)
Physical constraints:
hot_metal_radius: Maximum transport distance for hot commodities (~5 km by default). Enforced in several layers:LP-build time —
fix_to_zero_allocations_where_distance_doesnt_match_commodity()fixes hot-commodity flows to zero by scope (see the four modes above). Under"plant"scope (the default) it applies the radius itself; under"plant_group"it blocks flows between plant groups; under"iso3"it blocks flows between countries.Clustering — BOF FGs that no active hot-metal producer (any technology whose Bill of Materials outputs hot metal) can reach are excluded from their cluster. Reach follows one shared rule, also used for the plant agents’ access flag: within the radius, and in the same plant group under
"plant_group"scope or the same country under"iso3"scope. BOF cluster capacity is capped atmin(physical_cap, Σ[reachable hot-metal producer capacity] / min_hot_metal_share)so the LP cannot over-allocate.Disaggregation pre-pass (strict) — hot flows to destinations with a BOM minimum-share constraint are solved under strict radius with per-FG physical-capacity caps: radius-violating edges are omitted from the min-cost-flow graph, and when a geographic pocket can’t physically meet its demand, destination demand is scaled down (producing downstream shortfalls the drift mechanism rebalances).
Drift + rebalance — clusters whose actual joint-strict flow differs from LP get their Case 2 (cluster → demand) batches scaled by the drift factor and their Case 3 (supplier → cluster) batches rebalanced so per-cluster demand matches actual production × BOM ratio while per-supplier totals stay below LP (mine capacity hard-bounded).
Disaggregation (relabeling) — hot flows without a binding minimum constraint that exceed the radius are relabeled to their cold equivalent (e.g.
dri_high→hbi_high,hot_metal→pig_iron).Post-disaggregation — physical capacity and BOM consistency are validated for every FG; any BOF FG that received insufficient hot metal has its utilisation corrected downward.
closely_allocated_products: Hot commodities limited to short distances (hot_metal,dri_high/dri_mid/dri_low,liquid_iron).distantly_allocated_products: Cold equivalents that ship globally (pig_iron,hbi_high/hbi_mid/hbi_low,electrolytic_iron).enable_furnace_group_clustering(defaultTrue): When enabled, the LP works with meta-furnace-groups (clusters of same-technology-reductant-country FGs) to reduce problem size; apart from the LP-build and clustering checks above, radius and minimum-ratio enforcement runs at disaggregation time.geographical_clustering_scope: When clustering is enabled, controls the geographical granularity of clustering for FGs whoseeffective_primary_feedstockstouch a closely-allocated commodity. Options:"iso3": Cluster by country. Hot commodities are constrained to intra-country flows at the LP stage, and a BOF counts only in-country producers within the radius."plant_group": Cluster by corporate group (plant.ultimate_plant_group). Hot commodities are constrained to intra-plant-group flows at the LP stage, with no country check, and a BOF counts only its own group’s producers within the radius."plant"(default): Cluster by individual plant (plant.plant_id). Hot commodities may flow between plants withinhot_metal_radiusat the LP stage, whatever the owner or country, and a BOF counts every producer within the radius.
The same scope also sets the plant agents’ hot-metal access flag (see Hot-metal producers). With clustering off, the access flag uses the
"plant"rule.A FG is considered affected by the hot-metal radius by looking at its
effective_primary_feedstocks: any feedstock whosemetallic_chargeoroutputskey is inconfig.closely_allocated_products(hot_metal, dri_*, liquid_iron) triggers clustering-scope application. Non-affected techs always keep iso3 keying. The[CLUSTERING]log line reports the split per year (e.g., “X FGs keyed by plant_group, Y by iso3”). No effect whenenable_furnace_group_clusteringis off.
See the “Disaggregation: Hot-Metal Radius + Minimum-Ratio Enforcement” section in overview_trade_model.md for full details.
Economic data:
primary_products: Which commodities to optimize ([“steel”, “iron”])transport_kpis: Location-specific transport costs and emissions
Integration with Simulation¶
The trade model is called during each simulation time step:
Allocation Model prepares input data (plants, demand, suppliers for current year)
Setup phase builds LP model with
set_up_steel_trade_lp(); active carbon border mechanisms adjust the allocation costs insidebuild_lp_model(), before the objective is builtSolve phase optimizes with
solve_steel_trade_lp_and_return_commodity_allocations()Analysis phase identifies bottlenecks and validates results
Allocations are returned to simulation for plant-level profit calculations
For Detailed Implementation¶
For implementation details, parameter types, and code examples, see the comprehensive docstrings in each function within src/steelo/domain/trade_modelling/set_up_steel_trade_lp.py.