Maximize sum of the piecewise function

Hi there! Since it seems that you’re new to JuMP, you should take a read through the tutorials:

You can’t create a nonlinear objective by passing it a Julia function like that.

Do instead

@NLobjective(model, Max, sum_rate(β...)

You’ll also get a warning, so you’ll need

register(model, :sum_rate, 3, sum_rate; autodiff = true)

You should also consider writing out the expression directly. It lets JuMP compute more efficient derivatives that might improve performance.

model = Model(Ipopt.Optimizer)
@variable(model, β[i = 1:3] >= 0)
@constraint(model, sum(β) <= 1)
@NLobjective(
    model, 
    Max, 
    sum(0.5 * log2(1 + β[i]/(β[i] + 2)) for i in 1:length(β)-1) +
    0.5 * log2(1 + β[3] / 2)
)
optimize!(model)
2 Likes