All elements of a set before a certain element

Problems with modeling
Post Reply
pecenak21
User
User
Posts: 24
Joined: 5 years ago

All elements of a set before a certain element

Post 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
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: All elements of a set before a certain element

Post 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
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply