[1296] | 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 | |
---|
[1768] | 14 | import pyutilib.plugin.core |
---|
| 15 | import pyutilib.plugin.config |
---|
[1296] | 16 | from manager import * |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | # |
---|
| 20 | # An interface for AsynchronousSolverManager objects |
---|
| 21 | # |
---|
[1768] | 22 | class ISolverManager(pyutilib.plugin.core.Interface): |
---|
[1296] | 23 | pass |
---|
| 24 | |
---|
| 25 | |
---|
[1768] | 26 | class ISolverManagerRegistration(pyutilib.plugin.core.Interface): |
---|
[1296] | 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 | |
---|
| 35 | def SolverManagerFactory(name=None, instance_name=None): |
---|
[1768] | 36 | ep = pyutilib.plugin.core.ExtensionPoint(ISolverManagerRegistration) |
---|
[1296] | 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 | |
---|
[1768] | 45 | class SolverManagerRegistration(pyutilib.plugin.core.Plugin): |
---|
[1296] | 46 | |
---|
[1768] | 47 | pyutilib.plugin.core.implements(ISolverManagerRegistration) |
---|
[1296] | 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 | |
---|
[1768] | 64 | class AsynchronousSolverManager(AsynchronousActionManager, pyutilib.plugin.config.ManagedPlugin): |
---|
[1296] | 65 | |
---|
[1768] | 66 | pyutilib.plugin.core.implements(ISolverManager) |
---|
[1296] | 67 | |
---|
| 68 | def __init__(self, **kwds): |
---|
| 69 | AsynchronousActionManager.__init__(self) |
---|
[1768] | 70 | pyutilib.plugin.config.ManagedPlugin.__init__(self, **kwds) |
---|
[1296] | 71 | |
---|
| 72 | def solve(self, *args, **kwds): |
---|
| 73 | return self.execute(*args, **kwds) |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | |
---|