这是我需要解决的optimization problem的描述,但有一点曲折。我需要添加两个约束:
因此,我更改了OPL代码product.mod:
{string} categories=...;
{string} groups[categories]=...;
{string} allGroups=union (c in categories) groups[c];
{string} products[allGroups]=...;
{string} allProducts=union (g in allGroups) products[g];
float prices[allProducts]=...;
int Uc[categories]=...;
float Ug[allGroups]=...;
float budget=...;
dvar boolean z[allProducts]; // product out or in ?
dexpr int xg[g in allGroups]=(sum(p in products[g]) z[p]);
dexpr int xc[c in categories]=(1<=sum(g in groups[c]) xg[g]);
maximize
sum(c in categories) Uc[c]*xc[c]+
sum(c in categories) sum(g in groups[c]) Uc[c]*Ug[g]*xg[g];
subject to
{
ctBudget:// first constraint
sum(p in allProducts) z[p]*prices[p]<=budget;
ctGroups: // second constraint
forall( g in allGroups )
xg[g]==1;
ctCategories: // third constraint
forall( c in categories )
Uc[c]==xc[c];
}
{string} solution={p | p in allProducts : z[p]==1};
execute
{
writeln("xg=",xc);
writeln("xg=",xg);
writeln("Solution=",solution);
}
这里是product.data的代码
categories={"Carbs","Protein","Fat"};
groups=[{"Meat","Milk"},{"Pasta","Bread"},{"Oil","Butter"}];
products=[
{"Product11","Product12"},{"Product21","Product22","Product23"},
{"Product31","Product32"},{"Product41","Product42"},
{"Product51"},{"Product61","Product62"}];
prices=[1,1,3,3,2,1,2,1,3,1,2,1];
Uc=[1,0,0];
Ug=[0.8,0.2,0.1,1,0.01,0.6];
budget=2;
IBM Studio给出的结果如下:{Product12,Product31};而我想要的结果是{Product11}或{Product12}。
所以我有五个问题:
如何让优化器不放松最后一个约束? (请注意,更改设置文件product.ops以仅放宽documentation中的带标签的约束没有帮助,因为我只想放宽一个约束)
在关于relaxing infeasible models的文档中,我发现了这一点:
但是,请注意,不可行可能是另一个约束建模错误的结果。
这是我的情况吗?
预先感谢您的帮助
答案 0 :(得分:0)
ctBudget:// first constraint, ctGroups: // second constraint, ctCategories: // third constraint
,如果您希望所有约束都像给定数据一样得到遵守...