I am using the Python API to cplex to solve an optimization problem: finding the set of binary variables of size N (e.g. 10) to maximize their mutual distance. To do so, I have put together the following:
matrix = pd.read_csv("matrix.csv", index_col=0)
# declare integer variables
im = Model(name='max_weight_clique')
b = im.binary_var_dict(matrix.index.values)
# define objective function
clique_weight = im.sum(b[i] * b[j] * (matrix.loc[i, j] + matrix.loc[j, i])
for i, j in itertools.combinations(matrix.index, 2))
# add to key performance indicators
im.add_kpi(clique_weight, 'clique_weight')
# set size of clique
im.add_constraint(im.sum(b) == 10)
im.maximize(clique_weight)
I would like to modify my objective function to, instead, maximize the minimum distance. When I try to specify this as the following, I run into an error:
# minimum within clique
clique_min = im.min(adj_mat.loc[i, j] for i in adj_mat.index for j in adj_mat.index if b[i] == 1 and b[j] == 1)
im.add_kpi(clique_min, 'clique_min')
TypeError: cannot convert a constraint to boolean: acc_num_NC_015394 == 1
How should I correctly specify this constraint? This seems related to this SO, but my issue is specific to the python API.