Gurobi封装了更高级的Python数据结构,即Multidict、Tuplelist、Tupledict。在对复杂或大规模问题建模时,可以大大提高模型求解效率采用list和tuplelist的速度对比
multdict
multdict函数允许在一个语句中初始化一个或多个字典,举例如下:
import gurobipy as grb
# mutidict 用法
student, chinese, math, english = grb.multidict({
'student1': [10, 2, 300],
'student2': [20, 3, 400],
'student3': [30, 4, 500],
'student4': [40, 5, 600]
})
print(student) # 字典的键
# 输出
# ['student1', 'student2', 'student3', 'student4']
print(chinese) # 语文成绩的字典
# 输出
# {'student1': 10, 'student2': 20, 'student3': 30, 'student4': 40}
print(math) # 数学成绩的字典
# 输出
# {'student1': 2, 'student2': 3, 'student3': 4, 'stu