Request
It would be nice if the interface provides the option to use Gurobi. For now, the implementation is hard-coded to use scipy.optimize.linprog. For example:
|
tem1 = linprog(np.matmul(P[i], f1), A, b, bounds=(None, None)).fun |
|
# tem1 = solve_LP(np.matmul(P[i], f1), A, b, bounds=None) |
|
tem2 = -linprog(-np.matmul(P[i], f1), A, b, bounds=(None, None)).fun |
|
# tem2 = solve_LP(np.matmul(P[i], f1), A, b, bounds=None, is_minimum=False) |
|
out_lowerbound = linprog(c[i], bound_A, bound_b, bounds=[None, None]).fun + d[i] |
|
# out_lowerbound = solve_LP(c[i].detach().numpy(), bound_A, bound_b, bounds=None)+d[i] |
|
out_upperbound = -linprog(-c[i], bound_A, bound_b, bounds=[None, None]).fun + d[i] |
|
# out_upperbound = solve_LP(c[i].detach().numpy(), bound_A, bound_b, is_minimum=False, bounds=None)+d[i] |
|
def solve_LP(c: np.array, A: np.array, b: np.array, bounds, is_minimum=True, DualReductions=1): |
|
# assert len(c) == len(A[0]) |
|
# assert len(A) == len(b) |
|
# x_dim = len(c) |
|
# m = Model() |
|
# blockPrint() |
|
# m.Params.DualReductions = DualReductions |
|
# m.Params.LogToConsole = 0 |
|
# enablePrint() |
|
# if bounds: |
|
# x = m.addMVar(x_dim, lb=bounds[0], ub=bounds[1]) |
|
# else: |
|
# x = m.addMVar(x_dim, lb=-GRB.INFINITY, ub=GRB.INFINITY) |
|
# if is_minimum: |
|
# m.setObjective(c @ x, GRB.MINIMIZE) |
|
# else: |
|
# m.setObjective(c @ x, GRB.MAXIMIZE) |
|
# m.addConstr(A @ x <= b, name='Ab') |
|
# m.optimize() |
|
# if m.status == GRB.UNBOUNDED: |
|
# if is_minimum: |
|
# return -np.inf |
|
# else: |
|
# return np.inf |
|
# elif m.status == GRB.OPTIMAL: |
|
# obj = m.getObjective() |
|
# return obj.getValue() |
|
# elif DualReductions == 1: |
|
# return solve_LP(c, A, b, bounds, is_minimum, DualReductions=0) |
|
# else: |
|
# print('error') |
|
if is_minimum: |
|
return linprog(c, A, b, bounds).fun |
|
else: |
|
return -linprog(-c, A, b, bounds).fun |
Possible Solution
Perhaps the solve_LP function could be the interface to decide whether to use Gurobi or not.
Comments
Gurobi by default uses up to 32 threads. This restriction can be lifted by setting Model.Params.Threads=os.cpu_count().
Request
It would be nice if the interface provides the option to use Gurobi. For now, the implementation is hard-coded to use
scipy.optimize.linprog. For example:REASSURE/ICLR/tools/build_PNN.py
Lines 121 to 124 in 4781c8e
REASSURE/ICLR/tools/build_PNN.py
Lines 61 to 64 in 4781c8e
REASSURE/ICLR/tools/gurobi_solver.py
Lines 14 to 48 in 4781c8e
Possible Solution
Perhaps the
solve_LPfunction could be the interface to decide whether to use Gurobi or not.Comments
Gurobi by default uses up to 32 threads. This restriction can be lifted by setting
Model.Params.Threads=os.cpu_count().