duplicatessetampldat-protocol

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 duplicate? Every path has got more than one intersection, they are not duplicated.


Solution

  • 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);