當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。