[英]How to implement This MP problem in ECLIPSE CLP or Prolog?
I want to implement this Summations as Objective and Constraints(1-6) Could anyone help me that how I can Implement them? 我想以目标和约束(1-6)的方式实现总结:有人可以帮助我如何实现它们吗?
OBJ: Min ∑(i=1..N)∑(j=1..N) Cij * ∑(k=1..K)Xijk OBJ:最小值∑(i = 1..N)∑(j = 1..N)Cij * ∑(k = 1..K)Xijk
constraint : ∑(k=1..K) Yik=1 (for all i in N) 约束:∑(k = 1..K)Yik = 1(对于N中的所有i)
The following answer is specific to ECLiPSe (it uses loops, array and array slice notation, which are not part of standard Prolog). 以下答案特定于ECLiPSe(它使用循环,数组和数组切片符号,这不是标准Prolog的一部分)。
I assume that N
and K
(and presumably C
) are given, and your matrices are declared as 我假设给出了N
和K
(大概是C
),并且您的矩阵被声明为
dim(C, [N,N]),
dim(X, [N,N,K]),
dim(Y, [N,K]),
You can then set up the constraints in a loop: 然后,您可以循环设置约束:
constraint : ∑(k=1..K) Yik=1 (for all i in N) 约束:∑(k = 1..K)Yik = 1(对于N中的所有i)
( for(I,1,N), param(Y) do
sum(Y[I,*]) $= 1
),
Note that the notation sum(Y[I,*])
here is a shorthand for sum([Y[I,1],Y[I,2],...,Y[I,K]])
when K
is the size of this array dimension. 需要注意的是符号sum(Y[I,*])
这里是简写sum([Y[I,1],Y[I,2],...,Y[I,K]])
K
是此数组维度的大小。
For your objective, because of the nested sum, an auxiliary loop/list is still necessary: 对于您的目标,由于嵌套的总和,仍然需要一个辅助循环/列表:
OBJ: Min ∑(i=1..N)∑(j=1..N) Cij * ∑(k=1..K)Xijk OBJ:最小值∑(i = 1..N)∑(j = 1..N)Cij * ∑(k = 1..K)Xijk
( multifor([I,J],1,N), foreach(Term,Terms), param(C,X) do
Term = (C[I,J] * sum(X[I,J,*]))
),
Objective = sum(Terms),
...
You then have to pass this objective expression to the solver -- the details depend on which solver you use (eg eplex, ic). 然后,您必须将此目标表达式传递给求解器-具体信息取决于您使用的求解器(例如,eplex,ic)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.