Page 1 of 1

All elements of a set before a certain element

Posted: Thu Aug 29, 2019 12:05 am
by pecenak21
Hello,

I have a questions that seems straightforward, that I cannot figure out. I am trying to assign a value to all set-elements in a parameter before the set-element in a parameter that meets a certain criteria. For example, see the following code:

Code: Select all

set i
 /first, second, third, fourth/;

parameter TT(i);
TT('first')=0;
TT('second')=0;
TT('third')=1
TT('fourth')=0

K$(ord(i)<(TT(i)=1))=1;
;
The idea is that I want all i before the entry TT(i)=1 to be set to 1 in K. Therefore the output should look like

K('first')=1
K('second')=1
K('third')=0
K('fourth')=0

In reality, I want to use this in an equation to restrict the domain of the equation, to only include elements of the set less than a certain element.

Please let me know if this is clear,
Zack

Re: All elements of a set before a certain element

Posted: Fri Aug 30, 2019 10:16 am
by Renger
Hi Zack

I don't know if this helps:

Code: Select all

set i
 /first, second, third, fourth/;

parameter TT(i);
TT('first')=0;
TT('second')=0;
TT('third')=1;
TT('fourth')=0;

parameter k(i);
alias(i,j);

K(i) = 1-sum(j$(ord(j) < ord(i)+1), TT(j));;

display k;
This gives:

Code: Select all

----     15 PARAMETER k  

first  1.000,    second 1.000
Cheers
Renger