'Adds EQ/LEQ constraints to the model using the data from mat and vec.
Parameters
model : GUROBI model
The problem model.
variables : list
The problem variables.
rows : range
The rows to be constrained.
ctype : GUROBI constraint type
The type of constraint.
nonzero_locs : GUROBI tuplelist
A list of all the nonzero locations.
mat : SciPy COO matrix
The matrix representing the constraints.
vec : NDArray
The constant part of the constraints.
Returns
list
A list of constraints.'

def add_model_lin_constr(self, model, variables, rows, ctype, nonzero_locs, mat, vec):

    import gurobipy
    constr = []
    for i in rows:
        expr_list = []
        for loc in nonzero_locs.select(i, '*'):
            expr_list.append((mat[loc], variables[loc[1]]))
        if (len(expr_list) > 0):
            expr = gurobipy.LinExpr(expr_list)
            constr.append(model.addConstr(expr, ctype, vec[i]))
        else:
            constr.append(None)
    return constr
