10from gams
import GamsWorkspace, SV_UNDEF, SV_EPS
27$load PythonUndef PythonNA PythonPInf PythonMInf PythonEps
33abort$(GUndef <> PythonUndef) 'PythonUndef not as expected', GUndef, PythonUndef;
34abort$(GNA <> PythonNA ) 'PythonNA not as expected', GNA, PythonNA;
35abort$(GPInf <> PythonPInf ) 'PythonPInf not as expected', GPInf, PythonPInf;
36abort$(GMInf <> PythonMInf ) 'PythonMInf not as expected', GMInf, PythonMInf;
37abort$(GEps <> PythonEps ) 'PythonEps not as expected', GEps, PythonEps;
40if __name__ ==
"__main__":
41 sys_dir = sys.argv[1]
if len(sys.argv) > 1
else None
42 work_dir = sys.argv[2]
if len(sys.argv) > 2
else None
43 ws = GamsWorkspace(system_directory=sys_dir, working_directory=work_dir)
45 db_in = ws.add_database(in_model_name=
"myDB")
46 db_in.add_parameter(
"PythonUndef", 0).add_record().value = SV_UNDEF
47 db_in.add_parameter(
"PythonNA", 0).add_record().value = float(
"nan")
48 db_in.add_parameter(
"PythonPInf", 0).add_record().value = float(
"inf")
49 db_in.add_parameter(
"PythonMInf", 0).add_record().value = float(
"-inf")
50 db_in.add_parameter(
"PythonEps", 0).add_record().value = SV_EPS
52 job = ws.add_job_from_string(GAMS_MODEL)
53 job.run(databases=db_in)
56 GUndef = db_out[
"GUndef"].first_record().value
57 if GUndef != SV_UNDEF:
58 raise Exception(f
"GUndef not as expected: {GUndef}")
59 GNA = db_out[
"GNA"].first_record().value
60 if not math.isnan(GNA):
61 raise Exception(f
"GNA not as expected: {GNA}")
62 GPInf = db_out[
"GPInf"].first_record().value
63 if GPInf != float(
"inf"):
64 raise Exception(f
"GPInf not as expected: {GPInf}")
65 GMInf = db_out[
"GMInf"].first_record().value
66 if GMInf != float(
"-inf"):
67 raise Exception(f
"GMInf not as expected: {GMInf}")
68 GEps = db_out[
"GEps"].first_record().value
70 raise Exception(f
"GEps not as expected: {GEps}")