7from gams
import GamsWorkspace
11<category>:category:</category>
12<solver>:solver:</solver>
13<inputType>GAMS</inputType>
15<priority>short</priority>
16<model><![CDATA[:model:]]></model>
17<wantgdx><![CDATA[yes]]></wantgdx>
18<wantlog><![CDATA[yes]]></wantlog>
19<wantlst><![CDATA[yes]]></wantlst>
22if __name__ ==
"__main__":
23 sys_dir = sys.argv[1]
if len(sys.argv) > 1
else None
24 ws = GamsWorkspace(system_directory=sys_dir)
29 ssl_context = ssl.create_default_context()
32 if sys.platform ==
"win32":
33 ssl_context.load_verify_locations(certifi.where())
35 neos = xmlrpc.client.ServerProxy(
36 "https://neos-server.org:3333", context=ssl_context
38 if "NeosServer is alive" not in neos.ping():
39 raise Exception(
"Could not make connection to NEOS server")
42 xml = xml.replace(
":category:",
"MILP")
43 xml = xml.replace(
":solver:",
"CBC")
44 if "NEOS_EMAIL" in os.environ:
45 xml = xml.replace(
":email:", os.environ[
"NEOS_EMAIL"])
47 raise Exception(
"Environment variable 'NEOS_EMAIL' not found")
48 with open(os.path.join(ws.working_directory, model +
".gms"),
"r")
as f:
49 xml = xml.replace(
":model:", f.read())
51 job_number, password = neos.submitJob(xml)
52 print(f
"Job number: {job_number}")
53 print(f
"Job password: {password}")
56 raise Exception(f
"NEOS server error: {password}")
61 while status !=
"Done":
63 result, offset = neos.getIntermediateResults(job_number, password, offset)
64 result = result.data.decode()
66 if "Composing results." in result:
67 result = result.split(
"Composing results.", 1)[0]
70 status = neos.getJobStatus(job_number, password)
72 result = neos.getFinalResults(job_number, password)
74 f
"{job_number}-{os.path.splitext(os.path.basename(model + '.gms'))[0]}.lst",
"w"
76 f.write(result.data.decode())
77 result = neos.getOutputFile(job_number, password,
"solver-output.zip")
78 with open(f
"{job_number}-solver-output.zip",
"wb")
as f: