special_values.py
Go to the documentation of this file.
8
9from __future__ import print_function
10from gams import *
11import sys
12import math
13
15 return '''
16Scalar GUndef
17 GNA / NA /
18 GPInf / +Inf /
19 GMInf / -Inf /
20 GEps / eps /
21 pythonUndef
22 pythonNA
23 pythonPInf
24 pythonMInf
25 pythonEps ;
26
27$onUndf
28$gdxIn %myDB%
29$load pythonUndef pythonNA pythonPInf pythonMInf pythonEps
30$gdxIn
31
32GUndef = 1/0;
33ExecError = 0;
34
35abort$(GUndef <> pythonUndef) 'pythonUndef not as expected', GUndef, pythonUndef;
36abort$(GNA <> pythonNA ) 'pythonNA not as expected', GNA, pythonNA;
37abort$(GPInf <> pythonPInf ) 'pythonPInf not as expected', GPInf, pythonPInf;
38abort$(GMInf <> pythonMInf ) 'pythonMInf not as expected', GMInf, pythonMInf;
39abort$(GEps <> pythonEps ) 'pythonEps not as expected', GEps, pythonEps;'''
40
41
42if __name__ == "__main__":
43 try:
44 if len(sys.argv) > 1:
45 ws = GamsWorkspace(system_directory = sys.argv[1])
46 else:
47 ws = GamsWorkspace()
48
49 dbIn = ws.add_database(in_model_name = "myDB")
50 dbIn.add_parameter("pythonUndef", 0).add_record().value = SV_UNDEF
51 dbIn.add_parameter("pythonNA", 0).add_record().value = float('nan')
52 dbIn.add_parameter("pythonPInf", 0).add_record().value = float('inf')
53 dbIn.add_parameter("pythonMInf", 0).add_record().value = float('-inf')
54 dbIn.add_parameter("pythonEps", 0).add_record().value = SV_EPS
55
56 gj = ws.add_job_from_string(get_model())
57
58 gj.run(databases = dbIn)
59 dbOut = gj.out_db
60
61 GUndef = dbOut["GUndef"].first_record().value
62 if GUndef != SV_UNDEF:
63 raise Exception("GUndef not as expected: " + str(GUndef))
64 GNA = dbOut["GNA"].first_record().value
65 if not math.isnan(GNA):
66 raise Exception("GNA not as expected: " + str(GNA))
67 GPInf = dbOut["GPInf"].first_record().value
68 if GPInf != float('inf'):
69 raise Exception("GPInf not as expected: " + str(GPInf))
70 GMInf = dbOut["GMInf"].first_record().value
71 if GMInf != float('-inf'):
72 raise Exception("GMInf not as expected: " + str(GMInf))
73 GEps = dbOut["GEps"].first_record().value
74 if GEps != SV_EPS:
75 raise Exception("GEps not as expected: " + GEps);
76 except Exception as e:
77 raise Exception("\n###\n### Exception caught:" + str(e) + "\n###")
78