0

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?

2
  • You may need to check your indexers i and j. Commented Jul 12, 2022 at 20:58
  • @GregGlockner I'm trying to find the dist between 2 points there, and there may be double counting taking place. Other than changing the inner for loop to 'range(i,N)' to not double count, what else can I do to compute the distances within the gurobi constraint function? Is the ":" indexing causing the problem? Commented Jul 13, 2022 at 8:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.