Changeset 2657


Ignore:
Timestamp:
Jun 14, 2010 5:58:18 PM (11 years ago)
Author:
prsteel
Message:

Changes to coopr.opt to support SOS constraints.

Added function 'has_capability' to 'OptSolve?', the generic base class
for all solvers. Accepts a string 'st', and returns true if
self._capabilities[st] == True, and False otherwise. Derived classes are
responsible for overriding the contents of self._capabilities.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.opt/trunk/coopr/opt/base/solver.py

    r2633 r2657  
    103103        # want to persistence of this parameter to be violated.
    104104        self.mipgap = None
     105
     106    def has_capability(self, cap):
     107        """
     108        Returns a boolean value representing whether a solver supports
     109        a specific feature. Defaults to 'False' if the solver is unaware
     110        of an option. Expects a string.
     111
     112        Example:
     113        print solver.sos1 # prints True if solver supports sos1 constraints,
     114                          # and False otherwise
     115        print solver.feature # prints True is solver supports 'feature', and
     116                             # False otherwise
     117        """
     118        try:
     119            # See if self.capabilities has been defined
     120            caps = self._capabilities
     121        except:
     122            raise NotImplementedError, "Generic solver has no capabilities"
     123       
     124        if not isinstance(cap, str):
     125            raise TypeError, "Expected argument to be of type '%s', not " + \
     126                  "'%s'." % (str(type(str())), str(type(cap)))
     127        else:
     128            val = self._capabilities[str(cap)]
     129            if val is None:
     130                return False
     131            else:
     132                return True
    105133
    106134    def available(self, exception_flag=True):
Note: See TracChangeset for help on using the changeset viewer.