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 ws = GamsWorkspace(system_directory=sys_dir)
44 db_in = ws.add_database(in_model_name=
"myDB")
45 db_in.add_parameter(
"PythonUndef", 0).add_record().value = SV_UNDEF
46 db_in.add_parameter(
"PythonNA", 0).add_record().value = float(
"nan")
47 db_in.add_parameter(
"PythonPInf", 0).add_record().value = float(
"inf")
48 db_in.add_parameter(
"PythonMInf", 0).add_record().value = float(
"-inf")
49 db_in.add_parameter(
"PythonEps", 0).add_record().value = SV_EPS
51 job = ws.add_job_from_string(GAMS_MODEL)
52 job.run(databases=db_in)
55 GUndef = db_out[
"GUndef"].first_record().value
56 if GUndef != SV_UNDEF:
57 raise Exception(f
"GUndef not as expected: {GUndef}")
58 GNA = db_out[
"GNA"].first_record().value
59 if not math.isnan(GNA):
60 raise Exception(f
"GNA not as expected: {GNA}")
61 GPInf = db_out[
"GPInf"].first_record().value
62 if GPInf != float(
"inf"):
63 raise Exception(f
"GPInf not as expected: {GPInf}")
64 GMInf = db_out[
"GMInf"].first_record().value
65 if GMInf != float(
"-inf"):
66 raise Exception(f
"GMInf not as expected: {GMInf}")
67 GEps = db_out[
"GEps"].first_record().value
69 raise Exception(f
"GEps not as expected: {GEps}")