【发布时间】:2018-01-15 17:35:01
【问题描述】:
通常是 pyomo 和 python 的新手,我正在尝试为二进制整数编程问题实现一个简单的解决方案。然而,问题很大,但矩阵 x 的大部分值是事先已知的。我一直在试图弄清楚如何“告诉” pyomo 一些值是预先知道的以及它们是什么。
from __future__ import division # converts to float before division
from pyomo.environ import * # Make symbolds used by pyomo known to python
model = AbstractModel() # Declaration of an abstract model, called model
model.users = Set()
model.slots = Set()
model.prices=Param(model.users, model.slots)
model.users_balance=Param(model.users)
model.slot_bounds=Param(model.slots)
model.x = Var(model.users, model.slots, domain=Binary)
# Define the objective function
def obj_expression(model):
return sum(sum(model.prices[i,j] * model.x[i,j] for i in model.users)
for j in model.slots)
model.OBJ = Objective(rule=obj_expression, sense=maximize)
# A user can only be assigned to one slot
def one_slot_rule(model, users):
return sum(model.x[users,n] for n in model.slots) <= 1
model.OneSlotConstraint = Constraint(model.users, rule=one_slot_rule)
# Certain slots have a minimum balance requirement.
def min_balance_rule1(model, slots):
return sum(model.x[n,slots] * model.users_balance[n] for n in
model.users) >= model.slot_bounds[slots]
model.MinBalanceConstraint1 = Constraint(model.slots,
rule=min_balance_rule1)
所以我希望能够从我知道 x[i,j] 的某些值为 0 的事实中受益。例如,我有一个额外条件列表
x[1,7] = 0
x[3,6] = 0
x[5,8] = 0
如何包含这些信息以从减少搜索空间中受益? 非常感谢。
【问题讨论】:
-
为什么要使用抽象模型?您是使用
pyomo命令还是 Python 脚本求解模型?
标签: pyomo