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 60 of file transport11.py.

References get_base_model_text().

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

◆ get_base_model_text()

def transport11.get_base_model_text ( )

Definition at line 12 of file transport11.py.

Referenced by create_save_restart().

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

◆ get_model_text()

def transport11.get_model_text ( )

Definition at line 50 of file transport11.py.

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

Variable Documentation

◆ a

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

Definition at line 110 of file transport11.py.

◆ all_model_types

transport11.all_model_types

Definition at line 130 of file transport11.py.

◆ b

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

Definition at line 114 of file transport11.py.

◆ capacity

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

Definition at line 83 of file transport11.py.

◆ cp_base

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

Definition at line 126 of file transport11.py.

◆ d

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

Definition at line 118 of file transport11.py.

◆ databases

transport11.databases

Definition at line 131 of file transport11.py.

◆ db

transport11.db = ws.add_database()

Definition at line 99 of file transport11.py.

◆ demand

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

Definition at line 84 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 86 of file transport11.py.

◆ f

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

Definition at line 122 of file transport11.py.

◆ i

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

Definition at line 102 of file transport11.py.

◆ j

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

Definition at line 106 of file transport11.py.

◆ markets

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

Definition at line 82 of file transport11.py.

◆ opt

transport11.opt = ws.add_options()

Definition at line 128 of file transport11.py.

◆ plants

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

Definition at line 81 of file transport11.py.

◆ t4

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

Definition at line 127 of file transport11.py.

◆ value

transport11.value

Definition at line 112 of file transport11.py.

◆ w_dir

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

Definition at line 78 of file transport11.py.

◆ ws

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

Definition at line 95 of file transport11.py.