GET A QUOTE
SEARCH
Products
GAMS - The Modeling Language
GAMS MIRO
GAMS Engine
GAMSPy
Documentation
GAMS
MIRO
Engine
GAMSPy
Academics
Download
GAMS
MIRO
Engine
GAMSPy
Consulting
Support
Community
Sign-up for our Newsletter
Case Studies
The GAMS Forum
Meet us at a Conference
Read our GAMS Blog
Visit a GAMS Webinar
Take a GAMS Course
About Us
Company Information
The GAMS team
Career
Openings
Internships
Advisory Board
Information Security
Search
×
Search
Case sensitive
Match whole word
GAMS Documentation
Model Library
MIRO Documentation
ENGINE Documentation
Website & Blog
All
User's Guide
Solvers
Tools
APIs
Release Notes
All
Model
Test
Data
EMP
API
FIN
NOA
PSOPT
49 (latest)
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25.1
Version:
Documentation
Preface
Release Notes
Installation and Licensing
Tutorials and Examples
GAMS Language and Environment
Solver Manuals
Tools Manuals
Application Programming Interfaces
Glossary
Bibliograhpy
Model Libraries
GAMS Model Library
GAMS Test Library
GAMS Data Library
GAMS EMP Library
GAMS API Library
FIN Library
NOA Library
PSOPT Library
Index
Help
Hide Table of Contents
GAMS Documentation 49
•
All
Classes
Namespaces
Files
Functions
Variables
Properties
Loading...
Searching...
No Matches
control
transport5.py
Go to the documentation of this file.
1
7
8
import
sys
9
from
gams
import
GamsWorkspace
10
11
GAMS_MODEL =
"""
12
Set
13
i 'canning plants' / seattle, san-diego /
14
j 'markets' / new-york, chicago, topeka /;
15
16
Parameter
17
a(i) 'capacity of plant i in cases'
18
/ seattle 350
19
san-diego 600 /
20
21
b(j) 'demand at market j in cases'
22
/ new-york 325
23
chicago 300
24
topeka 275 /;
25
26
Table d(i,j) 'distance in thousands of miles'
27
new-york chicago topeka
28
seattle 2.5 1.7 1.8
29
san-diego 2.5 1.8 1.4;
30
31
Scalar
32
f 'freight in dollars per case per thousand miles' / 90 /
33
bmult 'demand multiplier' / 1 /;
34
35
Parameter c(i,j) 'transport cost in thousands of dollars per case';
36
c(i,j) = f*d(i,j)/1000;
37
38
Variable
39
x(i,j) 'shipment quantities in cases'
40
z 'total transportation costs in thousands of dollars';
41
42
Positive Variable x;
43
44
Equations
45
cost 'define objective function'
46
supply(i) 'observe supply limit at plant i'
47
demand(j) 'satisfy demand at market j';
48
49
cost.. z =e= sum((i,j), c(i,j)*x(i,j));
50
51
supply(i).. sum(j, x(i,j)) =l= a(i);
52
53
demand(j).. sum(i, x(i,j)) =g= bmult*b(j);
54
55
Model transport /all/;
56
57
Scalar ms 'model status', ss 'solve status';
58
"""
59
60
if
__name__ ==
"__main__"
:
61
sys_dir = sys.argv[1]
if
len(sys.argv) > 1
else
None
62
work_dir = sys.argv[2]
if
len(sys.argv) > 2
else
None
63
ws = GamsWorkspace(system_directory=sys_dir, working_directory=work_dir)
64
65
cp = ws.add_checkpoint()
66
67
# initialize a GamsCheckpoint by running a GamsJob
68
job = ws.add_job_from_string(GAMS_MODEL)
69
job.run(checkpoint=cp)
70
71
bmult = [0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3]
72
73
# create a new GamsJob that is initialized from the GamsCheckpoint
74
for
b
in
bmult:
75
job = ws.add_job_from_string(
76
f
"bmult={b}; solve transport min z use lp; ms=transport.modelstat; ss=transport.solvestat;"
,
77
cp,
78
)
79
job.run()
80
print(f
"Scenario bmult={b}:"
)
81
print(f
" Modelstatus: {job.out_db['ms'].find_record().value}"
)
82
print(f
" Solvestatus: {job.out_db['ss'].find_record().value}"
)
83
print(f
" Obj: {job.out_db['z'].find_record().level}"
)