本文整理汇总了Python中pulp.LpMaximize方法的典型用法代码示例。如果您正苦于以下问题:Python pulp.LpMaximize方法的具体用法?Python pulp.LpMaximize怎么用?Python pulp.LpMaximize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp
的用法示例。
在下文中一共展示了pulp.LpMaximize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: define_lp
# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpMaximize [as 别名]
def define_lp(fares, product_names):
"""Set up LP.
Parameters
----------
fares: 2D np array
contains fares for products, size n_classes*n_products
products_names: list
product names (typically relation/class combinations)
Returns
-------
tuple of the form (LP problem, decision variables)
"""
prob = pulp.LpProblem('network_RM', pulp.LpMaximize)
# decision variables: available seats per product
x = pulp.LpVariable.dicts('x', product_names, lowBound=0)
# objective function
revenue = pulp.lpSum([x[it]*fares.ravel()[i] for i, it in
enumerate(product_names)])
prob += revenue
return prob, x
示例2: __init__
# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpMaximize [as 别名]
def __init__(self):
self.prob = LpProblem('Daily Fantasy Sports', LpMaximize)
示例3: get_objective_type
# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpMaximize [as 别名]
def get_objective_type(self):
''' Returns pulp.LpMaximize - we maximize objective function in case
of input-oriented multiplier model.
Returns:
pulp.LpMaximize.
'''
return pulp.LpMaximize
示例4: get_objective_type
# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpMaximize [as 别名]
def get_objective_type(self):
''' Returns pulp.LpMinimize - we minimize objective function in case
of input-oriented envelopment model.
Returns:
pulp.LpMaximize: type of objective function.
'''
return pulp.LpMinimize
示例5: _create_lp
# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpMaximize [as 别名]
def _create_lp(self):
''' See base class.
'''
self.model._create_lp()
self.lp_model_max_slack = self.model.lp_model.deepcopy()
input_slack_vars = pulp.LpVariable.dicts(
'input_slack', self.strongly_disposal_input_categories,
0, None, pulp.LpContinuous)
output_slack_vars = pulp.LpVariable.dicts(
'output_slack', self.strongly_disposal_output_categories,
0, None, pulp.LpContinuous)
# change objective function
self.lp_model_max_slack.sense = pulp.LpMaximize
self.lp_model_max_slack.objective = (
pulp.lpSum(list(input_slack_vars.values())) +
pulp.lpSum(list(output_slack_vars.values())))
# change constraints
for input_category in self.strongly_disposal_input_categories:
name = self.model._constraints[input_category]
self.lp_model_max_slack.constraints[name].addterm(
input_slack_vars[input_category], 1)
self.lp_model_max_slack.constraints[name].sense = pulp.LpConstraintEQ
for output_category in self.strongly_disposal_output_categories:
name = self.model._constraints[output_category]
self.lp_model_max_slack.constraints[name].addterm(
output_slack_vars[output_category], -1)
self.lp_model_max_slack.constraints[name].sense = pulp.LpConstraintEQ
示例6: solve_ilp
# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpMaximize [as 别名]
def solve_ilp(self, N):
# build the A matrix: a_ij is 1 if j-th gram appears in the i-th sentence
A = np.zeros((len(self.sentences_idx), len(self.ref_ngrams_idx)))
for i in self.sentences_idx:
sent = self.sentences[i].untokenized_form
sngrams = list(extract_ngrams2([sent], self.stemmer, self.LANGUAGE, N))
for j in self.ref_ngrams_idx:
if self.ref_ngrams[j] in sngrams:
A[i][j] = 1
# Define ILP variable, x_i is 1 if sentence i is selected, z_j is 1 if gram j appears in the created summary
x = pulp.LpVariable.dicts('sentences', self.sentences_idx, lowBound=0, upBound=1, cat=pulp.LpInteger)
z = pulp.LpVariable.dicts('grams', self.ref_ngrams_idx, lowBound=0, upBound=1, cat=pulp.LpInteger)
# Define ILP problem, maximum coverage of grams from the reference summaries
prob = pulp.LpProblem("ExtractiveUpperBound", pulp.LpMaximize)
prob += pulp.lpSum(z[j] for j in self.ref_ngrams_idx)
# Define ILP constraints, length constraint and consistency constraint (impose that z_j is 1 if j
# appears in the created summary)
prob += pulp.lpSum(x[i] * self.sentences[i].length for i in self.sentences_idx) <= self.sum_length
for j in self.ref_ngrams_idx:
prob += pulp.lpSum(A[i][j] * x[i] for i in self.sentences_idx) >= z[j]
# Solve ILP problem and post-processing to get the summary
try:
print('Solving using CPLEX')
prob.solve(pulp.CPLEX(msg=0))
except:
print('Fall back to GLPK')
prob.solve(pulp.GLPK(msg=0))
summary_idx = []
for idx in self.sentences_idx:
if x[idx].value() == 1.0:
summary_idx.append(idx)
return summary_idx
示例7: get_reaction
# 需要导入模块: import pulp [as 别名]
# 或者: from pulp import LpMaximize [as 别名]
def get_reaction(self, var, facet=None):
"""
For a given composition, what is the maximum delta_composition reaction
on the given facet. If None, returns the whole reaction for the given
PhaseSpace.
Examples::
>>> space = PhaseSpace('Fe2O3-Li2O')
>>> equilibria = space.hull[0]
>>> space.get_reaction('Li2O', facet=equilibria)
"""
if isinstance(var, basestring):
var = parse_comp(var)
if facet:
phases = facet
else:
phases = self.stable
prob = pulp.LpProblem('BalanceReaction', pulp.LpMaximize)
pvars = pulp.LpVariable.dicts('prod', phases, 0)
rvars = pulp.LpVariable.dicts('react', phases, 0)
prob += sum([ p.fraction(var)['var']*pvars[p] for p in phases ])-\
sum([ p.fraction(var)['var']*rvars[p] for p in phases ]),\
"Maximize delta comp"
for celt in self.space:
prob += sum([ p.fraction(var)[celt]*pvars[p] for p in phases ]) ==\
sum([ p.fraction(var)[celt]*rvars[p] for p in phases ]),\
'identical %s composition on both sides' % celt
prob += sum([ rvars[p] for p in phases ]) == 1
if pulp.GUROBI().available():
prob.solve(pulp.GUROBI(msg=False))
elif pulp.COIN_CMD().available():
prob.solve(pulp.COIN_CMD())
elif pulp.COINMP_DLL().available():
prob.solve(pulp.COINMP_DLL())
else:
prob.solve()
prods = defaultdict(float,[ (c, pvars[c].varValue) for c in phases
if pvars[c].varValue > 1e-4 ])
reacts = defaultdict(float,[ (c, rvars[c].varValue) for c in phases
if rvars[c].varValue > 1e-4 ])
n_elt = pulp.value(prob.objective)
return reacts, prods, n_elt