[英]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:
我想添加一个新的约束,如下所示:
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.