-1

Ι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;
----------
==========
Kotsos
  • 19
  • 5

1 Answers1

1

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:

  • If an array is indexed by VEC, LEN, then the second index should always be part of that set.
  • sum is it's own looping structure; it doesn't need an forall expression.

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:

  • sumTotal is your only variable, but it's defined by parameters. It cannot be optimised as it only has 1 solution.
  • Should i and j be able to take the same value? If not, then you should use i,j in LEN where i < j.
  • Do you expect any results other than sumTotal?
Dekker1
  • 5,565
  • 25
  • 33
  • *i run this code:* int : vlen; set of int : LEN = 1..vlen; set of int : VECS = 1..2; array[VECS,LEN] of int : vector; var int: sumTotal; constraint sumTotal = sum(i,j in LEN)( vector[1,i] * vector[2,j] * abs(i-j) ); solve minimize sumTotal; output ["vector1=["]++["\(vector[1,j])"|j in LEN]++["];\nvector2=["]++["\(vector[2,j])"|j in LEN]++["];\nsumTotal=\(sumTotal);"]; and i get this result: vector1=[23]; vector2=[45]; sumTotal=22; ---------- ========== FALSE FOR MY MODEL :( – Kotsos Nov 27 '17 at 17:26
  • i want my model to compute the minimum sum of x1i * x2j * |i-j| where i.j are coordinates of V1 V2. ******Every coordinate must be used ONLY once in ONE sum condition****** (How could it be?) Examples: for vectors (a) [2,3] & [4,5] --> 2*4 * (|1-1|) + 3*5 (|2 - 2|) = 0. (sumTotal) (b) [-2,3] & [-4,5] --> (-2)*(5) * (| 1-2|) + 3 * (-4) * |2-1| = -22 (sumTotal) expexted results in my model: vector1 = [2, 3]; vector2 = [4, 5]; sumTotal = 0; ---------- ========== Also, how can i edit my output to looks like the above? ("comma" between 2-2 and 4-5)? – Kotsos Nov 27 '17 at 17:27