minizincinner-product

inner product in minizinc


Ιn two Vectors V1(x11, x12) και V2(x21,x22) we can compute their inner product as V1 • V2.= (x11* x21 + x12 * x22 ).

I try to compute minimum inner product as (x1ix2j|i-j|, i.j the places of coordinates at V1, V2. Every cooedinate is used once in a sum condition.

 I TRIED THIS:


   int : vlen;
set of int : LEN  = 1..vlen;
set of int : VECS = 1..2;
array[VECS,LEN] of -25..25 : vector;
var -600..700 : sumTotal;

constraint exists(i,j,k,l in LEN where i!=k \/ j!=l)(
exists(v,v2 in VECS)(sumTotal=(vector[v,i] * vector[v2,j] * abs(i-j)+vector[v,k] * vector[v2,l] * abs(k-l)
)));
solve minimize sumTotal;
output ["vector1=["]++[" \(vector[1,j])"|j in LEN]++[" ];\nvector2=["]++[" \(vector[2,j])"|j in LEN]++[" ];\nsumTotal=\(sumTotal);"]

for
vlen = 2;
vector = [|-2,3|-4,5|];

i expect:

vector1 = [-2, 3];
vector2 = [-4, 5];
sumTotal = -22;
----------
==========

but i take:

vector1=[ -2 3 ];
vector2=[ -4 5 ];
sumTotal=-40;
----------
==========

Solution

  • I'm afraid I don't understand the meaning of your model, but it does contain some errors in the constraint that should be easy to fix:

    The resulting constraint would be:

    constraint sumTotal = sum(i,j in LEN)(
        vector[1,i] * vector[2,j] * abs(i,j)
    );
    

    This still leaves a rather strange model, so you might want to take a look at the following: