Python pulp.LpContinuous() Examples
The following are 8
code examples of pulp.LpContinuous().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pulp
, or try the search function
.
Example #1
Source File: run_mskmeans.py From MinSizeKmeans with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: optimization_model_pulp.py From optimization-tutorial with MIT License | 5 votes |
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 ==================
Example #3
Source File: minmax_kmeans.py From MinSizeKmeans with GNU General Public License v3.0 | 5 votes |
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)
Example #4
Source File: envelopment_model_decorators.py From pyDEA with MIT License | 5 votes |
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)
Example #5
Source File: multiplier_model_decorators.py From pyDEA with MIT License | 5 votes |
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)
Example #6
Source File: envelopment_model_base.py From pyDEA with MIT License | 5 votes |
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)
Example #7
Source File: envelopment_model_decorators.py From pyDEA with MIT License | 4 votes |
def _create_lp(self): ''' See base class. ''' self.model._create_lp() self.lp_model = self.model.lp_model self.new_vars_lb.clear() self.new_vars_ub.clear() for elem in self.input_data.DMU_codes: dmu_code = elem break if self._concrete_model.get_orientation() == 'input': self._multiplier = 1 else: self._multiplier = -1 # make objective variable unrestricted self._variables['obj_var'].lowBound = None self._variables['obj_var'].upBound = None for category, (lower_bound, upper_bound) in self.bounds.items(): if lower_bound: variable = pulp.LpVariable( '{0}_category_{1}_lb'.format( self._get_var_name(), category), None, 0, pulp.LpContinuous) self.new_vars_lb[category] = variable name = self.model._constraints[category] self.lp_model.constraints[name].addterm(variable, 1) self.lp_model.objective += (self._get_multiplier( dmu_code, category) * lower_bound * variable) if upper_bound: variable = pulp.LpVariable( '{0}_category_{1}_ub'.format(self._get_var_name(), category), 0, None, pulp.LpContinuous) self.new_vars_ub[category] = variable name = self.model._constraints[category] self.lp_model.constraints[name].addterm(variable, 1) self.lp_model.objective += (self._get_multiplier( dmu_code, category) * upper_bound * variable) #if self._multiplier == -1: # add constraint that objective function is >= 1 for # output-oriented model # self.lp_model += self.lp_model.objective >= 1
Example #8
Source File: multiplier_model_base.py From pyDEA with MIT License | 4 votes |
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')