Simple way to find maximum index of a set:
you need to declare an ordered set NODE:
*set NODE ordered;*
*display thing [last (NODE)];*
воскресенье, 21 февраля 2021 г. в 06:16:33 UTC+3, Mikhail:
On Sun, Feb 21, 2021 at 3:16 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
You can return the value of the parameter with the index value "5" as
follows:
*set NODE;*
*param thing {NODE};*
*data;*
*param: NODE: thing: =*
*1 10*
*2 11*
*5 12;*
*display thing [5],*
*sum {i in NODE: i in {5}} thing ,*
*sum {i in NODE: i = 5} thing ;*
if NODE is a literal set then its element must be enclosed in '' or "".
*set NODE;*
*param thing {NODE};*
*data;*
*param: NODE: thing: =*
*1 10*
*2 11*
*A5 12;*
*display thing ['A5'],*
*sum {i in NODE: i in {'A5'}} thing ,*
*sum {i in NODE: i = 'A5'} thing ;*
Q2: First of all, you need to declare a new set:
*set NODE2: = {1..5};*
then declare a new parameter, *newthing*, based on the values of thing:
*param newthing {i in NODE2}: = if i in NODE then thing else 0;*
You can also declare the *thing* parameter with a default value of 0:
*set NODE: = {1..5};*
*param thing {NODE};*
*data;*
*param thing default 0: =*
*1 10*
*2 11*
*5 12;*
*display thing [3];*