简体   繁体   English

OPL CPLEX,向我的优化问题添加相似性约束的问题

[英]OPL CPLEX, Problem adding a similarity constraint to my optimization problem

Here is my the optimization problem I want to solve.这是我要解决的优化问题 I want to add a new constraint which is the following:我想添加一个新的约束,如下所示:

在此处输入图片说明

  • Z is the set of products in the user basket Z 是用户购物篮中的产品集合
  • similarity(zi,zj) is a similarity function measuring the similarity of products zi and zj. similarity(zi,zj) 是测量产品 zi 和 zj 相似度的相似度函数。

The goal of this new constraint is to ensure that our user basket does not contain similar (redundant) products.这个新约束的目标是确保我们的用户篮不包含类似(冗余)的产品。

How can I add this constraint, if we suppose that I have a similarity function called similarity(product1, product2) that takes as argument two products and gives as a result the similarity between them.如果我们假设我有一个名为 Similarity(product1, product2) 的相似性函数,它将两个产品作为参数,并给出它们之间的相似性,我该如何添加这个约束。

Thank谢谢

Let me share an example.让我分享一个例子。 Compared to the previous model I shared you could add:与我分享的先前模型相比,您可以添加:

float similarity[i in allProducts][j in allProducts]=
abs(ord(allProducts,i)-ord(allProducts,j));

float sim=4;

before the subject to block and then:在要阻止的主题之前,然后:

ctSim:
     forall(ordered i,j in allProducts) z[i]*z[j]*similarity[i][j]<=sim;
}

in the subject to block.在要阻止的主题中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM