From d2b8b1a085dfde0f32c77c33865ecc5960749362 Mon Sep 17 00:00:00 2001 From: Nitish Malang <71919457+nitishmalang@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:20:33 +0530 Subject: [PATCH] Update redundant_facet_removal_backup.py --- .../backup/redundant_facet_removal_backup.py | 86 ------------------- 1 file changed, 86 deletions(-) diff --git a/dingo/backup/redundant_facet_removal_backup.py b/dingo/backup/redundant_facet_removal_backup.py index 5692fd8d..45399c0e 100644 --- a/dingo/backup/redundant_facet_removal_backup.py +++ b/dingo/backup/redundant_facet_removal_backup.py @@ -304,89 +304,3 @@ def fast_remove_redundant_facets(lb, ub, S, c, opt_percentage=100): -def fast_inner_ball(A, b): - """A Python function to compute the maximum inscribed ball in the given polytope using gurobi LP solver - Returns the optimal solution for the following linear program: - max r, subject to, - a_ix + r||a_i|| <= b, i=1,...,n - - Keyword arguments: - A -- an mxn matrix that contains the normal vectors of the facets of the polytope row-wise - b -- a m-dimensional vector - """ - - extra_column = [] - - m = A.shape[0] - n = A.shape[1] - - for i in range(A.shape[0]): - entry = np.linalg.norm( - A[ - i, - ] - ) - extra_column.append(entry) - - column = np.asarray(extra_column) - A_expand = np.c_[A, column] - - with gp.Env(empty=True) as env: - env.setParam("OutputFlag", 0) - env.start() - - d = A_expand.shape[1] - - with gp.Model(env=env) as model: - - # Create variable - x = model.addMVar( - shape=d, - vtype=GRB.CONTINUOUS, - name="x", - lb=-GRB.INFINITY, - ub=GRB.INFINITY, - ) - model.update() - - # Make A_full_dim sparse - A_expand_sparse = sp.csr_matrix(A_expand.astype("float")) - - # Add constraints - model.addMConstr(A_expand_sparse, x, "<", b, name="c") - model.update() - - # Set the ith row of the A matrix as the objective function - a = np.ones((1, n + 1)) - azero = np.zeros((1, n)) - a[:, :-1] = azero - objective_function = a[0] - - # Set the objective function in the model - model.setMObjective( - None, objective_function, 0.0, None, None, x, GRB.MAXIMIZE - ) - model.update() - - # Optimize model - model.optimize() - - # Get the solution returned - varss = model.getVars() - - # Get the center point and the radius of max ball from the solution of LP; its last element is the radius - point = [] - for i in range(len(varss)): - if i == len(varss) - 1: - r = varss[i].x - else: - value = varss[i].x - point.append(value) - - # And check whether the computed radius is negative - if r < 0: - print( - "The radius calculated has negative value. The polytope is infeasible or something went wrong with the solver" - ) - else: - return point, r