# \[AMPL 25036\] Doubt VRP code

**URL:** <https://discuss.ampl.com/t/ampl-25036-doubt-vrp-code/1077>\
**Category:** Google Group Mirror\
**Created:** [April 28, 2024, 9:46pm UTC](https://discuss.ampl.com/t/ampl-25036-doubt-vrp-code/1077 "2024-04-28T21:46:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maria\_Vargas\_Magan](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Maria\_Vargas\_Magan](https://discuss.ampl.com/u/Maria_Vargas_Magan)\
**Post date:** [April 28, 2024, 9:46pm UTC](https://discuss.ampl.com/t/ampl-25036-doubt-vrp-code/1077/1 "2024-04-28T21:46:48Z")

</div>

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?

```auto
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!!!

 ![2024-04-28 (12).jpg](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/1aefabcaa224a4071833da8cd8d5d4478ebeb2e5.jpeg)

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [April 29, 2024, 10:57pm UTC](https://discuss.ampl.com/t/ampl-25036-doubt-vrp-code/1077/2 "2024-04-29T22:57:40Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group1](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@AMPL\_Google\_Group1](https://discuss.ampl.com/u/AMPL_Google_Group1)\
**Post date:** [April 30, 2024, 12:10am UTC](https://discuss.ampl.com/t/ampl-25036-doubt-vrp-code/1077/3 "2024-04-30T00:10:04Z")

</div>

Your question has been moved to our new user forum at [discuss.ampl.com](http://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](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.)
