Stochastic Linear Programming (Gas Company)

Now I’m studying Stochastic Linear Programming (SLP). I’m using MATLAB to model some SLP problems.

What’s SLP ? I’ll not discuss here in deep. This entry is referring to a very simple SLP problem, a gas company. Let’s see how I solve this problem on MATLAB.

The original post is from Think Cloud – my new weblog using only in my research topics.

Recourse Action

Recourse is to take corrective action after a random event has taken place.

Two-stage recourse

  • Choose variables, x, to control what happens the 1st stage
  • A random event happens. In the next stage, take some recourse actions, y

Gas Company [Example]

We’re the owner of a gas company. We know the total demand of gas for the current year, while we don’t know such demand. The demand depends on the weather (i.e., very cold = more demand = higher gas cost / unit).

Suppose the current year = normal weather. Three Scenarios for the next year

  1. Normal: p=1/3, Cost = $5 / unit, Demand = 100 units
  2. Cold: p=1/3, Cost = $6 / unit, Demand = 150 units
  3. Very Cold: p=1/3, Cost = $7.5 / unit, Demand = 180 units

Note: storage cost is constant: $1 / gas unit

 

The things we have to make decision

  • How much gas to deliver to customers
  • How much gas to store (for the next year)
    • store too much = more storage cost
    • store too less = more gas cost to buy that time (next year the price might  be higher cuz cold / very cold)

 

Formulating  an Original Linear Programming

The current year (1st stage), we know the demand (100 units) so we purchase exactly 100 for delivery to ours. Then we makes a decision how much gas we will purchase & store for the next year. Then it must be optimal. For original LP, we can determine the next year weather.

Using MATLAB

function [x, fval] = gaslp1(cf, d)

% cs = storage cost = 1 by default
% ct = current cost = 5 by default
% cf = future cost (to buy more for the next year)
% d = demand

    cs = 1.0;
    ct = 5.0;
    f = [cs + ct, cf];
    aeq = [1 1];
    beq = d;
    lb = zeros(2, 1);

    [x, fval] = linprog(f, [], [], aeq, beq, lb, [])
 

From the code, there’re only 2 variables (x, y) we need to solve: x = units for store, y = units for purchase more.

After running, if the next year the weather is

  • Normal: We store 0 for the current year & purchase more 100 for the next year
  • Cold: We store 75 for the current year & purchase more 75 for the next year
  • Very Cold: We store 180 for the current year & purchase more 0 for the next year

 

Formulating  a Stochastic Linear Programming

In fact we cannot predict the weather and demand for the next year. We use SLP to solve the problem.

Using MATLAB

function [x,fval] = gaslp3()
    % cs = storage cost = 1 by default
    % ct = current cost = 5 by default

    cs = 1.0;
    ct = 5.0;

    cf1 = 1/3 * 5.0;
    cf2 = 1/3 * 6.0;
    cf3 = 1/3 * 7.5;
    d1 = 100;
    d2 = 150;
    d3 = 180;

    f = [cs + ct, cf1, cf2, cf3];
    aeq = [1 1 0 0
           1 0 1 0
           1 0 0 1];
    beq = [d1 ; d2 ; d3];
    lb = zeros(4, 1);

    [x,fval] = linprog(f, [], [], aeq, beq, lb, [])
 

From the code, there’re only 4 variables (x, y1, y2, y3) we need to solve: x = units for store, yi = units for purchase more if the weather is i (normal / cold / very cold)

After running, we store 100 units (= x) for the current year. If the next year the weather is

  • Normal: We purchase more 0 for the next year
  • Cold: We purchase more 50 for the next year
  • Very Cold: We purchase more 80 for the next year

This is the optimal decision for uncertainty event!!!

 

Expected-Value Formulation

More detail, please see from the reference. This method finds expected values of demands and gas costs. I just need to publish my MATLAB code here.

function [x,fval] = gaslp2()
    % cs = storage cost = 1 by default
    % ct = current cost = 5 by default
    % Find expected cf and d

    cs = 1.0;
    ct = 5.0;

    cf = 1/3*5 + 1/3*6 + 1/3*7.5;
    d = 1/3*100 + 1/3*150 + 1/3 * 180;

    f = [cs + ct, cf];
    aeq = [1 1];
    beq = d;
    lb = zeros(2, 1);

     [x,fval] = linprog(f, [], [], aeq, beq, lb, [])
 

 

 

Reference

http://www-fp.mcs.anl.gov/OTC/guide/OptWeb/continuous/constrained/stochastic/index.html

One thought on “Stochastic Linear Programming (Gas Company)

  1. p-joy says:

    ดูชื่อแล้ว ตกใจ Stochastic มัน linear ได้ด้วยเหรอ

    ใครหนอช่างตั้งชื่อ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s