本文整理汇总了Python中gurobipy.Model.addConstrs方法的典型用法代码示例。如果您正苦于以下问题:Python Model.addConstrs方法的具体用法?Python Model.addConstrs怎么用?Python Model.addConstrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gurobipy.Model
的用法示例。
在下文中一共展示了Model.addConstrs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _initialize_model
# 需要导入模块: from gurobipy import Model [as 别名]
# 或者: from gurobipy.Model import addConstrs [as 别名]
def _initialize_model(self):
problem = Model()
problem.setParam('OutputFlag', False)
# edges from source to reviewers, capacity controls maximum reviewer load
self._source_vars = problem.addVars(self.numrev, vtype=GRB.CONTINUOUS, lb=0.0,
ub=self.ability, name='reviewers')
# edges from papers to sink, capacity controls a number of reviewers per paper
self._sink_vars = problem.addVars(self.numpapers, vtype=GRB.CONTINUOUS, lb=0.0,
ub=self.demand, name='papers')
# edges between reviewers and papers. Initially capacities are set to 0 (no edge is added in the network)
self._mix_vars = problem.addVars(self.numrev, self.numpapers, vtype=GRB.CONTINUOUS,
lb=0.0, ub=0.0, name='assignment')
problem.update()
# flow balance equations for reviewers' nodes
self._balance_reviewers = problem.addConstrs((self._source_vars[i] == self._mix_vars.sum(i, '*')
for i in range(self.numrev)))
# flow balance equations for papers' nodes
self._balance_papers = problem.addConstrs((self._sink_vars[i] == self._mix_vars.sum('*', i)
for i in range(self.numpapers)))
problem.update()
self._problem = problem