I have the following objective function :
Minimize(sum(abs(di[i]-d[i]) ) )
and I want to add a constraint to make sure that d[i] is appeared at least k times in d
d is a vector of ordered integers like d=[14, 14, 13, 12, 12, 11, 11, 9, 8, 8, 6, 6, 5, 5, 5, 5, 3, 3, 2, 1]
I am using GEKKO to solve it, but I didn't manage to formulate the constraint
this is the code for solving the objective function
from gekko import GEKKO
z = GEKKO()
z.options.SOLVER=1 # APOPT is an MINLP solver
d=[14, 14, 13, 12, 12, 11, 11, 9, 8, 8, 6, 6, 5, 5, 5, 5, 3, 3, 2, 1]
n=len(d)
di = [z.Var(i,lb=i,ub=len(d),integer=True) for i in d]
#Objective function
z.Obj(sum(abs(di[i]-d[i])for i in range(n)) )
z.solve()
for Example : for k = 3 , I would like to get
di = [14, 14, 14, 12, 12, 12, 12, 9, 9, 9, 6, 6, 6, 5, 5, 5, 3, 3, 3, 3]