# Path: pyDEA/core/models/input_output_model_bases.py
# class InputOrientedModel(object):
# 
#     ''' This class implements methods that are the same for all input-oriented
#         models.
#     '''
#     def get_orientation(self):
#         ''' Returns orientation of the model as a string.
# 
#             Returns:
#                 str: a string 'input'.
#         '''
#         return 'input'
# 
#     def process_obj_var(self, obj_value):
#         ''' Post-process objective function value if necessary.
# 
#             Args:
#                 obj_value (double): value of the objective function.
# 
#             Returns:
#                 double: value of obj_variable, since efficiency score is in
#                     the interval [0, 1] for input-oriented model.
#         '''
#         if obj_value > 1 and obj_value <= 1 + ZERO_TOLERANCE:
#             return 1.0
#         return obj_value
# 
#     def process_dual_value(self, dual_value):
#         ''' Post-process given value of a dual variable if necessary.
# 
#             Args:
#                 dual_value (double): value of the dual variable.
# 
#             Returns:
#                 double: dual_value since in input-oriented model we do nothing
#                     with duals.
#         '''
#         return dual_value
# 
# Path: pyDEA/core/models/input_output_model_bases.py
# class OutputOrientedModel(object):
#     ''' This class implements methods that are the same for all output-oriented
#         models.
#     '''
#     def get_orientation(self):
#         ''' Returns orientation of the model as a string.
# 
#             Returns:
#                 str: a string 'output'.
#         '''
#         return 'output'
# 
#     def process_obj_var(self, obj_value):
#         ''' Post-process objective function value if necessary.
# 
#             Args:
#                 obj_value (double): value of the objective function.
# 
#             Returns:
#                 double: 1/obj_variable, since in the case of output-oriented
#                     models the value of objective function corresponds to
#                     inverse of efficiency spyDEA.core.
#         '''
#         if obj_value == 0:
#             return float('inf')
#         return 1.0/obj_value
# 
#     def process_dual_value(self, dual_value):
#         ''' Post-process given value of a dual variable if necessary.
# 
#             Args:
#                 dual_value (double): value of the dual variable.
# 
#             Returns:
#                 double: -dual_value if it is non-zero since in output-oriented
#                     models.
#         '''
#         if dual_value:
#             return -dual_value
#         return dual_value


import pulp
from pyDEA.core.models.input_output_model_bases import InputOrientedModel
from pyDEA.core.models.input_output_model_bases import OutputOrientedModel
                    that maps variable name to pulp variable corresponding
                    to output categories.

            Returns:
                pulp.LpConstraint: equality constraint.
        '''
        return pulp.lpSum([input_data.coefficients[dmu_code, category] *
                          input_variables[category]
                          for category in input_data.input_categories]) == 1

    def update_equality_constraint(self, input_data, dmu_code, input_variables,
                                   output_variables, lp_model):
        ''' Updates coefficients of the equality constraint of a given model.

            Args:
                input_data (InputData): object that stores input data.
                dmu_code (str): DMU code.
                input_variables (dict of str to pulp.LpVariable): dictionary
                    that maps variable name to pulp variable corresponding
                    to input categories.
                output_variables (dict of str to pulp.LpVariable): dictionary
                    that maps variable name to pulp variable corresponding
                    to output categories.
                lp_model (pulp.LpProblem): linear programming model.
        '''
        for category, var in input_variables.items():
            lp_model.constraints['equality_constraint'][var] = input_data.coefficients[
                dmu_code, category]



# Path: pyDEA/core/models/input_output_model_bases.py
# class InputOrientedModel(object):
# 
#     ''' This class implements methods that are the same for all input-oriented
#         models.
#     '''
#     def get_orientation(self):
#         ''' Returns orientation of the model as a string.
# 
#             Returns:
#                 str: a string 'input'.
#         '''
#         return 'input'
# 
#     def process_obj_var(self, obj_value):
#         ''' Post-process objective function value if necessary.
# 
#             Args:
#                 obj_value (double): value of the objective function.
# 
#             Returns:
#                 double: value of obj_variable, since efficiency score is in
#                     the interval [0, 1] for input-oriented model.
#         '''
#         if obj_value > 1 and obj_value <= 1 + ZERO_TOLERANCE:
#             return 1.0
#         return obj_value
# 
#     def process_dual_value(self, dual_value):
#         ''' Post-process given value of a dual variable if necessary.
# 
#             Args:
#                 dual_value (double): value of the dual variable.
# 
#             Returns:
#                 double: dual_value since in input-oriented model we do nothing
#                     with duals.
#         '''
#         return dual_value
# 
# Path: pyDEA/core/models/input_output_model_bases.py
# class OutputOrientedModel(object):
#     ''' This class implements methods that are the same for all output-oriented
#         models.
#     '''
#     def get_orientation(self):
#         ''' Returns orientation of the model as a string.
# 
#             Returns:
#                 str: a string 'output'.
#         '''
#         return 'output'
# 
#     def process_obj_var(self, obj_value):
#         ''' Post-process objective function value if necessary.
# 
#             Args:
#                 obj_value (double): value of the objective function.
# 
#             Returns:
#                 double: 1/obj_variable, since in the case of output-oriented
#                     models the value of objective function corresponds to
#                     inverse of efficiency spyDEA.core.
#         '''
#         if obj_value == 0:
#             return float('inf')
#         return 1.0/obj_value
# 
#     def process_dual_value(self, dual_value):
#         ''' Post-process given value of a dual variable if necessary.
# 
#             Args:
#                 dual_value (double): value of the dual variable.
# 
#             Returns:
#                 double: -dual_value if it is non-zero since in output-oriented
#                     models.
#         '''
#         if dual_value:
#             return -dual_value
#         return dual_value


# Path: pyDEA/core/models/multiplier_model.py
import pulp
from pyDEA.core.models.input_output_model_bases import InputOrientedModel
from pyDEA.core.models.input_output_model_bases import OutputOrientedModel

                    that maps variable name to pulp variable corresponding
                    to output categories.

            Returns:
                pulp.LpConstraint: equality constraint.
        '''
        return pulp.lpSum([input_data.coefficients[dmu_code, category] *
                          input_variables[category]
                          for category in input_data.input_categories]) == 1

    def update_equality_constraint(self, input_data, dmu_code, input_variables,
                                   output_variables, lp_model):
        ''' Updates coefficients of the equality constraint of a given model.

            Args:
                input_data (InputData): object that stores input data.
                dmu_code (str): DMU code.
                input_variables (dict of str to pulp.LpVariable): dictionary
                    that maps variable name to pulp variable corresponding
                    to input categories.
                output_variables (dict of str to pulp.LpVariable): dictionary
                    that maps variable name to pulp variable corresponding
                    to output categories.
                lp_model (pulp.LpProblem): linear programming model.
        '''
        for category, var in input_variables.items():
            lp_model.constraints['equality_constraint'][var] = input_data.coefficients[
                dmu_code, category]



class MultiplierOutputOrientedModel(OutputOrientedModel):