【问题标题】:IBM Optimization Studio OPL, why constraint is not respected?IBM Optimization Studio OPL,为什么不遵守约束?
【发布时间】:2019-02-27 17:36:37
【问题描述】:

这里是我需要解决的optimization problem 的描述,但有一点小改动。我需要添加两个约束:

  • 第一个约束:从每个组中我们只想选择一个产品,这意味着我们不能允许同一组中的两个产品在同一个购物篮中(即 Product11 和 Product12 永远不应在同一个购物篮中)
  • 第二个约束:在用户购物篮中,我们只需要用户感兴趣的类别中的产品。即,如果用户对“蛋白质”类别感兴趣,他永远不会在他的购物篮中找到“碳水化合物”类别中的产品'也不是'胖'。

因此我更改了 OPL 代码 products.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);

  }

这里是 products.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}。

我在冲突选项卡中也注意到了这一点:

在放松标签中:

所以我有五个问题:

  1. 我看不出约束之间有任何冲突,因为如果我们选择产品“Product12”(或 Product11”),我们会遵守所有约束,预算将
  2. 我不明白为什么优化器选择不尊重最后一个约束,而是最大化目标函数。
  3. 如果优化器不使用任何松弛,这是否会导致模型不可行(无法解决问题)?我不明白为什么?对我来说,只选择“Product12”(或“Product11”)是一个完美的解决方案,无需任何放松。
  4. 如何强制优化器不放松最后一个约束? (请注意,更改设置文件 products.ops 以仅放松 documentation 中的标记约束没有帮助,因为我只想放松一个约束)

  5. 在有关 relaxing infeasible models 的文档中,我发现了这个:

但是请注意,不可行可能是另一个约束建模错误的结果。

这是我的情况吗?

提前感谢您的帮助

【问题讨论】:

    标签: optimization cplex nonlinear-optimization opl


    【解决方案1】:
    • on no.1+2 = 你有一些模型中没有定义的东西......你能说如果 AllGroups 和组单独存在或者 2 相同,那么这些数据是什么?您还使用“产品”和“所有产品”,与“组”相同的 Q。你会在这里粘贴一个完整的 .mod 和 .dat,你已经运行并产生了你展示的轻松结果......?一旦我至少可以重现您显示的问题,我就可以开始研究“为什么”:-)
    • 在 3 号 = 是的,它应该是
    • on no.4 = 获得非松弛模型的方法是删除约束的命名。 IE。如果没有放松可能没有解决方案,则每个命名的约束都被认为是放松的。每个未命名的约束都是“硬”的,即它必须得到尊重,不能放松。只需删除或注释掉这些行: ctBudget:// first constraint, ctGroups: // second constraint, ctCategories: // third constraint如果您希望所有约束都像给定数据一样得到尊重...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 2015-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多