[AMPL 25036] Doubt VRP code

Hello, I’m writing the following code for the problem attached in the photo (I’ve taken v(S)=2) and I’m getting an error. Can someone help me?

param n:=7;
param m:=2;

set V := 1..n;
set Vprima := 2..n;
set A := {(i,j) in V cross V : i < j};
set NOT := {(i,j) in Vprima cross Vprima : i != j};
param c{1..n,1..n};

set S := 0 .. n - 1;
set SS := 0 .. 2**n - 1;
set POW {k in SS} := {i in S: (k div 2**i) mod 2 = 1};

let c[1,2]:=1;
let c[1,3]:=6;
let c[1,4]:=2;
let c[1,5]:=2;
let c[1,6]:=5; 
let c[1,7]:=1;

let c[2,3]:=2;
let c[2,4]:=6;
let c[2,5]:=2;
let c[2,6]:=8;
let c[2,7]:=9;

let c[3,4]:=1;
let c[3,5]:=6;
let c[3,6]:=6; 
let c[3,7]:=9;

let c[4,5]:=8;
let c[4,6]:=10; 
let c[4,7]:=11;

let c[5,6]:=2; 
let c[5,7]:=4;

let c[6,7]:=1;

var x{Vprima,Vprima}, binary;

minimize Costo: sum{(i,j) in A} c[i,j] * x[i,j];
subject to R0 {j in V}: x[1, j] in {0, 1, 2};
subject to R1: sum{j in 2..n} x[1, j] = 2 * m;
subject to R2 {k in 2..n}: 
   sum{(i,j) in A} x[i, k] + sum{(i,j) in A} x[k, j] = 2;
subject to R3: sum{i in S, j in S} x[i, j] <= card(S) - 2;

Thanks!!!

There are two problems here:

  • AMPL does not recognize constraints of the form variable in set. Thus, your constraint R0 is rejected with the message “Cannot test whether a variable is in a set expression.”

  • You define x as being indexed over {2..n,2..n}, so x[1,j] is not defined, and cannot be used in R0 or any other constraint.

To define x in AMPL corresponding to (12) and (13) in the mathematical description, you could write

var x {i in V, j in Vprima: i <> j} 
   integer >= 0, <= if i = 1 then 2 else 1;

Your question has been moved to our new user forum at discuss.ampl.com, and a response has been posted there. To see the response, use this link:

https://discuss.ampl.com/t/ampl-25036-doubt-vrp-code/1077/2

To reply, click the red “Reply” button that follows the response. (Do not send an email reply to this message.)