为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕容森 2022-08-02 17:22:32
我在AMPL中有一个优化问题。我想知道如何在不同的步骤中使用自己的算法运行优化?我应该使用AMPL或Python或其他软件吗?这是我想做的:我想逐层搜索可行的统治。例如,如果我的问题在维度 3 中,我想在 3 个图层中搜索,例如:first layer :  x1+x2+x3=1second layer:  x1+x2+x3=2third 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)
查看完整描述

1 回答

?
元芳怎么了

TA贡献1798条经验 获得超7个赞

您可以使用脚本在 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 unconstrained


s.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}{

    let layer := i;

    printf "\nLayer = %1.0f\n", layer; 

    solve;

    display x;

}

您还可以使用 和 语句来打开和关闭约束,具体取决于您希望自动执行约束的程度。droprestore


查看完整回答
反对 回复 2022-08-02
  • 1 回答
  • 0 关注
  • 124 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号