Oil refinery production optimization (ampl-only version)

oil_refining_ampl_only.ipynb Open In Colab Kaggle Gradient Open In SageMaker Studio Lab Hits

Description: In this document, we present an enhanced approach to oil refining optimization for improved decision-making.

This notebook showcases how to model a complex model with AMPL, solving it with the open-source solver Highs.

Tags: Oil production, Production optimization, Profitability, Refinery, mip, ampl-only, highs, industry

Notebook author: Mikhail Riabtsev <mail@solverytic.com>

1. Introduction

Context and Significance

The petroleum refining industry is one of the most crucial and intricate sectors in the global economy. It plays a pivotal role in converting crude oil into an array of valuable products such as gasoline, diesel, jet fuel, lubricants, and petrochemicals, which are indispensable to modern life and industrial processes. The industry’s complexity arises from the need to manage and optimize a series of interconnected processes, each with its own set of constraints and requirements. Furthermore, the industry operates in a highly volatile environment, influenced by fluctuating crude oil prices, stringent environmental regulations, technological advancements, and dynamic market demands.

Effective decision-making in this context is paramount. Refinery managers must balance multiple objectives: maximizing output and profitability, minimizing costs, ensuring compliance with environmental standards, and maintaining operational efficiency. These challenges underscore the necessity for sophisticated optimization models that can integrate various facets of refinery operations and provide strategic insights.

Problem Statement

The primary goal of this project is to develop a comprehensive optimization model for a petroleum refinery. This model aims to maximize the refinery’s total profit over a specified planning horizon. To achieve this, the model will encompass various stages of the refining process, including distillation, reforming, cracking, and lubricating. Additionally, it will incorporate elements such as production planning, blending operations, inventory management, financial planning, pollutant emission controls, and maintenance scheduling.

The proposed model will serve as a decision-support tool, guiding refinery managers in:

  1. Production Planning: Optimizing the production levels of intermediate and final products to align with market demand and operational capacities.

  2. Blending Operations: Determining optimal blending ratios to meet product quality specifications while maximizing efficiency.

  3. Inventory Management: Efficiently managing the storage and movement of crude oil and intermediate products to minimize holding costs and avoid shortages or surpluses.

  4. Market and Demand Management: Adjusting production and blending strategies in response to market demand and price fluctuations.

  5. Financial Planning: Ensuring effective management of cash flows, loans, and financial balances to support ongoing operations and investments.

  6. Regulatory Compliance: Adhering to environmental regulations by managing pollutant emissions and other environmental impacts.

  7. Maintenance Scheduling: Planning for equipment maintenance and plant shutdowns to minimize downtime and associated costs.

Scope and Objectives

The scope of this optimization model is to provide a holistic framework that integrates all aspects of refinery operations. The specific objectives include:

  • Decision Variables: Identifying key variables such as production levels, blending ratios, inventory levels, cash flows, loan amounts, and binary variables for plant and equipment status.

  • Constraints: Incorporating constraints related to operational capacities, storage limits, delivery schedules, pollutant emission limits, financial balances, loan limits, market demand, product quality standards, and maintenance requirements.

  • Objective Function: Developing a total profit maximization function that accounts for revenues from product sales, costs of production and blending, inventory holding costs, costs of disposal of production waste, costs of planned plant shutdown,loan interest expenses, and maintenance costs. By achieving these objectives, the model will provide actionable insights and recommendations for optimizing refinery operations, thereby enhancing profitability and sustainability.

In this example, we’ll demonstrate how to use mathematical optimization to optimize the output of a refinery. You’ll learn how to generate an optimal production plan that maximizes total profit, while taking into account production capacity and other restrictions.

Expected Outcomes

The successful implementation of this optimization model is anticipated to deliver several key benefits:

  • Enhanced Profitability: Optimizing production, blending, and financial decisions will maximize profit margins and overall financial performance.

  • Operational Efficiency: Improved planning and scheduling will enhance the efficiency of production processes and maintenance activities.

  • Market Responsiveness: The model’s ability to incorporate demand elasticity will allow the refinery to adapt swiftly to changes in market conditions.

  • Regulatory Compliance: Ensuring adherence to environmental standards will help avoid legal penalties and enhance the refinery’s reputation.

  • Strategic Financial Management: Effective management of cash flows and loans will ensure financial stability and reduce the cost of capital.

Conclusion

In conclusion, the development and implementation of this optimization model will provide a powerful tool for refinery management. It will facilitate informed decision-making, driving long-term success in a competitive and ever-changing industry. By addressing the multifaceted challenges of refinery operations, this model will help achieve a balance between profitability, efficiency, and sustainability, ensuring the refinery’s resilience and growth in the face of future challenges.

Partner with the AMPL team to transform complex problems into optimized solutions. AMPL consulting services combine deep technical knowledge with industry-leading insights, helping you unlock the full potential of optimization within your organization.


The operating pattern of an oil refinery depends on its specialization (type of equipment installed) and the type(s) of oil processed. In this example, we will use the part of the general scheme of oil refining.

2. Problem Description

Stage 1: Distillation

An oil refinery purchases two types of crude oil (Crude1 and Crude2). The cost of purchased oil changes over time periods, $/barrel:

Oil type

1

2

3

4

5

6

7

8

9

10

11

12

Crude1

80

80

82

83

84

85

86

87

88

89

90

91

Crude2

85

86

87

88

89

90

90

90

90

91

91

91

The terms of the concluded contracts include restrictions on the maximum volume of oil supplied in each period, barrels:

Oil type

Max

Crude1

40000

Crude2

25000

Purchased crude oil is distilled into several fractions:

  • Light Naphta (with an octane number of 90)

  • Medium Naphta (with an octane number of 80)

  • Heavy Naphta (with an octane number of 70)

  • Light Oil (with an vapor pressur of 1)

  • Heavy Oil (with an vapor pressur of 0.6)

  • Residuum (with an vapor pressur of 0.05)

One barrel of crude separates into the following fractions:

Operating mode

Oil type

Light Naphta

Medium Naphta

Heavy Naphta

Light Oil

Heavy Oil

Residuum

D1

Crude1

0.1

0.2

0.2

0.12

0.2

0.13

D1

Crude2

0.15

0.25

0.18

0.08

0.19

0.12

D2

Crude1

0.12

0.19

0.19

0.13

0.19

0.13

D2

Crude2

0.14

0.24

0.19

0.09

0.18

0.13

The distillation process operates under different modes (e.g., D1, D2), each with its own capacity, cost, setup characteristics, pollution level and the cost of waste disposal:

Operating mode

Maximum productivity, barrels/period

Duration of the equipment setup period

Equipment reconfiguring cost, $

D1

45 000

50 000

0.5

D2

47 000

70 000

0.5

*The costs of reconfiguring equipment are taken into account only if reconfiguration is needed.

The cost of distilling 1 barrel of crude oil and the cost of disposal of process residues are:

Operating mode

Oil type

Cost of Distillation, per barrel

Residue disposal cost, per barrel

D1

Crude1

18

2

D1

Crude2

15

3

D2

Crude1

17

1.5

D2

Crude2

16

2.2

The process of recycling the residues of the distillation process is accompanied by the release of the following amount of harmful substances:

Operating mode

Oil type

Hydrocarbon

Sulfur dioxide

D1

Crude1

100

120

D1

Crude2

105

116

D2

Crude1

99

115

D2

Crude2

108

111

The refinery then uses some amount of the distillation products as inputs for further processing in Reforming, Cracking, and Lubricating processes.

Stage 2:

2.1. Reforning

This process converts specific distillation products (Light Naphta,Medium Naphta, Heavy Naphta ) into reforming products such as Reformed gasoline (with an octane number of 115).

From 1 barrel of distillation products, the following amounts of reformed gasoline can be obtained:

Operating mode

Distillation product

Reformed gasoline

R1

Light Naphta

0.6

R1

Medium Naphta

0.52

R1

Heavy Naphta

0.45

R2

Light Naphta

0.6

R2

Medium Naphta

0.52

R2

Heavy Naphta

0.48

The reforming installation can operate in different modes (e.g., R1, R2), each with its own capacity and cost.

Operating mode

Maximum productivity, barrels/period

Duration of the equipment setup period

Equipment reconfiguring cost, $

R1

10 000

0.5

80 000

R2

12 000

0.6

90 000

*The costs of reconfiguring equipment are taken into account only if reconfiguration is needed.

The cost of reforming 1 barrel of distilling products and the cost of disposal of process residues are:

Operating mode

Distillation product

Cost of Reforming, per barrel

Residue disposal cost, per barrel

R1

Light Naphta

20

2

R1

Medium Naphta

26

1.8

R1

Heavy Naphta

28

2.2

R2

Light Naphta

22

2

R2

Medium Naphta

24

3

R2

Heavy Naphta

26

1.3

The process of recycling the residues of the reforming process is accompanied by the release of the following amount of harmful substances:

Operating mode

Distillation product

Hydrocarbon

Sulfur dioxide

R1

Light Naphta

60

180

R1

Medium Naphta

70

140

R1

Heavy Naphta

72

115

R2

Light Naphta

65

180

R2

Medium Naphta

40

150

R2

Heavy Naphta

70

118

2.2. Cracking

This process converts specific distillation products (Light Oil,Heavy Oil) into cracking products such as Cracked oil (with an vapor pressur of 1.5) and Cracked gasoline (with an octane number of 105). From 1 barrel of distillation products the following amounts of cracked products can be obtained:

Operating mode

Distillation product

Cracked oil

Cracked gasoline

CR1

Light Oil

0.68

0.28

CR1

Heavy Oil

0.75

0.2

CR2

Light Oil

0.6

0.34

CR2

Heavy Oil

0.52

0.25

The cracking installation can operate in different modes (e.g., CR1, CR2), each with its own capacity and cost.

Operating mode

Maximum productivity, barrels/period

Duration of the equipment setup period

Equipment reconfiguring cost, $

CR1

8 000

0.3

25 000

CR2

9 000

0.2

36 300

*The costs of reconfiguring equipment are taken into account only if reconfiguration is needed.

The cost of cracking 1 barrel of distilling products and the cost of disposal of process residues are:

Operating mode

Distillation product

Cost of Cracking, per barrel

Residue disposal cost, per barrel

CR1

Light Oil

20

1

CR1

Heavy Oil

22

1.2

CR2

Light Oil

21

1.36

CR2

Heavy Oil

18

1.05

The process of recycling the residues of the cracking process is accompanied by the release of the following amount of harmful substances:

Operating mode

Distillation product

Hydrocarbon

Sulfur dioxide

CR1

Light Oil

100

200

CR1

Heavy Oil

150

250

CR2

Light Oil

120

180

CR2

Heavy Oil

150

240

2.3. Lubricating

This process converts specific distillation products (Residuum) into Lube Oil. From 1 barrel of distillation products the following amounts of lubrication products can be obtained:

Operating mode

Distillation product

Lube Oil

L1

Residuum

0.5

L2

Residuum

0.6

The lubricating installation can operate in different modes (e.g., L1, L2), each with its own capacity and cost.

Operating mode

Maximum productivity, barrels/period

Duration of the equipment setup period

Equipment reconfiguring cost, per barrel

L1

500

0.2

5 000

L2

1 000

0.1

8 000

*The costs of reconfiguring equipment are taken into account only if reconfiguration is needed.

The cost of lubricating 1 barrel of distilling products and the cost of disposal of process residues are:

Operating mode

Distillation product

Cost of Lubricating, per barrel

Residue disposal cost, per barrel

L1

Residuum

21

1.2

L2

Residuum

22

1.4

The process of recycling the residues of the lubricating process is accompanied by the release of the following amount of harmful substances:

Operating mode

Distillation product

Hydrocarbon

Sulfur dioxide

L1

Residuum

60

180

L2

Residuum

70

140

It is advisable to produce Lube Oil in a volume of no more than 1000.

Stage 3: Blending

All intermediate components obtained at the stages Distillation, Reforming, Cracking, Lubricating can be mixed to obtain the final petroleum products:

3.1. Regular and premium gasoline

Can be made by blending Light Naphta, Medium Naphta, Heavy Naphta, Reformed gasoline and Cracked gasoline. The only requirement is that Regular gasoline must have an octane of at least 84 and Premium gasoline must have an octane number of at least 94. It is assumed that octane numbers blend linearly by volume.

Premium gasoline production must be at least 40% of Regular gasoline production.

3.2. Jet Fuel

Can be made by blending Light Oil, Heavy Oil, Residuum, and Cracked Oil. Jet fuel must have a vapor pressure that does not exceed 1.0. It is assumed that vapor pressures blend linearly by volume.

3.3. Fuel Oil

To produce Fuel Oil, it is necessary to mix Light Oil, Cracked Oil, Heavy Oil and Residuum in the ratio of 10:4:3:1.

3.4. Lube Oil

Was produced at the Stage 2.3. Lubricating.

The cost of the process of blending various petroleum products has the following cost:

Product

Cost of blending, $/barrel

Premium Gasoline

2

Regular Gasoline

1.9

Jet Fuel

2.2

Fuel Oil

2

Lube Oil

2.4

Stage 4: Storage

Finished petroleum products are delivered to fuel storage facilities. Storage capacity, storage cost, loss percentage during storage are presented below:

Product

Storage Capacity, barrels

Storage Cost, $/barrel

Storage Waste, %

Premium Gasoline

50 000

3

0.3

Regular Gasoline

50 000

5

0.2

Jet Fuel

30 000

7

0.1

Fuel Oil

10 000

2

0.05

Lube Oil

4 500

4

0.05

The cost of delivery petroleum products to gas stations is:

Product

Station1, $/barrel

Premium Gasoline

2

Regular Gasoline

2

Jet Fuel

3

Fuel Oil

2

Lube Oil

4

Factory restrictions

Operating an oil refinery involves fixed costs of 300,000 each period. In addition, during the periods under review, a planned technical shutdown of the plant lasting 1 period is required. During the planned shutdown, the plant can only release finished petroleum products to customers but not produce new ones. The cost of various technical works during the suspension is 100,000. During the technological shutdown, all fixed costs of the plant continue to apply. At the beginning of the period under review, the plant’s current account contains 2 million.

Demand

Historical data on demand for petroleum products demonstrates seasonal variations in demand:

Product

1

2

3

4

5

6

7

8

9

10

11

12

‘Premium Gasoline’

4 500

4 500

4 500

4 500

5 000

7 000

7 500

7 000

6 000

5 000

4 500

5 000

‘Regular Gasoline’

8 500

8 500

8 500

8 800

9 200

13 500

14 000

13 500

12 000

10 000

9 000

10 000

‘Jet Fuel’

7 000

7 000

7 000

9 000

12 000

10 000

9 000

8 000

8 000

9 000

7 000

7 000

‘Fuel Oil’

4 000

3 800

3 800

3 800

2 900

2 500

2 500

2 800

3 300

3 400

3 500

3 600

‘Lube Oil’

500

500

700

700

700

500

400

500

600

700

700

700

During the periods under review, the following changes in the average market price are expected:

Average market price:

1

2

3

4

5

6

7

8

9

10

11

12

‘Premium Gasoline’

162

165

165

165

165

165

165

167

168

168

167

165

‘Regular Gasoline’

126

126

127

127

128

128

129

129

129

129

130

130

‘Jet Fuel’

115

115

115

115

115

116

116

116

117

117

118

118

‘Fuel Oil’

154

154

154

155

155

155

155

156

156

156

155

155

‘Lube Oil’

176

176

177

177

177

178

178

178

178

178

177

178

The following price elasticities apply for all petroleum products:

Relative price change*

Relative change in demand

+6%

-20%

+4%

-12%

+2%

-5%

-2%

+2%

-4%

+5%

-6%

+9%

This means that when the price of petroleum products increases by 6% relative to the market average, demand decreases by 20% relative to average historical data.

Finance

To financially evaluate all transactions, use a discount rate of 5%. The purchase of raw materials and the sale of finished petroleum products assumes the availability of the full amount of necessary payments. In case of a shortage of working capital, the oil refinery has the opportunity to obtain bank loans every period on the following conditions:

Name

Term

Interest rate

Maximum amount, $

I

1

6.5

10 000 000

The loan received in the previous period and the interest accrued on it must be paid in the current period.

Objective

How should the operations of the refinery be planned in order to maximize total profit?

Let’s start by downloading the necessary extensions and libraries

# Install dependencies
%pip install -q amplpy pandas
import pandas as pd
import numpy as np
# Google Colab & Kaggle integration
from amplpy import AMPL, ampl_notebook

ampl = ampl_notebook(
    modules=["highs"],  # modules to install
    license_uuid="default",  # license to use
)  # instantiate AMPL object and register magics

3. Formulation of the model

%%writefile oil_refining.mod
reset ;
### SETS
 set CRUD ;       # Types of crude oil (Crude1, Crude2)
 set DIST ;       # Distillation products
 set REF ;        # Reforming products
 set CRACK ;      # Cracking products
 set LUBR ;       # Lubricating products
 set PROD ;       # Final products
 set STAT ;       # Delivery stations
 set D_MODE ;     # Operating modes of the equipment of the Distillation installation
 set R_MODE ;     # Operating modes of the equipment of the Reforming installation
 set CR_MODE ;    # Operating modes of the equipment of the Cracking installation
 set L_MODE ;     # Operating modes of the equipment of the Lubrication process
 set POLLUT ;     # Types of pollutants

 set DISTILLATION within {D_MODE, CRUD, DIST} ;   # Pairs of the Distillation process
 set REFORMING within {R_MODE, DIST, REF} ;       # Pairs of the Reforming process
 set DIST_R := setof{(m,d,r) in REFORMING}(d) ;   # List of included components
 set CRACKING within {CR_MODE, DIST, CRACK} ;     # Pairs of the Cracking process
 set DIST_CR := setof{(m,d,cr) in CRACKING}(d) ;  # List of included components
 set LUBRICATING within {L_MODE, DIST, LUBR} ;    # Pairs of the Lubricating process
 set DIST_L := setof{(m,d,l) in LUBRICATING}(d) ; # List of included components
 set BLENDING within                              # Pairs of Intermediate and final products involved in blending
  {DIST union REF union CRACK union LUBR, PROD} ;
 set INTERMED:= setof{(i,j) in BLENDING}i ;       # Set of Intermediate products before blending

### PARAMETERS
  param nPeriod >= 0 ;                            # Number of weeks in the planning period
  param nPeriodByYear >= 0 ;                      # Number of nPeriods in the Year

 ## Crude oil
  param crude_Min{CRUD} >= 0 ;                    # Minimum supply limits for each crude oil type
  param crude_Max{c in CRUD} >= crude_Min[c] ;    # Maximum supply limits for each crude oil type
  param crude_Cost{CRUD, 1..nPeriod} >= 0 ;       # Cost of crude oil per week

 ## Distillation
  param distill_Yield{DISTILLATION} >= 0 ;        # Yield of products
  param distill_Pollute{D_MODE, CRUD, POLLUT} ;   # Pollutant emissions
  param distill_Cost{D_MODE, CRUD} >= 0 ;         # Cost of process
  param distill_Waste_Cost{D_MODE, CRUD} >= 0 ;   # Residue disposal cost
  param distill_Equipment_Setup_Period{D_MODE} >= 0 ;   # Equipment setup period
  param distill_Equipment_Setup_Cost{D_MODE} >= 0 ;     # Equipment setup cost
  param distill_Cap_Max{D_MODE} >= 0 ;            # Maximum capacity

 ## Reforming
  param reform_Yield{REFORMING} >= 0 ;            # Yield of products
  param reform_Pollute{R_MODE, DIST_R, POLLUT} ;  # Pollutant emissions
  param reform_Cost{R_MODE, DIST_R} >= 0 ;        # Cost of process
  param reform_Waste_Cost{R_MODE, DIST_R} >= 0 ;  # Residue disposal cost
  param reform_Cap_Max{R_MODE} >= 0 ;             # Maximum capacity
  param reform_Equipment_Setup_Period{R_MODE} >= 0 ;  # Equipment setup period
  param reform_Equipment_Setup_Cost{R_MODE} >= 0 ;# Equipment setup cost

 ## Cracking
  param crack_Yield{CRACKING} >= 0 ;              # Yield of products
  param crack_Pollute{CR_MODE, DIST, POLLUT} ;    # Pollutant emissions
  param crack_Cost{CR_MODE, DIST} >= 0 ;          # Cost of process
  param crack_Waste_Cost{CR_MODE, DIST_CR} >= 0 ; # Residue disposal cost
  param crack_Cap_Max{CR_MODE} >= 0 ;             # Maximum capacity
  param crack_Equipment_Setup_Period{CR_MODE} >= 0 ;  # Equipment setup period
  param crack_Equipment_Setup_Cost{CR_MODE} >=0 ; # Equipment setup cost

 ## Lubrication
  param lube_Yield{LUBRICATING} >= 0 ;            # Yield of products
  param lube_Pollute{L_MODE, DIST_L, POLLUT} ;    # Pollutant emissions
  param lube_Waste_Cost{L_MODE, DIST_L} >= 0 ;    # Residue disposal cost
  param lube_Cost{L_MODE, DIST_L} >= 0 ;          # Cost of process
  param lube_Cap_Max{L_MODE} >= 0 ;               # Maximum production of lube oil
  param lube_Equipment_Setup_Period{L_MODE} >= 0 ;# Equipment setup period
  param lube_Equipment_Setup_Cost{L_MODE} >= 0 ;  # Equipment setup cost
  param lube_limit_Min >= 0 ;                     # Minimum production of lube oil
  param lube_limit_Max >= lube_limit_Min ;        # Maximum production of lube oil

 ## Intermediate components
  param Intermed_Octane{INTERMED} >= 0 ;          # Octane number
  param Intermed_VaporPressure{INTERMED} >= 0 ;   # Vapor pressure

 ## Blending
  param blending_Cost{PROD} >= 0 ;                # Cost of blending

 ## Products
  param prod_Octane_Min{PROD} >= 0 ;              # Minimum octane number for final products
  param prod_VaporPressure_Max{PROD} >= 0 ;       # Maximum vapor pressure for final products
  param prod_Premium_Regular_Gas_Min >= 0 ;       # Minimum production of premium gas
  param prod_FuelOil_Ratio{INTERMED} >= 0 ;       # Ratios for fuel oil production components

 ## Storage
  param storage_Capacity{PROD} >=0 ;              # Storage capacity for each product
  param storage_Cost{PROD} >= 0 ;                 # Storage cost per product
  param storage_Waste{PROD} >= 0 ;                # Waste during storage

 ## Product delivery
  param delivery_Cost{PROD, STAT} >= 0 ;          # Delivery cost per product to each station

 ## Plant
  param plant_Shutdown_Period >= 0 ;              # Equipment setup period
  param plant_Shutdown_Cost >= 0 ;                # Equipment setup cost
  param plant_Const_Cost >= 0 ;                   # Plant fixed costs

 ## Market
  param seasonal_Base_Demand{PROD, 1..nPeriod} >= 0 ; # Base demand for products per week.
  param seasonal_Base_Price {PROD, 1..nPeriod} >= 0 ; # Base price for products per week.
  # Price elasticity
  param nStep integer > 0 ;                       # Number of steps for price elasticity
  param price_nStep_Value{1..nStep+1} >= 0 ;      # Step values for price elasticity
  param demand_nStep_Value{1..nStep+1} >= 0 ;     # Step values for price elasticity

 ## Finance
  param discount_Rate >= 0 ;                      # Discount rate for future cash flows
  param initial_Cash  >= 0 ;                      # Initial cash available

 ## Loans
  set LOANS;                                      # Set of loan periods
  set LOAN_param;                                 # Parameters of loans (term, interest, Max_Money)
  param loan{LOANS, LOAN_param} >= 0 ;            # Conditions for obtaining credit

### VARIABLES
 ## Plant working
  var Plant_Working{t in 1..nPeriod} binary;                  # 1 if the plant is running. 0 if the plant is shutdown

 ## Distillation
  var Crude_Supply{D_MODE, CRUD, 1..nPeriod} >= 0 ;           # Amount of crude supplied
  var Distill_X{D_MODE, 1..nPeriod} binary ;                  # Additional binary variable for selecting the operating mode of the equipment

 ## Reforming
  var Distill_to_Reforming{R_MODE, DIST_R, 1..nPeriod} >= 0 ; # Quantity of distillation products used for Reforming
  var Reform_X{R_MODE, 1..nPeriod} binary ;                   # Additional binary variable for selecting the operating mode of the equipment

 ## Cracking
  var Distill_to_Cracking{CR_MODE, DIST_CR, 1..nPeriod} >= 0 ;# Quantity of distillation products used for Cracking
  var Cracking_X{CR_MODE, 1..nPeriod} binary ;                # Additional binary variable for selecting the operating mode of the equipment


 ## Lubricating
  var Distill_to_Lubricating{L_MODE, DIST_L, 1..nPeriod} >= 0 ;# Quantity of distillation products used for Lubricating
  var Lubricating_X{L_MODE, 1..nPeriod} binary ;              # Additional binary variable for selecting the operating mode of the equipment

 ## Blending:
  var Blending{BLENDING, 1..nPeriod} >= 0 ;                   # Amount of ingredients mixed to obtain final products

 ## Demand
  var Demand{PROD, STAT, 1..nPeriod, 1..nStep} >= 0 ;         # Demand for each pr oduct at each station over time
  var X{PROD, STAT, 1..nPeriod, 1..nStep} binary ;            # Additional binary variable for demand steps (1 if for product p in period t the price is selected at step nStep, or 0 otherwise)

 ## Storage
  var Storage_Fraction{p in PROD, t in 1..nPeriod} =          # Amount of each product in Storage each period
    sum{tt in 1..t} (sum{(i,p) in BLENDING} Blending[i,p,tt]
    - sum{s in STAT, n in 1..nStep} Demand[p,s,tt,n]) * (1-storage_Waste[p]) ;

 ## Loan
 # Amount of loan taken every period
  var Loan_In{l in LOANS, 1..nPeriod-1} >= 0 , <= loan[l,'Max_Money'] ;

 # Amount of loan taken every period
  var Loan_Out{l in LOANS, t in 2..nPeriod} = Loan_In[l,t-1] * (1+loan[l, 'interest']/nPeriodByYear);

 ## Pollutant emissions
 var Waste_Pollutant{p in POLLUT, t in 1..nPeriod} =
  # Pollution from waste disposal from the Distillation process
  sum{m in D_MODE, c in CRUD} Crude_Supply[m,c,t] * (1 - sum{d in DIST}distill_Yield[m,c,d]) * distill_Pollute[m,c,p]
  # Pollution from waste disposal from the Reforming process
  + sum{m in R_MODE, c in DIST_R} Distill_to_Reforming[m,c,t] * (1 - sum{d in REF} reform_Yield[m,c,d]) * reform_Pollute[m,c,p]
  # Pollution from waste disposal from the Cracking process
  + sum{m in CR_MODE, c in DIST_CR} Distill_to_Cracking[m,c,t] * (1 - sum{d in CRACK} crack_Yield[m,c,d]) * crack_Pollute[m,c,p]
  # Pollution from waste disposal from the Lubricating process
  + sum{m in L_MODE, c in DIST_L} Distill_to_Lubricating[m,c,t] * (1 - sum{d in LUBR} lube_Yield[m,c,d]) * lube_Pollute[m,c,p];

 ## Cash flow with incomes and costs
  var CashFlow{t in 1..nPeriod} =
   # sales income
    sum{p in PROD, s in STAT, n in 1..nStep} Demand[p,s,t,n] * (seasonal_Base_Price[p,t] * price_nStep_Value[n] - delivery_Cost[p,s])
   # minus the cost of purchasing crude oil	+ the costs of the Distillation process	+ costs for disposal of waste from the Distillation process
    - sum{m in D_MODE, c in CRUD} Crude_Supply[m,c,t] * (crude_Cost[c,t] + distill_Cost[m,c] + (1 - sum{d in DIST}distill_Yield[m,c,d]) * distill_Waste_Cost[m,c])
   # minus the costs of the Reforming process	+ costs for disposal of waste from the Reforming process
    - sum{m in R_MODE, c in DIST_R} Distill_to_Reforming[m,c,t] * (reform_Cost[m,c] + (1 - sum{d in REF} reform_Yield[m,c,d]) * reform_Waste_Cost[m,c])
   # minus the costs of the Cracking process	+ costs for disposal of waste from the Cracking process
    - sum{m in CR_MODE, c in DIST_CR} Distill_to_Cracking[m,c,t] * (crack_Cost[m,c] + (1 - sum{d in CRACK} crack_Yield[m,c,d]) * crack_Waste_Cost[m,c])
   # minus the costs of the Lubricating process	+ costs for disposal of waste from the Lubricating process
    - sum{m in L_MODE, c in DIST_L} Distill_to_Lubricating[m,c,t] * (lube_Cost[m,c] + (1 - sum{d in LUBR} lube_Yield[m,c,d]) * lube_Waste_Cost[m,c])
   # minus the costs of reconfiguring equipment (if available)
    - (if t > 1 then          /*Nonliner piece*/
      # Distillation equipment
        sum{m in D_MODE} (if Distill_X[m,t] - Distill_X[m,t-1] > 0 then distill_Equipment_Setup_Cost[m] else 0)
      # Reforming equipment
        + sum{m in R_MODE} (if Reform_X[m,t] - Reform_X[m,t-1] > 0 then reform_Equipment_Setup_Cost[m] else 0)
      # Cracking equipment
        + sum{m in CR_MODE} (if Cracking_X[m,t] - Cracking_X[m,t-1] > 0 then crack_Equipment_Setup_Cost[m] else 0)
      # Lubricating equipment
        + sum{m in L_MODE}(if Lubricating_X[m,t] - Lubricating_X[m,t-1] > 0 then lube_Equipment_Setup_Cost[m] else 0)
        else 0)
   # minus the cost of the Blending
    - sum{(i,p) in BLENDING} Blending[i,p,t] * blending_Cost[p]
    # minus cost of shutdown
    - (1 - Plant_Working[t]) * plant_Shutdown_Cost
   # minus the storage cost
    - sum{p in PROD} Storage_Fraction[p,t] * storage_Cost[p]
   # minus fixed plant costs
    - plant_Const_Cost
   # plus the amount of the loan received
    + (if t = nPeriod then 0 else sum{l in LOANS} Loan_In[l,t])
   # minus the amount of repaid loans with accrued interest
    - (if t = 1 then 0  else sum{l in LOANS} Loan_Out[l,t]);

### OBJECTIVE FUNCTION
 # Maximize the total profit considering all incomes and costs, discounted by the discount rate
  maximize Total_Profit:
    sum{t in 1..nPeriod} CashFlow[t] / (1 + discount_Rate/nPeriodByYear)^t ;

### CONSTRAINTS
 subject to
 ## Distillation
  # Ensure that total supply of crude oil does not exceed the maximum capacity.
  Crude_Supply_Min_Max{c in CRUD, t in 1..nPeriod}:crude_Min[c] <= sum{m in D_MODE} Crude_Supply[m,c,t] <= crude_Max[c];

  # Ensure distillation capacity does not exceed the maximum. Сapacity is reduced during downtime caused by equipment reconfiguring.
  DistillCapacity_Max {m in D_MODE, t in 1..nPeriod}: sum{c in CRUD} Crude_Supply[m,c,t] <= distill_Cap_Max [m]
    /* Nonliner piece*/ * (if t > 1 then (if Distill_X[m,t] > Distill_X[m,t-1] then 1 - distill_Equipment_Setup_Period[m] else 1) else 1) ;

  # Ensure only one mode per period
  ForEachPeriodOnlyOne_Distill_X { t in 1..nPeriod}: sum{m in D_MODE} Distill_X[m,t] <= 1 ;

  # Ensure that Crude_Supply > 0 only when Distill_X > 0
  Distill_{m in D_MODE, t in 1..nPeriod}: sum{c in CRUD} Crude_Supply[m,c,t] <= Distill_X[m,t] * 10e5;

 ## Reforming
  # Ensure reforming capacity does not exceed the maximum. Сapacity is reduced during downtime caused by equipment reconfiguring.
  Reforming_Capacity_Max {m in R_MODE, t in 1..nPeriod}: sum{c in DIST_R} Distill_to_Reforming[m,c,t] <= reform_Cap_Max[m]
    /* Nonliner piece*/ * (if t > 1 then (if Reform_X[m,t] > Reform_X[m,t-1] then 1 - reform_Equipment_Setup_Period[m] else 1) else 1);

  # Ensure only one mode per period
  ForEachPeriodOnlyOne_Reform_X { t in 1..nPeriod}:  sum{m in R_MODE} Reform_X[m,t] <= 1 ;

  # Ensure that Distill_to_Reforming > 0 only when Reform_X > 0
  Reform_{m in R_MODE, t in 1..nPeriod}:sum{c in DIST_R}Distill_to_Reforming[m,c,t] <= Reform_X[m,t] * 10e5;

 ## Cracking
  # Ensure cracking capacity does not exceed the maximum. Сapacity is reduced during downtime caused by equipment reconfiguring.
  CrackingCapacity_Max {m in CR_MODE, t in 1..nPeriod}: sum{c in DIST_CR} Distill_to_Cracking[m,c,t] <= crack_Cap_Max[m]
    /* Nonliner piece*/ * (if t > 1 then (if Cracking_X[m,t] > Cracking_X[m,t-1] then 1 - crack_Equipment_Setup_Period[m] else 1) else 1);

  # Ensure only one mode per period
  ForEachPeriodOnlyOne_Cracking_X { t in 1..nPeriod}: sum{m in CR_MODE} Cracking_X[m,t] <= 1 ;

  # Ensure that Distill_to_Cracking > 0 only when Cracking_X > 0
  Cracking_{m in CR_MODE, t in 1..nPeriod}: sum{c in DIST_CR} Distill_to_Cracking[m,c,t] <= Cracking_X[m,t] * 10e5;

 ## Lubricating
  # Ensure cracking does not exceed the minimum & maximum volume
  Lube_Oil_Min_Max {t in 1..nPeriod}:
  lube_limit_Min <= sum{(m,d,l)in LUBRICATING} Distill_to_Lubricating[m,d,t] * lube_Yield[m,d,l] <= lube_limit_Max  ;

  # Сapacity is reduced during downtime caused by equipment reconfiguring.
  Lube_Oil_Capacity_Max {m in L_MODE, t in 1..nPeriod}: sum{c in DIST_L} Distill_to_Lubricating[m,c,t] <= lube_Cap_Max[m]
    /* Nonliner piece*/ * (if t > 1 then (if Lubricating_X[m,t] > Lubricating_X[m,t-1] then 1 - lube_Equipment_Setup_Period[m] else 1) else 1); # Nonliner piece

  # Ensure only one mode per period
  ForEachPeriodOnlyOne_Lubricating_X { t in 1..nPeriod}: sum{m in L_MODE} Lubricating_X[m,t] <= 1 ;

  # Ensure that Distill_to_Lubricating> 0 only when Lubricating_X > 0
  Lubricating_{m in L_MODE, t in 1..nPeriod}: sum{c in DIST_L}Distill_to_Lubricating[m,c,t] <= Lubricating_X[m,t] * 10e5;

 ## Blending
  PremiumRegularGasRatio {t in 1..nPeriod}:                   # Premium gasoline production: at least 40% of regular gasoline production
    sum{(i,p) in BLENDING: p='Premium Gasoline'} Blending[i,p,t] >=
    sum{(i,p) in BLENDING: p='Regular Gasoline'} Blending[i,p,t] * prod_Premium_Regular_Gas_Min ;

  OctaneNumberMin {p in PROD, t in 1..nPeriod: p = 'Premium Gasoline'}:# Ensure octane number requirements for final products
    sum{(i,p) in BLENDING} Blending[i,p,t] * Intermed_Octane[i] >=
    sum{(ii,p) in BLENDING} Blending[ii,p,t] * prod_Octane_Min[p] ;

  OctaneNumberMin_2 {p in PROD, t in 1..nPeriod: p = 'Regular Gasoline'}:# Ensure octane number requirements for final products
    sum{(i,p) in BLENDING} Blending[i,p,t] * Intermed_Octane[i] >=
    sum{(ii,p) in BLENDING} Blending[ii,p,t] * prod_Octane_Min[p] ;

  VaporPressure_Max {p in PROD, t in 1..nPeriod: p='Jet Fuel'}:# Ensure vapor pressure limits for products
    sum{(i,p) in BLENDING} Blending[i,p,t] * Intermed_VaporPressure[i] <=
    sum{(i,p) in BLENDING} Blending[i,p,t] * prod_VaporPressure_Max[p] ;

  FuelOilRatio {(i,p) in BLENDING, t in 1..nPeriod: p = 'Fuel Oil'}:   # Maintain the correct ratio for fuel oil production
    Blending['Residuum',p, t] = Blending[i,p,t] * prod_FuelOil_Ratio[i] ;

 ## Storage
 # Ensure storage fractions are non-negative and within capacity
  Storage_non_negative {p in PROD, t in 1..nPeriod}:
    0 <= Storage_Fraction[p,t] <= storage_Capacity[p];

 ## Financial calculations
  CashFlow_Balance{t in 1..nPeriod}:                  # Cash flow balance
    initial_Cash
    + sum{tt in 1..t}CashFlow[tt] >= 0;

 ## Ensure sufficient distillation output
  Distillation_Out {d in DIST, t in 1..nPeriod}:
    sum{m in D_MODE, c in CRUD} Crude_Supply[m,c,t] * distill_Yield[m,c,d]
    >=
    sum{m in R_MODE, dd in DIST_R: dd=d} Distill_to_Reforming[m,dd,t]
    + sum{m in CR_MODE, dd in DIST_CR: dd=d} Distill_to_Cracking[m,dd,t]
    + sum{m in L_MODE, dd in DIST_L: dd=d} Distill_to_Lubricating[m,dd,t] ;

 ## Balance INTERMED products before blending
  INTERMED_Balance{i in INTERMED, t in 1..nPeriod}:
    sum{(i,p) in BLENDING} Blending[i,p,t] <=
    sum{(m,c,d) in DISTILLATION:d=i} Crude_Supply[m,c,t] * distill_Yield[m,c,d]

    - sum{m in R_MODE, d in DIST_R: d=i} Distill_to_Reforming[m,d,t]
    - sum{m in CR_MODE, d in DIST_CR: d=i} Distill_to_Cracking[m,d,t]
    - sum{m in L_MODE, d in DIST_L: d=i} Distill_to_Lubricating[m,d,t]

    + sum{(m,d,r) in REFORMING: r=i} Distill_to_Reforming[m,d,t] * reform_Yield[m,d,r]
    + sum{(m,d,cr) in CRACKING: cr=i} Distill_to_Cracking[m,d,t] * crack_Yield[m,d,cr]
    + sum{(m,d,l) in LUBRICATING: l=i} Distill_to_Lubricating[m,d,t] * lube_Yield[m,d,l] ;

 ## Prices elastisity
  ForEachPeriodOnlyOne_X {p in PROD, s in STAT, t in 1..nPeriod}:
    sum{i in 1..nStep} X [p,s,t,i] = 1 ;            # Ensure only one price per product per period

  # Double restriction. Ensure demand is within the range dictated by price steps.
  # The constraint of type min must be set after solving a model without this constraint. #Use Min constraint after ensuring that it does not conflict with other model constraints.
   Demand_Min {p in PROD, s in STAT, t in 1..nPeriod, n in 1..nStep}:
     Demand[p,s,t,n] >= demand_nStep_Value[n] * X[p,s,t,n] * seasonal_Base_Demand[p,t];
  Demand_Max {p in PROD, s in STAT, t in 1..nPeriod, n in 1..nStep}:
    Demand[p,s,t,n] <= X[p,s,t,n] * demand_nStep_Value[n+1] * seasonal_Base_Demand[p,t];

 ## Shutdown contstraints
  # The number of working periods is equal to the total number of periods under consideration minus the duration of the planned suspension
  Plant_Working_nPeriods: sum{t in 1..nPeriod - plant_Shutdown_Period + 1} Plant_Working[t] = nPeriod - plant_Shutdown_Period;

  # Additionally, there is a restriction in case of a longer (more than 1 period) plant shutdown.
  Shutdown_Distill{t in 1..nPeriod - plant_Shutdown_Period + 1}:
    sum{m in D_MODE, c in CRUD, tt in 0..plant_Shutdown_Period-1} Crude_Supply[m,c,t+tt] <= Plant_Working[t] * 10e5;
Writing oil_refining.mod

5. Solve problem

# Download data from a repository
import requests

data_filename = "oil_refining.dat"

url = "https://raw.githubusercontent.com/ampl/colab.ampl.com/master/authors/mikhail/Petroleum_refining/oil_refining.dat"

response = requests.get(url)
if response.status_code == 200:
    with open(data_filename, 'wb') as file:
        file.write(response.content)
    print(f"File downloaded successfully as {data_filename}")
else:
    print(f"Failed to download file. Status code: {response.status_code}")
File downloaded successfully as oil_refining.dat
# Read model
ampl.read('oil_refining.mod')
# Read data
ampl.read('oil_refining.dat')

# Solve the Mixed-Integer Linear problem with Highs solver
ampl.option['highs_options'] = 'outlev=1 timelim=60'
ampl.solve(solver='highs')
HiGHS 1.7.1:   tech:outlev = 1
  lim:time = 60
Running HiGHS 1.7.1 (git hash: dcf3813): Copyright (c) 2024 HiGHS under MIT licence terms
Coefficient ranges:
  Matrix [5e-03, 1e+06]
  Cost   [1e-03, 1e+05]
  Bound  [4e-01, 1e+07]
  RHS    [1e+00, 3e+06]
Presolving model
1466 rows, 1322 cols, 13150 nonzeros  0s
1399 rows, 1255 cols, 13247 nonzeros  0s

Solving MIP model with:
   1399 rows
   1255 cols (491 binary, 9 integer, 0 implied int., 755 continuous)
   13247 nonzeros

        Nodes      |    B&B Tree     |            Objective Bounds              |  Dynamic Constraints |       Work      
     Proc. InQueue |  Leaves   Expl. | BestBound       BestSol              Gap |   Cuts   InLp Confl. | LpIters     Time

         0       0         0   0.00%   321884160.1052  -inf                 inf        0      0      0         0     0.1s
         0       0         0   0.00%   990392.889203   -inf                 inf        0      0      6      1095     0.2s
 L       0       0         0   0.00%   923417.4411     685848.771966     34.64%      213     70     56      1268     4.0s

0.2% inactive integer columns, restarting
Model after restart has 1394 rows, 1251 cols (489 bin., 9 int., 0 impl., 753 cont.), and 13197 nonzeros

         0       0         0   0.00%   923359.161705   685848.771966     34.63%       43      0      0      5278     4.8s
         0       0         0   0.00%   923359.161705   685848.771966     34.63%       43     37      9      5454     4.8s
         0       0         0   0.00%   923359.161705   685848.771966     34.63%       74     39    221     11620    14.6s
         9       0         1   0.39%   923359.161705   685848.771966     34.63%       79     39    326     19629    20.4s

Solving report
  Status            Optimal
  Primal bound      685848.771966
  Dual bound        685848.771966
  Gap               0% (tolerance: 0.01%)
  Solution status   feasible
                    685848.771966 (objective)
                    0 (bound viol.)
                    9.43689570931e-11 (int. viol.)
                    0 (row viol.)
  Timing            22.22 (total)
                    0.08 (presolve)
                    0.00 (postsolve)
  Nodes             19
  LP iterations     26803 (total)
                    9045 (strong br.)
                    376 (separation)
                    14619 (heuristics)
HiGHS 1.7.1: optimal solution; objective 685848.772
26803 simplex iterations
19 branching nodes
absmipgap=1.16415e-10, relmipgap=0
------------ WARNINGS ------------
WARNING:  "Tolerance violations"
  Type                         MaxAbs [Name]   MaxRel [Name]
  objective(s)                 1E+05           2E-01         
Documentation: mp.ampl.com/modeling-tools.html#automatic-solution-check.

6. Display the solution

%%ampl_eval

display Plant_Working, Crude_Supply, Distill_to_Reforming, Distill_to_Cracking, Distill_to_Lubricating,  Blending, OctaneNumberMin, VaporPressure_Max, Storage_Fraction, Demand, Loan_In, Loan_Out, CashFlow, Waste_Pollutant;

printf {p in PROD, t in 1..nPeriod}: "Octane number for products: %u %s %6.2f\n", t, p, sum{(i,p) in BLENDING} Blending[i,p,t] * Intermed_Octane[i] / sum{(ii,p) in BLENDING}(if Blending[ii,p,t] = 0 then 1 else Blending[ii,p,t]);

printf {p in PROD, t in 1..nPeriod: p='Jet Fue'}: "Vapor pressure limits of product Jet Fuel: %u %s %6.2f\n", t, p, sum{(i,p) in BLENDING} Blending[i,p,t] * Intermed_VaporPressure[i] / (if sum{(ii,p) in BLENDING} Blending[ii,p,t] = 0 then 1 else sum{(ii,p) in BLENDING}Blending[ii,p,t]) ;

printf {t in 1..nPeriod}: "Premium / Regular percentage: %u %6.2f\n", t,
sum{(i,p) in BLENDING: p ='Premium Gasoline'} Blending[i,p,t] / (if sum{(ii,pp) in BLENDING: pp ='Regular Gasoline'}Blending[ii,pp,t] = 0 then 1 else sum{(ii,pp) in BLENDING: pp ='Regular Gasoline'}Blending[ii,pp,t]) ;

printf {(i,p) in BLENDING, t in 1..nPeriod: p='Fuel Oil'}: "Production Fuel Oil ratio: %u   %s %6.2f\n", t, i,
    Blending[i,p,t] / (if Blending['Residuum',p,t] = 0 then 1 else Blending['Residuum',p,t]);
Plant_Working [*] :=
 1  1
 2  1
 3  1
 4  1
 5  1
 6  0
 7  1
 8  1
 9  1
10  1
11  1
12  1
;

:                                            Crude_Supply      :=
D1                  Crude1             1        0
D1                  Crude1             2        0
D1                  Crude1             3        0
D1                  Crude1             4        0
D1                  Crude1             5        7.27963e-11
D1                  Crude1             6       -1.31266e-09
D1                  Crude1             7     9497.48
D1                  Crude1             8    10039.4
D1                  Crude1             9     5225.87
D1                  Crude1             10       0
D1                  Crude1             11       0
D1                  Crude1             12       0
D1                  Crude2             1        0
D1                  Crude2             2        0
D1                  Crude2             3        0
D1                  Crude2             4        0
D1                  Crude2             5        0
D1                  Crude2             6       -2.58296e-10
D1                  Crude2             7    25000
D1                  Crude2             8    25000
D1                  Crude2             9    25000
D1                  Crude2             10   25000
D1                  Crude2             11   23925.5
D1                  Crude2             12   25000
D2                  Crude1             1    25711.8
D2                  Crude1             2    25849.3
D2                  Crude1             3    25711.8
D2                  Crude1             4    40000
D2                  Crude1             5    40000
D2                  Crude1             6       -1.28057e-10
D2                  Crude1             7        3.63798e-11
D2                  Crude1             8        0
D2                  Crude1             9        0
D2                  Crude1             10       0
D2                  Crude1             11       0
D2                  Crude1             12       0
D2                  Crude2             1        0
D2                  Crude2             2        0
D2                  Crude2             3        0
D2                  Crude2             4     2083.63
D2                  Crude2             5     7000
D2                  Crude2             6        1.39423e-10
D2                  Crude2             7        2.18279e-11
D2                  Crude2             8        2.18279e-11
D2                  Crude2             9        1.45519e-11
D2                  Crude2             10      -7.27596e-12
D2                  Crude2             11       0
D2                  Crude2             12      -7.27596e-12
;
# $1 = Distill_to_Reforming
# $2 = Distill_to_Cracking
:                                                 $1            $2       :=
CR1                 'Heavy Oil'        1           .            0
CR1                 'Heavy Oil'        2           .            0
CR1                 'Heavy Oil'        3           .            0
CR1                 'Heavy Oil'        4           .            0
CR1                 'Heavy Oil'        5           .            0
CR1                 'Heavy Oil'        6           .            0
CR1                 'Heavy Oil'        7           .            0
CR1                 'Heavy Oil'        8           .            0
CR1                 'Heavy Oil'        9           .            0
CR1                 'Heavy Oil'        10          .            0
CR1                 'Heavy Oil'        11          .            0
CR1                 'Heavy Oil'        12          .            0
CR1                 'Light Oil'        1           .            0
CR1                 'Light Oil'        2           .            0
CR1                 'Light Oil'        3           .            0
CR1                 'Light Oil'        4           .            0
CR1                 'Light Oil'        5           .            0
CR1                 'Light Oil'        6           .            0
CR1                 'Light Oil'        7           .            0
CR1                 'Light Oil'        8           .            0
CR1                 'Light Oil'        9           .            0
CR1                 'Light Oil'        10          .            0
CR1                 'Light Oil'        11          .            0
CR1                 'Light Oil'        12          .            0
CR2                 'Heavy Oil'        1           .            0
CR2                 'Heavy Oil'        2           .            0
CR2                 'Heavy Oil'        3           .            0
CR2                 'Heavy Oil'        4           .            0
CR2                 'Heavy Oil'        5           .            0
CR2                 'Heavy Oil'        6           .            0
CR2                 'Heavy Oil'        7           .            0
CR2                 'Heavy Oil'        8           .            0
CR2                 'Heavy Oil'        9           .            0
CR2                 'Heavy Oil'        10          .            0
CR2                 'Heavy Oil'        11          .            0
CR2                 'Heavy Oil'        12          .            0
CR2                 'Light Oil'        1           .         1167.61
CR2                 'Light Oil'        2           .         1035.18
CR2                 'Light Oil'        3           .         1167.61
CR2                 'Light Oil'        4           .         4932.84
CR2                 'Light Oil'        5           .         3912.38
CR2                 'Light Oil'        6           .            0
CR2                 'Light Oil'        7           .         2877.14
CR2                 'Light Oil'        8           .         2883.48
CR2                 'Light Oil'        9           .         2431.72
CR2                 'Light Oil'        10          .         1433.34
CR2                 'Light Oil'        11          .          503.968
CR2                 'Light Oil'        12          .          598.348
R1                  'Heavy Naphta'     1       0                 .
R1                  'Heavy Naphta'     2       0                 .
R1                  'Heavy Naphta'     3       0                 .
R1                  'Heavy Naphta'     4       0                 .
R1                  'Heavy Naphta'     5       0                 .
R1                  'Heavy Naphta'     6       0                 .
R1                  'Heavy Naphta'     7       0                 .
R1                  'Heavy Naphta'     8       0                 .
R1                  'Heavy Naphta'     9       0                 .
R1                  'Heavy Naphta'     10      0                 .
R1                  'Heavy Naphta'     11      0                 .
R1                  'Heavy Naphta'     12      0                 .
R1                  'Light Naphta'     1       0                 .
R1                  'Light Naphta'     2       0                 .
R1                  'Light Naphta'     3       0                 .
R1                  'Light Naphta'     4       0                 .
R1                  'Light Naphta'     5       0                 .
R1                  'Light Naphta'     6       0                 .
R1                  'Light Naphta'     7       0                 .
R1                  'Light Naphta'     8       0                 .
R1                  'Light Naphta'     9       0                 .
R1                  'Light Naphta'     10      0                 .
R1                  'Light Naphta'     11      0                 .
R1                  'Light Naphta'     12      0                 .
R1                  'Medium Naphta'    1       0                 .
R1                  'Medium Naphta'    2       0                 .
R1                  'Medium Naphta'    3       0                 .
R1                  'Medium Naphta'    4       0                 .
R1                  'Medium Naphta'    5       0                 .
R1                  'Medium Naphta'    6       0                 .
R1                  'Medium Naphta'    7       0                 .
R1                  'Medium Naphta'    8       0                 .
R1                  'Medium Naphta'    9       0                 .
R1                  'Medium Naphta'    10      0                 .
R1                  'Medium Naphta'    11      0                 .
R1                  'Medium Naphta'    12      0                 .
R2                  'Heavy Naphta'     1    3486.33              .
R2                  'Heavy Naphta'     2    3531.92              .
R2                  'Heavy Naphta'     3    3486.33              .
R2                  'Heavy Naphta'     4    5887.8               .
R2                  'Heavy Naphta'     5    5659.97              .
R2                  'Heavy Naphta'     6      -2.20109e-10       .
R2                  'Heavy Naphta'     7    4475.33              .
R2                  'Heavy Naphta'     8    4730.96              .
R2                  'Heavy Naphta'     9    4037.92              .
R2                  'Heavy Naphta'     10   3437.19              .
R2                  'Heavy Naphta'     11   3531.93              .
R2                  'Heavy Naphta'     12   3528.82              .
R2                  'Light Naphta'     1       0                 .
R2                  'Light Naphta'     2       0                 .
R2                  'Light Naphta'     3       0                 .
R2                  'Light Naphta'     4       0                 .
R2                  'Light Naphta'     5       0                 .
R2                  'Light Naphta'     6       0                 .
R2                  'Light Naphta'     7       0                 .
R2                  'Light Naphta'     8       0                 .
R2                  'Light Naphta'     9       0                 .
R2                  'Light Naphta'     10      0                 .
R2                  'Light Naphta'     11      0                 .
R2                  'Light Naphta'     12      0                 .
R2                  'Medium Naphta'    1       0                 .
R2                  'Medium Naphta'    2       0                 .
R2                  'Medium Naphta'    3       0                 .
R2                  'Medium Naphta'    4       0                 .
R2                  'Medium Naphta'    5       0                 .
R2                  'Medium Naphta'    6       0                 .
R2                  'Medium Naphta'    7       0                 .
R2                  'Medium Naphta'    8       0                 .
R2                  'Medium Naphta'    9       0                 .
R2                  'Medium Naphta'    10      0                 .
R2                  'Medium Naphta'    11      0                 .
R2                  'Medium Naphta'    12      0                 .
;
# $1 = Distill_to_Lubricating
:                                              $1         Blending       :=
'Cracked gasoline'  'Premium Gasoline' 1        .       132.16
'Cracked gasoline'  'Premium Gasoline' 2        .       351.961
'Cracked gasoline'  'Premium Gasoline' 3        .       396.988
'Cracked gasoline'  'Premium Gasoline' 4        .         0
'Cracked gasoline'  'Premium Gasoline' 5        .         0
'Cracked gasoline'  'Premium Gasoline' 6        .         0
'Cracked gasoline'  'Premium Gasoline' 7        .       978.228
'Cracked gasoline'  'Premium Gasoline' 8        .         0
'Cracked gasoline'  'Premium Gasoline' 9        .       826.785
'Cracked gasoline'  'Premium Gasoline' 10       .       487.337
'Cracked gasoline'  'Premium Gasoline' 11       .         0
'Cracked gasoline'  'Premium Gasoline' 12       .       203.438
'Cracked gasoline'  'Regular Gasoline' 1        .       264.828
'Cracked gasoline'  'Regular Gasoline' 2        .         0
'Cracked gasoline'  'Regular Gasoline' 3        .         0
'Cracked gasoline'  'Regular Gasoline' 4        .      1677.17
'Cracked gasoline'  'Regular Gasoline' 5        .      1330.21
'Cracked gasoline'  'Regular Gasoline' 6        .         0
'Cracked gasoline'  'Regular Gasoline' 7        .         0
'Cracked gasoline'  'Regular Gasoline' 8        .       980.384
'Cracked gasoline'  'Regular Gasoline' 9        .         0
'Cracked gasoline'  'Regular Gasoline' 10       .         0
'Cracked gasoline'  'Regular Gasoline' 11       .       171.349
'Cracked gasoline'  'Regular Gasoline' 12       .         0
'Cracked oil'       'Fuel Oil'         1        .       585.634
'Cracked oil'       'Fuel Oil'         2        .       621.108
'Cracked oil'       'Fuel Oil'         3        .       585.634
'Cracked oil'       'Fuel Oil'         4        .      1136.71
'Cracked oil'       'Fuel Oil'         5        .         5.56673
'Cracked oil'       'Fuel Oil'         6        .         0
'Cracked oil'       'Fuel Oil'         7        .       656.387
'Cracked oil'       'Fuel Oil'         8        .       803.122
'Cracked oil'       'Fuel Oil'         9        .       488.458
'Cracked oil'       'Fuel Oil'         10       .        48.0192
'Cracked oil'       'Fuel Oil'         11       .       302.381
'Cracked oil'       'Fuel Oil'         12       .       359.009
'Cracked oil'       'Jet Fuel'         1        .       114.934
'Cracked oil'       'Jet Fuel'         2        .         0
'Cracked oil'       'Jet Fuel'         3        .       114.934
'Cracked oil'       'Jet Fuel'         4        .      1822.99
'Cracked oil'       'Jet Fuel'         5        .      2341.86
'Cracked oil'       'Jet Fuel'         6        .         2.99352e-12
'Cracked oil'       'Jet Fuel'         7        .      1069.9
'Cracked oil'       'Jet Fuel'         8        .       926.969
'Cracked oil'       'Jet Fuel'         9        .       970.574
'Cracked oil'       'Jet Fuel'         10       .       811.987
'Cracked oil'       'Jet Fuel'         11       .         0
'Cracked oil'       'Jet Fuel'         12       .         0
'Heavy Naphta'      'Premium Gasoline' 1        .      1398.92
'Heavy Naphta'      'Premium Gasoline' 2        .        46.5014
'Heavy Naphta'      'Premium Gasoline' 3        .         0
'Heavy Naphta'      'Premium Gasoline' 4        .         0
'Heavy Naphta'      'Premium Gasoline' 5        .         0
'Heavy Naphta'      'Premium Gasoline' 6        .         0
'Heavy Naphta'      'Premium Gasoline' 7        .         0
'Heavy Naphta'      'Premium Gasoline' 8        .      1606.58
'Heavy Naphta'      'Premium Gasoline' 9        .      1458.67
'Heavy Naphta'      'Premium Gasoline' 10       .      1062.81
'Heavy Naphta'      'Premium Gasoline' 11       .         0
'Heavy Naphta'      'Premium Gasoline' 12       .       741.18
'Heavy Naphta'      'Regular Gasoline' 1        .         0
'Heavy Naphta'      'Regular Gasoline' 2        .      1332.94
'Heavy Naphta'      'Regular Gasoline' 3        .      1398.92
'Heavy Naphta'      'Regular Gasoline' 4        .      2108.09
'Heavy Naphta'      'Regular Gasoline' 5        .      3270.03
'Heavy Naphta'      'Regular Gasoline' 6        .        -8.71348e-11
'Heavy Naphta'      'Regular Gasoline' 7        .      1924.16
'Heavy Naphta'      'Regular Gasoline' 8        .       170.345
'Heavy Naphta'      'Regular Gasoline' 9        .        48.5866
'Heavy Naphta'      'Regular Gasoline' 10       .         0
'Heavy Naphta'      'Regular Gasoline' 11       .       774.668
'Heavy Naphta'      'Regular Gasoline' 12       .       230
'Heavy Oil'         'Fuel Oil'         1        .       780.845
'Heavy Oil'         'Fuel Oil'         2        .       828.144
'Heavy Oil'         'Fuel Oil'         3        .       780.845
'Heavy Oil'         'Fuel Oil'         4        .      1515.62
'Heavy Oil'         'Fuel Oil'         5        .         7.42231
'Heavy Oil'         'Fuel Oil'         6        .         0
'Heavy Oil'         'Fuel Oil'         7        .       875.183
'Heavy Oil'         'Fuel Oil'         8        .      1070.83
'Heavy Oil'         'Fuel Oil'         9        .       651.278
'Heavy Oil'         'Fuel Oil'         10       .        64.0256
'Heavy Oil'         'Fuel Oil'         11       .       403.174
'Heavy Oil'         'Fuel Oil'         12       .       478.679
'Heavy Oil'         'Jet Fuel'         1        .      4104.4
'Heavy Oil'         'Jet Fuel'         2        .      4083.22
'Heavy Oil'         'Jet Fuel'         3        .      4104.4
'Heavy Oil'         'Jet Fuel'         4        .      6459.44
'Heavy Oil'         'Jet Fuel'         5        .      8852.58
'Heavy Oil'         'Jet Fuel'         6        .        -3.10085e-10
'Heavy Oil'         'Jet Fuel'         7        .      5774.31
'Heavy Oil'         'Jet Fuel'         8        .      5687.06
'Heavy Oil'         'Jet Fuel'         9        .      5143.9
'Heavy Oil'         'Jet Fuel'         10       .      4685.97
'Heavy Oil'         'Jet Fuel'         11       .      4142.67
'Heavy Oil'         'Jet Fuel'         12       .      4271.32
L1                  Residuum           1       0              .
L1                  Residuum           2       0              .
L1                  Residuum           3       0              .
L1                  Residuum           4       0              .
L1                  Residuum           5       0              .
L1                  Residuum           6       0              .
L1                  Residuum           7       0              .
L1                  Residuum           8       0              .
L1                  Residuum           9       0              .
L1                  Residuum           10      0              .
L1                  Residuum           11      0              .
L1                  Residuum           12      0              .
L2                  Residuum           1    1000              .
L2                  Residuum           2     875.973          .
L2                  Residuum           3    1000              .
L2                  Residuum           4     924.027          .
L2                  Residuum           5    1000              .
L2                  Residuum           6       0              .
L2                  Residuum           7     533.333          .
L2                  Residuum           8     666.667          .
L2                  Residuum           9     800              .
L2                  Residuum           10    933.333          .
L2                  Residuum           11    933.333          .
L2                  Residuum           12    933.333          .
'Light Naphta'      'Premium Gasoline' 1        .       755.487
'Light Naphta'      'Premium Gasoline' 2        .      3101.91
'Light Naphta'      'Premium Gasoline' 3        .         0
'Light Naphta'      'Premium Gasoline' 4        .      2913.97
'Light Naphta'      'Premium Gasoline' 5        .      5370.49
'Light Naphta'      'Premium Gasoline' 6        .         0
'Light Naphta'      'Premium Gasoline' 7        .         0
'Light Naphta'      'Premium Gasoline' 8        .      2282.56
'Light Naphta'      'Premium Gasoline' 9        .         0
'Light Naphta'      'Premium Gasoline' 10       .      1588
'Light Naphta'      'Premium Gasoline' 11       .        74.5326
'Light Naphta'      'Premium Gasoline' 12       .         0
'Light Naphta'      'Regular Gasoline' 1        .      2329.93
'Light Naphta'      'Regular Gasoline' 2        .         0
'Light Naphta'      'Regular Gasoline' 3        .      3085.42
'Light Naphta'      'Regular Gasoline' 4        .      2177.74
'Light Naphta'      'Regular Gasoline' 5        .       409.515
'Light Naphta'      'Regular Gasoline' 6        .        -1.66018e-10
'Light Naphta'      'Regular Gasoline' 7        .      4699.75
'Light Naphta'      'Regular Gasoline' 8        .      2471.38
'Light Naphta'      'Regular Gasoline' 9        .      4272.59
'Light Naphta'      'Regular Gasoline' 10       .      2162
'Light Naphta'      'Regular Gasoline' 11       .      3514.29
'Light Naphta'      'Regular Gasoline' 12       .      3750
'Light Oil'         'Fuel Oil'         1        .       234.253
'Light Oil'         'Fuel Oil'         2        .       248.443
'Light Oil'         'Fuel Oil'         3        .       234.253
'Light Oil'         'Fuel Oil'         4        .       454.685
'Light Oil'         'Fuel Oil'         5        .         2.22669
'Light Oil'         'Fuel Oil'         6        .         0
'Light Oil'         'Fuel Oil'         7        .       262.555
'Light Oil'         'Fuel Oil'         8        .       321.249
'Light Oil'         'Fuel Oil'         9        .       195.383
'Light Oil'         'Fuel Oil'         10       .        19.2077
'Light Oil'         'Fuel Oil'         11       .       120.952
'Light Oil'         'Fuel Oil'         12       .       143.604
'Light Oil'         'Jet Fuel'         1        .      1940.67
'Light Oil'         'Jet Fuel'         2        .      2076.78
'Light Oil'         'Jet Fuel'         3        .      1940.67
'Light Oil'         'Jet Fuel'         4        .         0
'Light Oil'         'Jet Fuel'         5        .      1915.4
'Light Oil'         'Jet Fuel'         6        .        -1.86314e-10
'Light Oil'         'Jet Fuel'         7        .         0
'Light Oil'         'Jet Fuel'         8        .         0
'Light Oil'         'Jet Fuel'         9        .         0
'Light Oil'         'Jet Fuel'         10       .       547.449
'Light Oil'         'Jet Fuel'         11       .      1289.12
'Light Oil'         'Jet Fuel'         12       .      1258.05
'Lube Oil'          'Lube Oil'         1        .       600
'Lube Oil'          'Lube Oil'         2        .       525.584
'Lube Oil'          'Lube Oil'         3        .       600
'Lube Oil'          'Lube Oil'         4        .       554.416
'Lube Oil'          'Lube Oil'         5        .       600
'Lube Oil'          'Lube Oil'         6        .         1.08497e-10
'Lube Oil'          'Lube Oil'         7        .       320
'Lube Oil'          'Lube Oil'         8        .       400
'Lube Oil'          'Lube Oil'         9        .       480
'Lube Oil'          'Lube Oil'         10       .       560
'Lube Oil'          'Lube Oil'         11       .       560
'Lube Oil'          'Lube Oil'         12       .       560
'Medium Naphta'     'Premium Gasoline' 1        .         0
'Medium Naphta'     'Premium Gasoline' 2        .         0
'Medium Naphta'     'Premium Gasoline' 3        .      2262.57
'Medium Naphta'     'Premium Gasoline' 4        .      3406.65
'Medium Naphta'     'Premium Gasoline' 5        .         0
'Medium Naphta'     'Premium Gasoline' 6        .        -1.06411e-10
'Medium Naphta'     'Premium Gasoline' 7        .      3068.38
'Medium Naphta'     'Premium Gasoline' 8        .         0
'Medium Naphta'     'Premium Gasoline' 9        .      1056.35
'Medium Naphta'     'Premium Gasoline' 10       .         0
'Medium Naphta'     'Premium Gasoline' 11       .      2521.69
'Medium Naphta'     'Premium Gasoline' 12       .      1430
'Medium Naphta'     'Regular Gasoline' 1        .      4885.24
'Medium Naphta'     'Regular Gasoline' 2        .      4911.36
'Medium Naphta'     'Regular Gasoline' 3        .      2622.67
'Medium Naphta'     'Regular Gasoline' 4        .      4693.42
'Medium Naphta'     'Regular Gasoline' 5        .      9280
'Medium Naphta'     'Regular Gasoline' 6        .        -2.13285e-10
'Medium Naphta'     'Regular Gasoline' 7        .      5081.11
'Medium Naphta'     'Regular Gasoline' 8        .      8257.89
'Medium Naphta'     'Regular Gasoline' 9        .      6238.83
'Medium Naphta'     'Regular Gasoline' 10       .      6250
'Medium Naphta'     'Regular Gasoline' 11       .      3459.69
'Medium Naphta'     'Regular Gasoline' 12       .      4820
'Reformed gasoline' 'Premium Gasoline' 1        .      1673.44
'Reformed gasoline' 'Premium Gasoline' 2        .       459.624
'Reformed gasoline' 'Premium Gasoline' 3        .      1300.44
'Reformed gasoline' 'Premium Gasoline' 4        .      2826.14
'Reformed gasoline' 'Premium Gasoline' 5        .      1022.95
'Reformed gasoline' 'Premium Gasoline' 6        .        -7.09406e-11
'Reformed gasoline' 'Premium Gasoline' 7        .      1533.18
'Reformed gasoline' 'Premium Gasoline' 8        .      2270.86
'Reformed gasoline' 'Premium Gasoline' 9        .      1938.2
'Reformed gasoline' 'Premium Gasoline' 10       .      1261.85
'Reformed gasoline' 'Premium Gasoline' 11       .      1695.32
'Reformed gasoline' 'Premium Gasoline' 12       .      1693.83
'Reformed gasoline' 'Regular Gasoline' 1        .         0
'Reformed gasoline' 'Regular Gasoline' 2        .      1235.7
'Reformed gasoline' 'Regular Gasoline' 3        .       373
'Reformed gasoline' 'Regular Gasoline' 4        .         0
'Reformed gasoline' 'Regular Gasoline' 5        .      1693.84
'Reformed gasoline' 'Regular Gasoline' 6        .        -3.47119e-11
'Reformed gasoline' 'Regular Gasoline' 7        .       614.976
'Reformed gasoline' 'Regular Gasoline' 8        .         0
'Reformed gasoline' 'Regular Gasoline' 9        .         0
'Reformed gasoline' 'Regular Gasoline' 10       .       388
'Reformed gasoline' 'Regular Gasoline' 11       .         0
'Reformed gasoline' 'Regular Gasoline' 12       .         0
Residuum            'Fuel Oil'         1        .      2342.53
Residuum            'Fuel Oil'         2        .      2484.43
Residuum            'Fuel Oil'         3        .      2342.53
Residuum            'Fuel Oil'         4        .      4546.85
Residuum            'Fuel Oil'         5        .        22.2669
Residuum            'Fuel Oil'         6        .         0
Residuum            'Fuel Oil'         7        .      2625.55
Residuum            'Fuel Oil'         8        .      3212.49
Residuum            'Fuel Oil'         9        .      1953.83
Residuum            'Fuel Oil'         10       .       192.077
Residuum            'Fuel Oil'         11       .      1209.52
Residuum            'Fuel Oil'         12       .      1436.04
Residuum            'Jet Fuel'         1        .         0
Residuum            'Jet Fuel'         2        .         0
Residuum            'Jet Fuel'         3        .         0
Residuum            'Jet Fuel'         4        .         0
Residuum            'Jet Fuel'         5        .      5087.73
Residuum            'Jet Fuel'         6        .        -3.80169e-10
Residuum            'Jet Fuel'         7        .      1075.79
Residuum            'Jet Fuel'         8        .       425.974
Residuum            'Jet Fuel'         9        .       925.53
Residuum            'Jet Fuel'         10       .      1874.59
Residuum            'Jet Fuel'         11       .       728.205
Residuum            'Jet Fuel'         12       .       630.631
;

:                     OctaneNumberMin VaporPressure_Max  Storage_Fraction    :=
'Fuel Oil'         1          .                .            143.195
'Fuel Oil'         2          .                .            715.037
'Fuel Oil'         3          .                .           1048.14
'Fuel Oil'         4          .                .           5089.97
'Fuel Oil'         5          .                .           2373.81
'Fuel Oil'         6          .                .             -4.54747e-13
'Fuel Oil'         7          .                .           2043.65
'Fuel Oil'         8          .                .           4789.96
'Fuel Oil'         9          .                .           4943.84
'Fuel Oil'         10         .                .           2038.62
'Fuel Oil'         11         .                .            750.297
'Fuel Oil'         12         .                .             -5.83896e-10
'Jet Fuel'         1          .                0              0
'Jet Fuel'         2          .                0             -7.27596e-12
'Jet Fuel'         3          .                0              3.63798e-12
'Jet Fuel'         4          .                0            362.071
'Jet Fuel'         5          .                0           7992
'Jet Fuel'         6          .                0             -4.91127e-11
'Jet Fuel'         7          .                0             -4.00178e-11
'Jet Fuel'         8          .                0             -6.45741e-11
'Jet Fuel'         9          .                0             -4.36557e-11
'Jet Fuel'         10         .                0             -1.82192e-11
'Jet Fuel'         11         .                0             -6.45741e-11
'Jet Fuel'         12         .                0             -9.31255e-11
'Lube Oil'         1          .                .            199.9
'Lube Oil'         2          .                .            325.421
'Lube Oil'         3          .                .            365.401
'Lube Oil'         4          .                .            359.82
'Lube Oil'         5          .                .            399.8
'Lube Oil'         6          .                .              3.58114e-12
'Lube Oil'         7          .                .              9.66338e-13
'Lube Oil'         8          .                .              5.51381e-12
'Lube Oil'         9          .                .              3.63798e-12
'Lube Oil'         10         .                .              3.86535e-12
'Lube Oil'         11         .                .              3.63798e-12
'Lube Oil'         12         .                .              3.63798e-12
'Premium Gasoline' 1          0                .             -2.72848e-12
'Premium Gasoline' 2          0                .             -1.81899e-12
'Premium Gasoline' 3          0                .             -2.72848e-12
'Premium Gasoline' 4          0                .           5171.21
'Premium Gasoline' 5          0                .           7158.66
'Premium Gasoline' 6          0                .           1017.14
'Premium Gasoline' 7          0                .              3.36513e-11
'Premium Gasoline' 8          0                .              2.63753e-11
'Premium Gasoline' 9          0                .              3.27418e-11
'Premium Gasoline' 10         0                .              2.09184e-11
'Premium Gasoline' 11         0                .            330.553
'Premium Gasoline' 12         0                .              3.09228e-11
'Regular Gasoline' 1          .                .              0
'Regular Gasoline' 2          .                .              1.81899e-12
'Regular Gasoline' 3          .                .              1.81899e-12
'Regular Gasoline' 4          .                .           2906.59
'Regular Gasoline' 5          .                .          10778.4
'Regular Gasoline' 6          .                .             -1.27329e-11
'Regular Gasoline' 7          .                .             -2.72848e-11
'Regular Gasoline' 8          .                .              2.00089e-11
'Regular Gasoline' 9          .                .              1.81899e-11
'Regular Gasoline' 10         .                .              3.63798e-11
'Regular Gasoline' 11         .                .              2.72848e-11
'Regular Gasoline' 12         .                .              2.72848e-11
;

Demand ['Fuel Oil',Station1,*,*]
:     1      2          3         4   5   6    :=
1       0   3800    0             0   0   0
2       0   3610    0             0   0   0
3       0   3610    0             0   0   0
4       0   3610    0             0   0   0
5       0   2755    0             0   0   0
6       0   2375    0             0   0   0
7       0   2375   -5.16758e-13   0   0   0
8       0   2660    0             0   0   0
9       0   3135    0             0   0   0
10      0   3230    0             0   0   0
11      0   3325    0             0   0   0
12   3168      0    0             0   0   0

 ['Jet Fuel',Station1,*,*]
:      1          2             3        4   5   6    :=
1     6160   0              0            0   0   0
2     6160   0              0            0   0   0
3     6160   0              0            0   0   0
4     7920   0              0            0   0   0
5    10560   0              0            0   0   0
6     8000   0              0            0   0   0
7     7920   0              0            0   0   0
8     7040   0              0            0   0   0
9     7040   0              0            0   0   0
10    7920   0             -9.9851e-12   0   0   0
11    6160   0              0            0   0   0
12    6160   9.46141e-12    0            0   0   0

 ['Lube Oil',Station1,*,*]
:     1    2   3   4   5   6    :=
1    400   0   0   0   0   0
2    400   0   0   0   0   0
3    560   0   0   0   0   0
4    560   0   0   0   0   0
5    560   0   0   0   0   0
6    400   0   0   0   0   0
7    320   0   0   0   0   0
8    400   0   0   0   0   0
9    480   0   0   0   0   0
10   560   0   0   0   0   0
11   560   0   0   0   0   0
12   560   0   0   0   0   0

 ['Premium Gasoline',Station1,*,*]
:     1     2   3   4   5   6    :=
1    3960   0   0   0   0   0
2    3960   0   0   0   0   0
3    3960   0   0   0   0   0
4    3960   0   0   0   0   0
5    4400   0   0   0   0   0
6    6160   0   0   0   0   0
7    6600   0   0   0   0   0
8    6160   0   0   0   0   0
9    5280   0   0   0   0   0
10   4400   0   0   0   0   0
11   3960   0   0   0   0   0
12   4400   0   0   0   0   0

 ['Regular Gasoline',Station1,*,*]
:      1     2   3   4   5   6    :=
1     7480   0   0   0   0   0
2     7480   0   0   0   0   0
3     7480   0   0   0   0   0
4     7744   0   0   0   0   0
5     8096   0   0   0   0   0
6    10800   0   0   0   0   0
7    12320   0   0   0   0   0
8    11880   0   0   0   0   0
9    10560   0   0   0   0   0
10    8800   0   0   0   0   0
11    7920   0   0   0   0   0
12    8800   0   0   0   0   0
;

:      Loan_In  Loan_Out    :=
I 1          0      .
I 2          0         0
I 3          0         0
I 4          0         0
I 5    1326110         0
I 6          0   1333300
I 7          0         0
I 8          0         0
I 9          0         0
I 10         0         0
I 11         0         0
I 12      .            0
;

CashFlow [*] :=
 1     80369.8
 2     51996
 3     46748.7
 4  -1588420
 5   -590698
 6   2134110
 7     14722.9
 8   -232698
 9     73064.3
10    345713
11     93547.6
12    200758
;

Waste_Pollutant [*,*] (tr)
:      hydrocarbon      'sulfur dioxide'    :=
1    290583             430374
2    288496             425586
3    290583             430374
4    480456             703234
5    482872             698860
6        -1.55711e-08       -2.25528e-08
7    324788             479531
8    340582             506003
9    291768             437185
10   240317             365653
11   233689             357689
12   237640             362257
;

Octane number for products: 1 Premium Gasoline  93.98
Octane number for products: 2 Premium Gasoline  93.98
Octane number for products: 3 Premium Gasoline  93.95
Octane number for products: 4 Premium Gasoline  93.98
Octane number for products: 5 Premium Gasoline  93.96
Octane number for products: 6 Premium Gasoline  -0.00
Octane number for products: 7 Premium Gasoline  93.97
Octane number for products: 8 Premium Gasoline  93.97
Octane number for products: 9 Premium Gasoline  93.98
Octane number for products: 10 Premium Gasoline  93.98
Octane number for products: 11 Premium Gasoline  93.96
Octane number for products: 12 Premium Gasoline  93.98
Octane number for products: 1 Regular Gasoline  83.98
Octane number for products: 2 Regular Gasoline  83.98
Octane number for products: 3 Regular Gasoline  83.99
Octane number for products: 4 Regular Gasoline  83.99
Octane number for products: 5 Regular Gasoline  84.00
Octane number for products: 6 Regular Gasoline  -0.00
Octane number for products: 7 Regular Gasoline  83.99
Octane number for products: 8 Regular Gasoline  83.99
Octane number for products: 9 Regular Gasoline  83.98
Octane number for products: 10 Regular Gasoline  83.98
Octane number for products: 11 Regular Gasoline  83.99
Octane number for products: 12 Regular Gasoline  83.98
Octane number for products: 1 Jet Fuel   0.00
Octane number for products: 2 Jet Fuel   0.00
Octane number for products: 3 Jet Fuel   0.00
Octane number for products: 4 Jet Fuel   0.00
Octane number for products: 5 Jet Fuel   0.00
Octane number for products: 6 Jet Fuel   0.00
Octane number for products: 7 Jet Fuel   0.00
Octane number for products: 8 Jet Fuel   0.00
Octane number for products: 9 Jet Fuel   0.00
Octane number for products: 10 Jet Fuel   0.00
Octane number for products: 11 Jet Fuel   0.00
Octane number for products: 12 Jet Fuel   0.00
Octane number for products: 1 Fuel Oil   0.00
Octane number for products: 2 Fuel Oil   0.00
Octane number for products: 3 Fuel Oil   0.00
Octane number for products: 4 Fuel Oil   0.00
Octane number for products: 5 Fuel Oil   0.00
Octane number for products: 6 Fuel Oil   0.00
Octane number for products: 7 Fuel Oil   0.00
Octane number for products: 8 Fuel Oil   0.00
Octane number for products: 9 Fuel Oil   0.00
Octane number for products: 10 Fuel Oil   0.00
Octane number for products: 11 Fuel Oil   0.00
Octane number for products: 12 Fuel Oil   0.00
Octane number for products: 1 Lube Oil   0.00
Octane number for products: 2 Lube Oil   0.00
Octane number for products: 3 Lube Oil   0.00
Octane number for products: 4 Lube Oil   0.00
Octane number for products: 5 Lube Oil   0.00
Octane number for products: 6 Lube Oil   0.00
Octane number for products: 7 Lube Oil   0.00
Octane number for products: 8 Lube Oil   0.00
Octane number for products: 9 Lube Oil   0.00
Octane number for products: 10 Lube Oil   0.00
Octane number for products: 11 Lube Oil   0.00
Octane number for products: 12 Lube Oil   0.00
Premium / Regular percentage: 1   0.53
Premium / Regular percentage: 2   0.53
Premium / Regular percentage: 3   0.53
Premium / Regular percentage: 4   0.86
Premium / Regular percentage: 5   0.40
Premium / Regular percentage: 6   0.35
Premium / Regular percentage: 7   0.45
Premium / Regular percentage: 8   0.52
Premium / Regular percentage: 9   0.50
Premium / Regular percentage: 10   0.50
Premium / Regular percentage: 11   0.54
Premium / Regular percentage: 12   0.46
Production Fuel Oil ratio: 1   Light Oil   0.10
Production Fuel Oil ratio: 2   Light Oil   0.10
Production Fuel Oil ratio: 3   Light Oil   0.10
Production Fuel Oil ratio: 4   Light Oil   0.10
Production Fuel Oil ratio: 5   Light Oil   0.10
Production Fuel Oil ratio: 6   Light Oil   0.00
Production Fuel Oil ratio: 7   Light Oil   0.10
Production Fuel Oil ratio: 8   Light Oil   0.10
Production Fuel Oil ratio: 9   Light Oil   0.10
Production Fuel Oil ratio: 10   Light Oil   0.10
Production Fuel Oil ratio: 11   Light Oil   0.10
Production Fuel Oil ratio: 12   Light Oil   0.10
Production Fuel Oil ratio: 1   Heavy Oil   0.33
Production Fuel Oil ratio: 2   Heavy Oil   0.33
Production Fuel Oil ratio: 3   Heavy Oil   0.33
Production Fuel Oil ratio: 4   Heavy Oil   0.33
Production Fuel Oil ratio: 5   Heavy Oil   0.33
Production Fuel Oil ratio: 6   Heavy Oil   0.00
Production Fuel Oil ratio: 7   Heavy Oil   0.33
Production Fuel Oil ratio: 8   Heavy Oil   0.33
Production Fuel Oil ratio: 9   Heavy Oil   0.33
Production Fuel Oil ratio: 10   Heavy Oil   0.33
Production Fuel Oil ratio: 11   Heavy Oil   0.33
Production Fuel Oil ratio: 12   Heavy Oil   0.33
Production Fuel Oil ratio: 1   Residuum   1.00
Production Fuel Oil ratio: 2   Residuum   1.00
Production Fuel Oil ratio: 3   Residuum   1.00
Production Fuel Oil ratio: 4   Residuum   1.00
Production Fuel Oil ratio: 5   Residuum   1.00
Production Fuel Oil ratio: 6   Residuum   0.00
Production Fuel Oil ratio: 7   Residuum   1.00
Production Fuel Oil ratio: 8   Residuum   1.00
Production Fuel Oil ratio: 9   Residuum   1.00
Production Fuel Oil ratio: 10   Residuum   1.00
Production Fuel Oil ratio: 11   Residuum   1.00
Production Fuel Oil ratio: 12   Residuum   1.00
Production Fuel Oil ratio: 1   Cracked oil   0.25
Production Fuel Oil ratio: 2   Cracked oil   0.25
Production Fuel Oil ratio: 3   Cracked oil   0.25
Production Fuel Oil ratio: 4   Cracked oil   0.25
Production Fuel Oil ratio: 5   Cracked oil   0.25
Production Fuel Oil ratio: 6   Cracked oil   0.00
Production Fuel Oil ratio: 7   Cracked oil   0.25
Production Fuel Oil ratio: 8   Cracked oil   0.25
Production Fuel Oil ratio: 9   Cracked oil   0.25
Production Fuel Oil ratio: 10   Cracked oil   0.25
Production Fuel Oil ratio: 11   Cracked oil   0.25
Production Fuel Oil ratio: 12   Cracked oil   0.25

7. Further steps

Here is a list of steps required to successfully implement the results of mathematical optimization into the refinery production:

  • Verify Solution Accuracy

    • Check Constraints

    • Validate Assumptions

    • Cross-Check with Historical Data

  • Sensitivity Analysis

    • Analyze how changes in key parameters (e.g., crude oil prices, demand forecasts) affect the solution

  • Scenario Analysis

    • Evaluate the solution under different scenarios (e.g., market fluctuations, supply disruptions)

  • Risk Management

    • Identify Potential Risks: Operational, Market, External

  • Monitoring and Feedback

    • Implementation Monitoring

    • Continuous Improvement

  • Review and Update

    • Post-Implementation Review