How to use max function within integral in the objective function #305
-
I'm trying to set up an optimization where my objective function is in the following form: i.e., I want to find
Any thoughts/ comments/ help would be greatly appreciated!! The codes I've got so far as well as the error message are posted below. I got the error msg while executing the line for objective function. The long formula is just to the exact form of function p and q listed above. The errors are enclosed after the codes.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Hi @christineymshen and welcome. Yes, we can set this up in InfiniteOpt without too much issue. First, we can reformulate using a common linear programming trick shown here to address the max function. In InfiniteOpt, I get: using InfiniteOpt, Ipopt
# Initialize the model
model = InfiniteModel(Ipopt.Optimizer)
# Define the infinite parameters
@infinite_parameter(model, x ∈ [-10000, 10000], num_supports = 100)
@infinite_parameter(model, θ ∈ [-10000, 0], num_supports = 100)
# Define the decision variables and their bounds
@variable(model, λ ≥ 0, Infinite(θ)) # creates λ(θ)
@variable(model, z ≥ 0) # creates z
@variable(model, aux ≥ 0, Infinite(x)) # creates auxiliary variable for handling the max operation
# Define the known functions
q = # put function here
p = # put function here
# Define the objective function
α = 0.05
@objective(model, Min, ∫(aux, x) + α * z)
@constraint(model, aux ≥ q - z * ∫(p * λ, θ))
# Add the constraints
@constraint(model, ∫(λ, θ) == 1)
# Optimize and get the results
optimize!(model)
if has_values(model)
opt_z = value(z)
opt_λ = value(λ)
end I should note that the use of The code you provided had a number of errors, I would recommend working through a few of the tutorials provided by JuMP.jl here and then review the InfiniteOpt tutorials. These will help you get a much better feel for the syntax and workflows. |
Beta Was this translation helpful? Give feedback.
Hi @christineymshen and welcome.
Yes, we can set this up in InfiniteOpt without too much issue. First, we can reformulate using a common linear programming trick shown here to address the max function.
In InfiniteOpt, I get: