julia - 在 Julia 中使用 MathProgBase 的非线性约束最大化问题
问题描述
目标函数为 f(x,y)=sqrt(x^2+2*y^2-xy),服从 10 > x > 0, 10 > y > 0, x > y。我将找到最大化目标函数的 x 和 y。我需要在 MathProgBase.jl 包中使用非线性模型。https://mathprogbasejl.readthedocs.io/en/latest/nlp.html的教程对我来说很难理解,因为我是初学者。我真的很感谢你的帮助!
解决方案
似乎JuMP 不支持严格的更大/更低的约束(因此大多数求解器引擎也不支持)。
您的问题在 Julia 中的建模将是:
using JuMP, Ipopt
m = Model(with_optimizer(Ipopt.Optimizer, print_level=0))
@variable(m, 0 <= x <= 10, start=1)
@variable(m, 0 <= y <= 10, start=1)
@constraint(m, c1, y <= x )
@NLobjective(m, Max, sqrt(x^2+2*y^2-x*y))
optimize!(m)
status = termination_status(m)
if (status == MOI.OPTIMAL || status == MOI.LOCALLY_SOLVED || status == MOI.TIME_LIMIT) && has_values(m)
if (status == MOI.OPTIMAL)
println("** Problem solved correctly **")
else
println("** Problem returned a (possibly suboptimal) solution **")
end
println("- Objective value : ", objective_value(m))
println("- Optimal solutions:")
println("x: $(value.(x))")
println("y: $(value.(y))")
else
println("The model was not solved correctly.")
println(status)
end
(有关各个步骤的说明,请参见https://lobianco.org/antonello/personal/blog/2017/0203_jump_for_gams_users )
该脚本的结果是:
** Problem returned a (possibly suboptimal) solution **
- Objective value : 14.14213575988668
- Optimal solutions:
x: 10.0
y: 10.0
推荐阅读
- javascript - 根据值在两个对象数组之间进行过滤
- angular - 如何使用模拟的 MsalGuard 为 Angular 9 应用程序编写量角器 2e2 测试?
- javascript - 访问数据集以获取值(shopify)
- sox - 如何使用 sox 创建均衡器曲线
- sql - 需要索引哪个子句的列?
- python - discord.py 在特定时间和日期发送消息
- woocommerce - 获取与 woocommerce 面包屑相同的类别
- .net - 如何使用 Gremlin Cosmos DB 过滤相关对象?
- section508 - 我是否需要表格的标题标签和标题?
- javascript - 如何使用 javascript StartsWith 查找 Discord 频道