Hi all
I have binary parameter b(j) , j/1*100/ . I need to change the element of b (change 1 to 0 and 0 to 1 ) to get new parameter c(j). I want to use macro option, is it possible?
Thanks!
Instead of putting the 0/1 swap logic in a complicated loop/if structure, you can just use a one-liner parallel assignment statement. But your can also put the parallel assignment or the complicated loop/if logic into a macro:
set j/1*10/;
parameter c(j);
c(j)=uniformInt(0,1);
display c;
loop(j,
if(c(j)=1,
c(j)=0;
else
c(j)=1;
)
);
display c;
* Simple parallel assignment
c(j) = not c(j);
display c;
* Macro with simple parallel assignment
$macro swap1(sym,dom) sym(dom) = not sym(dom)
swap1(c,j);
display c;
* Macro with loop/if statements
$macro swap2(sym,dom) loop(dom, if(sym(dom)=1, sym(dom)=0; else sym(dom)=1;))
swap2(c,j);
display c;
-Michael
Realy thanks!