I am trying to create an optimization problem using CVXPY with a variable number of summed expressions. Unfortunately, it keeps erroring out and saying that I am not following DCP rules. From my limited understanding, I am following the rules, but nothing I do seems to stop the error. The equation I would like to optimize is A * (x^B)/(C + x^B) where A, B, and C are parameters that don't change per expression and x is the variable being manipulated. A, B, and C are retrieved using the dictionary param_dict in the objective.
def optimize(optimization_granularity, number_scenarios, brands, channels,
param_dict, media):
variables = {}
# create one optimization problem per brand
for brand in brands:
variables[brand] = {}
for media_channel in channels[brand]:
variables[brand][media_channel] = cp.Variable(nonneg=True) # set variable per channel
# Constraints
constraint = [cp.sum([variables[brand][channel] for channel in variables[brand].keys()]) <= budgets[brand]]
# Objective of the form A * (x**B)/(C + x**B)
obj = cp.Maximize( cp.sum([ param_dict[brand][channel]['A'] * (variables[brand][channel]**param_dict[brand][channel]['B']) / ( param_dict[brand][channel]['C'] + (variables[brand][channel]**param_dict[brand][channel]['B']) ) for channel in channels]) )
# Solve
prob = cp.Problem(obj, constraint)
prob.solve(solver='ECOS', verbose=True)
Below is the error:
DCPError: Problem does not follow DCP rules. Specifically:
The objective is not DCP. Its following subexpressions are not:
211570.41977859367 @ power(var4366, 1.3) / (40669791827.45178 + power(var4366, 1.3))
699231.8358226985 @ power(var4368, 1.3) / (52384445853.403046 + power(var4368, 1.3))
123474.761394506 @ power(var4373, 1.275) / (2778556157.2277045 + power(var4373, 1.275))...```