transport11 Namespace Reference

Functions

def get_base_model_text ()
 
def get_model_text ()
 
def create_save_restart (cp_file_name)
 

Variables

 w_dir = os.path.join(".", "tmp")
 
list plants = [ "Seattle", "San-Diego" ]
 
list markets = [ "New-York", "Chicago", "Topeka" ]
 
dictionary capacity = { "Seattle": 350.0, "San-Diego": 600.0 }
 
dictionary demand = { "New-York": 325.0, "Chicago": 300.0, "Topeka": 275.0 }
 
dictionary distance
 
 ws = GamsWorkspace(w_dir, sys.argv[1])
 
 db = ws.add_database()
 
 i = db.add_set("i", 1, "canning plants")
 
 j = db.add_set("j", 1, "markets")
 
 a = db.add_parameter_dc("a", [i], "capacity of plant i in cases")
 
 value
 
 b = db.add_parameter_dc("b", [j], "demand at market j in cases")
 
 d = db.add_parameter_dc("d", [i,j], "distance in thousands of miles")
 
 f = db.add_parameter("f", 0, "freight in dollars per case per thousand miles")
 
 cp_base = ws.add_checkpoint("tbase")
 
 t4 = ws.add_job_from_string(get_model_text(), cp_base)
 
 opt = ws.add_options()
 
 all_model_types
 
 databases
 

Function Documentation

◆ create_save_restart()

def transport11.create_save_restart (   cp_file_name)

Definition at line 61 of file transport11.py.

References get_base_model_text().

61def create_save_restart(cp_file_name):
62 if len(sys.argv) > 1:
63 ws = GamsWorkspace(os.path.dirname(cp_file_name), sys.argv[1])
64 else:
65 ws = GamsWorkspace(os.path.dirname(cp_file_name))
66
67 j1 = ws.add_job_from_string(get_base_model_text())
68 opt = ws.add_options()
69
70 opt.action = Action.CompileOnly
71 cp = ws.add_checkpoint(os.path.basename(cp_file_name))
72 j1.run(opt, cp)
73 del opt
74
75
def create_save_restart(cp_file_name)
Definition: transport11.py:61
def get_base_model_text()
Definition: transport11.py:13

◆ get_base_model_text()

def transport11.get_base_model_text ( )

Definition at line 13 of file transport11.py.

Referenced by create_save_restart().

14 return '''
15$onempty
16 Sets
17 i(*) canning plants / /
18 j(*) markets / /
19
20 Parameters
21 a(i) capacity of plant i in cases / /
22 b(j) demand at market j in cases / /
23 d(i,j) distance in thousands of miles / /
24 Scalar f freight in dollars per case per thousand miles /0/;
25
26 Parameter c(i,j) transport cost in thousands of dollars per case ;
27
28 c(i,j) = f * d(i,j) / 1000 ;
29
30 Variables
31 x(i,j) shipment quantities in cases
32 z total transportation costs in thousands of dollars ;
33
34 Positive Variable x ;
35
36 Equations
37 cost define objective function
38 supply(i) observe supply limit at plant i
39 demand(j) satisfy demand at market j ;
40
41 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
42
43 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
44
45 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
46
47 Model transport /all/ ;
48
49 Solve transport using lp minimizing z ; '''
50
def get_base_model_text()
Definition: transport11.py:13

◆ get_model_text()

def transport11.get_model_text ( )

Definition at line 51 of file transport11.py.

51def get_model_text():
52 return '''
53$if not set gdxincname $abort 'no include file name for data file provided'
54$gdxin %gdxincname%
55$onMulti
56$load i j a b d f
57$gdxin
58
59 Display x.l, x.m ; '''
60
def get_model_text()
Definition: warehouse.py:18

Variable Documentation

◆ a

transport11.a = db.add_parameter_dc("a", [i], "capacity of plant i in cases")

Definition at line 111 of file transport11.py.

◆ all_model_types

transport11.all_model_types

Definition at line 131 of file transport11.py.

◆ b

transport11.b = db.add_parameter_dc("b", [j], "demand at market j in cases")

Definition at line 115 of file transport11.py.

◆ capacity

dictionary transport11.capacity = { "Seattle": 350.0, "San-Diego": 600.0 }

Definition at line 84 of file transport11.py.

◆ cp_base

transport11.cp_base = ws.add_checkpoint("tbase")

Definition at line 127 of file transport11.py.

◆ d

transport11.d = db.add_parameter_dc("d", [i,j], "distance in thousands of miles")

Definition at line 119 of file transport11.py.

◆ databases

transport11.databases

Definition at line 132 of file transport11.py.

◆ db

transport11.db = ws.add_database()

Definition at line 100 of file transport11.py.

◆ demand

dictionary transport11.demand = { "New-York": 325.0, "Chicago": 300.0, "Topeka": 275.0 }

Definition at line 85 of file transport11.py.

◆ distance

dictionary transport11.distance
Initial value:
1= { ("Seattle", "New-York") : 2.5,
2 ("Seattle", "Chicago") : 1.7,
3 ("Seattle", "Topeka") : 1.8,
4 ("San-Diego", "New-York") : 2.5,
5 ("San-Diego", "Chicago") : 1.8,
6 ("San-Diego", "Topeka") : 1.4
7 }

Definition at line 87 of file transport11.py.

◆ f

transport11.f = db.add_parameter("f", 0, "freight in dollars per case per thousand miles")

Definition at line 123 of file transport11.py.

◆ i

transport11.i = db.add_set("i", 1, "canning plants")

Definition at line 103 of file transport11.py.

◆ j

transport11.j = db.add_set("j", 1, "markets")

Definition at line 107 of file transport11.py.

◆ markets

list transport11.markets = [ "New-York", "Chicago", "Topeka" ]

Definition at line 83 of file transport11.py.

◆ opt

transport11.opt = ws.add_options()

Definition at line 129 of file transport11.py.

◆ plants

list transport11.plants = [ "Seattle", "San-Diego" ]

Definition at line 82 of file transport11.py.

◆ t4

transport11.t4 = ws.add_job_from_string(get_model_text(), cp_base)

Definition at line 128 of file transport11.py.

◆ value

transport11.value

Definition at line 113 of file transport11.py.

◆ w_dir

transport11.w_dir = os.path.join(".", "tmp")

Definition at line 79 of file transport11.py.

◆ ws

transport11.ws = GamsWorkspace(w_dir, sys.argv[1])

Definition at line 96 of file transport11.py.