AMPL Example


The National Steel Corporation (NSC) produces a special-purpose steel that is used in the aircraft and aerospace industries. The marketing department of NSC has received orders for 2400, 2200, 2700 and 2500 tons of steel during each of the next four months. NSC can meet these demands by producing the steel, by drawing from its inventory, or by a combination of both.

The production costs per ton of steel during each of the next four months are projected to be $7400, $7500, $7600 and $7800. Because of these inflationary costs, it might be advantageous for NSC to produce more steel than it needs in a given month and store the excess, although production capacity can never exceed 4000 tons in any month. All production takes place at the beginning of the month and immediately thereafter the demand is met. The remaining steel is then stored in inventory at a holding cost of $120/ton for each month that it remains there.

The current inventory level is 1000 tons and at the end of the fourth month it should be at least 1500 tons. Formulate a mathematical program for NSC that will minimize the total production cost over the next four months while satisfying the demand.

Formulation:

Decision variables
Let Pi be the tons of steel produced in month i.
Let Ii be the inventory at the end of month i.

Objective Function:
production cost = 7400 P1 + 7500 P2 + 7600 P3 + 7800 P4
holding cost = 120 (I1 + I2 + I3+I4).

The objective function is thus 7400 P1 + 7500 P2 + 7600 P3 + 7800 P4 + 120 (I1 + I2 + I3+I4).

Constraints:

First, we have to meet the demand. Thus, we have the following constraints.
P1 + I0 >= 2400
P2 + I1 >= 2200
P3 + I2 >= 2700
P4 + I3 >= 2500

Next, we consider the inventory levels at the end of each month.
I1 = P1 + I0 - 2400
I2 = P2 + I1 - 2200
I3 = P3 + I2 - 2700
I4 = P4 + I3 - 2500
I0 = 1000
I4 >= 1500
Since at most 4000 tons of steel can be produced each month, we have the following constraints.
Pi <= 4000 for i = 1, 2, 3, 4

Finally, we have to ensure that the Pi and Ii variables are all non-negative.
Pi >= 0 for i = 1,2,3,4
Ii >= 0 for i = 1,2,3,4
 

An optimal solution  is shown below.

variable value
P1 2300 
P2 4000 
P3 4000 
P4
I1 900 
I2 2700 
I3 4000 
I4 1500 

 
 

The cost of this production plan is $78,512,000.
 

The file nsc_model_1.txt contains an AMPL model file for this problem and the file nsc_data_1.txt has the corresponding data. You can run the model by logging on to any of the School of Engineering's general use Compaq systems, downloading the two files listed above and typing the commands show in bold, italic type. In the AMPL session shown below, we use the "expand" command to see how AMPL takes the data and model files and creates an LP.

% ampl

ampl: model nsc_model_1.txt;
ampl: data nsc_data_1.txt;
ampl: expand;
minimize cost:
        7400*P[1] + 7500*P[2] + 7600*P[3] + 7800*P[4] + 120*I[1] + 120*I[2] + 
        120*I[3] + 120*I[4];

s.t. demand[1]:
        P[1] + I[0] >= 2400;

s.t. demand[2]:
        P[2] + I[1] >= 2200;

s.t. demand[3]:
        P[3] + I[2] >= 2700;

s.t. demand[4]:
        P[4] + I[3] >= 2500;

s.t. inventory[1]:
        -P[1] - I[0] + I[1] = -2400;

s.t. inventory[2]:
        -P[2] - I[1] + I[2] = -2200;

s.t. inventory[3]:
        -P[3] - I[2] + I[3] = -2700;

s.t. inventory[4]:
        -P[4] - I[3] + I[4] = -2500;

s.t. initial_inventory:
        I[0] = 1000;

s.t. final_inventory:
        I[4] >= 1500;

s.t. max_production[1]:
        P[1] <= 4000;

s.t. max_production[2]:
        P[2] <= 4000;

s.t. max_production[3]:
        P[3] <= 4000;

s.t. max_production[4]:
        P[4] <= 4000;

ampl: solve;
CPLEX 6.6.0: 
CPLEX 6.6.0: optimal solution; objective 78512000
4 simplex iterations (3 in phase I)
ampl: display P;
P [*] :=
1  2300
2  4000
3  4000
4     0
;

ampl: display I;
I [*] :=
0  1000
1   900
2  2700
3  4000
4  1500
;

ampl: quit;
% exit

Run Files

 You may find it convenient to work with a run file instead of typing the same set of commands over and over again. For example, we can write the set of commands used in the previous example in the file nsc_run1.txt. Now, we can solve the LP and save the results to file with a single Unix command as shown below:

% ampl < nsc_run1.txt > nsc.out

% cat nsc.out
minimize cost:
        7400*P[1] + 7500*P[2] + 7600*P[3] + 7800*P[4] + 120*I[1] + 120*I[2] + 
        120*I[3] + 120*I[4];

s.t. demand[1]:
        P[1] + I[0] >= 2400;

s.t. demand[2]:
        P[2] + I[1] >= 2200;

s.t. demand[3]:
        P[3] + I[2] >= 2700;

s.t. demand[4]:
        P[4] + I[3] >= 2500;

s.t. inventory[1]:
        -P[1] - I[0] + I[1] = -2400;

s.t. inventory[2]:
        -P[2] - I[1] + I[2] = -2200;

s.t. inventory[3]:
        -P[3] - I[2] + I[3] = -2700;

s.t. inventory[4]:
        -P[4] - I[3] + I[4] = -2500;

s.t. initial_inventory:
        I[0] = 1000;

s.t. final_inventory:
        I[4] >= 1500;

s.t. max_production[1]:
        P[1] <= 4000;

s.t. max_production[2]:
        P[2] <= 4000;

s.t. max_production[3]:
        P[3] <= 4000;

s.t. max_production[4]:
        P[4] <= 4000;

CPLEX 6.6.0: 
CPLEX 6.6.0: optimal solution; objective 78512000
4 simplex iterations (3 in phase I)
P [*] :=
1  2300
2  4000
3  4000
4     0
;

I [*] :=
0     1000
1   900
2  2700
3  4000
4  1500
;

% exit

Alternative Method to Save Output to a File

The runfile nsc_run1.1.txt illustrates another way to save output to file.


Adding a Second Product

Now suppose that NSC also produces aluminum and has capacity to produce 5000 tons each month (including steel and aluminum).  In addition to the demand for steel listed above, the marketing department of NSC has received orders for 1000, 1200, 1400 and 1600 tons of aluminum during each of the next four months. NSC can meet these demands by producing the aluminum, by drawing from its inventory or by a combination of both. The production costs per ton of aluminum during each of the next four months are projected to be $3400, $3500, $3600 and $3800.  Formulate a mathematical programming model to solve the production planning for NSC if the inventory levels of steel and aluminum must each be 1500 at the end of month 4. Assume that the initial inventories of steel and aluminimum are zero tons each.

The files nsc_model_2.txt and nsc_data_2.txt contain an AMPL model and data file for this version of the problem and the solution (as generated by the runfile nsc_run2.txt can be found in the file nsc2.txt.

To illustrate the flexibility of AMPL, see the data file nsc_data_3.txt for version of the problem with a 12-month planning horizon. The solution (as generated by the runfile nsc_run3.txt can be found in the file nsc3.txt.