I want to add a constraint that says the number of nonzero elements of a variable couldn't be more than a certain value.
So following constraints passed through my mind (By defining an extra variable counting nonzero elements of a variable called "attack"):
Code: Select all
Con20(bus).. nonzero(bus) $ (attack(bus)=0) =e= 0;
Con21(bus).. nonzero(bus) $ (attack(bus)<>0) =e= 1;
Con22.. sum(bus,nonzero(bus)) =l= 2;
endogenous $ operator not allowed.
Please help! what is wrong with this?