EMIS 3360 Fall 2001

Homework Assignment 9 Solutions



The problems may be solved with the AMPL model and data files listed below:

Problem Model File Data File
1) dietmodel.txt diet1.txt
2) dietmodel.txt diet2.txt
3) gtmodel.txt GT1.txt
4) gtmodel.txt GT2.txt

The following is a transcript of an AMPL session in which we use the model and data files described above to solve the homework problems. Command that you would type are shown in bold.

% ampl
ampl: model dietmodel.txt;
ampl: data diet1.txt;
ampl: expand;
minimize Total_Cost:
        Buy['milk'] + 2.5*Buy['cheese'] + 0.75*Buy['apples'];

s.t. Diet['protein']:
        -40*Buy['milk'] - 20*Buy['cheese'] - 10*Buy['apples'] <= -80;

s.t. Diet['vitamin_A']:
        -5*Buy['milk'] - 40*Buy['cheese'] - 30*Buy['apples'] <= -60;

s.t. Diet['vitamin_B']:
        -20*Buy['milk'] - 30*Buy['cheese'] - 40*Buy['apples'] <= -50;

s.t. Diet['vitamin_C']:
        -30*Buy['milk'] - 50*Buy['cheese'] - 60*Buy['apples'] <= -30;

ampl: solve;
CPLEX 6.6.0: 
CPLEX 6.6.0: optimal solution; objective 2.869565217
3 simplex iterations (1 in phase I)

ampl: display Buy;
Buy [*] :=
apples  1.73913
cheese  0
  milk  1.56522
;
Before reading in the data file for problem (diet2.txt), type reset data;.
ampl: reset data;
ampl: data diet2.txt;
ampl: display amt;
amt :=
protein   apples     10
protein   cheese     20
protein   milk       40
protein   powerbar   10
vitamin_A apples     30
vitamin_A cheese     40
vitamin_A milk        5
vitamin_A powerbar    0
vitamin_B apples     40
vitamin_B cheese     30
vitamin_B milk       20
vitamin_B powerbar    0
vitamin_C apples     60
vitamin_C cheese     50
vitamin_C milk       30
vitamin_C powerbar   30
;

ampl: expand;
minimize Total_Cost:
        Buy['milk'] + 2.5*Buy['cheese'] + 0.75*Buy['apples'] + 
        1.5*Buy['powerbar'];

s.t. Diet['protein']:
        -40*Buy['milk'] - 20*Buy['cheese'] - 10*Buy['apples'] - 
        10*Buy['powerbar'] <= -80;

s.t. Diet['vitamin_A']:
        -5*Buy['milk'] - 40*Buy['cheese'] - 30*Buy['apples'] <= -60;

s.t. Diet['vitamin_B']:
        -20*Buy['milk'] - 30*Buy['cheese'] - 40*Buy['apples'] <= -50;

s.t. Diet['vitamin_C']:
        -30*Buy['milk'] - 50*Buy['cheese'] - 60*Buy['apples'] - 
        30*Buy['powerbar'] <= -30;

ampl: solve;
CPLEX 6.6.0: 
CPLEX 6.6.0: optimal solution; objective 2.869565217
3 simplex iterations (1 in phase I)
ampl: display Buy;
Buy [*] :=
  apples  1.73913
  cheese  0
    milk  1.56522
powerbar  0
;

We can use the let command in AMPL to change the cost of powerbars:
ampl: let cost['powerbar'] := 0.75;
ampl: expand Total_Cost;
minimize Total_Cost:
        Buy['milk'] + 2.5*Buy['cheese'] + 0.75*Buy['apples'] + 
        0.75*Buy['powerbar'];

ampl: solve;
CPLEX 6.6.0: 
CPLEX 6.6.0: optimal solution; objective 2.869565217
0 simplex iterations (0 in phase I)
ampl: display Buy;
Buy [*] :=
  apples  1.73913
  cheese  0
    milk  1.56522
powerbar  0
;

ampl: reset;
ampl: model gtmodel.txt;
ampl: data GT1.txt;
ampl: expand;
minimize cost:
        13*x['IE_Junction','A_Station'] + 35*x['IE_Junction','Fine_Place'] + 
        42*x['IE_Junction','Goodville'] + 9*x['IE_Junction','Somewhere_Street']
         + 6*x['Centerville','A_Station'] + 61*x['Centerville','Fine_Place'] + 
        18*x['Centerville','Goodville'] + 
        30*x['Centerville','Somewhere_Street'] + 
        15*x['Wayover_City','A_Station'] + 10*x['Wayover_City','Fine_Place'] + 
        5*x['Wayover_City','Goodville'] + 
        9*x['Wayover_City','Somewhere_Street'] + 
        20*x['Mockingbird','A_Station'] + 15*x['Mockingbird','Fine_Place'] + 
        12*x['Mockingbird','Goodville'] + 
        40*x['Mockingbird','Somewhere_Street'];

s.t. supply['IE_Junction']:
        x['IE_Junction','A_Station'] + x['IE_Junction','Fine_Place'] + 
        x['IE_Junction','Goodville'] + x['IE_Junction','Somewhere_Street'] <= 4;

s.t. supply['Centerville']:
        x['Centerville','A_Station'] + x['Centerville','Fine_Place'] + 
        x['Centerville','Goodville'] + x['Centerville','Somewhere_Street'] <= 1;

s.t. supply['Wayover_City']:
        x['Wayover_City','A_Station'] + x['Wayover_City','Fine_Place'] + 
        x['Wayover_City','Goodville'] + x['Wayover_City','Somewhere_Street']
         <= 2;

s.t. supply['Mockingbird']:
        x['Mockingbird','A_Station'] + x['Mockingbird','Fine_Place'] + 
        x['Mockingbird','Goodville'] + x['Mockingbird','Somewhere_Street'] <= 2;

s.t. demand['A_Station']:
        x['IE_Junction','A_Station'] + x['Centerville','A_Station'] + 
        x['Wayover_City','A_Station'] + x['Mockingbird','A_Station'] >= 1;

s.t. demand['Fine_Place']:
        x['IE_Junction','Fine_Place'] + x['Centerville','Fine_Place'] + 
        x['Wayover_City','Fine_Place'] + x['Mockingbird','Fine_Place'] >= 1;

s.t. demand['Goodville']:
        x['IE_Junction','Goodville'] + x['Centerville','Goodville'] + 
        x['Wayover_City','Goodville'] + x['Mockingbird','Goodville'] >= 1;

s.t. demand['Somewhere_Street']:
        x['IE_Junction','Somewhere_Street'] + 
        x['Centerville','Somewhere_Street'] + 
        x['Wayover_City','Somewhere_Street'] + 
        x['Mockingbird','Somewhere_Street'] >= 1;

ampl: solve;
CPLEX 6.6.0: 
CPLEX 6.6.0: optimal solution; objective 30
6 simplex iterations (4 in phase I)
ampl: display x;
x :=
Centerville  A_Station          1
Centerville  Fine_Place         0
Centerville  Goodville          0
Centerville  Somewhere_Street   0
IE_Junction  A_Station          0
IE_Junction  Fine_Place         0
IE_Junction  Goodville          0
IE_Junction  Somewhere_Street   1
Mockingbird  A_Station          0
Mockingbird  Fine_Place         0
Mockingbird  Goodville          0
Mockingbird  Somewhere_Street   0
Wayover_City A_Station          0
Wayover_City Fine_Place         1
Wayover_City Goodville          1
Wayover_City Somewhere_Street   0
;
The optimal solution sends one locomotive from Centerville to A Station, one from IE Junction to Somewhere Street. It also sends two locomotives from Wayover City: one to Fine Place and one to Goodville. We can display the results in a more compact way by just displaying the non-zero x's:
ampl: display {i in O, j in D: x[i,j] > 0} x[i,j];
x[i,j] :=
Centerville  A_Station          1
IE_Junction  Somewhere_Street   1
Wayover_City Fine_Place         1
Wayover_City Goodville          1
;


ampl: reset data;
ampl: data GT2.txt;
ampl: expand;
minimize cost:
        13*x['IE_Junction','A_Station'] + 35*x['IE_Junction','Fine_Place'] + 
        42*x['IE_Junction','Goodville'] + 9*x['IE_Junction','Somewhere_Street']
         + 6*x['Centerville','A_Station'] + 61*x['Centerville','Fine_Place'] + 
        18*x['Centerville','Goodville'] + 
        30*x['Centerville','Somewhere_Street'] + 
        15*x['Wayover_City','A_Station'] + 10*x['Wayover_City','Fine_Place'] + 
        5*x['Wayover_City','Goodville'] + 
        9*x['Wayover_City','Somewhere_Street'] + 
        20*x['Mockingbird','A_Station'] + 15*x['Mockingbird','Fine_Place'] + 
        12*x['Mockingbird','Goodville'] + 
        40*x['Mockingbird','Somewhere_Street'];

s.t. supply['IE_Junction']:
        x['IE_Junction','A_Station'] + x['IE_Junction','Fine_Place'] + 
        x['IE_Junction','Goodville'] + x['IE_Junction','Somewhere_Street'] <= 4;

s.t. supply['Centerville']:
        x['Centerville','A_Station'] + x['Centerville','Fine_Place'] + 
        x['Centerville','Goodville'] + x['Centerville','Somewhere_Street'] <= 1;

s.t. supply['Wayover_City']:
        x['Wayover_City','A_Station'] + x['Wayover_City','Fine_Place'] + 
        x['Wayover_City','Goodville'] + x['Wayover_City','Somewhere_Street']
         <= 2;

s.t. supply['Mockingbird']:
        x['Mockingbird','A_Station'] + x['Mockingbird','Fine_Place'] + 
        x['Mockingbird','Goodville'] + x['Mockingbird','Somewhere_Street'] <= 2;

s.t. demand['A_Station']:
        x['IE_Junction','A_Station'] + x['Centerville','A_Station'] + 
        x['Wayover_City','A_Station'] + x['Mockingbird','A_Station'] >= 3;

s.t. demand['Fine_Place']:
        x['IE_Junction','Fine_Place'] + x['Centerville','Fine_Place'] + 
        x['Wayover_City','Fine_Place'] + x['Mockingbird','Fine_Place'] >= 2;

s.t. demand['Goodville']:
        x['IE_Junction','Goodville'] + x['Centerville','Goodville'] + 
        x['Wayover_City','Goodville'] + x['Mockingbird','Goodville'] >= 0;

s.t. demand['Somewhere_Street']:
        x['IE_Junction','Somewhere_Street'] + 
        x['Centerville','Somewhere_Street'] + 
        x['Wayover_City','Somewhere_Street'] + 
        x['Mockingbird','Somewhere_Street'] >= 3;

ampl: solve;
CPLEX 6.6.0: 
CPLEX 6.6.0: optimal solution; objective 84
8 simplex iterations (5 in phase I)
ampl: display {i in O, j in D: x[i,j] > 0} x[i,j];
x[i,j] :=
Centerville  A_Station          1
IE_Junction  A_Station          2
IE_Junction  Somewhere_Street   2
Mockingbird  Fine_Place         1
Wayover_City Fine_Place         1
Wayover_City Somewhere_Street   1
;