transport8 Namespace Reference

Functions

def get_model_text ()
 
def scen_solve (workspace, checkpoint, bmult_list, list_lock, io_lock)
 

Variables

 ws = GamsWorkspace(system_directory = sys.argv[1])
 
 cp = ws.add_checkpoint()
 
 t8 = ws.add_job_from_string(get_model_text())
 
 checkpoint
 
list bmult_list = [ 1.3, 1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6 ]
 
 list_lock = threading.Lock()
 
 io_lock = threading.Lock()
 
int nr_workers = 2
 
dictionary threads = {}
 
 target
 
 scen_solve
 
 args
 

Function Documentation

◆ get_model_text()

def transport8.get_model_text ( )

Definition at line 15 of file transport8.py.

15def get_model_text():
16 return '''
17 Sets
18 i canning plants / seattle, san-diego /
19 j markets / new-york, chicago, topeka / ;
20
21 Parameters
22
23 a(i) capacity of plant i in cases
24 / seattle 350
25 san-diego 600 /
26
27 b(j) demand at market j in cases
28 / new-york 325
29 chicago 300
30 topeka 275 / ;
31
32 Table d(i,j) distance in thousands of miles
33 new-york chicago topeka
34 seattle 2.5 1.7 1.8
35 san-diego 2.5 1.8 1.4 ;
36
37 Scalar f freight in dollars per case per thousand miles /90/ ;
38 Scalar bmult demand multiplier /1/;
39
40 Parameter c(i,j) transport cost in thousands of dollars per case ;
41
42 c(i,j) = f * d(i,j) / 1000 ;
43
44 Variables
45 x(i,j) shipment quantities in cases
46 z total transportation costs in thousands of dollars ;
47
48 Positive Variable x ;
49
50 Equations
51 cost define objective function
52 supply(i) observe supply limit at plant i
53 demand(j) satisfy demand at market j ;
54
55 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
56
57 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
58
59 demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ;
60
61 Model transport /all/ ;
62'''
63
64
def get_model_text()
Definition: warehouse.py:17

◆ scen_solve()

def transport8.scen_solve (   workspace,
  checkpoint,
  bmult_list,
  list_lock,
  io_lock 
)

Definition at line 65 of file transport8.py.

References scen_solve.

65def scen_solve(workspace, checkpoint, bmult_list, list_lock, io_lock):
66 list_lock.acquire()
67 mi = checkpoint.add_modelinstance()
68 list_lock.release()
69 bmult = mi.sync_db.add_parameter("bmult", 0, "demand multiplier")
70 opt = ws.add_options()
71 opt.all_model_types = "cplexd"
72
73 # instantiate the GAMSModelInstance and pass a model definition and GAMSModifier to declare bmult mutable
74 mi.instantiate("transport use lp min z", GamsModifier(bmult), opt)
75 bmult.add_record().value = 1.0
76
77 while True:
78 # dynamically get a bmult value from the queue instead of passing it to the different threads at creation time
79 list_lock.acquire()
80 if 0 == len(bmult_list):
81 list_lock.release()
82 return
83 b = bmult_list.pop()
84 list_lock.release()
85 bmult.first_record().value = b
86 mi.solve()
87
88 # we need to make the ouput a critical section to avoid messed up report informations
89 io_lock.acquire()
90 print("Scenario bmult=" + str(b) + ":")
91 print(" Modelstatus: " + str(mi.model_status))
92 print(" Solvestatus: " + str(mi.solver_status))
93 print(" Obj: " + str(mi.sync_db.get_variable("z").find_record().level))
94 io_lock.release()
95
def scen_solve(workspace, checkpoint, bmult_list, list_lock, io_lock)
Definition: transport8.py:65

Variable Documentation

◆ args

transport8.args

Definition at line 118 of file transport8.py.

◆ bmult_list

list transport8.bmult_list = [ 1.3, 1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6 ]

Definition at line 108 of file transport8.py.

◆ checkpoint

transport8.checkpoint

Definition at line 106 of file transport8.py.

◆ cp

transport8.cp = ws.add_checkpoint()

Definition at line 102 of file transport8.py.

◆ io_lock

transport8.io_lock = threading.Lock()

Definition at line 112 of file transport8.py.

◆ list_lock

transport8.list_lock = threading.Lock()

Definition at line 111 of file transport8.py.

◆ nr_workers

int transport8.nr_workers = 2

Definition at line 115 of file transport8.py.

◆ scen_solve

transport8.scen_solve

Definition at line 118 of file transport8.py.

Referenced by scen_solve().

◆ t8

transport8.t8 = ws.add_job_from_string(get_model_text())

Definition at line 105 of file transport8.py.

◆ target

transport8.target

Definition at line 118 of file transport8.py.

◆ threads

dictionary transport8.threads = {}

Definition at line 116 of file transport8.py.

◆ ws

transport8.ws = GamsWorkspace(system_directory = sys.argv[1])

Definition at line 98 of file transport8.py.