Ejemplo n.º 1
0
    def __init__(self, **kwargs):
        configure_glpk()
        #
        # Call base constructor
        #
        kwargs['type'] = 'glpk'
        SystemCallSolver.__init__(self, **kwargs)

        self._rawfile = None

        #
        # Valid problem formats, and valid results for each format
        #
        self._valid_problem_formats = [
            ProblemFormat.cpxlp, ProblemFormat.mps, ProblemFormat.mod
        ]
        self._valid_result_formats = {
            ProblemFormat.mod: ResultsFormat.soln,
            ProblemFormat.cpxlp: ResultsFormat.soln,
            ProblemFormat.mps: ResultsFormat.soln,
        }
        self.set_problem_format(ProblemFormat.cpxlp)

        # Note: Undefined capabilities default to 'None'
        self._capabilities = Options()
        self._capabilities.linear = True
        self._capabilities.integer = True
Ejemplo n.º 2
0
Archivo: GLPK.py Proyecto: Pyomo/pyomo
    def __init__ (self, **kwargs):
        configure_glpk()
        #
        # Call base constructor
        #
        kwargs['type'] = 'glpk'
        SystemCallSolver.__init__(self, **kwargs)

        self._rawfile = None

        #
        # Valid problem formats, and valid results for each format
        #
        self._valid_problem_formats = [ProblemFormat.cpxlp,
                                       ProblemFormat.mps,
                                       ProblemFormat.mod]
        self._valid_result_formats = {
          ProblemFormat.mod:   ResultsFormat.soln,
          ProblemFormat.cpxlp: ResultsFormat.soln,
          ProblemFormat.mps:   ResultsFormat.soln,
        }
        self.set_problem_format(ProblemFormat.cpxlp)

        # Note: Undefined capabilities default to 'None'
        self._capabilities = Options()
        self._capabilities.linear = True
        self._capabilities.integer = True
Ejemplo n.º 3
0
 def __init__(self, **kwds):
     #
     # Call base constructor
     #
     if not 'type' in kwds:
         kwds["type"] = "asl"
     SystemCallSolver.__init__(self, **kwds)
     self._metasolver = True
     #
     # Setup valid problem formats, and valid results for each problem format.
     # Also set the default problem and results formats.
     #
     self._valid_problem_formats = [ProblemFormat.nl]
     self._valid_result_formats = {}
     self._valid_result_formats[ProblemFormat.nl] = [ResultsFormat.sol]
     self.set_problem_format(ProblemFormat.nl)
     #
     # Note: Undefined capabilities default to 'None'
     #
     self._capabilities = Bunch()
     self._capabilities.linear = True
     self._capabilities.integer = True
     self._capabilities.quadratic_objective = True
     self._capabilities.quadratic_constraint = True
     self._capabilities.sos1 = True
     self._capabilities.sos2 = True
Ejemplo n.º 4
0
    def __init__(self, **kwds):
        #
        # Call base class constructor
        #
        kwds['type'] = 'baron'
        SystemCallSolver.__init__(self, **kwds)

        self._tim_file = None

        self._valid_problem_formats = [ProblemFormat.bar]
        self._valid_result_formats = {}
        self._valid_result_formats[ProblemFormat.bar] = [ResultsFormat.soln]
        self.set_problem_format(ProblemFormat.bar)

        self._capabilities = Options()
        self._capabilities.linear = True
        self._capabilities.quadratic_objective = True
        self._capabilities.quadratic_constraint = True
        self._capabilities.integer = True
        self._capabilities.sos1 = False
        self._capabilities.sos2 = False

        # CLH: Coppied from cpxlp.py, the cplex file writer.
        # Keven Hunter made a nice point about using %.16g in his attachment
        # to ticket #4319. I am adjusting this to %.17g as this mocks the
        # behavior of using %r (i.e., float('%r'%<number>) == <number>) with
        # the added benefit of outputting (+/-). The only case where this
        # fails to mock the behavior of %r is for large (long) integers (L),
        # which is a rare case to run into and is probably indicative of
        # other issues with the model.
        # *** NOTE ***: If you use 'r' or 's' here, it will break code that
        #               relies on using '%+' before the formatting character
        #               and you will need to go add extra logic to output
        #               the number's sign.
        self._precision_string = '.17g'
Ejemplo n.º 5
0
 def __init__(self, **kwds):
     kwds["type"] = "neos"
     SystemCallSolver.__init__(self, **kwds)
     self._valid_problem_formats = [ProblemFormat.nl]
     self._valid_result_formats = {}
     self._valid_result_formats[ProblemFormat.nl] = [ResultsFormat.sol]
     self._problem_format = ProblemFormat.nl
     self._results_format = ResultsFormat.sol
Ejemplo n.º 6
0
    def test_set_executable_isexe_nopath(self):
        with SystemCallSolver(type='test') as opt:
            self.assertEqual(id(opt._user_executable), id(None))
            # because it is not in the PATH
            with self.assertRaises(ValueError):
                opt.set_executable(isexe_nopath)
            self.assertEqual(id(opt._user_executable), id(None))
            opt.set_executable(isexe_nopath, validate=False)
            self.assertEqual(opt._user_executable, isexe_nopath)
            self.assertEqual(opt.executable(), isexe_nopath)
            opt._user_executable = None

            # now add the exedir to the PATH
            rm_PATH = False
            orig_PATH = None
            if "PATH" in os.environ:
                orig_PATH = os.environ["PATH"]
            else:
                rm_PATH = True
                os.environ["PATH"] = ""
            os.environ["PATH"] = exedir + os.pathsep + os.environ["PATH"]
            try:
                opt.set_executable(isexe_nopath)
                self.assertEqual(opt._user_executable, isexe_abspath)
                self.assertEqual(opt.executable(), isexe_abspath)
            finally:
                if rm_PATH:
                    del os.environ["PATH"]
                else:
                    os.environ["PATH"] = orig_PATH
Ejemplo n.º 7
0
 def test_available(self):
     with SystemCallSolver(type='test') as opt:
         self.assertEqual(id(opt._user_executable), id(None))
         # both cases should fail because this class is only
         # a partial implementation
         with self.assertRaises(ApplicationError):
             opt.available(exception_flag=True)
Ejemplo n.º 8
0
 def _presolve(self, *args, **kwds):
     if (not isinstance(args[0], six.string_types)) and \
        (not isinstance(args[0], IBlock)):
         self._instance = args[0]
         xfrm = TransformationFactory('mpec.nl')
         xfrm.apply_to(self._instance)
         if len(self._instance._transformation_data['mpec.nl'].compl_cuids) == 0:
             # There were no complementarity conditions
             # so we don't hold onto the instance
             self._instance = None
         else:
             args = (self._instance,)
     else:
         self._instance = None
     #
     SystemCallSolver._presolve(self, *args, **kwds)
Ejemplo n.º 9
0
 def test_set_executable_notexe_abspath_user(self):
     with SystemCallSolver(type='test') as opt:
         self.assertEqual(id(opt._user_executable), id(None))
         with self.assertRaises(ValueError):
             opt.set_executable(notexe_abspath_user)
         self.assertEqual(id(opt._user_executable), id(None))
         opt.set_executable(notexe_abspath_user, validate=False)
         self.assertEqual(opt._user_executable, notexe_abspath_user)
         self.assertEqual(opt.executable(), notexe_abspath_user)
Ejemplo n.º 10
0
 def test_set_executable_isexe_abspath_user(self):
     with SystemCallSolver(type='test') as opt:
         self.assertEqual(id(opt._user_executable), id(None))
         opt.set_executable(isexe_abspath_user)
         self.assertEqual(opt._user_executable, isexe_abspath)
         self.assertEqual(opt.executable(), isexe_abspath)
         opt._user_executable = None
         opt.set_executable(isexe_abspath_user, validate=False)
         self.assertEqual(opt._user_executable, isexe_abspath_user)
         self.assertEqual(opt.executable(), isexe_abspath_user)
Ejemplo n.º 11
0
 def test_reset_executable(self):
     with SystemCallSolver(type='test') as opt:
         self.assertEqual(id(opt._user_executable), id(None))
         with self.assertRaises(NotImplementedError):
             opt.set_executable()
         opt._user_executable = 'x'
         opt.set_executable(validate=False)
         self.assertEqual(id(opt._user_executable), id(None))
         with self.assertRaises(NotImplementedError):
             opt.executable()
Ejemplo n.º 12
0
    def __init__(self, **kwds):
        #
        # Call base constructor
        #
        kwds["type"] = "pico"
        SystemCallSolver.__init__(self, **kwds)
        #
        # Setup valid problem formats, and valid results for each problem format
        #
        self._valid_problem_formats=[ProblemFormat.cpxlp, ProblemFormat.nl, ProblemFormat.mps]
        self._valid_result_formats = {}
        self._valid_result_formats[ProblemFormat.cpxlp] = [ResultsFormat.soln]
        self._valid_result_formats[ProblemFormat.nl] = [ResultsFormat.sol]
        self._valid_result_formats[ProblemFormat.mps] = [ResultsFormat.soln]
        self.set_problem_format(ProblemFormat.cpxlp)

        # Note: Undefined capabilities default to 'None'
        self._capabilities = Options()
        self._capabilities.linear = True
        self._capabilities.integer = True
Ejemplo n.º 13
0
 def _postsolve(self):
     #
     # Reclassify complementarity components
     #
     mpec=False
     if not self._instance is None:
         from pyomo.mpec import Complementarity
         for cuid in self._instance._transformation_data['mpec.nl'].compl_cuids:
             mpec=True
             cobj = cuid.find_component_on(self._instance)
             cobj.parent_block().reclassify_component_type(cobj, Complementarity)
     #
     self._instance = None
     return SystemCallSolver._postsolve(self)
Ejemplo n.º 14
0
 def test_noexe(self):
     with SystemCallSolver(type='test') as opt:
         self.assertEqual(id(opt._user_executable), id(None))
         with self.assertRaises(NotImplementedError):
             opt.executable()