Transportation Problem (Train vs Truck), Please help me with the error

Sets
    i   Origin plants           / columbus, marshall, cedar_rapids /
    j   Destination plants      / blair, clinton, decatur /
    k   Transport modes         / truck, rail /;

Alias (ii, i), (jj, j);

Parameters
    c(i,j,k)   Unit transport cost ($/ton)
    s(i)       Supply at each origin (tons)
    d(j)       Demand (capacity) at each destination (tons);

Table c(i,j,k)
                            truck     rail
    columbus.blair          11        0
    columbus.clinton        34.19    34.5
    columbus.decatur        49.32    41.87
    marshall.blair          22.5      0
    marshall.clinton        40.05    43.69
    marshall.decatur        56.25    57.35
    cedar_rapids.blair      23.67     0
    cedar_rapids.clinton    11      18.2
    cedar_rapids.decatur    26      25.37;

* Replace 0 with a very high cost (or use equations to restrict routes)
* c(i,j,'rail')$((j='blair')) = 1e6;

s(i) = / columbus 360, marshall 288, cedar_rapids 656 /;
d(j) = / blair 280, clinton 1600, decatur 1500 /;

Variables
    x(i,j,k)   Shipment from i to j via k (tons)
    z          Total transportation cost;

Positive Variable x;

Equations
    obj           Objective function
    supply(i)     Supply constraint at each origin
    demand(j)     Demand constraint at each destination
    blair_min     Min limit to Blair (optional)
    blair_max     Max limit to Blair;

* Objective Function
obj.. z =e= sum((i,j,k), c(i,j,k) * x(i,j,k));

* Supply constraints
supply(i).. sum((j,k), x(i,j,k)) =e= s(i);

* Demand constraints
demand(j).. sum((i,k), x(i,j,k)) =l= d(j);

* Optional Cargill Blair constraint range
blair_min.. sum((i,k)$(j='blair'), x(i,'blair',k)) =g= 250;
blair_max.. sum((i,k)$(j='blair'), x(i,'blair',k)) =l= 280;

Model CornLogisticsLP / all /;
Solve CornLogisticsLP using lp minimizing z;

There were some simple syntax errors. This tutorial may be useful as it walks you through the fundamentals of GAMS based on a simple problem.

I fixed the syntax errors. Please make sure you understand the changes.

I hope this helps!

Sets
    i   Origin plants           / columbus, marshall, cedar_rapids /
    j   Destination plants      / blair, clinton, decatur /
    k   Transport modes         / truck, rail /;

Alias (ii, i), (jj, j);

Parameters
    c(i,j,k)   'Unit transport cost ($/ton)'
    s(i)       'Supply at each origin (tons)' / columbus 360, marshall 288, cedar_rapids 656 /
    d(j)       'Demand (capacity) at each destination (tons)' / blair 280, clinton 1600, decatur 1500 /;

Table c(i,j,k)
                            truck     rail
    columbus.blair          11        0
    columbus.clinton        34.19    34.5
    columbus.decatur        49.32    41.87
    marshall.blair          22.5      0
    marshall.clinton        40.05    43.69
    marshall.decatur        56.25    57.35
    cedar_rapids.blair      23.67     0
    cedar_rapids.clinton    11      18.2
    cedar_rapids.decatur    26      25.37;

* Replace 0 with a very high cost (or use equations to restrict routes)
* c(i,j,'rail')$((j='blair')) = 1e6;


Variables
    x(i,j,k)   Shipment from i to j via k (tons)
    z          Total transportation cost;

Positive Variable x;

Equations
    obj           Objective function
    supply(i)     Supply constraint at each origin
    demand(j)     Demand constraint at each destination
    blair_min     Min limit to Blair (optional)
    blair_max     Max limit to Blair;

* Objective Function
obj.. z =e= sum((i,j,k), c(i,j,k) * x(i,j,k));

* Supply constraints
supply(i).. sum((j,k), x(i,j,k)) =e= s(i);

* Demand constraints
demand(j).. sum((i,k), x(i,j,k)) =l= d(j);

* Optional Cargill Blair constraint range
blair_min.. sum((i,k), x(i,'blair',k)) =g= 250;
blair_max.. sum((i,k), x(i,'blair',k)) =l= 280;

Model CornLogisticsLP / all /;
Solve CornLogisticsLP using lp minimizing z;
1 Like

Thank you for helping. I am trying to simplify the code in a standard Transportation model by following the examples on your website, but I am still getting errors.

Sets
i supply nodes /Blair, Clinton, Decatour/
j demand nodes /Columbus, Marshall, Cedar_rapids/;

Parameters
a(i) supply capacities
/Blair 280
Clinton 1600
Decatour 1500 /

b(j) demands
/Columbus 360
Marshall 288
Cedar_rapids 656
Dummy 2076 /;

Table c1(i,j) transport costs for Rails
Columbus Marshall Cedar_rapids Dummy
Blair 0 34.50 41.87 0
Clinton 0 43.69 57.35 0
Decatour 0 18.20 25.37 0 ;

Table c2(i,j) transport costs for Truck
Columbus Marshall Cedar_rapids Dummy
Blair 11 34.19 49.32 0
Clinton 22 40.05 56.25 0
Decatour 23.67 11 26 0 ;

Positive Variables
x(i,j) flow between supply node i and demand node j;
Variables
y(i,j) whether a ship is bought for the trasfer from i to j
z total cost;
Binary Variables y;
Equations
cost objective function
supply(i) supply constraint
demand(j) demand constraint;

cost.. Z =e= sum ((i,j), c1(i,j) * x(i,j) + c2(i,j) * x(i,j)) ;
supply(i).. sum(j, x(i,j)) =l= a(i);
demand(j).. sum(i, x(i,j)) =g= b(j);

Model TransportaionCorn /all/;

Solve TransportaionCorn using lp minimizing Z;

Display x.l, x.m ;