[英]AMPL nonquadratic nonlinear constraints with cplex
I'm working on an optimization project and I faced a small problem. 我正在做一个优化项目,但遇到了一个小问题。 For my project, I'm using AMPL and CPLEX as a solver.
对于我的项目,我使用AMPL和CPLEX作为求解器。 In my code, I have some elements indicated by e1, e2, ..., en.
在我的代码中,我有一些元素由e1,e2,...,en表示。 I also have a set which contains tuples within these elements.
我也有一个在这些元素中包含元组的集合。 I must assign a number between 1 and 'n' to each element such that I maximize the distance between every 2 elements in 1 tuple in the moveTuples set (I need to order them but try to keep a distance between elements in the same tuple).
我必须为每个元素分配一个介于1到'n'之间的数字,以使我在moveTuples集合中的1个元组中的每2个元素之间的距离最大化(我需要对其进行排序,但尝试保持同一元组中的元素之间的距离) 。
Every element MUST have ONLY 1 assigned number and each number should be given to ONLY 1 element. 每个元素必须仅分配1个编号,每个编号应仅分配给1个元素。 For this purpose, I wrote the following code:
为此,我编写了以下代码:
set Elements;
set moveTuples dimen 2;
set Numbers;
var assign {Elements,Numbers} binary;
var maximizer{moveTuples} integer >= 0;
maximize obj: sum {(A,B) in moveTuples} maximizer[A,B];
subject to assign1NumberPerElement {i in Element}: sum {c in Numbers} assign[i,c] = 1;
subject to assign1ElementPerNumber {c in Numbers}: sum {i in Element} assign[i,c] = 1;
subject to moveApart {(A,B) in moveTuples}: abs(sum{i in Numbers}(assign[A,i]*i) - (sum{j in Numbers}x[B,j]*j)) - maximizer[A,B] = 0 ;
data;
set Elements:= e1 e2 e3;
set Numbers:= 1 2 3;
set moveTuples: e1 e2 e3:=
(e1, e2);
solve;
display assign;
Now the problem is clear and for the previous example, the output must be either: 现在问题已经很清楚了,对于前面的示例,输出必须为:
e1 -> 1 e1-> 1
e2 -> 3 e2-> 3
e3 -> 2 e3-> 2
or 要么
e1 -> 3 e1-> 3
e2 -> 1 e2-> 1
e3 -> 2 e3-> 2
since it is required to only move e1 from e2 using the tuple (e1,e2). 因为只需要使用元组(e1,e2)从e2中移出e1。 When running the previous code, I get the error: ... contains a non-quadratic non-linear constraint (definitely the "moveApart" constraint).
运行前面的代码时,出现错误:...包含非二次非线性约束(肯定是“ moveApart”约束)。 Can you please guide me on how to solve this problem?
您能指导我如何解决这个问题吗? Thanks in advance.
提前致谢。
The constraint moveApart
is nonlinear (and non-quadratic) because it contains a call to abs
. 约束
moveApart
是非线性的(并且是非二次的),因为它包含对abs
的调用。 However, since your problem is purely integer, you can solve it with CPLEX CP Optimizer (ilogcp) . 但是,由于您的问题纯粹是整数,因此可以使用CPLEX CP Optimizer(ilogcp)来解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.