Gurobi/python euclidean/manhattan distance calculations inside of a constraint, addConstr(...)

151 Views Asked by At

Is it possible to use the sklearn pairwise_distances function inside an addConstr(...) for computing the distance between 2 D-dimensional points in the constraint? I'd like to do something like this:

for i in range(N):
    for j in range(N):
        constr1 = m.addConstr( pairwise_distances(X[i,:], Y[j,:]) <= 50 for i in range(N), name="constr1") 

# X and Y are N by D numpy arrays 

I know that Gurobi only allows optimization functions that are linear, piecewise linear or Quadratic (as far as I know), so most other functions like sqrt aren't implementable (even for constraints). So trying to manually implement distance calculations involving square roots or absolute values may not be possible in gurobi constraints - though if I'm wrong, I'd like to be corrected.

Also how would I do this if Y wasn't a pre-set numpy array but actually a gurobi variable I'm trying to find?

0

There are 0 best solutions below