0

I need to use the step function in order to count the number of non-zero elements in a parameter. The step function that I am considering is the following:

f(x)={0 if x = 0 else 1} Plot of step function (where f(0)=0)

After searching on the internet for solution, I realized we can create stepwise functions in GAMS, but I need a continuous function for x > 1. I tried the following code to reproduce a step-like function:

round(1 / (1 + exp(-x)) - 0.01)

which is:

step-like function enter image description here

Unfortunately, this formula does not work with GAMS. When I try to run the code, I got this error:

Endogenous function argument(s) not allowed in linear models

I am working with a MIP (Mixed Integer Linear Program) model. Is there a way to use a step function in GAMS?

Cynnexis
  • 63
  • 1
  • 5

1 Answers1

1

I assume, that x is a variable in your code? Then you can try something like this (if x would be a parameter, it would be easier):

Equation        a, b;
Variable        x;
Binary Variable y;

Scalar BigM   / 1e3/
       SmallM /1e-3/;

a.. y*BigM   =g= x;
b.. y*SmallM =l= x;

So, if x=0, y will be 0 as well because of equation b. And if x>0, y will become 1 because of equation a. The BigM you should choose as small as possible and as big as necessary (so it should be the maximum value x can take) and SmallM the other way around. This assumes of course, that there is something like a lower and upper bound for x, if it is not 0...

Hope that helps!

Lutz

Lutz
  • 2,197
  • 1
  • 10
  • 12