source: trunk/coopr/core/parallel/solver.py @ 1296

Last change on this file since 1296 was 1296, checked in by wehart, 11 years ago

Adding a facility for managing asynchronous events. In particular,
this facility has been setup to support the application of Coopr
solvers.

Tests have been developed to exercise the API of the AsynchronousSolverManager?.

File size: 2.0 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
15from manager import *
16
17
18#
19# An interface for AsynchronousSolverManager objects
20#
21class ISolverManager(pyutilib.plugin.Interface):
22    pass
23
24
25class ISolverManagerRegistration(pyutilib.plugin.Interface):
26
27    def create(self, name=None):
28        """Create a manager, optionally specifying the name"""
29
30    def type(self):
31        """The type of manager supported by this service"""
32
33
34def SolverManagerFactory(name=None, instance_name=None):
35    ep = pyutilib.plugin.ExtensionPoint(ISolverManagerRegistration)
36    if name is None:
37        return map(lambda x:x.name, ep())
38    service = ep.service(name)
39    if service is None:
40        return None
41    return service.create(instance_name)
42
43
44class SolverManagerRegistration(pyutilib.plugin.Plugin):
45
46    pyutilib.plugin.implements(ISolverManagerRegistration)
47
48    def __init__(self, type, cls):
49        self.name = type
50        self._type = type
51        self._cls = cls
52
53    def type(self):
54        return self._type
55
56    def create(self, name=None):
57        if name is None:
58            return self._cls()
59        return self._cls(name=name)
60
61
62
63class AsynchronousSolverManager(AsynchronousActionManager, pyutilib.plugin.ManagedPlugin):
64
65    pyutilib.plugin.implements(ISolverManager)
66
67    def __init__(self, **kwds):
68        AsynchronousActionManager.__init__(self)
69        pyutilib.plugin.ManagedPlugin.__init__(self, **kwds)
70
71    def solve(self, *args, **kwds):
72        return self.execute(*args, **kwds)
73
74
75
Note: See TracBrowser for help on using the repository browser.