I am working on an algorithm where I would like to solve convex programs (CP) repeatedly; in the algorithm, the CP’s structure remains the same (same variables, same number of constraints, etc.), but coefficients to the constraints get updated. Thus, to automate the modification to the JuMP.Model (without having to reinstantiate one at each iteration), I am trying to use Parameter ’s.
However, the issue I am having is that any nonlinear operation on Parameter ’s are recognized as nonlinearity of the optimization problem itself (even though it is meant to be a fixed value & not an optimization variable), thus making the resulting model appear as though it is not a CP.
Please see below a minimal example that I would like to resolve:
using ECOS
using JuMP
model = Model(ECOS.Optimizer)
@variable(model, x[1:2] >= 0)
@variable(model, θ in Parameter(0)) # initialize storage for parameter
set_parameter_value(θ, 0.5) # parameter value would be updated by outer loop
@constraint(model, x[1] + x[2] <= cos(θ)) # problematic due to nonlinear operation!
@objective(model, Min, 2x[1] + 3x[2])
optimize!(model)
@show objective_value(model)
for which I get the error
ERROR: LoadError: Constraints of type MathOptInterface.ScalarNonlinearFunction-in-MathOptInterface.LessThan{Float64} are not supported by the solver.
If you expected the solver to support your problem, you may have an error in your formulation. Otherwise, consider using a different solver.
The list of available solvers, along with the problem types they support, is available at https://jump.dev/JuMP.jl/stable/installation/#Supported-solvers.
Is there something that I am missing about how I should be using Parameter…?
If not (and if this is unavoidable), what would be a good way for me to be able to update the value of \theta in the above code without having to recreate the model/overwrite the constraint?
Thank you for your reply!
I see, I am for now resorting with using set_normalized_rhs().
Concerning Option 2 in your code, I imagine using fix(cos_θ, cos(rad); force = true) still does not make cos_θnot a variable as far as the model is concerned?
I am asking for a scenario where I might have, for example, a constraint like