本文整理匯總了Python中pulp.LpVariable方法的典型用法代碼示例。如果您正苦於以下問題:Python pulp.LpVariable方法的具體用法?Python pulp.LpVariable怎麽用?Python pulp.LpVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pulp
的用法示例。
在下文中一共展示了pulp.LpVariable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_decision_variables
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def _create_decision_variables(self):
self.production_variables = pulp.LpVariable.dicts(name='X', indexs=self.input_data.index,
lowBound=0, cat=pulp.LpContinuous)
self.inventory_variables = pulp.LpVariable.dicts(name='I', indexs=self.input_data.index,
lowBound=0, cat=pulp.LpContinuous)
# Alternative way of creating the variables:
# self.production_variables = {
# index: pulp.LpVariable(name='X_' + str(row['period']),
# lowBound=0, cat=pulp.LpContinuous)
# for index, row in self.input_data.iterrows()}
#
# self.inventory_variables = {
# index: pulp.LpVariable(name='I_' + str(row['period']),
# lowBound=0, cat=pulp.LpContinuous)
# for index, row in self.input_data.iterrows()}
# ================== Constraints ==================
示例2: get_objective_function
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def get_objective_function(self, input_data, dmu_code, input_variables,
output_variables):
''' Generates objective function of input-oriented multiplier 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.
Returns:
pulp.LpSum: objective function.
'''
return pulp.lpSum([input_data.coefficients[dmu_code, category] *
output_variables[category]
for category in input_data.output_categories])
示例3: update_objective
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def update_objective(self, input_data, dmu_code, input_variables,
output_variables, lp_model):
''' Updates coefficients of the objective function 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 in input_data.output_categories:
lp_model.objective[output_variables[category]] = input_data.coefficients[
dmu_code, category]
示例4: get_equality_constraint
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def get_equality_constraint(self, input_data, dmu_code, input_variables,
output_variables):
''' Generates equality constraint of input-oriented multiplier 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.
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
示例5: update_equality_constraint
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
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]
示例6: get_input_variable_coefficient
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def get_input_variable_coefficient(self, obj_variable, input_category):
''' Returns proper coefficient depending on the fact if variable
is discretionary or not.
Args:
obj_variable (pulp.LpVariable): pulp variable that corresponds
to input category of current DMU.
input_category (str): input category for which current
constraint is being created.
Returns:
double or pulp.LpVariable: input variable coefficient.
'''
if input_category in self.non_disc_inputs:
return 1
return obj_variable
示例7: update_output_category_coefficient
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def update_output_category_coefficient(self, current_output, constraint,
obj_var, output_category):
''' Updates coefficient of a given output category with a new
value.
Args:
current_output (double): new value for the coefficient.
constraint (pulp.LpConstraint): constraint whose coefficient
should be updated.
obj_var (pulp.LpVariable): variable of the envelopment
model that is optimised in the objective function.
output_category (str): output category name.
'''
if output_category in self.non_disc_outputs:
constraint.changeRHS(current_output)
else:
constraint[obj_var] = -current_output
示例8: _get_variables
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def _get_variables(self):
''' Returns proper variables.
Returns:
dict of str to pulp.LpVariable: dictionary of
pulp variables than maps variable names to pulp variables.
'''
raise NotImplementedError()
示例9: add_variable
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def add_variable(self, name):
return LpVariable(name, cat=LpBinary)
示例10: get_output_variable_coefficient
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def get_output_variable_coefficient(self, obj_variable, output_category):
''' Returns 1, since in input-oriented model we do not multiply
current output by anything.
Args:
obj_variable (pulp.LpVariable): pulp variable that corresponds
to output category of the current DMU.
output_category (str): output category for which current
constraint is being created.
Returns:
double: output variable coefficient.
'''
return 1
示例11: update_input_category_coefficient
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def update_input_category_coefficient(self, current_input, constraint,
obj_var, input_category):
''' Updates coefficient of a given input category with a new
value.
Args:
current_output (double): new value for the coefficient.
constraint (pulp.LpConstraint): constraint whose coefficient
should be updated.
obj_var (pulp.LpVariable): variable of the envelopment
model that is optimised in the objective function.
output_category (str): input category name.
'''
constraint.changeRHS(-current_input)
示例12: _add_constraints_for_outputs
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def _add_constraints_for_outputs(self, variables, dmu_code,
obj_variable):
''' Adds constraints for outputs to linear program.
Args:
variables (dict of str to pulp.LpVariable): a dictionary
that maps DMU codes to pulp.LpVariable, created with
pulp.LpVariable.dicts.
dmu_code (str): DMU code for which LP is being created.
obj_variable (pulp.LpVariable): LP variable that is optimised
(either efficiency score or inverse of efficiency score).
'''
self._model_to_decorate._add_constraints_for_outputs(variables,
dmu_code,
obj_variable)
示例13: _add_constraints_for_inputs
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def _add_constraints_for_inputs(self, variables,
dmu_code, obj_variable):
''' Adds constraints for inputs to LP.
Args:
variables (dict of {str: pulp.LpVariable}): a dictionary that
maps DMU codes to pulp.LpVariable, created with
pulp.LpVariable.dicts.
dmu_code (str): DMU code for which LP is being created.
obj_variable (pulp.LpVariable): LP variable that is optimised
(either efficiency score or inverse of efficiency score).
'''
self._model_to_decorate._add_constraints_for_inputs(variables,
dmu_code,
obj_variable)
示例14: _create_lp
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def _create_lp(self):
''' Creates initial LP.
'''
self._model_to_decorate._create_lp()
self.lp_model = self._model_to_decorate.lp_model
self._vrs_variable = pulp.LpVariable('VRS_variable', None, None,
pulp.LpContinuous)
self._model_to_decorate.lp_model.objective += self._vrs_variable
for dmu_constraint in self._model_to_decorate._dmu_constraint_names.keys():
self._model_to_decorate.lp_model.constraints[dmu_constraint] += (
self.multiplier * self._vrs_variable)
示例15: _change_lower_bound
# 需要導入模塊: import pulp [as 別名]
# 或者: from pulp import LpVariable [as 別名]
def _change_lower_bound(self, variables):
''' Changes lower bound for variables corresponding to weakly
disposable categories.
Args:
variables (dict of str to pulp.LpVariable): dictionary of
pulp variables than maps variable names to pulp variables.
'''
for category, var in variables.items():
if category in self.weakly_disposable_categories:
var.lowBound = None