equal
deleted
inserted
replaced
1 #!/usr/bin/env python |
|
2 import sys |
|
3 import xmlrpclib |
|
4 import time |
|
5 import re |
|
6 |
|
7 from config import Variables |
|
8 |
|
9 if len(sys.argv) < 3 or len(sys.argv) > 3: |
|
10 sys.stderr.write("Usage: NeosCSDPClient <input_filename> <output_filename>\n") |
|
11 sys.exit(1) |
|
12 |
|
13 neos=xmlrpclib.Server("http://%s:%d" % (Variables.NEOS_HOST, Variables.NEOS_PORT)) |
|
14 |
|
15 xmlfile = open(sys.argv[1],"r") |
|
16 xml_pre = "<document>\n<category>sdp</category>\n<solver>csdp</solver>\n<inputMethod>SPARSE_SDPA</inputMethod>\n<dat><![CDATA[" |
|
17 xml_post = "]]></dat>\n</document>\n" |
|
18 xml = xml_pre |
|
19 buffer = 1 |
|
20 while buffer: |
|
21 buffer = xmlfile.read() |
|
22 xml += buffer |
|
23 xmlfile.close() |
|
24 xml += xml_post |
|
25 |
|
26 (jobNumber,password) = neos.submitJob(xml) |
|
27 |
|
28 if jobNumber == 0: |
|
29 sys.stdout.write("error submitting job: %s" % password) |
|
30 sys.exit(-1) |
|
31 else: |
|
32 sys.stdout.write("jobNumber = %d\tpassword = %s\n" % (jobNumber,password)) |
|
33 |
|
34 offset=0 |
|
35 status="Waiting" |
|
36 while status == "Running" or status=="Waiting": |
|
37 time.sleep(1) |
|
38 (msg,offset) = neos.getIntermediateResults(jobNumber,password,offset) |
|
39 sys.stdout.write(msg.data) |
|
40 status = neos.getJobStatus(jobNumber, password) |
|
41 |
|
42 msg = neos.getFinalResults(jobNumber, password).data |
|
43 result = msg.split("Solution:") |
|
44 |
|
45 sys.stdout.write(result[0]) |
|
46 if len(result) > 1: |
|
47 plain_msg = result[1].strip() |
|
48 if plain_msg != "": |
|
49 output = open(sys.argv[2],"w") |
|
50 output.write(plain_msg) |
|
51 output.close() |
|
52 sys.exit(0) |
|
53 |
|
54 sys.exit(2) |
|
55 |
|
56 |
|