Call a specific set element inside a procedure

40 views
Skip to first unread message

Gabriela G.

unread,
May 8, 2019, 3:33:11 PM5/8/19
to AIMMS - The Modeling System
I have a set called "Lines" and its respective index is "i"
I have an indexed paremeter called "Length(i)"
I have a scalar parameter called "best" that gives me a number representing whic is the best line.
I have a scalar parameter called "auxiliar"
When I try to change the value of the parameter inside a procedure there is no error:
Length(i | i=ElementCast(Lines, best)):= 0;
But when I try to change the value of another parameter with the expression Length(i | i=ElementCast(Lines, best)) on the other side of the assignment it shows an error.
auxiliar:=Length(i | i=ElementCast(Lines, best));
The error/warning that appears says: "The scope of index "c" has not been specified" 

Mohan

unread,
May 8, 2019, 3:41:28 PM5/8/19
to AIMMS - The Modeling System
Hello Gabriela,

If you double click on the error message, is it taking you to the auxiliar := Length(...) statement ?

The error message is about an index c and you are not using c anywhere in this statement, so I wonder if it is related to some other statement in that procedure. Can you paste the code you have in that procedure here ?

Gabriela G.

unread,
May 8, 2019, 4:00:42 PM5/8/19
to AIMMS - The Modeling System
It was a mistake, The error/warning that appears says: "The scope of index "i" has not been specified"
If I double click on the error message, is takes me to "auxiliar := Length(...) "

Mohan

unread,
May 8, 2019, 8:27:16 PM5/8/19
to AIMMS - The Modeling System
Thanks for the clarification Gabriela.

Can you clarify whether best is a numeric parameter or a string parameter or an element parameter ?

Are you using it to store the line (line-1, line-2 and so on) which has the max lengths(i) ?

Then make it an element parameter with range set Lines and definition argmax(i, Lengths(i)).

For auxiliar, you can use

auxiliar := Lengths(best)


Gabriela G.

unread,
May 8, 2019, 10:19:42 PM5/8/19
to AIMMS - The Modeling System
The elements of Lines are {1, 2, 3, 4, ...}
best is a numeric parameter
When I try to do auxiliar:=Length(best); it shows an error that says "The first index is of type numeric and cannot be casted to the declaration set Lines."


Mohan

unread,
May 9, 2019, 4:36:12 PM5/9/19
to AIMMS - The Modeling System
Hello Gabriela,

You need not and should not use ElementCast here as best is a numeric parameter and is not a set element.

You have two options.

Make the set Lines as a subset of the predeclared set, Integers. Then set the property - elements are Numeric.

Now, best will be argmax(l, lengths(l)).

Set Lines {
   
SubsetOf: Integers;
   
Index: l;
   
Property: ElementsAreNumerical;
   
Definition: data{1..4};
}

Parameter best {
   
Definition: argmax(l, Lengths(l));
}


Now, you can use

auxiliar := Lengths(best)

Another option will be to store the ordinance of the Line which has the best length. Here, you will not need to set Lines as a subset of Integers.

Parameter best {
   
Definition: Ord(argmax(l, Lengths(l)));
}

Now, auxiliar will be

auxiliar := Lengths(Element(Lines, best));

Gabriela G.

unread,
May 10, 2019, 4:20:28 PM5/10/19
to AIMMS - The Modeling System
Thanks!


El miércoles, 8 de mayo de 2019, 14:33:11 (UTC-5), Gabriela G. escribió:
Reply all
Reply to author
Forward
0 new messages