Gurobi的数据类型

mutidict

mutidict多重字典:顾名思义,该种结构可以一次性创建多个字典。

import gurobipy as grb
student, chinese, math, english = grb.multidict({
    'student1': [1, 2, 3],
    'student2': [2, 3, 4],
    'student3': [3, 4, 5],
    'student4': [4, 5, 6]
})

tuplelist

tuplelist,即元组列表

import gurobipy as grb

tl = grb.tuplelist([(1, 2), (1, 3), (2, 3), (2, 5)])

tupledict

import gurobipy as grb

model = grb.Model()

# 定义变量的下标
tl = [(1, 1), (1, 2), (1, 3),
      (2, 1), (2, 2), (2, 3),
      (3, 1), (3, 2), (3, 3)]
vars = model.addVars(tl, name="d")

# 基于元素下标的操作
print(sum(vars.select(1, '*')))
# 输出
# 

你可能感兴趣的:(python)