IBM Optimization Studio OPL,为什么不遵守约束? [英] IBM Optimization Studio OPL, why constraint is not respected?

查看:128
本文介绍了IBM Optimization Studio OPL,为什么不遵守约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是优化问题我需要解决,但要稍作调整.我需要添加两个约束:

Here is a description of the optimization problem I need to solve, but with a small twist. I need to add two constraints:

  • 第一个约束条件:我们只希望从每个组中选择一个产品,这意味着我们不能允许同一组中的两个产品位于同一购物篮中(即,Product11和Product12永远不应位于同一购物篮中)
  • 第二个约束:在用户购物篮中,我们只需要用户感兴趣的类别的产品.即,如果用户对蛋白质"类别感兴趣,那么他永远不会在篮子中找到碳水化合物"类别的产品或脂肪".

因此,我更改了OPL代码product.mod:

Accordingly I have changed the OPL code 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);

  }

这里是product.data的代码

Here the code for 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}.

The results given by IBM Studio are the following: {Product12,Product31}; while the result I want is either {Product11} or {Product12}.

我在冲突"标签中也注意到了这一点:

I have also noticed this in the conflicts tab:

这在放松选项卡中:

And this in the relaxation tab:

所以我有五个问题:

  1. 我看不到约束之间的任何冲突,因为如果我们选择产品"Product12"(或Product11"),我们将遵守所有约束,并且预算将为< = 2,因为price ["Product12"] = = 1.
  2. 我不明白为什么优化器选择不遵守最后一个约束,而是最大化目标函数.
  3. 如果优化器未使用任何松弛,是否会导致模型不可行(无法解决问题)?我不明白为什么?对我来说,仅选择"Product12"(或"Product11")是一个完美的解决方案,无需任何放松.
  4. 如何让优化器不放松最后一个约束? (请注意,如

  1. I don't see any conflicts between the constraints, because if we choose the product "Product12" (or Product11") we respect all the constraint and the budget would be <= 2 because price["Product12"]==1.
  2. I don't understand why does the optimizer chose to not respect the last constraint, and to maximize the objective function instead.
  3. If the optimizer did not use any relaxation, would this lead to an infeasible model (no solution to the problem)? I don't understand why? For me choosing only "Product12" (or "Product11") is a perfect solution with no need to any relaxation.
  4. How to oblige the optimizer to not relax the last constraint? (Note that changing the settings file, products.ops to relax only labeled constraints as in the documentation did not help, as I want to relax only one constraint )

在关于

In the documentation about relaxing infeasible models I found this:

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

Be aware, however, that infeasibility may be the consequence of an error in the modeling of another constraint.

这是我的情况吗?

预先感谢您的帮助

推荐答案

  • 在1 + 2上=您有一些未在模型中定义的东西...您能说说AllGroups和Groups分别存在还是2个相同,那么这些数据是什么?同样,您使用产品"和所有产品",即与组"相同的Q.您要在此处粘贴完整的.mod和.dat,它们已经运行并产生了显示的轻松结果...吗?一旦我至少可以重现您显示的问题,我就可以开始查看为什么":-)
  • 第3条=是,应该
  • 第4条=到达非松弛模型的方式是删除约束的命名. IE.如果没有解决方案而没有放松,则每个被命名的约束都被认为是放松的.每个未命名的约束都是硬"的,即必须遵守,不能放宽.只需删除或注释掉这些行: ctBudget:// first constraint, ctGroups: // second constraint, ctCategories: // third constraint如果您希望所有约束都像给定数据一样得到遵守...
    • on no.1+2 = you have some things which are not defined in the model... can you say if AllGroups and groups exist separately or the 2 are the same then what is the data for those? Also you use "products" and "AllProducts", the same Q as for "groups". Would you paste here a full .mod and .dat which you have run and produced the relaxed result you showed...? Once I can at least reproduce the problem you show, I can start looking at the "why's" :-)
    • on no.3 = yes, it supposed to
    • on no.4 = the way you could arrive to a non-relaxed model is that you remove the naming for the constraints. I.e. EVERY constraint which is named is considered to be relaxed if w/o relaxation there could be no solution. Every non-named constraint is "hard", i.e. it HAS to be respected, can not be relaxed. Simply remove or comment out these lines: ctBudget:// first constraint, ctGroups: // second constraint, ctCategories: // third constraintif you want all constraint to be respected as they are with the given data...
    • 这篇关于IBM Optimization Studio OPL,为什么不遵守约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆