Count the number of nonzero values in a variable array

273 views
Skip to first unread message

navin...@gmail.com

unread,
Apr 16, 2012, 8:29:18 PM4/16/12
to AIMMS - The Modeling System
Hi I am trying to restrict the number of non-zero occurrence of a
variable by using the count operator. To be more precise, I have a
constraint like this :

Count of Variable(t) < = 30 where t ranges from 1 to 500. I tried to
implement this constraint using "count" operator like this :

count( (t)|variable(t) ) < = 30.

But I get this error message : Unexpected end of the definition of
constraint..

Is my approach right ? Any Suggestions?

Guido Diepen

unread,
Apr 17, 2012, 3:52:13 PM4/17/12
to ai...@googlegroups.com
Hi,

I think the compile error is caused by the fact that you are having a space between the < and the = characters. The less-than-or-equal sign should be without any spaces, so <=.

However, please note that using the count operator like this does not result in a linear program. If the variable is a binary variable, counting the number of non zero values can be done by summing. If they are not binary variables, then you will have to do some additional modelling to achieve this goal.

Guido Diepen
AIMMS Specialist
Reply all
Reply to author
Forward
0 new messages