I have some points(N). For these points I have a distance matrix D (N*N). Also I have an attribute data for these points A (1*N). I want to select fixed number of points(K) such that sum of attribute is maximum
while distance between selected points lies between a range (min_dis,max_dis).
I tried implementing this optimization problem in Pulp with N=10,K=3.
A = [300,436,234,11,23,897,439,56,123,432]
.
import pulp
import numpy as np
inds = range(10)
#create a vector x which will only accept value 0,1
x = pulp.LpVariable.dicts('x', inds, lowBound = 0,upBound = 1,cat = pulp.LpInteger)
my_lp_problem = pulp.LpProblem("My LP Problem", pulp.LpMaximize)
#sum of x should be equal to no of points I want (which is 3)
my_lp_problem += sum([x[store] for store in inds]) == 3
#maximize dot product A.x (which would be sum of attributes)
my_lp_problem += sum([A[point] * x[point] for point in inds])
However I am not able to put the constraints on distance matrix. Which would be something like this:
np.multiply(x,D).max() < max_dis and np.multiply(x,D).min() > min_dis
As I could not find how to use max(), min() and matrix multiplication kind of things in pulp. What I understand is this has a linear objective function while the constraints are not linear. I also explored scipy.optimize
but as x can contain only 0 and 1 not a continuous variable I started with pulp.
Any help appreciated!