I have the following 1d array : A=[0,1,2,3,0,0,0,1,4] that represents a sequence of searched cells.
I would like to calculate the total travel time between cells: W[1,2]+W[2,3]+W[3,1]+W[1,4]
I used a set to extract the indices of (cells!=0) : PHI={2,3,4,8,9}
then to calculate the total travel time I used :sum(k,j in PHI where k<j)(W[A[k],A[j]])
My problem is :
using this expression the total travel time will be
W[1,2] +W[1,3]+W[1,4]+W[2,3]+W[2,4]+W[3,1]+W[1,4] .
My question is
How can I get the desired result in minizinc : W[1,2]+W[2,3]+W[3,1]+W[1,4]
The code
int: N=5;
int: T=6;
set of int: L=1..N;
set of int: C=1..N;
var set of 1..N : PHI={i| i in 1..T where Phi[i]!=0};
var 0..T: totalTravelTime= sum(k,j in PHI where k<j)(W[Phi[k],Phi[j]]);
array [L,C] of 0.0..1.0: Sigma=[];
array[0..N,0..N] of 0..T : W=array2d(0..N,0..N,[]);
array [1..N] of 0.0..1.0: g=[];
array [time_step] of var 0..N: Phi;
var int : energie=T-c;
constraint energie>=0;
var 0.0..1.0 :PD=sum( k in 2..T)(p[Phi[k]!=0,k]*g2D[Phi[k]!=0,k]);
solve maximize PD;
output ["(Phi):(PD)"];
*** END ***
Thank you <3