julia – JuMP:如何从getvalue(x)获得多个解决方案

我正在解决这个多目标问题

《julia – JuMP:如何从getvalue(x)获得多个解决方案》

    f1(x,y) = x
    f2(x,y) = (2.0-exp(-((y-0.2)/0.004)^2)-0.8*exp(-((y-0.6)/0.4)^2) )/x

    isdefined(:f1) || JuMP.register(:f1, 2, f1, autodiff=true)
    isdefined(:f2) || JuMP.register(:f2, 2, f2, autodiff=true)

    m = Model(solver=IpoptSolver(print_level=0))
@variable(m, 0.1 <= x <= 1.0)
@variable(m, 0.0 <= y <= 1.0)
@variable(m, alpha1)
@variable(m, alpha2)
@NLobjective(m, Min, alpha1 + alpha2)
@constraint(m, f1(x,y) - z1_id >= -alpha1)
@constraint(m, f1(x,y) - z1_id <= alpha1)

@NLconstraint(m, f2(x,y) - z2_id >= -alpha2)
@NLconstraint(m, f2(x,y) - z2_id <= alpha2)
solve(m)
x_opt = getvalue(x)
y_opt = getvalue(y)

println("GOAL Programming (p=1): F1 = $(f1(x_opt, y_opt)), F2 = $(f2(x_opt, y_opt))")

它应该有两个解决方案.我只得到了第一个带有getvalue(x)的东西,我怎样才能得到所有其他的?

最佳答案 我碰到了类似的东西,但是在整数编程中.然而,当我寻找答案把我带到这里时,这似乎是一个分享我的想法的好地方.

对我来说,似乎要解决这个问题的方法是首先解决系统,然后添加一个约束,以前找到的解决方案现在是不可行的.我的想法是按照以下方式追加:

solve(m)
x_opt = getvalue(x)
y_opt = getvalue(y)
println("GOAL Programming (p=1): F1 = $(f1(x_opt, y_opt)), F2 = $(f2(x_opt, y_opt))")

eps = 1.e-15
@constraint(m, x - x_opt <= eps)
@constraint(m, x - x_opt >= eps)
@constraint(m, y - y_opt <= eps)
@constraint(m, y - y_opt >= eps)
solve(m)
println("GOAL Programming (p=1): F1 = $(f1(x_opt, y_opt)), F2 = $(f2(x_opt, y_opt))")

我在循环中为我的整数编程做了同样的事情,即包括最后一行而在solve(m)==:Optimal,用于查找更多选项.

点赞