AMPL duplicate member "x" for set "y", how to fix it

I 'm working with AMPL. In the “.mod” I have declared a set like this: set path_intersections; It consists of rows of two numbers, the first one is the number of the path, and the second one the number of the intersection, in the .dat it looks like this:

set path_intersections:= 
1439 5
1439 74243
1441 5
1441 89
1441 90
... ;

With 200 rows. Obviously, each path has more than 1 intersection, but when I run it, i get this

error:
practica.dat, line 605 (offset 9912):
    duplicate member 1439 for set path_intersections
context:   >>> ; <<< 

practica.dat, line 605 (offset 9912):
    duplicate member 1439 for set path_intersections
context:   >>> ; <<< 
...

How can I fix it so that it doesn’t take it as a duplicate? Every path has got more than one intersection, they are not duplicated.

Thank you!

1 Like

Hi @Ares_Inglada_Grano,

Without specifying the arity of a set it defaults to 1 and any repeated value in the data section will then be a duplicate. You need to specify the arity of the set (i.e., set path_intersections dimen 2;) as follows:

set path_intersections dimen 2;
data;
set path_intersections := 
1439 5
1439 74243
1441 5
1441 89
1441 90;
display path_intersections;

This will produce the following output:

set path_intersections :=
(1439,5)       (1439,74243)   (1441,5)       (1441,89)      (1441,90);

Also replied on AMPL duplicate member "x" for set "y", how to fix it - Stack Overflow

Oh thank you! That fixes my problem, but I get another one, that I don’t know how to solve.

I have this code in .mod:

# Sets
set paths;
set intersections;
set fixed;
set prohibited;
set path_intersections dimen 2;

# Parámetros
param path_flow {paths} >= 0;

# Variables de decision
var x{intersections} binary;
var y{paths} binary;

# Función objetivo
maximize total:
         sum {p in paths} (path_flow[p]*y[p]);

# Constraints
subject to at_least_two_intersections {p in paths}:
    sum {i in path_intersections} x[i] >= 2*y[p];

subject to prohibited_intersections{i in prohibited}:
    x[i] = 0;

subject to fixed_intersections{i in fixed}:
    x[i] = 1;

subject to max_intersections:
         sum {i in intersections} x[i] <= 15;

And now the problem is with the first constraint, I want to say that the road is sensorized if at least two of its intersections are, " ∑(i ∈ path_intersections[p]) x_i ≥ 2y_p, ∀p ∈ paths".

And I get this error:

ampl: model practica.mod;

practica.mod, line 21 (offset 383):
	1 index for set of dimen 2
context:  sum {i in  >>> path_intersections} <<<  x[i] >= 2*y[p];

How can I solve it without changing it a lot?

Hi @Ares_Inglada_Grano,

In original the mathematical model what is path_intersections[p]supposed to be? In the AMPL model it is a set of pairs which is not indexed. It is supposed to be the list of paths that intersect with path p?

For that is could be:

subject to at_least_two_intersections {p in paths}:
    sum {(p,i) in path_intersections} x[i] + sum {(j,p) in path_intersections} x[j] >= 2*y[p];

The sum of x[i] for all i that intersect with p should be greater or equal than 2 if y[p]