18if __name__ == 
"__main__":
 
   21    from gams.magic 
import GamsInteractive
 
   22    gams = GamsInteractive()
 
   26    m = gams.exchange_container
 
   29    sites = m.addSet(
'sites', records = [
"1", 
"2", 
"3"])
 
   30    mills = m.addSet(
'mills', records = [
"Mill A",
"Mill B", 
"Mill C"])
 
   31    dist = m.addParameter(
'dist', [sites, mills], records = np.array([[ 8,15,50],
 
   34    supply = m.addParameter(
'supply', [sites], records = np.array([20,30,45]))
 
   35    demand = m.addParameter(
'demand', [mills], records = np.array([30,35,30]))
 
   36    cost_per_haul = m.addParameter(
'cost_per_haul', records = 4)
 
   40    m.addAlias(
'm', mills)
 
   41    ship = m.addVariable(
'ship', 
'positive', [sites, mills])
 
   42    obj = m.addVariable(
'obj', 
'free')
 
   47Equation defcost;   defcost..      cost_per_haul*sum((s,m), ship(s,m)*dist(s,m)) =e= obj; 
   48Equation defsupply; defsupply(s).. sum(m, ship(s,m)) =e= supply(s); 
   49Equation defdemand; defdemand(m).. sum(s, ship(s,m)) =e= demand(m); 
   51model millco / all /;''')
 
   54    gams.gams(
'solve millco min obj using lp;')
 
   57    print(m[
"ship"].pivot())
 
   58    print(f
'Total cost will be {obj.records["level"][0]}')
 
   61    gams.create(
'genmodel')
 
   62    m = gams.exchange_container
 
   65    i = m.addSet(
'i', records = [
'i'+str(i) 
for i 
in range(6)], description = 
'equation index')
 
   66    j = m.addSet(
'j', records = [
'j'+str(j) 
for j 
in range(9)], description = 
'variable index')
 
   67    A = m.addParameter(
'A', [i,j], records = np.array([[1,1,1,0,0,0,0,0,0],
 
   72                                                       [0,0,1,0,0,1,0,0,1]]))
 
   73    b = m.addParameter(
'b', [i], records = np.array([20,30,45,30,35,30]))
 
   74    c = m.addParameter(
'c', [j], records = np.array([8,15,50,10,17,20,30,26,15]))
 
   75    x = m.addVariable(
'x', 
'positive', [j])
 
   76    obj = m.addVariable(
'obj', 
'free')
 
   81Equation defobj; defobj.. 4*sum(j, c(j)*x(j)) =e= obj; 
   82Equation e(i);   e(i)..   sum(j, A(i,j)*x(j)) =e= b(i); 
   87    gams.gams(
'solve gen min obj using lp;')
 
   91    print(f
'Total cost will be {obj.records["level"][0]}')
 
   94    gams.gams_cleanup(closedown=
True)