source: coopr.misc/trunk/scripts/pyro_mip_server @ 2282

Last change on this file since 2282 was 2282, checked in by jwatson, 12 years ago

Adding propagation of the suffixes solver attribute to the pyro mip servers

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#! /usr/bin/env python
2#
3# pyro_mip_server: A script that sets up a Pyro server for solving MIPs in
4#           a distributed manner.
5#
6#  _________________________________________________________________________
7#
8#  Coopr: A COmmon Optimization Python Repository
9#  Copyright (c) 2008 Sandia Corporation.
10#  This software is distributed under the BSD License.
11#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
12#  the U.S. Government retains certain rights in this software.
13#  For more information, see the FAST README.txt file.
14#  _________________________________________________________________________
15
16import os
17import sys
18from os.path import abspath, dirname
19sys.path.insert(0, dirname(dirname(abspath(__file__))))
20sys.path.append(".")
21
22import coopr.opt
23import pyutilib.pyro
24import sys
25import pyutilib.services
26import pickle
27import os.path
28
29class CooprMIPWorker(pyutilib.pyro.TaskWorker):
30
31    def process(self, data):
32        # construct the solver on this end, based on the input type stored in "data.opt".
33        opt = coopr.opt.SolverFactory(data.opt)
34        if opt is None:
35            raise ValueError, "Problem constructing solver `"+data.opt+"'"
36        opt.mipgap = data.mipgap
37        opt.suffixes = data.suffixes
38
39        # here is where we should set any options required by the solver, available
40        # as specific attributes of the input data object.
41        solver_options = data.solver_options
42        del data.solver_options
43        for key,value in solver_options.items():
44#            print "RECEIVED SOLVER OPTION="+key+"WITH VALUE="+value
45            setattr(opt.options,key,value)
46
47        problem_filename_suffix = os.path.split(data.filename)[1]
48        temp_problem_filename = pyutilib.services.TempfileManager.create_tempfile(suffix="."+problem_filename_suffix)
49        OUTPUT=open(temp_problem_filename,'w')
50        print >>OUTPUT, data.file
51        OUTPUT.close()
52
53        if data.warmstart_file is not None:
54           warmstart_filename_suffix = os.path.split(data.warmstart_filename)[1]
55           temp_warmstart_filename = pyutilib.services.TempfileManager.create_tempfile(suffix="."+warmstart_filename_suffix)
56           OUTPUT=open(temp_warmstart_filename,'w')
57           print >>OUTPUT, data.warmstart_file
58           OUTPUT.close()
59           opt.warm_start_solve = True
60           opt.warm_start_file_name = temp_warmstart_filename
61       
62        print "Applying solver="+data.opt+" to solve problem="+temp_problem_filename
63        results = opt.solve(temp_problem_filename, **data.kwds)
64        pyutilib.services.TempfileManager.clear_tempfiles()
65        # disabling write of solutions for now - this was getting too verbose,
66        # especially when running Progressive Hedging.
67        print "Solve completed - number of solutions="+str(len(results.solution))
68        sys.stdout.flush()
69#        results.write()
70#        sys.stdout.flush()
71        return pickle.dumps(results)
72
73
74pyutilib.pyro.TaskWorkerServer(CooprMIPWorker, argv=sys.argv)
75
Note: See TracBrowser for help on using the repository browser.