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 16 of file transport8.py.

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

◆ scen_solve()

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

Definition at line 66 of file transport8.py.

References scen_solve.

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

Variable Documentation

◆ args

transport8.args

Definition at line 119 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 109 of file transport8.py.

◆ checkpoint

transport8.checkpoint

Definition at line 107 of file transport8.py.

◆ cp

transport8.cp = ws.add_checkpoint()

Definition at line 103 of file transport8.py.

◆ io_lock

transport8.io_lock = threading.Lock()

Definition at line 113 of file transport8.py.

◆ list_lock

transport8.list_lock = threading.Lock()

Definition at line 112 of file transport8.py.

◆ nr_workers

int transport8.nr_workers = 2

Definition at line 116 of file transport8.py.

◆ scen_solve

transport8.scen_solve

Definition at line 119 of file transport8.py.

Referenced by scen_solve().

◆ t8

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

Definition at line 106 of file transport8.py.

◆ target

transport8.target

Definition at line 119 of file transport8.py.

◆ threads

dictionary transport8.threads = {}

Definition at line 117 of file transport8.py.

◆ ws

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

Definition at line 99 of file transport8.py.