Exemple #1
0
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________

__all__ = ['convert_problem']

import copy
import os

from pyomo.opt.base.formats import guess_format
from pyomo.opt.base.error import ConverterError
from pyomo.common import Factory

# WEH - Should we treat these as singleton objects?  Not for now, since
# I can't think of a case where that would impact performance
ProblemConverterFactory = Factory('problem converter')


def convert_problem(args,
                    target_problem_type,
                    valid_problem_types,
                    has_capability=lambda x: False,
                    **kwds):
    """
    Convert a problem, defined by the 'args' tuple, into another
    problem.
    """

    if len(valid_problem_types) == 0:
        raise ConverterError("No valid problem types")
Exemple #2
0
            "The Transformation.apply_to method is not implemented.")

    def _create_using(self, model, **kwds):
        # Put all the kwds onto the model so that when we clone the
        # model any references to things on the model are correctly
        # updated to point to the new instance.  Note that users &
        # transformation developers cannot rely on things happening by
        # argument side effect.
        name = unique_component_name(model, '_kwds')
        setattr(model, name, kwds)
        instance = model.clone()
        kwds = getattr(instance, name)
        delattr(model, name)
        delattr(instance, name)
        self._apply_to(instance, **kwds)
        return instance


TransformationFactory = Factory('transformation type')


@deprecated(version='4.3.11323')
def apply_transformation(*args, **kwds):
    if len(args) == 0:
        return list(TransformationFactory)
    xfrm = TransformationFactory(args[0])
    if len(args) == 1 or xfrm is None:
        return xfrm
    tmp = (args[1], )
    return xfrm.apply(*tmp, **kwds)
Exemple #3
0
#  ___________________________________________________________________________
#
#  Pyomo: Python Optimization Modeling Objects
#  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________

__all__ = ['AsynchronousSolverManager', 'SolverManagerFactory']

from pyomo.common import Factory
from pyomo.opt.parallel.manager import *

SolverManagerFactory = Factory('solver manager')


class AsynchronousSolverManager(AsynchronousActionManager):
    def __init__(self, **kwds):
        AsynchronousActionManager.__init__(self)

    def solve(self, *args, **kwds):
        return self.execute(*args, **kwds)

    def solve_all(self, solver, instances, **kwds):
        """
        A simple utility to apply a solver to a list of problem instances.
        The solver is applied asynchronously and a barrier synchronization
        is performed to finalize all results.  All keywords are passed
        to each invocation of the solver, and the results are loaded
Exemple #4
0
#  ___________________________________________________________________________
#
#  Pyomo: Python Optimization Modeling Objects
#  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________

__all__ = ['AbstractResultsReader', 'ReaderFactory']

from pyomo.common import Factory

ReaderFactory = Factory('problem reader')


class AbstractResultsReader(object):
    """Base class that can read optimization results."""
    def __init__(self, results_format):
        self.format = results_format

    def __call__(self, filename, res=None, suffixes=[]):  #pragma:nocover
        raise TypeError("Method __call__ undefined in reader for format " +
                        str(self.format))

    #
    # Support "with" statements. Forgetting to call deactivate
    # on Plugins is a common source of memory leaks
    #
    def __enter__(self):
Exemple #5
0
#  National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________

__all__ = [
    "AbstractProblemWriter",
    "WriterFactory",
    "BranchDirection",
]

from pyomo.common import Factory

WriterFactory = Factory('problem writer')


class AbstractProblemWriter(object):
    """Base class that can write optimization problems."""
    def __init__(self, problem_format):  #pragma:nocover
        self.format = problem_format

    def __call__(self, model, filename, solver_capability,
                 **kwds):  #pragma:nocover
        raise TypeError("Method __call__ undefined in writer for format " +
                        str(self.format))

    #
    # Support "with" statements.
    #
Exemple #6
0
#  Pyomo: Python Optimization Modeling Objects
#  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________

__all__ = [
    'AbstractProblemWriter', 'WriterFactory', 'ProblemConfigFactory',
    'BaseProblemConfig'
]

from pyomo.common import Factory

ProblemConfigFactory = Factory('problem configuration object')


class BaseProblemConfig(object):
    """Base class for plugins generating problem configurations"""
    def config_block(self):
        pass


WriterFactory = Factory('problem writer')


class AbstractProblemWriter(object):
    """Base class that can write optimization problems."""
    def __init__(self, problem_format):  #pragma:nocover
        self.format = problem_format
Exemple #7
0
#  ___________________________________________________________________________
#
#  Pyomo: Python Optimization Modeling Objects
#  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________
"""
Define factory used for using OptProblem IO formats.
"""

from pyomo.common import Factory

BlackBoxOptProblemIOFactory = Factory('black box problem IO format')