param DiscMax >= 0 integer;
param X >= 3 integer;
param N >= 100 integer;
param D >= 0 integer;

param e = 0.0001;

set I ; 
# set C within I cross I;

param ny{I} >= 0, <= N;
param Pz{I} >= 0, <= 1;


#check : sum{i in I} ny[i] = N;
#check : sum{i in I} Pz[i] = 1.0;  # check banale ma non funzionano

var n{i in I, j in I};

minimize divergence: sum{i in I} ((ny[i] + sum{k in I : k != i}n[k,i] - sum{k in I: k!= i} n[i,k])/ N) * log((ny[i] + sum{k in I : k != i}n[k,i] - sum{k in I: k!= i} n[i,k] + e)/(N*Pz[i] + e));


subject to vincoloPositività1{i in I}:
ny[i] + sum{k in I: k != i} n[k,i] - sum{k in I: k != i } n[i,k] >= 0;

subject to vincoloPositività2{i in I, j in I}:
n[i,j] >= 0;

subject to vincoloPositività3{i in I}:
ny[i] - sum{k in I: k != i } n[i,k] >= 0;

#elimino ora i salti > 10.....

subject to vincoloSalti{i in I,  j in I: abs(i - j) > DiscMax}: # non perdo soluzioni imponendo questo vincolo
n[i,j] = 0;

#subject to vincoloConservazioneElementi:
#sum{i in I, j in I} n[i,j] = N;

subject to vincoloMaxDistorsione:
sum{i in I, j in I : i!= j} n[i,j]* abs(i - j) <= D;

subject to vincoloConservazioneNy{i in I}:
sum{k in I} n[i,k] = ny[i];




 



