source: trunk/coopr/opt/parallel/solver.py @ 1768

Last change on this file since 1768 was 1768, checked in by wehart, 10 years ago

Rework of Coopr to use the new PyUtilib? package decomposition.

NOTE: to use Coopr with this update, we need to work with a new version of coopr_install.

File size: 2.1 KB
Line 
1#  _________________________________________________________________________
2#
3#  Coopr: A COmmon Optimization Python Repository
4#  Copyright (c) 2008 Sandia Corporation.
5#  This software is distributed under the BSD License.
6#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7#  the U.S. Government retains certain rights in this software.
8#  For more information, see the Coopr README.txt file.
9#  _________________________________________________________________________
10
11
12__all__ = ['AsynchronousSolverManager', 'SolverManagerRegistration', 'SolverManagerFactory']
13
14import pyutilib.plugin.core
15import pyutilib.plugin.config
16from manager import *
17
18
19#
20# An interface for AsynchronousSolverManager objects
21#
22class ISolverManager(pyutilib.plugin.core.Interface):
23    pass
24
25
26class ISolverManagerRegistration(pyutilib.plugin.core.Interface):
27
28    def create(self, name=None):
29        """Create a manager, optionally specifying the name"""
30
31    def type(self):
32        """The type of manager supported by this service"""
33
34
35def SolverManagerFactory(name=None, instance_name=None):
36    ep = pyutilib.plugin.core.ExtensionPoint(ISolverManagerRegistration)
37    if name is None:
38        return map(lambda x:x.name, ep())
39    service = ep.service(name)
40    if service is None:
41        return None
42    return service.create(instance_name)
43
44
45class SolverManagerRegistration(pyutilib.plugin.core.Plugin):
46
47    pyutilib.plugin.core.implements(ISolverManagerRegistration)
48
49    def __init__(self, type, cls):
50        self.name = type
51        self._type = type
52        self._cls = cls
53
54    def type(self):
55        return self._type
56
57    def create(self, name=None):
58        if name is None:
59            return self._cls()
60        return self._cls(name=name)
61
62
63
64class AsynchronousSolverManager(AsynchronousActionManager, pyutilib.plugin.config.ManagedPlugin):
65
66    pyutilib.plugin.core.implements(ISolverManager)
67
68    def __init__(self, **kwds):
69        AsynchronousActionManager.__init__(self)
70        pyutilib.plugin.config.ManagedPlugin.__init__(self, **kwds)
71
72    def solve(self, *args, **kwds):
73        return self.execute(*args, **kwds)
74
75
76
Note: See TracBrowser for help on using the repository browser.