【Gurobi】Gurobi的MVar或者矩阵形式的变量处理方法小例子

Gurobi的MVar或者矩阵形式的变量处理方法小例子

A x = 1 \begin{aligned} Ax =1 \end{aligned} Ax=1

A = [ 2 1 1 3 ] \begin{aligned} A = \left[ \begin{matrix} 2&1 \\ 1& 3 \\ \end{matrix} \right] \end{aligned} A=[2113]



from gurobipy import *
import numpy as np

model = Model()

A = np.ones([2, 2])

A[0][0] = 2
A[1][1] = 3

b = np.ones([2, 1])

x = model.addVars(2, 1, vtype=GRB.BINARY)

model.update()

x = MVar(model.getVars())

model.addConstr(A @ x == 1)

model.write('A.lp')
print(A)

猜你喜欢

转载自blog.csdn.net/HsinglukLiu/article/details/125117406