[英]Gurobi-Python with set
这是基于功率集生成变量的示例代码(我假设这是使用model.addVar()
)。 电源集生成器从此处复制: https : //www.technomancy.org/python/powerset-generator-python/
def powerset(seq):
"""
Returns all the subsets of this set. This is a generator.
"""
if len(seq) <= 1:
yield seq
yield []
else:
for item in powerset(seq[1:]):
yield [seq[0]]+item
yield item
variables = []
for x in powerset([1, 2, 3]):
variables.append(model.addVar())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.