当前位置: 首页>>代码示例>>Python>>正文


Python pulp.LpContinuous方法代码示例

本文整理汇总了Python中pulp.LpContinuous方法的典型用法代码示例。如果您正苦于以下问题:Python pulp.LpContinuous方法的具体用法?Python pulp.LpContinuous怎么用?Python pulp.LpContinuous使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pulp的用法示例。


在下文中一共展示了pulp.LpContinuous方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_decision_variables

# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpContinuous [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 ================== 
开发者ID:ekhoda,项目名称:optimization-tutorial,代码行数:21,代码来源:optimization_model_pulp.py

示例2: create_model

# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpContinuous [as 别名]
def create_model(self):
        def distances(assignment):
            return l2_distance(self.data[assignment[0]], self.centroids[assignment[1]])

        clusters = list(range(self.k))
        assignments = [(i, j)for i in range(self.n) for j in range(self.k)]

        # outflow variables for data nodes
        self.y = pulp.LpVariable.dicts('data-to-cluster assignments',
                                  assignments,
                                  lowBound=0,
                                  upBound=1,
                                  cat=pulp.LpInteger)

        # outflow variables for cluster nodes
        self.b = pulp.LpVariable.dicts('cluster outflows',
                                  clusters,
                                  lowBound=0,
                                  upBound=self.n-self.min_size,
                                  cat=pulp.LpContinuous)

        # create the model
        self.model = pulp.LpProblem("Model for assignment subproblem", pulp.LpMinimize)

        # objective function
        self.model += pulp.lpSum(distances(assignment) * self.y[assignment] for assignment in assignments)

        # flow balance constraints for data nodes
        for i in range(self.n):
            self.model += pulp.lpSum(self.y[(i, j)] for j in range(self.k)) == 1

        # flow balance constraints for cluster nodes
        for j in range(self.k):
            self.model += pulp.lpSum(self.y[(i, j)] for i in range(self.n)) - self.min_size == self.b[j]

        # flow balance constraint for the sink node
        self.model += pulp.lpSum(self.b[j] for j in range(self.k)) == self.n - (self.k * self.min_size) 
开发者ID:Behrouz-Babaki,项目名称:MinSizeKmeans,代码行数:39,代码来源:run_mskmeans.py

示例3: create_model

# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpContinuous [as 别名]
def create_model(self):
        def distances(assignment):
            return l2_distance(self.data[assignment[0]], self.centroids[assignment[1]])

        clusters = list(range(self.k))
        assignments = [(i, j)for i in range(self.n) for j in range(self.k)]

        # outflow variables for data nodes
        self.y = pulp.LpVariable.dicts('data-to-cluster assignments',
                                  assignments,
                                  lowBound=0,
                                  upBound=1,
                                  cat=pulp.LpInteger)

        # outflow variables for cluster nodes
        self.b = pulp.LpVariable.dicts('cluster outflows',
                                  clusters,
                                  lowBound=0,
                                  upBound=self.n-self.min_size,
                                  cat=pulp.LpContinuous)

        # create the model
        self.model = pulp.LpProblem("Model for assignment subproblem", pulp.LpMinimize)

        # objective function
        self.model += pulp.lpSum([distances(assignment) * self.y[assignment] for assignment in assignments])

        # flow balance constraints for data nodes
        for i in range(self.n):
            self.model += pulp.lpSum(self.y[(i, j)] for j in range(self.k)) == 1

        # flow balance constraints for cluster nodes
        for j in range(self.k):
            self.model += pulp.lpSum(self.y[(i, j)] for i in range(self.n)) - self.min_size == self.b[j]
            
        # capacity constraint on outflow of cluster nodes
        for j in range(self.k):
            self.model += self.b[j] <= self.max_size - self.min_size 

        # flow balance constraint for the sink node
        self.model += pulp.lpSum(self.b[j] for j in range(self.k)) == self.n - (self.k * self.min_size) 
开发者ID:Behrouz-Babaki,项目名称:MinSizeKmeans,代码行数:43,代码来源:minmax_kmeans.py

示例4: _create_lp

# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpContinuous [as 别名]
def _create_lp(self):
        ''' See base class.
        '''
        self.model._create_lp()
        self.lp_model = self.model.lp_model

        # create varibales
        for (category_in_nom, category_in_denom), (lower_bound, upper_bound) in self.bounds.items():
            if lower_bound:
                variable = pulp.LpVariable(
                    'price_ratio_category_{0}_{1}_lb'.format(
                        category_in_nom, category_in_denom),
                    0, None, pulp.LpContinuous)
                name = self.model._constraints[category_in_nom]
                self.lp_model.constraints[name].addterm(variable, -1)
                name = self.model._constraints[category_in_denom]
                self.lp_model.constraints[name].addterm(variable, lower_bound)

            if upper_bound:
                variable = pulp.LpVariable(
                    'price_ratio_category_{0}_{1}_ub'.format(
                        category_in_nom, category_in_denom),
                    0, None, pulp.LpContinuous)
                name = self.model._constraints[category_in_nom]
                self.lp_model.constraints[name].addterm(variable, 1)
                name = self.model._constraints[category_in_denom]
                self.lp_model.constraints[name].addterm(variable, -upper_bound) 
开发者ID:araith,项目名称:pyDEA,代码行数:29,代码来源:envelopment_model_decorators.py

示例5: _create_lp

# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpContinuous [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) 
开发者ID:araith,项目名称:pyDEA,代码行数:15,代码来源:multiplier_model_decorators.py

示例6: _create_lp

# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpContinuous [as 别名]
def _create_lp(self):
        ''' Creates initial linear program.
        '''
        assert len(self.input_data.DMU_codes) != 0
        self._variables.clear()
        self._constraints.clear()
        # create LP for the first DMU - it is the easiest way to
        # adapt current code
        for elem in self.input_data.DMU_codes:
            dmu_code = elem
            break

        orientation = self._concrete_model.get_orientation()
        obj_type = self._concrete_model.get_objective_type()
        self.lp_model = pulp.LpProblem('Envelopment model: {0}-'
                                       'oriented'.format(orientation),
                                       obj_type)
        ub_obj = self._concrete_model.get_upper_bound_for_objective_variable()
        obj_variable = pulp.LpVariable('Variable in objective function',
                                       self._concrete_model.
                                       get_lower_bound_for_objective_variable(),
                                       ub_obj,
                                       pulp.LpContinuous)
        self._variables['obj_var'] = obj_variable

        self.lp_model += (obj_variable,
                          'Efficiency score or inverse of efficiency score')

        lambda_variables = pulp.LpVariable.dicts('lambda',
                                                 self.input_data.DMU_codes,
                                                 0, None, pulp.LpContinuous)
        self._variables.update(lambda_variables)
        self._add_constraints_for_outputs(lambda_variables, dmu_code,
                                          obj_variable)
        self._add_constraints_for_inputs(lambda_variables, dmu_code,
                                         obj_variable) 
开发者ID:araith,项目名称:pyDEA,代码行数:38,代码来源:envelopment_model_base.py

示例7: _create_lp

# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpContinuous [as 别名]
def _create_lp(self):
        ''' Creates initial LP model.
        '''
        assert len(self.input_data.DMU_codes) != 0
        # create LP for the first DMU - it is the easiest way to
        # adapt current code
        for elem in self.input_data.DMU_codes:
            dmu_code = elem
            break

        self.lp_model = pulp.LpProblem(
            'Multiplier model: {orientation}-oriented'.format(
            orientation=self._concrete_model.get_orientation()),
            self._concrete_model.get_objective_type())

        self._output_variables = pulp.LpVariable.dicts(
            'mu', self.input_data.output_categories, self.tolerance, None,
            pulp.LpContinuous)
        self._input_variables = pulp.LpVariable.dicts(
            'eta', self.input_data.input_categories, self.tolerance, None,
            pulp.LpContinuous)

        self.lp_model += (self._concrete_model.get_objective_function(
            self.input_data, dmu_code, self._input_variables,
            self._output_variables),
            'Efficiency score or inverse of efficiency score')

        self._dmu_constraint_names.clear()
        for dmu in self.input_data.DMU_codes:
            output_sum = pulp.lpSum([self.input_data.coefficients[
                dmu, category] * self._output_variables[category]
                for category in self.input_data.output_categories])
            input_sum = pulp.lpSum([self.input_data.coefficients[
                dmu, category] * self._input_variables[category]
                for category in self.input_data.input_categories])
            name = 'DMU_constraint_{count}'.format(count=dmu)
            self.lp_model += (output_sum - input_sum <= 0, name)
            self._dmu_constraint_names[name] = dmu

        self.lp_model += (self._concrete_model.get_equality_constraint(
            self.input_data, dmu_code, self._input_variables,
            self._output_variables), 'equality_constraint') 
开发者ID:araith,项目名称:pyDEA,代码行数:44,代码来源:multiplier_model_base.py


注:本文中的pulp.LpContinuous方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。