猿问

如何在不同的步骤中运行优化问题?

我在AMPL中有一个优化问题。我想知道如何在不同的步骤中使用自己的算法运行优化?我应该使用AMPL或Python或其他软件吗?


这是我想做的:


我想逐层搜索可行的统治。例如,如果我的问题在维度 3 中,我想在 3 个图层中搜索,例如:


first layer :  x1+x2+x3=1


second layer:  x1+x2+x3=2


third layer:    x1+x2+x3=3

在每个层中,我都有一些新的约束,当搜索在该层中时,这些约束将处于活动状态。假设 、 分别是层 1、2 和 3 的约束。我希望问题按如下方式运行:C1C2C3


首先在第一层运行,并且必须处于活动状态:C1


          `x1+x2+x3=1`   and `C1`     are active.  (the constraints C2 ,C3 and 2 other layers are non-active)

然后在第二层中运行并且必须处于活动状态:C2


          `x1+x2+x3=2`   and `C2`     are active.  (the constraints C1 ,C3 and 2 other layers are non-active)

第三层在第三层运行,必须处于活动状态:C3


          `x1+x2+x3=3`   and `C3`     are active.  (the constraints C1 ,C2 and 2 other layers are non-active)



慕容森
浏览 125回答 1
1回答

元芳怎么了

您可以使用脚本在 AMPL 中执行此操作。例如:reset;option solver gurobi;param n_x := 3;var x{1..n_x};param bignum := 1e4;param layer;set layers := 1..n_x;s.t. sum_constraint: x[1] + x[2] + x[3] = layer;s.t. c1a: x[1] >= (if layer = 1 then 10 else 10-bignum);s.t. c1b: x[1] <= (if layer = 1 then 10 else 10+bignum);# on layer 1, constrain x[1] = 10, otherwise leave it effectively unconstraineds.t. c2a: x[2] >= (if layer = 2 then 20 else 20-bignum);s.t. c2b: x[2] <= (if layer = 2 then 20 else 20+bignum);s.t. c3a: x[3] >= (if layer = 3 then 30 else 30-bignum);s.t. c3b: x[3] <= (if layer = 3 then 30 else 30+bignum);minimize of: x[1]^2+x[2]^2+x[3]^2;for {i in layers}{&nbsp; &nbsp; let layer := i;&nbsp; &nbsp; printf "\nLayer = %1.0f\n", layer;&nbsp;&nbsp; &nbsp; solve;&nbsp; &nbsp; display x;}您还可以使用 和 语句来打开和关闭约束,具体取决于您希望自动执行约束的程度。droprestore
随时随地看视频慕课网APP

相关分类

Python
我要回答